Browse Source

REPORT-51919 【主题切换】复用组件适配主题切换

【问题原因】
1. 创建复用组件时新增适用于复用组件模版主题的字段,值为当前模版的主题名称
2. 使用复用组件时,仅复用组件内元素设置了跟随主题,且复用组件适用的模版主题名称与
当前模版名称相同时,才设置主题样式

【改动思路】
同标题
fix-lag
Starryi 3 years ago
parent
commit
80af035ce6
  1. 36
      designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java
  2. 36
      designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java
  3. 10
      designer-form/src/main/java/com/fr/design/mainframe/share/generate/task/ComponentCreator.java
  4. 3
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/LocalWidgetBlock.java
  5. 9
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetBlock.java
  6. 16
      designer-form/src/main/java/com/fr/design/mainframe/share/util/ShareComponentUtils.java

36
designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java

@ -3,6 +3,11 @@
*/ */
package com.fr.design.designer.creator; 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.ExtraDesignClassManager;
import com.fr.design.designer.creator.cardlayout.XCardAddButton; import com.fr.design.designer.creator.cardlayout.XCardAddButton;
import com.fr.design.designer.creator.cardlayout.XCardSwitchButton; 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.XWCardTagLayout;
import com.fr.design.designer.creator.cardlayout.XWCardTitleLayout; import com.fr.design.designer.creator.cardlayout.XWCardTitleLayout;
import com.fr.design.designer.creator.cardlayout.XWTabFitLayout; 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.ChartWidgetOptionProvider;
import com.fr.design.fun.FormWidgetOptionProvider; import com.fr.design.fun.FormWidgetOptionProvider;
import com.fr.design.fun.ParameterWidgetOptionProvider; import com.fr.design.fun.ParameterWidgetOptionProvider;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.module.DesignModuleFactory; import com.fr.design.module.DesignModuleFactory;
import com.fr.design.utils.gui.LayoutUtils; 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.parameter.FormSubmitButton;
import com.fr.form.ui.Button; import com.fr.form.ui.Button;
import com.fr.form.ui.CardAddButton; import com.fr.form.ui.CardAddButton;
@ -216,6 +225,16 @@ public class XCreatorUtils {
return xClazz; 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 * 创建creator
* *
@ -356,4 +375,21 @@ public class XCreatorUtils {
} }
return null; 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<FormTheme> themedWidget = (TemplateThemeAware) widget;
themedWidget.onTemplateUsingThemeChange(currentTemplateUsingTheme, compatible);
}
@Override
public boolean dealWithAllCards() {
return true;
}
}, TemplateThemeAware.class);
}
} }

36
designer-form/src/main/java/com/fr/design/mainframe/FormDesigner.java

