From ec45d8457d3c897bb2a17f81f0a97883ee338a69 Mon Sep 17 00:00:00 2001 From: juhaoyu <2335173323@qq.com> Date: Fri, 2 Jun 2017 16:20:51 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BF=AE=E5=A4=8D=E5=B7=B2=E5=8F=91?= =?UTF-8?q?=E7=8E=B0=E7=9A=84=E9=97=AE=E9=A2=98=202=E3=80=81=E8=8F=9C?= =?UTF-8?q?=E5=8D=95=E7=9B=91=E5=90=AC=E7=9B=B8=E5=85=B3=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E5=8F=98=E5=8A=A8=EF=BC=8C=E8=87=AA=E5=8A=A8=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=8F=9C=E5=8D=95=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mainframe/toolbar/ToolBarMenuDock.java | 84 +++++++++++++++++-- .../src/com/fr/design/menu/MenuDef.java | 9 +- 2 files changed, 83 insertions(+), 10 deletions(-) diff --git a/designer_base/src/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java b/designer_base/src/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java index f80e20331c..c6adb1d4be 100644 --- a/designer_base/src/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java +++ b/designer_base/src/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java @@ -11,9 +11,9 @@ import com.fr.design.actions.UpdateAction; import com.fr.design.actions.community.*; import com.fr.design.actions.file.*; import com.fr.design.actions.help.AboutAction; -import com.fr.design.actions.help.alphafine.AlphafineAction; import com.fr.design.actions.help.TutorialAction; import com.fr.design.actions.help.WebDemoAction; +import com.fr.design.actions.help.alphafine.AlphafineAction; import com.fr.design.actions.server.*; import com.fr.design.file.NewTemplatePane; import com.fr.design.fun.MenuHandler; @@ -32,6 +32,13 @@ import com.fr.design.menu.ToolBarDef; import com.fr.env.RemoteEnv; import com.fr.general.ComparatorUtils; import com.fr.general.Inter; +import com.fr.plugin.context.PluginContext; +import com.fr.plugin.context.PluginRuntime; +import com.fr.plugin.manage.PluginFilter; +import com.fr.plugin.observer.PluginEvent; +import com.fr.plugin.observer.PluginEventListener; +import com.fr.plugin.observer.PluginEventType; +import com.fr.plugin.observer.PluginListenerRegistration; import com.fr.stable.ArrayUtils; import com.fr.stable.ProductConstants; @@ -570,17 +577,56 @@ public abstract class ToolBarMenuDock { protected void insertMenu(MenuDef menuDef, String anchor) { insertMenu(menuDef, anchor, new NoTargetAction()); } - + protected void insertMenu(MenuDef menuDef, String anchor, ShortCutMethodAction action) { - // 下面是插件接口接入点 - Set set = ExtraDesignClassManager.getInstance().getArray(MenuHandler.MARK_STRING); - java.util.List target = new ArrayList<>(); + + listenPluginMenuChange(menuDef, anchor, action); + addExtraMenus(menuDef, anchor, action, ExtraDesignClassManager.getInstance().getArray(MenuHandler.MARK_STRING)); + + } + + private void listenPluginMenuChange(MenuDef menuDef, String anchor, ShortCutMethodAction action) { + + PluginFilter filter = new PluginFilter() { + + @Override + public boolean accept(PluginContext context) { + + return context.contain(MenuHandler.MARK_STRING); + } + }; + + PluginListenerRegistration.getInstance().listen(PluginEventType.BeforeStop, new PluginEventListener() { + + @Override + public void on(PluginEvent event) { + PluginRuntime runtime = event.getContext().getRuntime(); + Set menuHandlers = runtime.get(MenuHandler.MARK_STRING); + removeExtraMenus(menuDef, anchor, action, menuHandlers); + } + }, filter); + PluginListenerRegistration.getInstance().listen(PluginEventType.AfterRun, new PluginEventListener() { + + @Override + public void on(PluginEvent event) { + + PluginRuntime runtime = event.getContext().getRuntime(); + Set menuHandlers = runtime.get(MenuHandler.MARK_STRING); + addExtraMenus(menuDef, anchor, action, menuHandlers); + } + }, filter); + } + + private void removeExtraMenus(MenuDef menuDef, String anchor, ShortCutMethodAction action, Set set) { + + + List target = new ArrayList<>(); for (MenuHandler handler : set) { if (ComparatorUtils.equals(handler.category(), anchor)) { target.add(handler); } } - + for (MenuHandler handler : target) { int insertPosition = handler.insertPosition(menuDef.getShortCutCount()); if (insertPosition == MenuHandler.HIDE) { @@ -590,7 +636,29 @@ public abstract class ToolBarMenuDock { if (shortCut == null){ continue; } - + menuDef.removeShortCut(shortCut); + } + } + + private void addExtraMenus(MenuDef menuDef, String anchor, ShortCutMethodAction action, Set set) { + + List target = new ArrayList<>(); + for (MenuHandler handler : set) { + if (ComparatorUtils.equals(handler.category(), anchor)) { + target.add(handler); + } + } + + for (MenuHandler handler : target) { + int insertPosition = handler.insertPosition(menuDef.getShortCutCount()); + if (insertPosition == MenuHandler.HIDE) { + return; + } + ShortCut shortCut = action.methodAction(handler); + if (shortCut == null){ + continue; + } + if (insertPosition == MenuHandler.LAST) { if (handler.insertSeparatorBefore()) { menuDef.addShortCut(SeparatorDef.DEFAULT); @@ -609,7 +677,7 @@ public abstract class ToolBarMenuDock { } } } - + /** * 设计器退出时, 做的一些操作. * diff --git a/designer_base/src/com/fr/design/menu/MenuDef.java b/designer_base/src/com/fr/design/menu/MenuDef.java index 9de4dba4ea..319b94f2e4 100644 --- a/designer_base/src/com/fr/design/menu/MenuDef.java +++ b/designer_base/src/com/fr/design/menu/MenuDef.java @@ -117,6 +117,11 @@ public class MenuDef extends ShortCut { this.shortcutList.add(i); } } + + public void removeShortCut(ShortCut shortCut) { + + this.shortcutList.remove(shortCut); + } /** * 清理 @@ -349,6 +354,6 @@ public class MenuDef extends ShortCut { public void setPopupMenu(JPopupMenu popupMenu) { this.popupMenu = popupMenu; } - - + + } \ No newline at end of file