From a138f031ef82fb382c8ad689fda4baa4682541d1 Mon Sep 17 00:00:00 2001 From: "Destiny.Lin" Date: Mon, 31 Oct 2022 16:40:49 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-80695=20=E6=A8=A1=E6=9D=BF=E5=85=A8?= =?UTF-8?q?=E5=B1=80=E6=9F=A5=E6=89=BE=E6=9B=BF=E6=8D=A2=20=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=A0=A1=E9=AA=8C=E9=80=BB=E8=BE=91=EF=BC=8C=E5=8F=AA?= =?UTF-8?q?=E5=85=81=E8=AE=B8=E7=BB=84=E4=BB=B6=E5=92=8C=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E9=9D=A2=E6=9D=BF=E6=8E=A7=E4=BB=B6=E5=8F=82=E4=B8=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../action/content/widget/FrmWidgetType.java | 2 +- .../content/widget/SearchWidgetAction.java | 2 +- .../actions/replace/info/WidgetInfo.java | 23 +++++- .../actions/replace/ui/ITCheckDialog.java | 1 + .../replace/ui/ITReplaceMainDialog.java | 14 +++- .../actions/replace/utils/CheckUtils.java | 77 +++++++++++++++++++ 6 files changed, 111 insertions(+), 8 deletions(-) create mode 100644 designer-realize/src/main/java/com/fr/design/actions/replace/utils/CheckUtils.java diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/widget/FrmWidgetType.java b/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/widget/FrmWidgetType.java index 5aa8e208c5..8c6333e11a 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/widget/FrmWidgetType.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/widget/FrmWidgetType.java @@ -130,7 +130,7 @@ public enum FrmWidgetType implements SearchFrmWidget, DealWithInfoValue { public List dealAbsoluteWidget(ITContent content, Widget widget) { ArrayList widgetInfos = new ArrayList<>(); ITContent newContent = ITContent.copy(content); - widgetInfos.add(new WidgetInfo(newContent)); + widgetInfos.add(new WidgetInfo(newContent, true)); return widgetInfos; } diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/widget/SearchWidgetAction.java b/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/widget/SearchWidgetAction.java index 32a21bee54..63b5df9d8f 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/widget/SearchWidgetAction.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/widget/SearchWidgetAction.java @@ -148,7 +148,7 @@ public class SearchWidgetAction implements SearchAction { newContent.setReplaceObject(widget); newContent.setJumpAble(false); newContent.setShowObject(Toolkit.i18nText("Fine-Design_Parameter_Panel")); - widgetInfos.add(new WidgetInfo(newContent)); + widgetInfos.add(new WidgetInfo(newContent, true)); } } diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/info/WidgetInfo.java b/designer-realize/src/main/java/com/fr/design/actions/replace/info/WidgetInfo.java index 7adfc01536..4ebae73da9 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/info/WidgetInfo.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/info/WidgetInfo.java @@ -3,6 +3,7 @@ package com.fr.design.actions.replace.info; import com.fr.design.actions.replace.action.content.widget.FrmWidgetType; import com.fr.design.actions.replace.info.base.ITContent; +import com.fr.design.actions.replace.utils.CheckUtils; import com.fr.design.actions.replace.utils.ShowValueUtils; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.JTemplate; @@ -30,11 +31,17 @@ import java.util.Map; public class WidgetInfo implements Info, DealWithInfoValue { private ITContent content; private boolean waterMarkFlag = true; + private boolean need2Check = false; public WidgetInfo(ITContent content) { this.content = content; } + public WidgetInfo(ITContent content, boolean need2Check) { + this.content = content; + this.need2Check = need2Check; + } + @Override public ITContent getContent() { return content; @@ -96,7 +103,9 @@ public class WidgetInfo implements Info, DealWithInfoValue { */ public WidgetInfo copy(WidgetInfo widgetInfo) { ITContent content = ITContent.copy(widgetInfo.getContent()); - return new WidgetInfo(content); + WidgetInfo info = new WidgetInfo(content); + info.setNeed2Check(widgetInfo.isNeed2Check()); + return info; } /** @@ -112,6 +121,14 @@ public class WidgetInfo implements Info, DealWithInfoValue { this.waterMarkFlag = waterMarkFlag; } + public boolean isNeed2Check() { + return need2Check; + } + + public void setNeed2Check(boolean need2Check) { + this.need2Check = need2Check; + } + /** * ReplaceObject是否存在 * @@ -138,9 +155,9 @@ public class WidgetInfo implements Info, DealWithInfoValue { this.getContent().setCheckStr(Toolkit.i18nText("Fine-Design_Replace_Not_Empty")); return false; } - if (!this.isWaterMark()) { + if (!this.isWaterMark() && this.isNeed2Check()) { String replacedName = ((Widget)this.getContent().getReplaceObject()).getWidgetName().replace(searchStr, replaceStr); - for (WidgetName name : jTemplate.getModel().getWidgetsName()) { + for (WidgetName name : CheckUtils.getNeed2CheckWidgetsName(jTemplate)) { String widgetName = name.getName(); if (StringUtils.equals(replacedName, widgetName)) { this.getContent().setCheckStr(Toolkit.i18nText("Fine-Design_Replace_Exist_Same_Name")); diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITCheckDialog.java b/designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITCheckDialog.java index 3c586fac4e..9b82dea3ce 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITCheckDialog.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITCheckDialog.java @@ -34,6 +34,7 @@ public class ITCheckDialog extends UIDialog { public ITCheckDialog() { super(ITReplaceMainDialog.getInstance()); + setModal(true); setTitle(Toolkit.i18nText("Fine-Design_Replace_Check_Title")); JPanel centerPanel = new JPanel(); JPanel southPanel = new JPanel(); diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITReplaceMainDialog.java b/designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITReplaceMainDialog.java index 7f2530d2c6..7fa5ad2804 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITReplaceMainDialog.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITReplaceMainDialog.java @@ -213,7 +213,13 @@ public class ITReplaceMainDialog extends UIDialog { clearContentCount(); if (isITReplaceValid() && checkTemplateChanged(searchContentResultList)) { if (StringUtils.equals(getSearchStr(), searchStr)) { - checkLegalValiditySelector(searchStr, replaceStr); + String str = GeneralUtils.objectToString(northPane.getFindCombobox().getSelectedItem()); + //如果是控件或组件才要进行合法性校验 + if (StringUtils.equals(str, Toolkit.i18nText("Fine-Design_Replace_Component")) || StringUtils.equals(str, Toolkit.i18nText("Fine-Design_Basic_Widget"))) { + checkLegalValiditySelector(searchStr, replaceStr); + } else { + replace(searchStr, replaceStr); + } } else { search4Content(); } @@ -273,9 +279,9 @@ public class ITReplaceMainDialog extends UIDialog { options, options[0] ); + updateCheckValidList(); //如果选择了直接替换,则直接执行替换 if (optionSelected == 1) { - updateCheckValidList(); replace(searchStr, replaceStr); } else { checkLegalValidity(); @@ -286,7 +292,6 @@ public class ITReplaceMainDialog extends UIDialog { * 检测 */ public void checkLegalValidity() { - updateCheckValidList(); if (contentReplaceFailedCount == 0) { ToastMsgDialog dialog = DesignerToastMsgUtil.createPromptDialog(Toolkit.i18nText("Fine-Design_Replace_Check_None")); dialog.setVisible(true); @@ -308,12 +313,15 @@ public class ITReplaceMainDialog extends UIDialog { checkValidList.add(info); serialNumber.add(count); info.getContent().setWrongful(true); + info.getContent().setReplaced(true); } else { contentReplaceCount++; } count++; } } + southPanel.getTableEditorPane().update(); + ITTableEditorPane.getEditTable().repaint(); } diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/utils/CheckUtils.java b/designer-realize/src/main/java/com/fr/design/actions/replace/utils/CheckUtils.java new file mode 100644 index 0000000000..18020aaf74 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/utils/CheckUtils.java @@ -0,0 +1,77 @@ +package com.fr.design.actions.replace.utils; + +import com.fr.design.mainframe.JTemplate; +import com.fr.form.main.Form; +import com.fr.form.main.WidgetGatherAdapter; +import com.fr.form.ui.Widget; +import com.fr.main.impl.WorkBook; +import com.fr.main.impl.WorkBookHelper; +import com.fr.stable.Filter; +import com.fr.stable.StringUtils; +import com.fr.stable.js.WidgetName; + +import java.util.ArrayList; +import java.util.List; + +/** + * 用于合法性检验相关的工具类 + * + * @author Destiny.Lin + * @version 11.0 + * created by Destiny.Lin on 2022-10-31 + */ +public class CheckUtils { + + /** + * 获取需要检测的控件名称 + * + * @param jTemplate 模板 + * @return 控件名称列表 + */ + public static List getNeed2CheckWidgetsName(JTemplate jTemplate) { + if (jTemplate.getTarget() instanceof WorkBook) { + return getWorkBookNeedWidgetsName((WorkBook) jTemplate.getTarget()); + } else if (jTemplate.getTarget() instanceof Form) { + return getFormNeedWidgetsName((Form) jTemplate.getTarget()); + } + return new ArrayList<>(); + } + + private static List getFormNeedWidgetsName(Form target) { + final List list = new ArrayList(); + Form.traversalFormWidget(target.getContainer(), new WidgetGatherAdapter() { + + @Override + public void dealWith(Widget widget) { + if (widgetAccepted(widget)) { + list.add(new WidgetName(widget.getWidgetName())); + } + } + + @Override + public boolean dealWithAllCards() { + return true; + } + }); + return list; + } + + private static List getWorkBookNeedWidgetsName(WorkBook wb) { + return WorkBookHelper.listWidgetNamesInWorkBook(wb, new Filter() { + @Override + public boolean accept(Widget widget) { + return widgetAccepted(widget); + } + }, new Filter() { + @Override + public boolean accept(Widget widget) { + return false; + } + }); + } + + + private static boolean widgetAccepted(Widget widget) { + return widget != null && StringUtils.isNotEmpty(widget.getWidgetName()); + } +}