@ -1195,9 +1195,6 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
* @param xCreator 组件 * @param xCreator 组件
*/ */
public void startDraggingBean(XCreator xCreator) { public void startDraggingBean(XCreator xCreator) {
// 新疆的图表块和报表块默认主题化
addThemeToDroppedNewWidget(xCreator);
// 根据所选择的组件的BeanInfo生成相应的AddingModel // 根据所选择的组件的BeanInfo生成相应的AddingModel
// AddingModel和StateModel不一样,适合当前选择的组件相关的 // AddingModel和StateModel不一样,适合当前选择的组件相关的
addingModel = new AddingModel(this, xCreator); addingModel = new AddingModel(this, xCreator);
@ -1862,37 +1859,4 @@ public class FormDesigner extends TargetComponent<Form> implements TreeSelection
public FormSpacingLineDrawer getSpacingLineDrawer() { public FormSpacingLineDrawer getSpacingLineDrawer() {
return spacingLineDrawer; 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();
}
} }

10
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.TableData;
import com.fr.base.iofile.attr.ExtendSharableAttrMark; import com.fr.base.iofile.attr.ExtendSharableAttrMark;
import com.fr.base.iofile.attr.SharableAttrMark; import com.fr.base.iofile.attr.SharableAttrMark;
import com.fr.base.theme.TemplateTheme;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.JTemplate;
import com.fr.design.mainframe.share.generate.impl.AbstractComponentCreatorProcessor; import com.fr.design.mainframe.share.generate.impl.AbstractComponentCreatorProcessor;
@ -39,6 +40,8 @@ public class ComponentCreator extends AbstractComponentCreatorProcessor {
@Override @Override
public ComponentReuBean create(JTemplate<?, ?> jt, Map<String, Object> paraMap, Widget widget, DefaultSharableWidget info) throws Exception { public ComponentReuBean create(JTemplate<?, ?> jt, Map<String, Object> paraMap, Widget widget, DefaultSharableWidget info) throws Exception {
// 适用于共享组件的模版主题
setSuitableTemplateThemeName(jt, info);
// 遍历判断是否存在共享组件 // 遍历判断是否存在共享组件
checkOriginStatus(widget, info); checkOriginStatus(widget, info);
@ -56,6 +59,13 @@ public class ComponentCreator extends AbstractComponentCreatorProcessor {
return new ComponentReuBean(generatePath, editor, info); 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) { protected void checkOriginStatus(Widget widget, final DefaultSharableWidget info) {
Form.traversalWidget(widget, new WidgetGatherAdapter() { Form.traversalWidget(widget, new WidgetGatherAdapter() {

3
designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/LocalWidgetBlock.java

@ -211,7 +211,8 @@ public class LocalWidgetBlock extends PreviewWidgetBlock<DefaultSharableWidget>
creatorSource.setWidgetID(UUID.randomUUID().toString()); creatorSource.setWidgetID(UUID.randomUUID().toString());
((AbstractBorderStyleWidget) creatorSource).addWidgetAttrMark(new SharableAttrMark(true)); ((AbstractBorderStyleWidget) creatorSource).addWidgetAttrMark(new SharableAttrMark(true));
//tab布局WCardMainBorderLayout通过反射出来的大小是960*480 //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); WidgetToolBarPane.getTarget().startDraggingBean(xCreator);
lastPressEvent = null; lastPressEvent = null;
this.setBorder(null); this.setBorder(null);

9
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.login.DesignerLoginSource;
import com.fr.design.mainframe.WidgetToolBarPane; import com.fr.design.mainframe.WidgetToolBarPane;
import com.fr.design.mainframe.share.collect.ComponentCollector; import com.fr.design.mainframe.share.collect.ComponentCollector;
import com.fr.form.share.DefaultSharableWidget;
import com.fr.form.share.group.DefaultShareGroup; import com.fr.form.share.group.DefaultShareGroup;
import com.fr.design.mainframe.share.ui.local.LocalWidgetRepoPane; import com.fr.design.mainframe.share.ui.local.LocalWidgetRepoPane;
import com.fr.design.mainframe.share.ui.online.OnlineWidgetRepoPane; import com.fr.design.mainframe.share.ui.online.OnlineWidgetRepoPane;
@ -143,7 +144,13 @@ public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock {
((AbstractBorderStyleWidget) creatorSource).addWidgetAttrMark(new SharableAttrMark(true)); ((AbstractBorderStyleWidget) creatorSource).addWidgetAttrMark(new SharableAttrMark(true));
SharableWidgetProvider bindInfo = ShareUtils.getElCaseBindInfoById(shareId); SharableWidgetProvider bindInfo = ShareUtils.getElCaseBindInfoById(shareId);
//tab布局WCardMainBorderLayout通过反射出来的大小是960*480 //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); WidgetToolBarPane.getTarget().startDraggingBean(xCreator);
lastPressEvent = null; lastPressEvent = null;
this.setBorder(null); this.setBorder(null);

16
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.io.IOFile;
import com.fr.base.iofile.attr.ExtendSharableAttrMark; 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.XCreator;
import com.fr.design.designer.creator.XCreatorUtils; import com.fr.design.designer.creator.XCreatorUtils;
import com.fr.design.designer.creator.XLayoutContainer; import com.fr.design.designer.creator.XLayoutContainer;
@ -50,6 +53,19 @@ public class ShareComponentUtils {
return xCreator; 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文件 * 检查readme.txt文件
*/ */

Loading…
Cancel
Save