99import com .xwintop .xcore .util .ConfigureUtil ;
1010import com .xwintop .xcore .util .HttpClientUtil ;
1111import com .xwintop .xcore .util .javafx .AlertUtil ;
12+ import com .xwintop .xcore .util .javafx .JavaFxSystemUtil ;
1213import com .xwintop .xcore .util .javafx .JavaFxViewUtil ;
1314import javafx .application .Platform ;
14- import javafx .beans .value .ChangeListener ;
15- import javafx .beans .value .ObservableValue ;
1615import javafx .event .ActionEvent ;
17- import javafx .event .EventHandler ;
1816import javafx .fxml .FXML ;
1917import javafx .fxml .FXMLLoader ;
18+ import javafx .scene .Parent ;
2019import javafx .scene .control .ContextMenu ;
2120import javafx .scene .control .Menu ;
2221import javafx .scene .control .MenuItem ;
2524import lombok .Getter ;
2625import lombok .Setter ;
2726import lombok .extern .slf4j .Slf4j ;
27+ import org .apache .commons .beanutils .BeanUtils ;
2828import org .apache .commons .lang .StringUtils ;
2929import org .apache .commons .lang3 .time .DateFormatUtils ;
30+ import org .dom4j .Document ;
31+ import org .dom4j .Element ;
32+ import org .dom4j .io .SAXReader ;
33+ import org .dom4j .tree .DefaultAttribute ;
34+ import org .dom4j .tree .DefaultElement ;
3035
36+ import java .io .File ;
37+ import java .io .FilenameFilter ;
38+ import java .io .InputStream ;
3139import java .net .URL ;
3240import java .util .*;
41+ import java .util .jar .JarEntry ;
42+ import java .util .jar .JarFile ;
3343
3444/**
3545 * @ClassName: IndexController
@@ -66,21 +76,92 @@ public void initialize(URL location, ResourceBundle resources) {
6676 }
6777
6878 private void initView () {
69- List <ToolFxmlLoaderConfiguration > toolList = XJavaFxSystemUtil .loaderToolFxmlLoaderConfiguration ();
70- List <ToolFxmlLoaderConfiguration > plugInToolList = XJavaFxSystemUtil .loaderPlugInToolFxmlLoaderConfiguration ();
71- toolList .addAll (plugInToolList );
7279 menuMap .put ("toolsMenu" , toolsMenu );
7380 menuMap .put ("moreToolsMenu" , moreToolsMenu );
74- menuMap .put ("netWorkToolsMenu" , netWorkToolsMenu );
81+ File libPath = new File ("libs/" );
82+ // 获取所有的.jar和.zip文件
83+ File [] jarFiles = libPath .listFiles (new FilenameFilter () {
84+ @ Override
85+ public boolean accept (File dir , String name ) {
86+ return name .endsWith (".jar" );
87+ }
88+ });
89+ if (jarFiles != null ) {
90+ for (File jarFile : jarFiles ) {
91+ try {
92+ this .addToolMenu (jarFile );
93+ } catch (Exception e ) {
94+ e .printStackTrace ();
95+ }
96+ }
97+ }
98+ }
99+
100+ private void initEvent () {
101+ myTextField .textProperty ().addListener ((observable , oldValue , newValue ) -> selectAction (newValue ));
102+ myButton .setOnAction (arg0 -> {
103+ selectAction (myTextField .getText ());
104+ // TooltipUtil.showToast(myTextField.getText());
105+ // TooltipUtil.showToast("test",Pos.BOTTOM_RIGHT);
106+ // JOptionPane.showMessageDialog(null, "test");
107+ });
108+ }
109+
110+ private void initService () {
111+ }
112+
113+ public void addToolMenu (File file ) throws Exception {
114+ XJavaFxSystemUtil .addJarClass (file );
115+ Map <String , ToolFxmlLoaderConfiguration > toolMap = new HashMap <>();
116+ List <ToolFxmlLoaderConfiguration > toolList = new ArrayList <>();
117+ JarFile jarFile = new JarFile (file );
118+ try {
119+ JarEntry entry = jarFile .getJarEntry ("config/toolFxmlLoaderConfiguration.xml" );
120+ if (entry == null ) {
121+ return ;
122+ }
123+ InputStream input = jarFile .getInputStream (entry );
124+ SAXReader saxReader = new SAXReader ();
125+ Document document = saxReader .read (input );
126+ Element root = document .getRootElement ();
127+ List <Element > elements = root .elements ("ToolFxmlLoaderConfiguration" );
128+ for (Element configurationNode : elements ) {
129+ ToolFxmlLoaderConfiguration toolFxmlLoaderConfiguration = new ToolFxmlLoaderConfiguration ();
130+ List <DefaultAttribute > attributes = configurationNode .attributes ();
131+ for (DefaultAttribute configuration : attributes ) {
132+ BeanUtils .copyProperty (toolFxmlLoaderConfiguration , configuration .getName (), configuration .getValue ());
133+ }
134+ List <DefaultElement > childrenList = configurationNode .elements ();
135+ for (DefaultElement configuration : childrenList ) {
136+ BeanUtils .copyProperty (toolFxmlLoaderConfiguration , configuration .getName (), configuration .getStringValue ());
137+ }
138+ if (StringUtils .isEmpty (toolFxmlLoaderConfiguration .getMenuParentId ())) {
139+ toolFxmlLoaderConfiguration .setMenuParentId ("moreToolsMenu" );
140+ }
141+ if (toolFxmlLoaderConfiguration .getIsMenu ()) {
142+ if (menuMap .get (toolFxmlLoaderConfiguration .getMenuId ()) == null ) {
143+ toolMap .putIfAbsent (toolFxmlLoaderConfiguration .getMenuId (), toolFxmlLoaderConfiguration );
144+ }
145+ } else {
146+ toolList .add (toolFxmlLoaderConfiguration );
147+ }
148+ }
149+ } finally {
150+ jarFile .close ();
151+ }
152+ toolList .addAll (toolMap .values ());
153+ this .addMenu (toolList );
154+ }
155+
156+ private void addMenu (List <ToolFxmlLoaderConfiguration > toolList ) {
75157 for (ToolFxmlLoaderConfiguration toolConfig : toolList ) {
76158 try {
77159 if (StringUtils .isEmpty (toolConfig .getResourceBundleName ())) {
78160 if (StringUtils .isNotEmpty (bundle .getString (toolConfig .getTitle ()))) {
79161 toolConfig .setTitle (bundle .getString (toolConfig .getTitle ()));
80162 }
81163 } else {
82- ResourceBundle resourceBundle = ResourceBundle .getBundle (toolConfig .getResourceBundleName (),
83- Config .defaultLocale );
164+ ResourceBundle resourceBundle = ResourceBundle .getBundle (toolConfig .getResourceBundleName (), Config .defaultLocale );
84165 if (StringUtils .isNotEmpty (resourceBundle .getString (toolConfig .getTitle ()))) {
85166 toolConfig .setTitle (resourceBundle .getString (toolConfig .getTitle ()));
86167 }
@@ -119,12 +200,10 @@ private void initView() {
119200 }
120201 if ("Node" .equals (toolConfig .getControllerType ())) {
121202 menuItem .setOnAction ((ActionEvent event ) -> {
122- indexService .addContent (menuItem .getText (), toolConfig .getUrl (), toolConfig .getResourceBundleName (),
123- toolConfig .getIconPath ());
203+ indexService .addContent (menuItem .getText (), toolConfig .getUrl (), toolConfig .getResourceBundleName (), toolConfig .getIconPath ());
124204 });
125205 if (toolConfig .getIsDefaultShow ()) {
126- indexService .addContent (menuItem .getText (), toolConfig .getUrl (), toolConfig .getResourceBundleName (),
127- toolConfig .getIconPath ());
206+ indexService .addContent (menuItem .getText (), toolConfig .getUrl (), toolConfig .getResourceBundleName (), toolConfig .getIconPath ());
128207 }
129208 } else if ("WebView" .equals (toolConfig .getControllerType ())) {
130209 menuItem .setOnAction ((ActionEvent event ) -> {
@@ -139,19 +218,6 @@ private void initView() {
139218 }
140219 }
141220
142- private void initEvent () {
143- myTextField .textProperty ().addListener ((observable , oldValue , newValue ) -> selectAction (newValue ));
144- myButton .setOnAction (arg0 -> {
145- selectAction (myTextField .getText ());
146- // TooltipUtil.showToast(myTextField.getText());
147- // TooltipUtil.showToast("test",Pos.BOTTOM_RIGHT);
148- // JOptionPane.showMessageDialog(null, "test");
149- });
150- }
151-
152- private void initService () {
153- }
154-
155221 public void selectAction (String selectText ) {
156222 if (contextMenu .isShowing ()) {
157223 contextMenu .hide ();
@@ -190,7 +256,10 @@ private void addLogConsoleAction(ActionEvent event) {
190256 @ FXML
191257 private void pluginManageAction (ActionEvent event ) throws Exception {
192258 FXMLLoader fXMLLoader = PluginManageController .getFXMLLoader ();
193- JavaFxViewUtil .openNewWindow (bundle .getString ("plugin_manage" ), fXMLLoader .load ());
259+ Parent root = fXMLLoader .load ();
260+ PluginManageController pluginManageController = fXMLLoader .getController ();
261+ pluginManageController .setIndexController (this );
262+ JavaFxViewUtil .openNewWindow (bundle .getString ("plugin_manage" ), root );
194263 }
195264
196265 @ FXML
@@ -207,22 +276,22 @@ private void setLanguageAction(ActionEvent event) throws Exception {
207276 @ FXML
208277 private void openLogFileAction (ActionEvent event ) throws Exception {
209278 String filePath = "logs/logFile." + DateFormatUtils .format (new Date (), "yyyy-MM-dd" ) + ".log" ;
210- XJavaFxSystemUtil .openDirectory (filePath );
279+ JavaFxSystemUtil .openDirectory (filePath );
211280 }
212281
213282 @ FXML
214283 private void openLogFolderAction (ActionEvent event ) throws Exception {
215- XJavaFxSystemUtil .openDirectory ("logs/" );
284+ JavaFxSystemUtil .openDirectory ("logs/" );
216285 }
217286
218287 @ FXML
219288 private void openConfigFolderAction (ActionEvent event ) throws Exception {
220- XJavaFxSystemUtil .openDirectory (ConfigureUtil .getConfigurePath ());
289+ JavaFxSystemUtil .openDirectory (ConfigureUtil .getConfigurePath ());
221290 }
222291
223292 @ FXML
224293 private void openPluginFolderAction (ActionEvent event ) throws Exception {
225- XJavaFxSystemUtil .openDirectory ("libs/" );
294+ JavaFxSystemUtil .openDirectory ("libs/" );
226295 }
227296
228297 @ FXML
0 commit comments