11package com .xwintop .xJavaFxTool .controller .index ;
22
33import com .xwintop .xJavaFxTool .controller .IndexController ;
4+ import com .xwintop .xJavaFxTool .plugin .PluginManager ;
45import com .xwintop .xJavaFxTool .services .index .PluginManageService ;
56import com .xwintop .xJavaFxTool .view .index .PluginManageView ;
67import com .xwintop .xcore .util .javafx .JavaFxViewUtil ;
1011import java .util .ResourceBundle ;
1112import javafx .collections .FXCollections ;
1213import javafx .collections .ObservableList ;
14+ import javafx .collections .transformation .FilteredList ;
1315import javafx .event .ActionEvent ;
1416import javafx .fxml .FXML ;
1517import javafx .fxml .FXMLLoader ;
1921import javafx .scene .control .MenuItem ;
2022import javafx .scene .control .TableCell ;
2123import javafx .scene .control .TableColumn ;
22- import javafx .scene .input .MouseButton ;
2324import javafx .util .Callback ;
2425import lombok .Getter ;
2526import lombok .Setter ;
3637@ Setter
3738@ Slf4j
3839public class PluginManageController extends PluginManageView {
40+
41+ public static final String FXML = "/com/xwintop/xJavaFxTool/fxmlView/index/PluginManage.fxml" ;
42+
3943 private PluginManageService pluginManageService = new PluginManageService (this );
40- private ObservableList <Map <String , String >> pluginDataTableData = FXCollections .observableArrayList ();
44+
45+ private ObservableList <Map <String , String >> originPluginData = FXCollections .observableArrayList ();
46+
47+ private FilteredList <Map <String , String >> pluginDataTableData = new FilteredList <>(originPluginData , m -> true );
4148
4249 private IndexController indexController ;
4350
4451 public static FXMLLoader getFXMLLoader () {
45- FXMLLoader fXMLLoader = new FXMLLoader (IndexController .class .getResource ("/com/xwintop/xJavaFxTool/fxmlView/index/PluginManage.fxml" ));
46- return fXMLLoader ;
52+ return new FXMLLoader (IndexController .class .getResource (FXML ));
4753 }
4854
4955 @ Override
@@ -58,68 +64,71 @@ private void initView() {
5864 JavaFxViewUtil .setTableColumnMapValueFactory (synopsisTableColumn , "synopsisTableColumn" );
5965 JavaFxViewUtil .setTableColumnMapValueFactory (versionTableColumn , "versionTableColumn" );
6066 JavaFxViewUtil .setTableColumnMapValueFactory (isDownloadTableColumn , "isDownloadTableColumn" );
61- JavaFxViewUtil .setTableColumnMapAsCheckBoxValueFactory (isEnableTableColumn , "isEnableTableColumn" , (mouseEvent , index ) -> {
62- pluginManageService .setIsEnableTableColumn (index );
63- });
67+ JavaFxViewUtil .setTableColumnMapAsCheckBoxValueFactory (isEnableTableColumn , "isEnableTableColumn" ,
68+ (mouseEvent , index ) -> {
69+ pluginManageService .setIsEnableTableColumn (index );
70+ });
6471
65- downloadTableColumn .setCellFactory (new Callback <TableColumn <Map <String , String >, String >, TableCell <Map <String , String >, String >>() {
66- @ Override
67- public TableCell <Map <String , String >, String > call (TableColumn <Map <String , String >, String > param ) {
68- TableCell <Map <String , String >, String > cell = new TableCell <Map <String , String >, String >() {
69- @ Override
70- protected void updateItem (String item , boolean empty ) {
71- super .updateItem (item , empty );
72- this .setText (null );
73- this .setGraphic (null );
74- if (!empty ) {
75- Map <String , String > dataRow = pluginDataTableData .get (this .getIndex ());
76- Button downloadButton = new Button (dataRow .get ("isDownloadTableColumn" ));
77- if ("已下载" .equals (dataRow .get ("isDownloadTableColumn" ))) {
78- downloadButton .setDisable (true );
79- }
80- this .setContentDisplay (ContentDisplay .CENTER );
81- downloadButton .setOnMouseClicked ((me ) -> {
82- try {
83- pluginManageService .downloadPluginJar (dataRow );
84- dataRow .put ("isEnableTableColumn" ,"true" );
85- dataRow .put ("isDownloadTableColumn" , "已下载" );
86- downloadButton .setText ("已下载" );
72+ downloadTableColumn .setCellFactory (
73+ new Callback <TableColumn <Map <String , String >, String >, TableCell <Map <String , String >, String >>() {
74+ @ Override
75+ public TableCell <Map <String , String >, String > call (TableColumn <Map <String , String >, String > param ) {
76+ return new TableCell <Map <String , String >, String >() {
77+ @ Override
78+ protected void updateItem (String item , boolean empty ) {
79+ super .updateItem (item , empty );
80+ this .setText (null );
81+ this .setGraphic (null );
82+ if (!empty ) {
83+ Map <String , String > dataRow = pluginDataTableData .get (this .getIndex ());
84+ Button downloadButton = new Button (dataRow .get ("isDownloadTableColumn" ));
85+ if ("已下载" .equals (dataRow .get ("isDownloadTableColumn" ))) {
8786 downloadButton .setDisable (true );
88- pluginDataTableView .refresh ();
89- TooltipUtil .showToast ("插件 " + dataRow .get ("nameTableColumn" ) + " 下载完成" );
90- } catch (Exception e ) {
91- log .error ("下载插件失败:" , e );
92- TooltipUtil .showToast ("下载插件失败:" + e .getMessage ());
9387 }
94- });
95- this .setGraphic (downloadButton );
88+ this .setContentDisplay (ContentDisplay .CENTER );
89+ downloadButton .setOnMouseClicked ((me ) -> {
90+ try {
91+ pluginManageService .downloadPluginJar (dataRow );
92+ dataRow .put ("isEnableTableColumn" , "true" );
93+ dataRow .put ("isDownloadTableColumn" , "已下载" );
94+ downloadButton .setText ("已下载" );
95+ downloadButton .setDisable (true );
96+ pluginDataTableView .refresh ();
97+ TooltipUtil .showToast ("插件 " + dataRow .get ("nameTableColumn" ) + " 下载完成" );
98+ } catch (Exception e ) {
99+ log .error ("下载插件失败:" , e );
100+ TooltipUtil .showToast ("下载插件失败:" + e .getMessage ());
101+ }
102+ });
103+ this .setGraphic (downloadButton );
104+ }
96105 }
97- }
98- };
99- return cell ;
100- }
101- });
106+ };
107+ }
108+ });
102109
103110 pluginDataTableView .setItems (pluginDataTableData );
104111 }
105112
106113 private void initEvent () {
107- pluginDataTableView .setOnMouseClicked (event -> {
108- if (event .getButton () == MouseButton .SECONDARY ) {
109- MenuItem menuSave = new MenuItem ("保存配置" );
110- menuSave .setOnAction (event1 -> {
111- try {
112- pluginManageService .savePluginJarList ();
113- TooltipUtil .showToast ("保存配置成功" );
114- } catch (Exception e ) {
115- log .error ("保存配置失败" , e );
116- }
117- });
118- pluginDataTableView .setContextMenu (new ContextMenu (menuSave ));
114+
115+ // 右键菜单
116+ MenuItem mnuSavePluginConfig = new MenuItem ("保存配置" );
117+ mnuSavePluginConfig .setOnAction (ev -> {
118+ try {
119+ PluginManager .getInstance ().saveLocalPlugins ();
120+ TooltipUtil .showToast ("保存配置成功" );
121+ } catch (Exception ex ) {
122+ log .error ("保存插件配置失败" , ex );
119123 }
120124 });
125+
126+ ContextMenu contextMenu = new ContextMenu (mnuSavePluginConfig );
127+ pluginDataTableView .setContextMenu (contextMenu );
128+
129+ // 搜索
121130 selectPluginTextField .textProperty ().addListener ((_ob , _old , _new ) -> {
122- pluginManageService .selectPluginAction ( );
131+ pluginManageService .searchPlugin ( _new );
123132 });
124133 }
125134
@@ -129,6 +138,6 @@ private void initService() {
129138
130139 @ FXML
131140 private void selectPluginAction (ActionEvent event ) {
132- pluginManageService .selectPluginAction ( );
141+ pluginManageService .searchPlugin ( selectPluginTextField . getText () );
133142 }
134143}
0 commit comments