From ae444f7eed8a8fc71d6fcce4837db9c6b02e3697 Mon Sep 17 00:00:00 2001 From: zack Date: Wed, 6 Nov 2019 22:04:55 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-22634=2019fdc=5F=E5=86=B3=E7=AD=96?= =?UTF-8?q?=E6=8A=A5=E8=A1=A8=E5=A2=9E=E5=8A=A0=E9=A2=84=E8=A7=88=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/ExtraDesignClassManager.java | 89 ++++++++++++++++--- .../com/fr/design/fun/PreviewProvider.java | 3 +- .../fun/impl/AbstractPreviewProvider.java | 10 +++ .../com/fr/design/mainframe/JTemplate.java | 18 ++-- .../design/ExtraDesignClassManagerTest.java | 2 + .../java/com/fr/design/mainframe/JForm.java | 3 +- .../com/fr/design/mainframe/JWorkBook.java | 13 +-- 7 files changed, 110 insertions(+), 28 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 bd2e50d57..656a7a6a7 100644 --- a/designer-base/src/main/java/com/fr/design/ExtraDesignClassManager.java +++ b/designer-base/src/main/java/com/fr/design/ExtraDesignClassManager.java @@ -7,7 +7,14 @@ package com.fr.design; import com.fr.base.BaseUtils; import com.fr.common.annotations.Open; import com.fr.design.data.datapane.TableDataNameObjectCreator; -import com.fr.design.fun.*; +import com.fr.design.fun.CellWidgetOptionProvider; +import com.fr.design.fun.FormWidgetOptionProvider; +import com.fr.design.fun.MobileWidgetStyleProvider; +import com.fr.design.fun.ParameterWidgetOptionProvider; +import com.fr.design.fun.PreviewProvider; +import com.fr.design.fun.ServerTableDataDefineProvider; +import com.fr.design.fun.TableDataDefineProvider; +import com.fr.design.fun.ToolbarItemProvider; import com.fr.design.gui.core.WidgetOption; import com.fr.design.gui.core.WidgetOptionFactory; import com.fr.design.menu.ShortCut; @@ -24,6 +31,7 @@ import com.fr.stable.Filter; import com.fr.stable.plugin.ExtraDesignClassManagerProvider; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -127,21 +135,25 @@ public class ExtraDesignClassManager extends AbstractExtraClassManager implement } 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 (filter != null && filter.accept(provider)) { - WidgetOption option = WidgetOptionFactory.createByWidgetClass( + return new DesignExtraBridge() { + + @Override + WidgetOption createT(ToolbarItemProvider provider) { + return WidgetOptionFactory.createByWidgetClass( provider.nameForWidget(), IOUtils.readIcon(provider.iconPathForWidget()), provider.classForWidget() ); - list.add(option); } - } - return list.toArray(new WidgetOption[list.size()]); + + @Override + WidgetOption[] toArray(Collection sCollection) { + if (sCollection == null) { + return new WidgetOption[0]; + } + return sCollection.toArray(new WidgetOption[sCollection.size()]); + } + }.filterSAndTransformT(set, filter); } @@ -224,8 +236,8 @@ public class ExtraDesignClassManager extends AbstractExtraClassManager implement return new MobileWidgetStyleProvider[0]; } List providers = new ArrayList<>(); - for (MobileWidgetStyleProvider provider: set) { - if(ComparatorUtils.equalsIgnoreCase(provider.xTypeForWidget(), xType)) { + for (MobileWidgetStyleProvider provider : set) { + if (ComparatorUtils.equalsIgnoreCase(provider.xTypeForWidget(), xType)) { providers.add(provider); } } @@ -256,4 +268,55 @@ public class ExtraDesignClassManager extends AbstractExtraClassManager implement return Collections.unmodifiableSet(shortCuts); } + + public PreviewProvider[] getTemplatePreviews(Filter filter) { + Set set = ExtraDesignClassManager.getInstance().getArray(PreviewProvider.MARK_STRING); + return new DesignExtraBridge() { + + @Override + PreviewProvider createT(PreviewProvider previewProvider) { + return previewProvider; + } + + @Override + PreviewProvider[] toArray(Collection sCollection) { + if (sCollection == null) { + return new PreviewProvider[0]; + } + return sCollection.toArray(new PreviewProvider[sCollection.size()]); + } + }.filterSAndTransformT(set, filter); + } + + /** + * 抽了一个可能用到的公用逻辑出来:通过filter过滤接口实现(Set)并将对外接口实例转成内部实例S转成T,比如ToolItemProvider转成WidgetOption,当然也可以不转 + * + * @param 你想要得到的类型,可以跟S相同 + * @param 待转换的目标类型 + */ + abstract class DesignExtraBridge { + T[] filterSAndTransformT(Set set, Filter filter) { + if (set == null || set.isEmpty()) { + return toArray(set); + } + List list = new ArrayList<>(); + for (S provider : set) { + if (filter == null || filter.accept(provider)) { + list.add(createT(provider)); + } + } + + return toArray(list); + } + + /** + * S转T + * @param s + * @return + */ + abstract T createT(S s); + + abstract T[] toArray(Collection sCollection); + + } } \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/fun/PreviewProvider.java b/designer-base/src/main/java/com/fr/design/fun/PreviewProvider.java index f6e8cb219..c07a4efe0 100644 --- a/designer-base/src/main/java/com/fr/design/fun/PreviewProvider.java +++ b/designer-base/src/main/java/com/fr/design/fun/PreviewProvider.java @@ -1,6 +1,7 @@ package com.fr.design.fun; import com.fr.design.mainframe.JTemplate; +import com.fr.stable.Filter; import com.fr.stable.fun.mark.Mutable; import java.util.Map; @@ -11,7 +12,7 @@ import java.util.Map; * @since 8.0 * 自定义预览方式接口 */ -public interface PreviewProvider extends Mutable { +public interface PreviewProvider extends Mutable, Filter { String MARK_STRING = "PreviewProvider"; diff --git a/designer-base/src/main/java/com/fr/design/fun/impl/AbstractPreviewProvider.java b/designer-base/src/main/java/com/fr/design/fun/impl/AbstractPreviewProvider.java index f0b780903..3cdac8035 100644 --- a/designer-base/src/main/java/com/fr/design/fun/impl/AbstractPreviewProvider.java +++ b/designer-base/src/main/java/com/fr/design/fun/impl/AbstractPreviewProvider.java @@ -1,7 +1,9 @@ package com.fr.design.fun.impl; +import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.fun.PreviewProvider; import com.fr.design.mainframe.JTemplate; +import com.fr.design.mainframe.JVirtualTemplate; import com.fr.general.ComparatorUtils; import com.fr.general.web.ParameterConstants; import com.fr.stable.fun.impl.AbstractProvider; @@ -52,4 +54,12 @@ public abstract class AbstractPreviewProvider extends AbstractProvider implement public String getActionType() { return ParameterConstants.VIEWLET; } + + @Override + 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/main/java/com/fr/design/mainframe/JTemplate.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java index 31944deb0..4ac020069 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java @@ -4,7 +4,6 @@ import com.fr.base.BaseUtils; import com.fr.base.FRContext; import com.fr.base.Parameter; import com.fr.base.ScreenResolution; -import com.fr.base.extension.FileExtension; import com.fr.base.io.BaseBook; import com.fr.base.iofile.attr.DesignBanCopyAttrMark; import com.fr.base.iofile.attr.TemplateIdAttrMark; @@ -27,8 +26,8 @@ import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.file.TemplateTreePane; import com.fr.design.fun.DesignerFrameUpButtonProvider; import com.fr.design.fun.MenuHandler; -import com.fr.design.fun.ReportSupportedFileUIProvider; import com.fr.design.fun.PreviewProvider; +import com.fr.design.fun.ReportSupportedFileUIProvider; import com.fr.design.gui.frpane.HyperlinkGroupPane; import com.fr.design.gui.frpane.HyperlinkGroupPaneActionProvider; import com.fr.design.gui.ibutton.UIButton; @@ -50,7 +49,6 @@ import com.fr.design.write.submit.DBManipulationPane; import com.fr.file.FILE; import com.fr.file.FILEChooserPane; import com.fr.file.MemFILE; -import com.fr.file.filter.ChooseFileFilter; import com.fr.form.ui.NoneWidget; import com.fr.form.ui.Widget; import com.fr.general.ComparatorUtils; @@ -58,6 +56,7 @@ import com.fr.log.FineLoggerFactory; import com.fr.report.cell.Elem; import com.fr.report.cell.cellattr.CellImage; import com.fr.stable.ArrayUtils; +import com.fr.stable.Filter; import com.fr.stable.ProductConstants; import com.fr.stable.StringUtils; import com.fr.stable.core.UUID; @@ -628,7 +627,7 @@ public abstract class JTemplate> } } - protected void addChooseFILEFilter(FILEChooserPane fileChooser){ + protected void addChooseFILEFilter(FILEChooserPane fileChooser) { } @@ -651,13 +650,13 @@ public abstract class JTemplate> return result; } - protected boolean saveToNewFile(String oldName){ + protected boolean saveToNewFile(String oldName) { boolean result = false; Set providers = ExtraDesignClassManager.getInstance().getArray(ReportSupportedFileUIProvider.XML_TAG); for (ReportSupportedFileUIProvider provider : providers) { result = result || provider.saveToNewFile(this.editingFILE.getPath(), this); } - if(!result){ + if (!result) { result = result || this.saveFile(); //更换最近打开 DesignerEnvManager.getEnvManager().replaceRecentOpenedFilePath(oldName, this.getPath()); @@ -1154,7 +1153,12 @@ public abstract class JTemplate> * @return 预览模式 */ public PreviewProvider[] supportPreview() { - return new PreviewProvider[0]; + return ExtraDesignClassManager.getInstance().getTemplatePreviews(new Filter() { + @Override + public boolean accept(PreviewProvider previewProvider) { + return previewProvider.accept(JTemplate.this); + } + }); } /** diff --git a/designer-base/src/test/java/com/fr/design/ExtraDesignClassManagerTest.java b/designer-base/src/test/java/com/fr/design/ExtraDesignClassManagerTest.java index 89f4ee1b2..781a5ee92 100644 --- a/designer-base/src/test/java/com/fr/design/ExtraDesignClassManagerTest.java +++ b/designer-base/src/test/java/com/fr/design/ExtraDesignClassManagerTest.java @@ -62,7 +62,9 @@ public class ExtraDesignClassManagerTest extends TestCase { return toolbarItemProvider.accept(jTemplate); } }); + WidgetOption[] widgetOptions1 = ExtraDesignClassManager.getInstance().getWebWidgetOptions(set, null); Assert.assertEquals(1, widgetOptions.length); + Assert.assertEquals(2, widgetOptions1.length); } catch (Exception e) { FineLoggerFactory.getLogger().error(e.getMessage(), e); } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/JForm.java b/designer-form/src/main/java/com/fr/design/mainframe/JForm.java index a37a1c466..a5b76e1fc 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/JForm.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/JForm.java @@ -937,7 +937,8 @@ public class JForm extends JTemplate implements BaseJForm { */ @Override public PreviewProvider[] supportPreview() { - Set set = ExtraDesignClassManager.getInstance().getArray(PreviewProvider.MARK_STRING); + PreviewProvider[] templatePreviews = super.supportPreview(); return ArrayUtils.addAll(new PreviewProvider[]{ new PagePreview(), new WritePreview(), new ViewPreview(), new WriteEnhancePreview(), new MobilePreview() - }, set.toArray(new PreviewProvider[set.size()])); + }, templatePreviews); } /**