diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/info/ComponentInfo.java b/designer-realize/src/main/java/com/fr/design/actions/replace/info/ComponentInfo.java index b302376fb6..77993c53db 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/info/ComponentInfo.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/info/ComponentInfo.java @@ -1,10 +1,14 @@ package com.fr.design.actions.replace.info; import com.fr.design.actions.replace.action.content.component.ComponentType; +import com.fr.design.actions.replace.action.content.component.SearchComponentAction; import com.fr.design.actions.replace.info.base.ITContent; +import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.JTemplate; import com.fr.form.ui.Widget; import com.fr.stable.StringUtils; import com.fr.stable.collections.combination.Pair; +import com.fr.stable.js.WidgetName; import java.util.HashMap; @@ -79,4 +83,23 @@ public class ComponentInfo implements Info { public String getInfoShowStr(Info info) { return this.getContent().getOldShowStr(); } + + @Override + public Boolean isLegalValid(JTemplate jTemplate, String searchStr, String replaceStr) { + if (StringUtils.isEmpty(replaceStr)) { + this.getContent().setCheckStr(Toolkit.i18nText("Fine-Design_Replace_Not_Empty")); + return false; + } + SearchComponentAction.getInstance().search4Infos(jTemplate); + List list = SearchComponentAction.getInstance().getComponentInfos(); + String replacedName = ((Widget)this.getContent().getReplaceObject()).getWidgetName().replace(searchStr, replaceStr); + for (ComponentInfo info : list) { + String widgetName = ((Widget)info.getContent().getReplaceObject()).getWidgetName(); + if (StringUtils.equals(replacedName, widgetName)) { + this.getContent().setCheckStr(Toolkit.i18nText("Fine-Design_Replace_Exist_Same_Name")); + return false; + } + } + return true; + } } diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/info/Info.java b/designer-realize/src/main/java/com/fr/design/actions/replace/info/Info.java index 6f26be2595..9fc5aedad6 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/info/Info.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/info/Info.java @@ -1,6 +1,7 @@ package com.fr.design.actions.replace.info; import com.fr.design.actions.replace.info.base.ITContent; +import com.fr.design.mainframe.JTemplate; /** @@ -40,4 +41,19 @@ public interface Info extends DealWithInfoValue { //todo 完善所有类型的校验 return true; } + + /** + * 校验合法性(内容是否合法 + * 当前需要检测的目标: + * 控件名:值是否为空、重名 + * 组件名:值是否为空、重名 + * + * @param jTemplate 要检测的模板 + * @param searchStr 搜索的内容 + * @param replaceStr 替换的内容 + * @return 检测合法则返回true + */ + default Boolean isLegalValid(JTemplate jTemplate,String searchStr, String replaceStr) { + return 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 afdf098028..7adfc01536 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 @@ -4,12 +4,16 @@ 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.ShowValueUtils; +import com.fr.design.i18n.Toolkit; +import com.fr.design.mainframe.JTemplate; import com.fr.form.ui.WaterMark; import com.fr.form.ui.Widget; import com.fr.form.ui.container.WScaleLayout; import com.fr.form.ui.widget.CRBoundsWidget; import com.fr.stable.AssistUtils; +import com.fr.stable.StringUtils; import com.fr.stable.collections.combination.Pair; +import com.fr.stable.js.WidgetName; import java.util.HashMap; @@ -128,4 +132,23 @@ public class WidgetInfo implements Info, DealWithInfoValue { } + @Override + public Boolean isLegalValid(JTemplate jTemplate,String searchStr, String replaceStr) { + if (StringUtils.isEmpty(replaceStr)) { + this.getContent().setCheckStr(Toolkit.i18nText("Fine-Design_Replace_Not_Empty")); + return false; + } + if (!this.isWaterMark()) { + String replacedName = ((Widget)this.getContent().getReplaceObject()).getWidgetName().replace(searchStr, replaceStr); + for (WidgetName name : jTemplate.getModel().getWidgetsName()) { + String widgetName = name.getName(); + if (StringUtils.equals(replacedName, widgetName)) { + this.getContent().setCheckStr(Toolkit.i18nText("Fine-Design_Replace_Exist_Same_Name")); + return false; + } + } + } + return true; + } + } diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/info/base/ITContent.java b/designer-realize/src/main/java/com/fr/design/actions/replace/info/base/ITContent.java index aecbe2ed10..e75b224649 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/info/base/ITContent.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/info/base/ITContent.java @@ -87,6 +87,13 @@ public class ITContent implements Cloneable { */ private boolean replaced = false; + /** + * + */ + private String checkStr = StringUtils.EMPTY; + + private boolean wrongful = false; + public ITContent() { this.sheetID = StringUtils.EMPTY; this.sheetName = StringUtils.EMPTY; @@ -133,6 +140,7 @@ public class ITContent implements Cloneable { result.setTemplatePath(content.getTemplatePath()); result.setAfterReplaceStr(content.getAfterReplaceStr()); result.setReplaced(content.isReplaced()); + result.setWrongful(content.isWrongful()); } return result; } @@ -245,6 +253,22 @@ public class ITContent implements Cloneable { this.replaced = replaced; } + public String getCheckStr() { + return checkStr; + } + + public void setCheckStr(String checkStr) { + this.checkStr = checkStr; + } + + public boolean isWrongful() { + return wrongful; + } + + public void setWrongful(boolean wrongful) { + this.wrongful = wrongful; + } + /** * 添加位置信息 * 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 new file mode 100644 index 0000000000..e597e3172e --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITCheckDialog.java @@ -0,0 +1,98 @@ +package com.fr.design.actions.replace.ui; + + +import com.fr.design.dialog.UIDialog; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.ilable.UILabel; + +import com.fr.design.gui.itableeditorpane.UITableEditorPane; + +import com.fr.design.i18n.Toolkit; + +import javax.swing.JPanel; +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import static com.fr.design.actions.replace.ui.ITTableEditorPane.getEditTable; + +/** + * 合法性校验的面板 + * + * @author Destiny.Lin + * @version 11.0 + * created by Destiny.Lin on 2022-10-28 + */ +public class ITCheckDialog extends UIDialog { + private UITableEditorPane editorPane; + private ITCheckEditor editor; + private static final int DIALOG_WIDTH = 660, DIALOG_HEIGHT = 400; + private static final int TABLE_WIDTH = 640, TABLE_HEIGHT = 320; + private static final int LABEL_HEIGHT = 20; + + public static final Object[] columnTitle = {Toolkit.i18nText("Fine-Design_Replace_Check_Content"), Toolkit.i18nText("Fine-Design_Replace_Check_Reason")}; + + public ITCheckDialog() { + super(ITReplaceMainDialog.getInstance()); + setTitle(Toolkit.i18nText("Fine-Design_Replace_Check_Title")); + JPanel centerPanel = new JPanel(); + JPanel southPanel = new JPanel(); + southPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); + + editor = new ITCheckEditor(); + editorPane = new UITableEditorPane(editor); + editor.add(ITReplaceMainDialog.getCheckValidList()); + + UILabel label = new UILabel("" + Toolkit.i18nText("Fine-Design_Replace_Check") + "" + ITReplaceMainDialog.contentReplaceFailedCount + "" + Toolkit.i18nText("Fine-Design_Replace_Check_Tip")); + JPanel center = new JPanel(new BorderLayout()); + UIButton location = new UIButton(Toolkit.i18nText("Fine-Design_Chart_Location")); + UIButton cancel = new UIButton(Toolkit.i18nText("Fine-Design_Basic_Cancel")); + + location.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + for (int i : ITReplaceMainDialog.getSerialNumber()) { + getEditTable().addRowSelectionInterval(i, i); + } + ITCheckDialog.this.dispose(); + } + }); + + cancel.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + ITCheckDialog.this.dispose(); + } + }); + + + editorPane.setPreferredSize(new Dimension(TABLE_WIDTH, TABLE_HEIGHT)); + label.setPreferredSize(new Dimension(TABLE_WIDTH, LABEL_HEIGHT)); + + centerPanel.add(editorPane); + southPanel.add(location); + southPanel.add(cancel); + center.add(southPanel, BorderLayout.SOUTH); + center.add(label, BorderLayout.NORTH); + center.add(centerPanel, BorderLayout.CENTER); + center.setVisible(true); + //主体部分 + add(center); + + + setSize(DIALOG_WIDTH, DIALOG_HEIGHT); + setMaximumSize(new Dimension(DIALOG_WIDTH, DIALOG_HEIGHT)); + setMinimumSize(new Dimension(DIALOG_WIDTH, DIALOG_HEIGHT)); + + setLocation(ITReplaceMainDialog.getInstance().getX() + ITReplaceMainDialog.getInstance().getWidth() / 2 - DIALOG_WIDTH / 2, ITReplaceMainDialog.getInstance().getY()); + setVisible(true); + } + + + @Override + public void checkValid() throws Exception { + + } +} diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITCheckEditor.java b/designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITCheckEditor.java new file mode 100644 index 0000000000..1efb8beffc --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITCheckEditor.java @@ -0,0 +1,64 @@ +package com.fr.design.actions.replace.ui; + +import com.fr.design.actions.replace.info.Info; +import com.fr.design.actions.replace.info.base.ITContent; +import com.fr.design.gui.ilable.UILabel; +import com.fr.design.gui.itableeditorpane.UITableEditAction; +import com.fr.design.gui.itableeditorpane.UITableModelAdapter; +import com.fr.design.i18n.Toolkit; + +import java.util.List; + +/** + * 合法性校验表格的Model + * + * @author Destiny.Lin + * @version 11.0 + * created by Destiny.Lin on 2022-10-28 + */ +public class ITCheckEditor extends UITableModelAdapter { + + public ITCheckEditor() { + super(new String[]{ + Toolkit.i18nText("Fine-Design_Replace_Check_Content"), + Toolkit.i18nText("Fine-Design_Replace_Check_Reason") + }); + + this.setColumnClass(new Class[]{ + UILabel.class, + UILabel.class, + }); + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + ITContent content = (ITContent) this.getList().get(rowIndex); + if (columnIndex == 0) { + return content.getShowStr(); + } else { + return content.getCheckStr(); + } + } + + @Override + public boolean isCellEditable(int row, int col) { + return false; + } + + @Override + public UITableEditAction[] createAction() { + return new UITableEditAction[0]; + } + + /** + * 添加数据 + * + * @param list + */ + public void add(List list) { + for (Info info : list) { + addRow(info.getContent()); + } + fireTableDataChanged(); + } +} 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 e207ca5004..868ad8ad2a 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 @@ -16,6 +16,8 @@ import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.JTemplate; +import com.fr.design.mainframe.toast.DesignerToastMsgUtil; +import com.fr.design.mainframe.toast.ToastMsgDialog; import com.fr.general.GeneralUtils; import com.fr.stable.StringUtils; @@ -45,6 +47,8 @@ import static com.fr.design.actions.replace.ui.ITTableEditorPane.getEditTable; public class ITReplaceMainDialog extends UIDialog { private static List searchContentResultList = new ArrayList<>(); private static List searchSettingResultList = new ArrayList<>(); + private static List checkValidList = new ArrayList<>(); + private static List serialNumber = new ArrayList<>(); private static boolean ITReplaceFlag = false; private static boolean matched = false; private static volatile ITReplaceMainDialog instance = null; @@ -184,26 +188,15 @@ public class ITReplaceMainDialog extends UIDialog { } /** - * 替换 + * 模板内容替换相关 */ private void replace4Content() { String searchStr = ((UITextField) (northPane.getFindInputCombobox().getEditor().getEditorComponent())).getText(); String replaceStr = ((UITextField) (northPane.getReplaceInputCombobox().getEditor().getEditorComponent())).getText(); clearContentCount(); if (isITReplaceValid() && checkTemplateChanged(searchContentResultList)) { - if (StringUtils.equals(getSearchStr(), searchStr) && StringUtils.isNotEmpty(replaceStr)) { - HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().fireTargetModified(true); - for (Info info : searchContentResultList) { - if (isAllow2Replace(info)) { - info.setValue(info, searchStr, replaceStr, info.getContent().getOperatorArray()); - info.getContent().setReplaced(true); - contentReplaceCount++; - } - } - northPane.getResultLabel().setText(ShowValueUtils.getResultTip(searchContentResultList.size(), contentReplaceCount, contentReplaceFailedCount)); - southPanel.getTableEditorPane().update(); - northPane.refreshReplaceInputComboBoxItems(); - ITTableEditorPane.getEditTable().repaint(); + if (StringUtils.equals(getSearchStr(), searchStr)) { + checkLegalValiditySelector(searchStr, replaceStr); } else { search4Content(); } @@ -227,6 +220,86 @@ public class ITReplaceMainDialog extends UIDialog { } } + /** + * 替换 + * + * @param searchStr + * @param replaceStr + */ + public void replace(String searchStr, String replaceStr) { + HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().fireTargetModified(true); + for (Info info : searchContentResultList) { + if (!info.getContent().isWrongful()) { + info.setValue(info, searchStr, replaceStr, info.getContent().getOperatorArray()); + } + info.getContent().setReplaced(true); + } + northPane.getResultLabel().setText(ShowValueUtils.getResultTip(searchContentResultList.size(), contentReplaceCount, contentReplaceFailedCount)); + southPanel.getTableEditorPane().update(); + northPane.refreshReplaceInputComboBoxItems(); + ITTableEditorPane.getEditTable().repaint(); + } + + /** + * 合法性校验选择器(选择是否进行校验) + */ + public void checkLegalValiditySelector(String searchStr, String replaceStr) { + Object[] options = new Object[]{Toolkit.i18nText("Fine-Design_Replace_Go_To_Check"), Toolkit.i18nText("Fine-Design_Replace_Direct")}; + int optionSelected = FineJOptionPane.showOptionDialog( + ITReplaceMainDialog.this, + Toolkit.i18nText("Fine-Design_Replace_Legal"), + Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"), + JOptionPane.YES_NO_CANCEL_OPTION, + JOptionPane.WARNING_MESSAGE, + null, + // 如果传null, 则按钮为 optionType 类型所表示的按钮(也就是确认对话框) + options, + options[0] + ); + //如果选择了直接替换,则直接执行替换 + if (optionSelected == 1) { + updateCheckValidList(); + replace(searchStr, replaceStr); + } else { + checkLegalValidity(); + } + } + + /** + * 检测 + */ + public void checkLegalValidity() { + updateCheckValidList(); + if (contentReplaceFailedCount == 0) { + ToastMsgDialog dialog = DesignerToastMsgUtil.createPromptDialog(Toolkit.i18nText("Fine-Design_Replace_Check_None")); + dialog.setVisible(true); + } else { + new ITCheckDialog(); + } + } + + private void updateCheckValidList() { + checkValidList.clear(); + serialNumber.clear(); + int count = 0; + String searchStr = ((UITextField) (northPane.getFindInputCombobox().getEditor().getEditorComponent())).getText(); + String replaceStr = ((UITextField) (northPane.getReplaceInputCombobox().getEditor().getEditorComponent())).getText(); + for (Info info : searchContentResultList) { + if (isAllow2Replace(info)) { + if (!info.isLegalValid(HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(), searchStr, replaceStr)) { + contentReplaceFailedCount++; + checkValidList.add(info); + serialNumber.add(count); + info.getContent().setWrongful(true); + } else { + contentReplaceCount++; + } + count++; + } + } + + } + /** * 是否能够替换 * @@ -520,6 +593,15 @@ public class ITReplaceMainDialog extends UIDialog { this.settingExtraStr = settingExtraStr; } + /** + * 获取不合法的序号 + * + * @return 不合法的元素的序号列表 + */ + public static List getSerialNumber() { + return serialNumber; + } + /** * 检测结果是否合法 */ @@ -529,6 +611,7 @@ public class ITReplaceMainDialog extends UIDialog { /** * 获取模板内容数据 + * * @return 存储数据的list */ public static List getSearchContentResultList() { @@ -537,6 +620,7 @@ public class ITReplaceMainDialog extends UIDialog { /** * 设置模板内容数据 + * * @param searchContentResultList 模板内容表格的数据 */ public static void setSearchContentResultList(List searchContentResultList) { @@ -545,6 +629,7 @@ public class ITReplaceMainDialog extends UIDialog { /** * 获取设置项数据 + * * @return 存储数据的list */ public static List getSearchSettingResultList() { @@ -553,12 +638,31 @@ public class ITReplaceMainDialog extends UIDialog { /** * 设置设置项的数据 + * * @param searchSettingResultList 设置项表格的数据 */ public static void setSearchSettingResultList(List searchSettingResultList) { ITReplaceMainDialog.searchSettingResultList = searchSettingResultList; } + /** + * 获取检测的列表 + * + * @return + */ + public static List getCheckValidList() { + return checkValidList; + } + + /** + * 设置检测列表 + * + * @param checkValidList + */ + public static void setCheckValidList(List checkValidList) { + ITReplaceMainDialog.checkValidList = checkValidList; + } + /** * 重置计数 */ diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/utils/ShowValueUtils.java b/designer-realize/src/main/java/com/fr/design/actions/replace/utils/ShowValueUtils.java index 8f1174e8fc..01205bf886 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/utils/ShowValueUtils.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/utils/ShowValueUtils.java @@ -395,7 +395,7 @@ public class ShowValueUtils { if (replaceCount != 0) { str.append(Toolkit.i18nText("Fine-Design_Replace_Also_Finish")).append("").append(replaceCount).append("").append(Toolkit.i18nText("Fine-Design_Replace_Result_Count")); if (failedCount != 0) { - str.append(Toolkit.i18nText("Fine-Design_Replace_Have")).append("").append(replaceCount).append("").append(Toolkit.i18nText("Fine-Design_Replace_Can_Not_Replace")); + str.append(Toolkit.i18nText("Fine-Design_Replace_Have")).append("").append(failedCount).append("").append(Toolkit.i18nText("Fine-Design_Replace_Can_Not_Replace")); } }