From 5c716eb147fc6032a824395baa85f9de91c7181e Mon Sep 17 00:00:00 2001 From: "Destiny.Lin" Date: Thu, 29 Sep 2022 17:36:40 +0800 Subject: [PATCH 1/2] =?UTF-8?q?REPORT-75998=20=E4=BF=AE=E5=A4=8D=E6=9F=A5?= =?UTF-8?q?=E6=89=BE=E5=AE=8C=E6=88=90=E5=90=8E=E6=89=93=E5=BC=80=E6=96=B0?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E6=97=A0=E6=9F=A5=E6=89=BE=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E4=B8=8D=E7=AC=A6=E7=9A=84=E6=8F=90=E7=A4=BA=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E8=BE=93=E5=85=A5img=E8=BF=94=E5=9B=9E=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E4=B8=8D=E6=AD=A3=E7=A1=AE=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../replace/ui/ITReplaceMainDialog.java | 55 ++++----- .../actions/replace/ui/ITTableButton.java | 9 +- .../actions/replace/utils/ShowValueUtils.java | 108 ++++++++++++++++-- 3 files changed, 130 insertions(+), 42 deletions(-) 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 4843df57f4..54e6a3bff4 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 @@ -48,13 +48,14 @@ public class ITReplaceMainDialog extends UIDialog { private static boolean matched = false; private static volatile ITReplaceMainDialog instance = null; private static String templateID; + private static String templateName; private ITReplaceNorthPanel northPane; private ITReplaceSouthPanel southPanel; private ITReplaceWestPanel westPanel; private boolean searchFlag; private String searchStr; private static final int FIRST_ROW = 0; - public static int selectCount = 0; + public static int selectCount = 0; public ITReplaceMainDialog() { super(DesignerContext.getDesignerFrame()); @@ -165,8 +166,9 @@ public class ITReplaceMainDialog extends UIDialog { String searchStr = ((UITextField) (northPane.getFindInputCombobox().getEditor().getEditorComponent())).getText(); String replaceStr = ((UITextField) (northPane.getReplaceInputCombobox().getEditor().getEditorComponent())).getText(); //替换内容为空需要触发搜索 - if (StringUtils.equals(getSearchStr(), searchStr) && StringUtils.isNotEmpty(replaceStr)) { - if (isITReplaceValid() && checkTemplateChanged(searchResultList)) { + if (isITReplaceValid() && checkTemplateChanged(searchResultList)) { + if (StringUtils.equals(getSearchStr(), searchStr) && StringUtils.isNotEmpty(replaceStr)) { + HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().fireTargetModified(true); for (Info info : searchResultList) { if (info.getContent().isSelected()) { info.setValue(info, searchStr, replaceStr, info.getContent().getOperatorArray()); @@ -175,29 +177,26 @@ public class ITReplaceMainDialog extends UIDialog { southPanel.getTableEditorPane().update(); northPane.refreshReplaceInputComboBoxItems(); ITTableEditorPane.getEditTable().repaint(); - HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().fireTargetModified(true); setSearchFlag(false); - search(); - } else { - Object[] options = new Object[]{Toolkit.i18nText("Fine-Design_Replace_Search_Again"), Toolkit.i18nText("Fine-Design_Basic_Cancel")}; - int optionSelected = FineJOptionPane.showOptionDialog( - ITReplaceMainDialog.this, - Toolkit.i18nText("Fine-Design_Replace_Message"), - Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"), - JOptionPane.YES_NO_CANCEL_OPTION, - JOptionPane.ERROR_MESSAGE, - null, - // 如果传null, 则按钮为 optionType 类型所表示的按钮(也就是确认对话框) - options, - options[0] - ); - //如果选择了重新查找,则再查找一遍 - if (optionSelected == 0) { - search(); - } } - } else { search(); + } else { + Object[] options = new Object[]{Toolkit.i18nText("Fine-Design_Replace_Search_Again"), Toolkit.i18nText("Fine-Design_Basic_Cancel")}; + int optionSelected = FineJOptionPane.showOptionDialog( + ITReplaceMainDialog.this, + Toolkit.i18nText("Fine-Design_Replace_Message"), + Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"), + JOptionPane.YES_NO_CANCEL_OPTION, + JOptionPane.ERROR_MESSAGE, + null, + // 如果传null, 则按钮为 optionType 类型所表示的按钮(也就是确认对话框) + options, + options[0] + ); + //如果选择了重新查找,则再查找一遍 + if (optionSelected == 0) { + search(); + } } @@ -220,7 +219,8 @@ public class ITReplaceMainDialog extends UIDialog { */ public boolean isITReplaceValid() { if (JTemplate.isValid(HistoryTemplateListCache.getInstance().getCurrentEditingTemplate())) { - return StringUtils.equals(HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getTarget().getTemplateID(), templateID); + return StringUtils.equals(HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getTarget().getTemplateID(), templateID) + && StringUtils.equals(HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getTemplateName(), templateName); } else { return false; } @@ -288,6 +288,7 @@ public class ITReplaceMainDialog extends UIDialog { if (JTemplate.isValid(HistoryTemplateListCache.getInstance().getCurrentEditingTemplate())) { JTemplate jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); templateID = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getTarget().getTemplateID(); + templateName = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().getTemplateName(); itTableEditor.clear(); String searchStr = ((UITextField) (northPane.getFindInputCombobox().getEditor().getEditorComponent())).getText(); //更新搜索内容 @@ -310,12 +311,12 @@ public class ITReplaceMainDialog extends UIDialog { setSearchFlag(true); selectCount = searchResultList.size(); //如果有结果,默认选中第一行 - if (searchResultList.size() > 0){ - getEditTable().addRowSelectionInterval(FIRST_ROW,FIRST_ROW); + if (searchResultList.size() > 0) { + getEditTable().addRowSelectionInterval(FIRST_ROW, FIRST_ROW); } //更新替换按钮可用性 - if (StringUtils.isEmpty(searchStr) || searchResultList.size() == 0){ + if (StringUtils.isEmpty(searchStr) || searchResultList.size() == 0) { northPane.getReplaceButton().setEnabled(false); } else { northPane.getReplaceButton().setEnabled(true); diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITTableButton.java b/designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITTableButton.java index 03717a725c..d64946d09d 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITTableButton.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITTableButton.java @@ -6,13 +6,14 @@ import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.DesignerContext; -import com.fr.design.mainframe.ReportComponentComposite; +import com.fr.file.FILEFactory; import com.fr.general.GeneralUtils; import com.fr.stable.StringUtils; +import com.fr.stable.project.ProjectConstants; + import javax.swing.AbstractCellEditor; import javax.swing.JTable; -import javax.swing.SwingUtilities; import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; import java.awt.Component; @@ -42,7 +43,9 @@ public class ITTableButton extends AbstractCellEditor implements TableCellEditor ITContent content = (ITContent) getEditTable().getValueAt(getEditTable().getEditingRow(), 6); if (StringUtils.isNotEmpty(GeneralUtils.objectToString(content.getTrlString()))) { ITReplaceMainDialog.setITReplaceFlag(true); - HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().navigate(new TRL(GeneralUtils.objectToString(content.getTrlString()))); + TRL trl = new TRL(GeneralUtils.objectToString(content.getTrlString())); + DesignerContext.getDesignerFrame().openTemplate(FILEFactory.createFILE(ProjectConstants.REPORTLETS_NAME + FILEFactory.SEPARATOR + content.getTemplateName())); + HistoryTemplateListCache.getInstance().getCurrentEditingTemplate().navigate(trl); } ITReplaceMainDialog.setITReplaceFlag(false); } 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 19ab2758f3..6c7b16cdd1 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 @@ -28,6 +28,25 @@ public class ShowValueUtils { public static final String ANY_THING_REGEX = "."; public static final String NUMBER_REGEX = "[0-9]"; public static final String ENGLISH_REGEX = "[a-zA-Z]"; + public static final char LEFT_HTML_CHAR = '<'; + public static final char RIGHT_HTML_CHAR = '>'; + public static final String HEAD = ""; + public static final String TAIL = ""; + public static final String FONT_HEAD = ""; + public static final String FONT_TAIL = ""; + public static final String HTML = ""; + public static final String NOBR = ""; + public static final String HTML_TAIL = ""; + public static final String NOBR_TAIL = ""; + public static final int HEAD_LEN = HEAD.length(); + public static final int TAIL_LEN = TAIL.length(); + public static final int FONT_HEAD_LEN = FONT_HEAD.length(); + public static final int FONT_TAIL_LEN = FONT_TAIL.length(); + public static final int HTML_LEN = HTML.length(); + public static final int HTML_TAIL_LEN = HTML_TAIL.length(); + public static final int NOBR_LEN = NOBR.length(); + public static final int NOBR_TAIL_LEN = NOBR_TAIL.length(); + public static Pattern containPattern; private static List specialCharList = new ArrayList<>(); @@ -135,33 +154,97 @@ public class ShowValueUtils { String result = str; Pattern pattern = containPattern; Matcher matcher = pattern.matcher(str); - String head = ""; - String tail = ""; - int size = head.length() + tail.length(); + int size = FONT_HEAD.length() + FONT_TAIL.length(); int index = 0; StringBuilder builder = new StringBuilder(str); while (matcher.find()) { - builder.replace(matcher.start() + index, matcher.end() + index, head + changeHtmlStr(matcher.group()) + tail); + builder.replace(matcher.start() + index, matcher.end() + index, FONT_HEAD + changeHtmlStr(matcher.group()) + FONT_TAIL); index += size; + index += getIncreaseCount(matcher.group()); } - return "
" + - builder.toString() + - "
"; + + return changeOriginHtmlStr(HEAD + builder.toString() + TAIL); } else { - return "
" + - replaceAll(str, searchStr, "" + changeHtmlStr(searchStr) + "") + - "
"; + String ans = HEAD + replaceAll(str, searchStr, FONT_HEAD + changeHtmlStr(searchStr) + FONT_TAIL) + TAIL; + return changeOriginHtmlStr(ans); + } + + } + + /** + * 用于处理原字符串中的尖括号 + */ + private static String changeOriginHtmlStr(String str) { + int count = 0; + int different = 3; + StringBuilder builder = new StringBuilder(str); + for (int i = 0; i < str.length(); i++) { + char c = str.charAt(i); + if (c == LEFT_HTML_CHAR) { + if (!checkValid(str, i)) { + builder.replace(i + count, i + count + 1, "<"); + count += different; + } + } } + return builder.toString(); + } + private static boolean checkValid(String str, int i) { + int leftLen = str.length() - (i + 1); + return checkStrValid(str, i, leftLen, HTML_LEN, HTML) || + checkStrValid(str, i, leftLen, HTML_TAIL_LEN, HTML_TAIL) || + checkStrValid(str, i, leftLen, FONT_HEAD_LEN, FONT_HEAD) || + checkStrValid(str, i, leftLen, FONT_TAIL_LEN, FONT_TAIL) || + checkStrValid(str, i, leftLen, NOBR_LEN, NOBR) || + checkStrValid(str, i, leftLen, NOBR_TAIL_LEN, NOBR_TAIL); } - private static String changeHtmlStr(String searchStr){ + /** + * 是否是所指定的字符串 + * + * @param str + * @param i + * @param leftLen + * @return + */ + private static boolean checkStrValid(String str, int i, int leftLen, int len, String checkStr) { + if (leftLen < len - 1) { + return false; + } else { + return StringUtils.equals(str.substring(i, i + len), checkStr); + } + } + + + /** + * 用于处理搜索的字符中的尖括号 + * + * @param searchStr + * @return + */ + private static String changeHtmlStr(String searchStr) { String showStr = searchStr; - showStr = showStr.replace("<","<"); + showStr = showStr.replace("<", "<"); showStr = showStr.replace(">", ">"); return showStr; } + private static int getIncreaseCount(String str) { + int count = 0; + int leftDifferent = 3; + int rightDifferent = 2; + for (int i = 0; i < str.length(); i++) { + if (str.charAt(i) == LEFT_HTML_CHAR) { + count += leftDifferent; + } + if (str.charAt(i) == RIGHT_HTML_CHAR) { + count += rightDifferent; + } + } + return count; + } + /** * 集合是否不为空 * @@ -193,6 +276,7 @@ public class ShowValueUtils { /** * 支持通配符的contains + * * @param originStr * @param matchStr * @return From 0afa23c3c33303301601d293090b6e3e9fe38acd Mon Sep 17 00:00:00 2001 From: "Destiny.Lin" Date: Fri, 30 Sep 2022 10:32:30 +0800 Subject: [PATCH 2/2] =?UTF-8?q?REPORT-75998=20=E4=BF=AE=E5=A4=8D=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E9=9B=86=E9=9D=A2=E6=9D=BF=E4=B8=8D=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=9A=84bug=E3=80=81=E4=BC=98=E5=8C=96=E9=AD=94=E6=9C=AF?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../actions/replace/info/ReplaceObject.java | 7 +++++++ .../actions/replace/utils/ShowValueUtils.java | 18 +++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/info/ReplaceObject.java b/designer-realize/src/main/java/com/fr/design/actions/replace/info/ReplaceObject.java index 53bd77a4d1..48a4dbf644 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/info/ReplaceObject.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/info/ReplaceObject.java @@ -1,7 +1,10 @@ package com.fr.design.actions.replace.info; import com.fr.data.impl.DBTableData; +import com.fr.design.DesignModelAdapter; import com.fr.design.actions.replace.utils.ShowValueUtils; +import com.fr.design.data.DesignTableDataManager; +import com.fr.design.data.datapane.TableDataTreePane; import com.fr.form.event.Listener; import com.fr.general.GeneralUtils; import com.fr.js.JavaScriptImpl; @@ -248,6 +251,10 @@ public enum ReplaceObject implements DealWithInfoValue { DBTableData dbTableData = (DBTableData) info.getContent().getReplaceObject(); info.updateOldStr(dbTableData.getQuery(), findStr); dbTableData.setQuery(ShowValueUtils.replaceAll(dbTableData.getQuery(), findStr, replaceStr)); + //清除缓存 + DesignTableDataManager.removeSelectedColumnNames(dbTableData.getName()); + //收缩菜单 + TableDataTreePane.getInstance(DesignModelAdapter.getCurrentModelAdapter()).refreshDockingView(); } @Override 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 6c7b16cdd1..d7baa0a733 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 @@ -46,6 +46,14 @@ public class ShowValueUtils { public static final int HTML_TAIL_LEN = HTML_TAIL.length(); public static final int NOBR_LEN = NOBR.length(); public static final int NOBR_TAIL_LEN = NOBR_TAIL.length(); + /** + * <转变为<的长度差 + */ + public static final int LEFT_DIFFERENT = 3; + /** + * >转变为>的长度差 + */ + public static final int RIGHT_DIFFERENT = 2; public static Pattern containPattern; private static List specialCharList = new ArrayList<>(); @@ -168,7 +176,6 @@ public class ShowValueUtils { String ans = HEAD + replaceAll(str, searchStr, FONT_HEAD + changeHtmlStr(searchStr) + FONT_TAIL) + TAIL; return changeOriginHtmlStr(ans); } - } /** @@ -176,14 +183,13 @@ public class ShowValueUtils { */ private static String changeOriginHtmlStr(String str) { int count = 0; - int different = 3; StringBuilder builder = new StringBuilder(str); for (int i = 0; i < str.length(); i++) { char c = str.charAt(i); if (c == LEFT_HTML_CHAR) { if (!checkValid(str, i)) { builder.replace(i + count, i + count + 1, "<"); - count += different; + count += LEFT_DIFFERENT; } } } @@ -232,14 +238,12 @@ public class ShowValueUtils { private static int getIncreaseCount(String str) { int count = 0; - int leftDifferent = 3; - int rightDifferent = 2; for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == LEFT_HTML_CHAR) { - count += leftDifferent; + count += LEFT_DIFFERENT; } if (str.charAt(i) == RIGHT_HTML_CHAR) { - count += rightDifferent; + count += RIGHT_DIFFERENT; } } return count;