From 23d2e69bb44f55828f7476dc1b529c18b8a709d5 Mon Sep 17 00:00:00 2001 From: zack Date: Mon, 16 Sep 2019 22:15:21 +0800 Subject: [PATCH 1/3] =?UTF-8?q?REPORT-19557=20ToolbarItemProvider=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E9=9C=80=E8=A6=81=E6=94=AF=E6=8C=81=E8=A1=A8=E5=8D=95?= =?UTF-8?q?=E6=8A=A5=E8=A1=A8=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/ExtraDesignClassManager.java | 19 ++++++++++++++++--- .../fr/design/fun/ToolbarItemProvider.java | 6 ++++++ .../design/fun/impl/AbstractToolbarItem.java | 10 ++++++++++ .../AccessibleElementCaseToolBarEditor.java | 3 +++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/ExtraDesignClassManager.java b/designer-base/src/main/java/com/fr/design/ExtraDesignClassManager.java index beb62c06e..acc59fcd4 100644 --- a/designer-base/src/main/java/com/fr/design/ExtraDesignClassManager.java +++ b/designer-base/src/main/java/com/fr/design/ExtraDesignClassManager.java @@ -43,7 +43,7 @@ public class ExtraDesignClassManager extends AbstractExtraClassManager implement private static ExtraDesignClassManager classManager = new ExtraDesignClassManager(); private Set shortCuts = new CloseableContainedSet<>(HashSet.class); - + public static ExtraDesignClassManager getInstance() { return classManager; } @@ -114,13 +114,28 @@ public class ExtraDesignClassManager extends AbstractExtraClassManager implement } + /** + * 获取插件注册的工具栏按钮(严格区分决策报表与普通模板) + * @return + */ + public WidgetOption[] getStrictWebWidgetOptions() { + return createWebWidgetOptions(true); + } + public WidgetOption[] getWebWidgetOptions() { + return createWebWidgetOptions(false); + } + + private WidgetOption[] createWebWidgetOptions(boolean filterByTemplateType) { Set set = getArray(ToolbarItemProvider.XML_TAG); if (set.isEmpty()) { return new WidgetOption[0]; } List list = new ArrayList<>(); for (ToolbarItemProvider provider : set) { + if (filterByTemplateType && !provider.accept()) { + continue; + } WidgetOption option = WidgetOptionFactory.createByWidgetClass( provider.nameForWidget(), IOUtils.readIcon(provider.iconPathForWidget()), @@ -132,7 +147,6 @@ public class ExtraDesignClassManager extends AbstractExtraClassManager implement } - public Map, Class> getFormWidgetOptionsMap() { Set set = getArray(FormWidgetOptionProvider.XML_TAG); Map, Class> map = new HashMap<>(); @@ -170,7 +184,6 @@ public class ExtraDesignClassManager extends AbstractExtraClassManager implement } - public WidgetOption[] getCellWidgetOptions() { Set set = getArray(CellWidgetOptionProvider.XML_TAG); if (set.isEmpty()) { diff --git a/designer-base/src/main/java/com/fr/design/fun/ToolbarItemProvider.java b/designer-base/src/main/java/com/fr/design/fun/ToolbarItemProvider.java index f4add0333..c04bcba2b 100644 --- a/designer-base/src/main/java/com/fr/design/fun/ToolbarItemProvider.java +++ b/designer-base/src/main/java/com/fr/design/fun/ToolbarItemProvider.java @@ -36,4 +36,10 @@ public interface ToolbarItemProvider extends Mutable { */ String nameForWidget(); + /** + * 当前编辑的模板类型(决策报表 or cpt)是否支持 + * @return 支持返回true,否则false + */ + boolean accept(); + } \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/fun/impl/AbstractToolbarItem.java b/designer-base/src/main/java/com/fr/design/fun/impl/AbstractToolbarItem.java index ec3c47bc1..0284c2810 100644 --- a/designer-base/src/main/java/com/fr/design/fun/impl/AbstractToolbarItem.java +++ b/designer-base/src/main/java/com/fr/design/fun/impl/AbstractToolbarItem.java @@ -1,6 +1,9 @@ package com.fr.design.fun.impl; +import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.fun.ToolbarItemProvider; +import com.fr.design.mainframe.JTemplate; +import com.fr.design.mainframe.JVirtualTemplate; import com.fr.stable.fun.impl.AbstractProvider; import com.fr.stable.fun.mark.API; @@ -10,6 +13,7 @@ import com.fr.stable.fun.mark.API; @API(level = ToolbarItemProvider.CURRENT_LEVEL) public abstract class AbstractToolbarItem extends AbstractProvider implements ToolbarItemProvider { + @Override public int currentAPILevel() { return CURRENT_LEVEL; } @@ -18,4 +22,10 @@ public abstract class AbstractToolbarItem extends AbstractProvider implements To public String mark4Provider() { return getClass().getName(); } + + @Override + public boolean accept() { + JTemplate currentTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + return currentTemplate.isJWorkBook() || currentTemplate instanceof JVirtualTemplate; + } } \ No newline at end of file diff --git a/designer-form/src/main/java/com/fr/design/mainframe/widget/accessibles/AccessibleElementCaseToolBarEditor.java b/designer-form/src/main/java/com/fr/design/mainframe/widget/accessibles/AccessibleElementCaseToolBarEditor.java index 0fcf1e25b..5f266e025 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/widget/accessibles/AccessibleElementCaseToolBarEditor.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/widget/accessibles/AccessibleElementCaseToolBarEditor.java @@ -1,5 +1,6 @@ package com.fr.design.mainframe.widget.accessibles; +import com.fr.design.ExtraDesignClassManager; import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.gui.core.WidgetOption; @@ -52,6 +53,8 @@ public class AccessibleElementCaseToolBarEditor extends UneditableAccessibleEdit List defaultOptions = Arrays.asList(FormWebWidgetConstants.getFormElementCaseToolBarInstance()); List options = new ArrayList(); options.addAll(defaultOptions); + WidgetOption[] widgetOptions = ExtraDesignClassManager.getInstance().getStrictWebWidgetOptions(); + options.addAll(Arrays.asList(widgetOptions)); return options.toArray(new WidgetOption[options.size()]); } From b0ea4d52166d4a82a83ef978535a48f4745a4eb6 Mon Sep 17 00:00:00 2001 From: zack Date: Mon, 16 Sep 2019 22:19:31 +0800 Subject: [PATCH 2/3] rt --- .../main/java/com/fr/design/fun/impl/AbstractToolbarItem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/designer-base/src/main/java/com/fr/design/fun/impl/AbstractToolbarItem.java b/designer-base/src/main/java/com/fr/design/fun/impl/AbstractToolbarItem.java index 0284c2810..0bb7f3101 100644 --- a/designer-base/src/main/java/com/fr/design/fun/impl/AbstractToolbarItem.java +++ b/designer-base/src/main/java/com/fr/design/fun/impl/AbstractToolbarItem.java @@ -26,6 +26,6 @@ public abstract class AbstractToolbarItem extends AbstractProvider implements To @Override public boolean accept() { JTemplate currentTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); - return currentTemplate.isJWorkBook() || currentTemplate instanceof JVirtualTemplate; + return currentTemplate == null || currentTemplate.isJWorkBook() || currentTemplate instanceof JVirtualTemplate; } } \ No newline at end of file From 1ac836a9db3d8f639290a14f774b40e55329a727 Mon Sep 17 00:00:00 2001 From: zack Date: Tue, 17 Sep 2019 13:17:05 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=8D=A2=E4=B8=80=E4=B8=AA=E6=89=A9?= =?UTF-8?q?=E5=B1=95=E6=80=A7=E6=9B=B4=E5=A5=BD=E7=9A=84=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/ExtraDesignClassManager.java | 40 +++++------ .../fr/design/fun/ToolbarItemProvider.java | 12 ++-- .../design/fun/impl/AbstractToolbarItem.java | 8 ++- .../design/ExtraDesignClassManagerTest.java | 70 +++++++++++++++++++ .../AccessibleElementCaseToolBarEditor.java | 10 ++- 5 files changed, 112 insertions(+), 28 deletions(-) create mode 100644 designer-base/src/test/java/com/fr/design/ExtraDesignClassManagerTest.java diff --git a/designer-base/src/main/java/com/fr/design/ExtraDesignClassManager.java b/designer-base/src/main/java/com/fr/design/ExtraDesignClassManager.java index acc59fcd4..77e0eb115 100644 --- a/designer-base/src/main/java/com/fr/design/ExtraDesignClassManager.java +++ b/designer-base/src/main/java/com/fr/design/ExtraDesignClassManager.java @@ -23,6 +23,7 @@ import com.fr.plugin.AbstractExtraClassManager; import com.fr.plugin.injectable.PluginModule; import com.fr.plugin.injectable.PluginSingleInjection; import com.fr.plugin.solution.closeable.CloseableContainedSet; +import com.fr.stable.Filter; import com.fr.stable.plugin.ExtraDesignClassManagerProvider; import java.util.ArrayList; @@ -113,35 +114,34 @@ public class ExtraDesignClassManager extends AbstractExtraClassManager implement return result.toArray(new WidgetOption[result.size()]); } - - /** - * 获取插件注册的工具栏按钮(严格区分决策报表与普通模板) - * @return - */ - public WidgetOption[] getStrictWebWidgetOptions() { - return createWebWidgetOptions(true); - } - public WidgetOption[] getWebWidgetOptions() { - return createWebWidgetOptions(false); + return getWebWidgetOptions(new Filter() { + @Override + public boolean accept(ToolbarItemProvider toolbarItemProvider) { + return true; + } + }); } - private WidgetOption[] createWebWidgetOptions(boolean filterByTemplateType) { + public WidgetOption[] getWebWidgetOptions(Filter filter) { Set set = getArray(ToolbarItemProvider.XML_TAG); - if (set.isEmpty()) { + return getWebWidgetOptions(set, filter); + } + + public WidgetOption[] getWebWidgetOptions(Set set, Filter filter) { + if (set == null || set.isEmpty()) { return new WidgetOption[0]; } List list = new ArrayList<>(); for (ToolbarItemProvider provider : set) { - if (filterByTemplateType && !provider.accept()) { - continue; + if (filter != null && filter.accept(provider)) { + WidgetOption option = WidgetOptionFactory.createByWidgetClass( + provider.nameForWidget(), + IOUtils.readIcon(provider.iconPathForWidget()), + provider.classForWidget() + ); + list.add(option); } - WidgetOption option = WidgetOptionFactory.createByWidgetClass( - provider.nameForWidget(), - IOUtils.readIcon(provider.iconPathForWidget()), - provider.classForWidget() - ); - list.add(option); } return list.toArray(new WidgetOption[list.size()]); } diff --git a/designer-base/src/main/java/com/fr/design/fun/ToolbarItemProvider.java b/designer-base/src/main/java/com/fr/design/fun/ToolbarItemProvider.java index c04bcba2b..0ba640b26 100644 --- a/designer-base/src/main/java/com/fr/design/fun/ToolbarItemProvider.java +++ b/designer-base/src/main/java/com/fr/design/fun/ToolbarItemProvider.java @@ -1,6 +1,8 @@ package com.fr.design.fun; +import com.fr.design.mainframe.JTemplate; import com.fr.form.ui.Widget; +import com.fr.stable.Filter; import com.fr.stable.fun.mark.Mutable; /** @@ -8,7 +10,7 @@ import com.fr.stable.fun.mark.Mutable; * @since : 8.0 * 自定义web工具栏菜单 */ -public interface ToolbarItemProvider extends Mutable { +public interface ToolbarItemProvider extends Mutable, Filter { String XML_TAG = "ToolbarItemProvider"; @@ -37,9 +39,11 @@ public interface ToolbarItemProvider extends Mutable { String nameForWidget(); /** - * 当前编辑的模板类型(决策报表 or cpt)是否支持 - * @return 支持返回true,否则false + * 模板(决策报表 or cpt)是否支持此工具栏按钮 + * JTemplate 模板 + * @return 支持返回true, 否则false */ - boolean accept(); + @Override + boolean accept(JTemplate template); } \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/fun/impl/AbstractToolbarItem.java b/designer-base/src/main/java/com/fr/design/fun/impl/AbstractToolbarItem.java index 0bb7f3101..49194049a 100644 --- a/designer-base/src/main/java/com/fr/design/fun/impl/AbstractToolbarItem.java +++ b/designer-base/src/main/java/com/fr/design/fun/impl/AbstractToolbarItem.java @@ -24,8 +24,10 @@ public abstract class AbstractToolbarItem extends AbstractProvider implements To } @Override - public boolean accept() { - JTemplate currentTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); - return currentTemplate == null || currentTemplate.isJWorkBook() || currentTemplate instanceof JVirtualTemplate; + public boolean accept(JTemplate jTemplate) { + if (jTemplate == null) { + jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + } + return jTemplate == null || jTemplate.isJWorkBook() || jTemplate instanceof JVirtualTemplate; } } \ No newline at end of file diff --git a/designer-base/src/test/java/com/fr/design/ExtraDesignClassManagerTest.java b/designer-base/src/test/java/com/fr/design/ExtraDesignClassManagerTest.java new file mode 100644 index 000000000..89f4ee1b2 --- /dev/null +++ b/designer-base/src/test/java/com/fr/design/ExtraDesignClassManagerTest.java @@ -0,0 +1,70 @@ +package com.fr.design; + +import com.fr.config.dao.DaoContext; +import com.fr.config.dao.impl.LocalClassHelperDao; +import com.fr.config.dao.impl.LocalEntityDao; +import com.fr.config.dao.impl.LocalXmlEntityDao; +import com.fr.design.fun.ToolbarItemProvider; +import com.fr.design.gui.core.WidgetOption; +import com.fr.design.mainframe.JTemplate; +import com.fr.design.mainframe.JVirtualTemplate; +import com.fr.general.ModuleContext; +import com.fr.log.FineLoggerFactory; +import com.fr.report.restriction.CellCountRestriction; +import com.fr.report.restriction.ReportRestrictionScene; +import com.fr.restriction.Restrictions; +import com.fr.stable.Filter; +import com.fr.stable.module.Module; +import junit.framework.TestCase; +import org.easymock.EasyMock; +import org.junit.Assert; + +import java.util.HashSet; +import java.util.Set; + +/** + * @author zack + * @version 10.0 + * Created by zack on 2019/9/17 + */ +public class ExtraDesignClassManagerTest extends TestCase { + @Override + protected void setUp() throws Exception { + DaoContext.setEntityDao(new LocalEntityDao()); + DaoContext.setClassHelperDao(new LocalClassHelperDao()); + DaoContext.setXmlEntityDao(new LocalXmlEntityDao()); + ModuleContext.startModule(Module.PAGE_MODULE); + Restrictions.register(ReportRestrictionScene.CELL_COUNT, new CellCountRestriction()); + } + + public void testGetWebOption() { + try { + final JTemplate jTemplate = new JVirtualTemplate(null); + ToolbarItemProvider item = EasyMock.mock(ToolbarItemProvider.class); + ToolbarItemProvider item1 = EasyMock.mock(ToolbarItemProvider.class); + EasyMock.expect(item.accept(jTemplate)).andReturn(false).anyTimes(); + EasyMock.expect(item.classForWidget()).andReturn(null).anyTimes(); + EasyMock.expect(item.iconPathForWidget()).andReturn("").anyTimes(); + EasyMock.expect(item.nameForWidget()).andReturn("1").anyTimes(); + EasyMock.expect(item1.accept(jTemplate)).andReturn(true).anyTimes(); + EasyMock.expect(item1.classForWidget()).andReturn(null).anyTimes(); + EasyMock.expect(item1.iconPathForWidget()).andReturn("").anyTimes(); + EasyMock.expect(item1.nameForWidget()).andReturn("2").anyTimes(); + EasyMock.replay(item); + EasyMock.replay(item1); + + Set set = new HashSet<>(); + set.add(item); + set.add(item1); + WidgetOption[] widgetOptions = ExtraDesignClassManager.getInstance().getWebWidgetOptions(set, new Filter() { + @Override + public boolean accept(ToolbarItemProvider toolbarItemProvider) { + return toolbarItemProvider.accept(jTemplate); + } + }); + Assert.assertEquals(1, widgetOptions.length); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + } +} \ No newline at end of file diff --git a/designer-form/src/main/java/com/fr/design/mainframe/widget/accessibles/AccessibleElementCaseToolBarEditor.java b/designer-form/src/main/java/com/fr/design/mainframe/widget/accessibles/AccessibleElementCaseToolBarEditor.java index 5f266e025..de429b414 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/widget/accessibles/AccessibleElementCaseToolBarEditor.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/widget/accessibles/AccessibleElementCaseToolBarEditor.java @@ -3,12 +3,15 @@ package com.fr.design.mainframe.widget.accessibles; import com.fr.design.ExtraDesignClassManager; import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.file.HistoryTemplateListCache; +import com.fr.design.fun.ToolbarItemProvider; import com.fr.design.gui.core.WidgetOption; import com.fr.design.mainframe.FormWebWidgetConstants; import com.fr.design.mainframe.widget.editors.ElementCaseToolBarPane; import com.fr.design.mainframe.widget.wrappers.ElementCaseToolBarWrapper; import com.fr.form.web.FormToolBarManager; import com.fr.stable.ArrayUtils; +import com.fr.stable.Filter; import javax.swing.SwingUtilities; import java.util.ArrayList; @@ -53,7 +56,12 @@ public class AccessibleElementCaseToolBarEditor extends UneditableAccessibleEdit List defaultOptions = Arrays.asList(FormWebWidgetConstants.getFormElementCaseToolBarInstance()); List options = new ArrayList(); options.addAll(defaultOptions); - WidgetOption[] widgetOptions = ExtraDesignClassManager.getInstance().getStrictWebWidgetOptions(); + WidgetOption[] widgetOptions = ExtraDesignClassManager.getInstance().getWebWidgetOptions(new Filter() { + @Override + public boolean accept(ToolbarItemProvider toolbarItemProvider) { + return toolbarItemProvider.accept(HistoryTemplateListCache.getInstance().getCurrentEditingTemplate()); + } + }); options.addAll(Arrays.asList(widgetOptions)); return options.toArray(new WidgetOption[options.size()]); }