From 80af035ce63bd01f092556ce21ec0386d9c2226a Mon Sep 17 00:00:00 2001 From: Starryi Date: Thu, 9 Sep 2021 15:43:34 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-51919=20=E3=80=90=E4=B8=BB=E9=A2=98?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E3=80=91=E5=A4=8D=E7=94=A8=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E9=80=82=E9=85=8D=E4=B8=BB=E9=A2=98=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【问题原因】 1. 创建复用组件时新增适用于复用组件模版主题的字段,值为当前模版的主题名称 2. 使用复用组件时,仅复用组件内元素设置了跟随主题,且复用组件适用的模版主题名称与 当前模版名称相同时,才设置主题样式 【改动思路】 同标题 --- .../designer/creator/XCreatorUtils.java | 36 +++++++++++++++++++ .../com/fr/design/mainframe/FormDesigner.java | 36 ------------------- .../share/generate/task/ComponentCreator.java | 10 ++++++ .../share/ui/block/LocalWidgetBlock.java | 3 +- .../share/ui/block/OnlineWidgetBlock.java | 9 ++++- .../share/util/ShareComponentUtils.java | 16 +++++++++ 6 files changed, 72 insertions(+), 38 deletions(-) diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java b/designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java index 945d3bfdd3..6e44ad1963 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java @@ -3,6 +3,11 @@ */ package com.fr.design.designer.creator; +import com.fr.base.theme.FineColorManager; +import com.fr.base.theme.FormTheme; +import com.fr.base.theme.TemplateTheme; +import com.fr.base.theme.TemplateThemeAware; +import com.fr.base.theme.TemplateThemeCompatible; import com.fr.design.ExtraDesignClassManager; import com.fr.design.designer.creator.cardlayout.XCardAddButton; import com.fr.design.designer.creator.cardlayout.XCardSwitchButton; @@ -11,11 +16,15 @@ import com.fr.design.designer.creator.cardlayout.XWCardMainBorderLayout; import com.fr.design.designer.creator.cardlayout.XWCardTagLayout; import com.fr.design.designer.creator.cardlayout.XWCardTitleLayout; import com.fr.design.designer.creator.cardlayout.XWTabFitLayout; +import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.fun.ChartWidgetOptionProvider; import com.fr.design.fun.FormWidgetOptionProvider; import com.fr.design.fun.ParameterWidgetOptionProvider; +import com.fr.design.mainframe.JTemplate; import com.fr.design.module.DesignModuleFactory; import com.fr.design.utils.gui.LayoutUtils; +import com.fr.form.main.Form; +import com.fr.form.main.WidgetGather; import com.fr.form.parameter.FormSubmitButton; import com.fr.form.ui.Button; import com.fr.form.ui.CardAddButton; @@ -216,6 +225,16 @@ public class XCreatorUtils { return xClazz; } + public static XCreator createThemedXCreator(Widget widget) { + XCreator creator = createXCreator(widget); + JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + TemplateTheme theme = template.getTemplateTheme(); + if (theme instanceof FormTheme) { + setupTemplateTheme(creator, (FormTheme) theme, TemplateThemeCompatible.NONE); + } + return creator; + } + /** * 创建creator * @@ -356,4 +375,21 @@ public class XCreatorUtils { } return null; } + + public static void setupTemplateTheme(XCreator container, final FormTheme currentTemplateUsingTheme, TemplateThemeCompatible compatible) { + FineColorManager.traverse(container.toData(), new FineColorManager.FineColorReplaceByTheme(currentTemplateUsingTheme, compatible)); + + Form.traversalWidget(container.toData(), new WidgetGather() { + @Override + public void dealWith(Widget widget) { + TemplateThemeAware themedWidget = (TemplateThemeAware) widget; + themedWidget.onTemplateUsingThemeChange(currentTemplateUsingTheme, compatible); + } + + @Override + public boolean dealWithAllCards() { + return true; + } + }, TemplateThemeAware.class); + } } \ No newline at end of file diff --git a/designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java b/designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java index 636f1f5489..cbe9e87e65 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java @@ -1195,9 +1195,6 @@ public class FormDesigner extends TargetComponent
implements TreeSelection * @param xCreator 组件 */ public void startDraggingBean(XCreator xCreator) { - - // 新疆的图表块和报表块默认主题化 - addThemeToDroppedNewWidget(xCreator); // 根据所选择的组件的BeanInfo生成相应的AddingModel // AddingModel和StateModel不一样,适合当前选择的组件相关的 addingModel = new AddingModel(this, xCreator); @@ -1862,37 +1859,4 @@ public class FormDesigner extends TargetComponent implements TreeSelection public FormSpacingLineDrawer getSpacingLineDrawer() { return spacingLineDrawer; } - - private void addThemeToDroppedNewWidget(XCreator addingXCreator) { - JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); - if (template == null) { - return; - } - TemplateTheme theme = template.getTemplateTheme(); - if (!(theme instanceof FormTheme)) { - return; - } - FormTheme formTheme = (FormTheme) theme; - - Form.traversalWidget(addingXCreator.toData(), new WidgetGather() { - @Override - public void dealWith(Widget widget) { - if (widget instanceof AbstractBorderStyleWidget) { - AbstractBorderStyleWidget styleWidget = (AbstractBorderStyleWidget) widget; - if (!styleWidget.supportThemed()) { - return; - } - - boolean followingTheme = (!addingXCreator.isShared()) || styleWidget.isBorderStyleFollowingTheme(); - styleWidget.setBorderStyleFollowingTheme(followingTheme); - if (followingTheme) { - styleWidget.onTemplateUsingThemeChange(formTheme, TemplateThemeCompatible.NONE); - } - } - } - @Override - public boolean dealWithAllCards() { return true; } - }, AbstractBorderStyleWidget.class); - addingXCreator.rebuid(); - } } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/generate/task/ComponentCreator.java b/designer-form/src/main/java/com/fr/design/mainframe/share/generate/task/ComponentCreator.java index b14229df67..126660665a 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/generate/task/ComponentCreator.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/share/generate/task/ComponentCreator.java @@ -3,6 +3,7 @@ package com.fr.design.mainframe.share.generate.task; import com.fr.base.TableData; import com.fr.base.iofile.attr.ExtendSharableAttrMark; import com.fr.base.iofile.attr.SharableAttrMark; +import com.fr.base.theme.TemplateTheme; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.share.generate.impl.AbstractComponentCreatorProcessor; @@ -39,6 +40,8 @@ public class ComponentCreator extends AbstractComponentCreatorProcessor { @Override public ComponentReuBean create(JTemplate jt, Map paraMap, Widget widget, DefaultSharableWidget info) throws Exception { + // 适用于共享组件的模版主题 + setSuitableTemplateThemeName(jt, info); // 遍历判断是否存在共享组件 checkOriginStatus(widget, info); @@ -56,6 +59,13 @@ public class ComponentCreator extends AbstractComponentCreatorProcessor { return new ComponentReuBean(generatePath, editor, info); } + private void setSuitableTemplateThemeName(JTemplate jt, DefaultSharableWidget info) { + TemplateTheme theme = jt.getTemplateTheme(); + if (theme != null) { + info.setSuitableTemplateThemeName(theme.getName()); + } + } + protected void checkOriginStatus(Widget widget, final DefaultSharableWidget info) { Form.traversalWidget(widget, new WidgetGatherAdapter() { diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/LocalWidgetBlock.java b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/LocalWidgetBlock.java index 911ff7b772..d927555021 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/LocalWidgetBlock.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/LocalWidgetBlock.java @@ -211,7 +211,8 @@ public class LocalWidgetBlock extends PreviewWidgetBlock creatorSource.setWidgetID(UUID.randomUUID().toString()); ((AbstractBorderStyleWidget) creatorSource).addWidgetAttrMark(new SharableAttrMark(true)); //tab布局WCardMainBorderLayout通过反射出来的大小是960*480 - XCreator xCreator = ShareComponentUtils.createXCreator(creatorSource, shareId, no.getBindInfo()); + String suitableTemplateThemeName = no.getWidget().getSuitableTemplateThemeName(); + XCreator xCreator = ShareComponentUtils.createThemedXCreator(creatorSource, suitableTemplateThemeName, shareId, no.getBindInfo()); WidgetToolBarPane.getTarget().startDraggingBean(xCreator); lastPressEvent = null; this.setBorder(null); diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetBlock.java b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetBlock.java index b8cb0e6788..8ad419b038 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetBlock.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetBlock.java @@ -12,6 +12,7 @@ import com.fr.design.login.DesignerLoginHelper; import com.fr.design.login.DesignerLoginSource; import com.fr.design.mainframe.WidgetToolBarPane; import com.fr.design.mainframe.share.collect.ComponentCollector; +import com.fr.form.share.DefaultSharableWidget; import com.fr.form.share.group.DefaultShareGroup; import com.fr.design.mainframe.share.ui.local.LocalWidgetRepoPane; import com.fr.design.mainframe.share.ui.online.OnlineWidgetRepoPane; @@ -143,7 +144,13 @@ public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock { ((AbstractBorderStyleWidget) creatorSource).addWidgetAttrMark(new SharableAttrMark(true)); SharableWidgetProvider bindInfo = ShareUtils.getElCaseBindInfoById(shareId); //tab布局WCardMainBorderLayout通过反射出来的大小是960*480 - XCreator xCreator = ShareComponentUtils.createXCreator(creatorSource, shareId, bindInfo); + XCreator xCreator; + if (bindInfo instanceof DefaultSharableWidget) { + String suitableTemplateThemeName = ((DefaultSharableWidget) bindInfo).getSuitableTemplateThemeName(); + xCreator = ShareComponentUtils.createThemedXCreator(creatorSource, suitableTemplateThemeName, shareId, bindInfo); + } else { + xCreator = ShareComponentUtils.createXCreator(creatorSource, shareId, bindInfo); + } WidgetToolBarPane.getTarget().startDraggingBean(xCreator); lastPressEvent = null; this.setBorder(null); diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/util/ShareComponentUtils.java b/designer-form/src/main/java/com/fr/design/mainframe/share/util/ShareComponentUtils.java index 80162a4065..72418b86be 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/util/ShareComponentUtils.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/share/util/ShareComponentUtils.java @@ -2,6 +2,9 @@ package com.fr.design.mainframe.share.util; import com.fr.base.io.IOFile; import com.fr.base.iofile.attr.ExtendSharableAttrMark; +import com.fr.base.theme.FormTheme; +import com.fr.base.theme.TemplateTheme; +import com.fr.base.theme.TemplateThemeCompatible; import com.fr.design.designer.creator.XCreator; import com.fr.design.designer.creator.XCreatorUtils; import com.fr.design.designer.creator.XLayoutContainer; @@ -50,6 +53,19 @@ public class ShareComponentUtils { return xCreator; } + public static XCreator createThemedXCreator(Widget creatorSource, String suitableTemplateThemeName, String shareId, SharableWidgetProvider provider) { + XCreator creator = createXCreator(creatorSource, shareId, provider); + JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + TemplateTheme theme = template.getTemplateTheme(); + if (theme instanceof FormTheme) { + boolean isCurrentUsingThemeSuitSharedComponent = StringUtils.isNotEmpty(theme.getName()) && + StringUtils.isNotEmpty(suitableTemplateThemeName) && + StringUtils.equals(theme.getName(), suitableTemplateThemeName); + XCreatorUtils.setupTemplateTheme(creator, (FormTheme) theme, isCurrentUsingThemeSuitSharedComponent ? TemplateThemeCompatible.NONE : TemplateThemeCompatible.ABSENT); + } + return creator; + } + /** * 检查readme.txt文件 */