55import com .xwintop .xJavaFxTool .event .AppEvents ;
66import com .xwintop .xJavaFxTool .event .PluginEvent ;
77import com .xwintop .xJavaFxTool .model .PluginJarInfo ;
8- import com .xwintop .xJavaFxTool .model .ToolFxmlLoaderConfiguration ;
98import com .xwintop .xJavaFxTool .newui .PluginCategoryController ;
109import com .xwintop .xJavaFxTool .newui .PluginItemController ;
1110import com .xwintop .xJavaFxTool .plugin .PluginManager ;
1211import com .xwintop .xJavaFxTool .plugin .PluginParser ;
1312import com .xwintop .xJavaFxTool .services .IndexService ;
14- import com .xwintop .xJavaFxTool .services .index .PluginManageService ;
1513import com .xwintop .xJavaFxTool .services .index .SystemSettingService ;
1614import com .xwintop .xJavaFxTool .utils .Config ;
1715import com .xwintop .xJavaFxTool .view .IndexView ;
3331import lombok .Getter ;
3432import lombok .Setter ;
3533import lombok .extern .slf4j .Slf4j ;
36- import org .apache .commons .beanutils .BeanUtils ;
3734import org .apache .commons .lang .StringUtils ;
3835import org .apache .commons .lang3 .BooleanUtils ;
3936import org .apache .commons .lang3 .time .DateFormatUtils ;
40- import org .dom4j .Attribute ;
41- import org .dom4j .Document ;
42- import org .dom4j .Element ;
43- import org .dom4j .io .SAXReader ;
4437
4538import java .io .File ;
46- import java .io .InputStream ;
4739import java .net .URL ;
4840import java .util .*;
49- import java .util .jar .JarEntry ;
50- import java .util .jar .JarFile ;
5141
5242/**
5343 * @ClassName: IndexController
@@ -65,8 +55,6 @@ public class IndexController extends IndexView {
6555
6656 public static final String FAVORITE_CATEGORY_NAME = "置顶" ;
6757
68- private Map <String , Menu > menuMap = new HashMap <>();
69-
7058 private Map <String , MenuItem > menuItemMap = new HashMap <>();
7159
7260 private IndexService indexService = new IndexService (this );
@@ -104,7 +92,6 @@ private void initNotepad() {
10492 }
10593
10694 private void initView () {
107- // menuMap.put("moreToolsMenu", moreToolsMenu);
10895 }
10996
11097 private void initEvent () {
@@ -126,7 +113,6 @@ public void loadPlugins() {
126113 this .pluginCategories .getChildren ().clear ();
127114 this .pluginItemControllers .clear ();
128115 this .categoryControllers .clear ();
129- this .menuMap .clear ();
130116 this .menuItemMap .clear ();
131117 this .moreToolsMenu .getItems ().clear ();
132118
@@ -182,122 +168,13 @@ private void addCategory(PluginCategoryController category) {
182168 }
183169 }
184170
185- public void addToolMenu (File file ) throws Exception {
186- Map <String , ToolFxmlLoaderConfiguration > toolMap = new HashMap <>();
187- List <ToolFxmlLoaderConfiguration > toolList = new ArrayList <>();
188-
189- try (JarFile jarFile = new JarFile (file )) {
190- JarEntry entry = jarFile .getJarEntry ("config/toolFxmlLoaderConfiguration.xml" );
191- if (entry == null ) {
192- return ;
193- }
194- InputStream input = jarFile .getInputStream (entry );
195- SAXReader saxReader = new SAXReader ();
196- Document document = saxReader .read (input );
197- Element root = document .getRootElement ();
198- List <Element > elements = root .elements ("ToolFxmlLoaderConfiguration" );
199- for (Element configurationNode : elements ) {
200- ToolFxmlLoaderConfiguration toolFxmlLoaderConfiguration = new ToolFxmlLoaderConfiguration ();
201- List <Attribute > attributes = configurationNode .attributes ();
202- for (Attribute configuration : attributes ) {
203- BeanUtils .copyProperty (toolFxmlLoaderConfiguration , configuration .getName (), configuration .getValue ());
204- }
205- List <Element > childrenList = configurationNode .elements ();
206- for (Element configuration : childrenList ) {
207- BeanUtils .copyProperty (toolFxmlLoaderConfiguration , configuration .getName (), configuration .getStringValue ());
208- }
209- if (StringUtils .isEmpty (toolFxmlLoaderConfiguration .getMenuParentId ())) {
210- toolFxmlLoaderConfiguration .setMenuParentId ("moreToolsMenu" );
211- }
212- if (toolFxmlLoaderConfiguration .getIsMenu ()) {
213- if (menuMap .get (toolFxmlLoaderConfiguration .getMenuId ()) == null ) {
214- toolMap .putIfAbsent (toolFxmlLoaderConfiguration .getMenuId (), toolFxmlLoaderConfiguration );
215- }
216- } else {
217- toolList .add (toolFxmlLoaderConfiguration );
218- }
219- }
220- }
221- toolList .addAll (toolMap .values ());
222- this .addMenu (toolList );
223- }
224-
225- private void addMenu (List <ToolFxmlLoaderConfiguration > toolList ) {
226- for (ToolFxmlLoaderConfiguration toolConfig : toolList ) {
227- try {
228- if (StringUtils .isEmpty (toolConfig .getResourceBundleName ())) {
229- if (StringUtils .isNotEmpty (bundle .getString (toolConfig .getTitle ()))) {
230- toolConfig .setTitle (bundle .getString (toolConfig .getTitle ()));
231- }
232- } else {
233- ResourceBundle resourceBundle = ResourceBundle .getBundle (toolConfig .getResourceBundleName (), Config .defaultLocale );
234- if (StringUtils .isNotEmpty (resourceBundle .getString (toolConfig .getTitle ()))) {
235- toolConfig .setTitle (resourceBundle .getString (toolConfig .getTitle ()));
236- }
237- }
238- } catch (Exception e ) {
239- log .error ("加载菜单失败" , e );
240- }
241- if (toolConfig .getIsMenu ()) {
242- Menu menu = new Menu (toolConfig .getTitle ());
243- if (StringUtils .isNotEmpty (toolConfig .getIconPath ())) {
244- ImageView imageView = new ImageView (new Image (toolConfig .getIconPath ()));
245- imageView .setFitHeight (18 );
246- imageView .setFitWidth (18 );
247- menu .setGraphic (imageView );
248- }
249- menuMap .put (toolConfig .getMenuId (), menu );
250- }
251- }
252-
253- for (ToolFxmlLoaderConfiguration toolConfig : toolList ) {
254- if (toolConfig .getIsMenu ()) {
255- menuMap .get (toolConfig .getMenuParentId ()).getItems ().add (menuMap .get (toolConfig .getMenuId ()));
256- }
257- }
258-
259- for (ToolFxmlLoaderConfiguration toolConfig : toolList ) {
260- if (toolConfig .getIsMenu ()) {
261- continue ;
262- }
263- MenuItem menuItem = new MenuItem (toolConfig .getTitle ());
264- if (StringUtils .isNotEmpty (toolConfig .getIconPath ())) {
265- ImageView imageView = new ImageView (new Image (toolConfig .getIconPath ()));
266- imageView .setFitHeight (18 );
267- imageView .setFitWidth (18 );
268- menuItem .setGraphic (imageView );
269- }
270- if ("Node" .equals (toolConfig .getControllerType ())) {
271- menuItem .setOnAction ((ActionEvent event ) -> {
272- indexService .addContent (menuItem .getText (), toolConfig .getUrl (), toolConfig .getResourceBundleName (), toolConfig .getIconPath ());
273- });
274- if (toolConfig .getIsDefaultShow ()) {
275- indexService .addContent (menuItem .getText (), toolConfig .getUrl (), toolConfig .getResourceBundleName (), toolConfig .getIconPath ());
276- }
277- } else if ("WebView" .equals (toolConfig .getControllerType ())) {
278- menuItem .setOnAction ((ActionEvent event ) -> {
279- indexService .addWebView (menuItem .getText (), toolConfig .getUrl (), toolConfig .getIconPath ());
280- });
281- if (toolConfig .getIsDefaultShow ()) {
282- indexService .addWebView (menuItem .getText (), toolConfig .getUrl (), toolConfig .getIconPath ());
283- }
284- }
285- menuMap .get (toolConfig .getMenuParentId ()).getItems ().add (menuItem );
286- menuItemMap .put (menuItem .getText (), menuItem );
287- }
288- }
289-
290171 private void addMenu (PluginJarInfo jarInfo ) {
291- // Optional<MenuItem> menu = moreToolsMenu.getItems().stream().filter(menuItem1 -> jarInfo.getMenuParentId().equals(menuItem1.getId())).findAny();
292- if (!menuMap .containsKey (jarInfo .getMenuParentId ())) {
293- // if (moreToolsMenu.getItems().stream().noneMatch(menuItem -> jarInfo.getMenuParentId().equals(menuItem.getId()))) {
294- // if (menu == null) {
295- Menu menu = new Menu (XJavaFxToolApplication .RESOURCE_BUNDLE .getString (jarInfo .getMenuParentTitle ()));
172+ MenuItem menu = moreToolsMenu .getItems ().stream ().filter (menuItem1 -> jarInfo .getMenuParentId ().equals (menuItem1 .getId ())).findAny ().orElse (null );
173+ if (menu == null ) {
174+ menu = new Menu (XJavaFxToolApplication .RESOURCE_BUNDLE .getString (jarInfo .getMenuParentTitle ()));
296175 menu .setId (jarInfo .getMenuParentId ());
297- menuMap .put (jarInfo .getMenuParentId (),menu );
298176 moreToolsMenu .getItems ().add (menu );
299177 }
300-
301178 MenuItem menuItem = new MenuItem (jarInfo .getTitle ());
302179 if (StringUtils .isNotEmpty (jarInfo .getIconPath ())) {
303180 ImageView imageView = new ImageView (new Image (jarInfo .getIconPath ()));
@@ -308,7 +185,7 @@ private void addMenu(PluginJarInfo jarInfo) {
308185 menuItem .setOnAction ((ActionEvent event ) -> {
309186 indexService .loadPlugin (jarInfo );
310187 });
311- menuMap . get ( jarInfo . getMenuParentId () ).getItems ().add (menuItem );
188+ (( Menu ) menu ).getItems ().add (menuItem );
312189 menuItemMap .put (menuItem .getText (), menuItem );
313190 }
314191
@@ -356,17 +233,6 @@ private void addLogConsoleAction(ActionEvent event) {
356233 private void pluginManageAction () throws Exception {
357234 FXMLLoader fXMLLoader = PluginManageController .getFXMLLoader ();
358235 Parent root = fXMLLoader .load ();
359- // PluginManageController pluginManageController = fXMLLoader.getController();
360- /*
361- pluginManageController.setOnPluginDownloaded(jarFile -> {
362- try {
363- this.addToolMenu(jarFile);
364- PluginManager.getInstance().loadLocalPlugins();
365- } catch (Exception e) {
366- log.error("加载工具出错:", e);
367- }
368- });
369- */
370236 JavaFxViewUtil .openNewWindow (bundle .getString ("plugin_manage" ), root );
371237 }
372238
0 commit comments