diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/formula/FormulaTag.java b/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/formula/FormulaTag.java index ff8755974b..c3f3c83a1d 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/formula/FormulaTag.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/formula/FormulaTag.java @@ -2,6 +2,7 @@ package com.fr.design.actions.replace.action.content.formula; import com.fr.chart.chartdata.MeterReportDefinition; import com.fr.data.VerifyItem; +import com.fr.data.impl.FormulaDictionary; import com.fr.design.actions.replace.info.DealWithInfoValue; import com.fr.design.actions.replace.info.Info; import com.fr.design.actions.replace.info.base.SearchTag; @@ -133,6 +134,24 @@ public enum FormulaTag implements DealWithInfoValue { attr.setTooltipText(ShowValueUtils.replaceAll(attr.getTooltipText(), findStr, replaceStr)); } } + }, + DICT_EXCUTE(SearchTag.DICT_EXCUTE) { + @Override + public void setValue(Info info, String findStr, String replaceStr, List> operatorArray) { + if (info.getContent().getHoldObject() instanceof FormulaDictionary) { + FormulaDictionary dictionary = (FormulaDictionary) info.getContent().getHoldObject(); + dictionary.setExcuteFormula(ShowValueUtils.replaceAll(dictionary.getExcuteFormula(), findStr, replaceStr)); + } + } + }, + DICT_PRODUCE(SearchTag.DICT_PRODUCE) { + @Override + public void setValue(Info info, String findStr, String replaceStr, List> operatorArray) { + if (info.getContent().getHoldObject() instanceof FormulaDictionary) { + FormulaDictionary dictionary = (FormulaDictionary) info.getContent().getHoldObject(); + dictionary.setProduceFormula(ShowValueUtils.replaceAll(dictionary.getProduceFormula(), findStr, replaceStr)); + } + } }; int index; diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/formula/widget/DictionaryType.java b/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/formula/widget/DictionaryType.java index 22d4cb3959..6a55aebf9b 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/formula/widget/DictionaryType.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/formula/widget/DictionaryType.java @@ -6,6 +6,7 @@ import com.fr.data.impl.FormulaDictionary; import com.fr.data.impl.TableDataDictionary; import com.fr.design.actions.replace.info.FormulaInfo; import com.fr.design.actions.replace.info.base.ITContent; +import com.fr.design.actions.replace.info.base.SearchTag; import com.fr.design.i18n.Toolkit; import org.jetbrains.annotations.Nullable; @@ -32,23 +33,27 @@ public enum DictionaryType implements DictionaryAction { //显示值 if (formulaDictionary.getExcuteFormula() != null) { ITContent excuteContent = ITContent.copy(content); - excuteContent.setReplaceObject(dictionary); + excuteContent.setReplaceObject(formulaDictionary.getExcuteFormula()); excuteContent.addOtherPos( Toolkit.i18nText("Fine-Design_Basic_DS_Dictionary"), Toolkit.i18nText("Fine-Design_Basic_Formula"), Toolkit.i18nText("Fine-Design_Basic_Display_Value") ); + excuteContent.setHoldObject(dictionary); + excuteContent.setTag(SearchTag.DICT_EXCUTE); formulaInfos.add(new FormulaInfo(excuteContent)); } //实际值 if (formulaDictionary.getProduceFormula() != null) { ITContent produceContent = ITContent.copy(content); - produceContent.setReplaceObject(dictionary); + produceContent.setReplaceObject(formulaDictionary.getProduceFormula()); produceContent.addOtherPos( Toolkit.i18nText("Fine-Design_Basic_DS_Dictionary"), Toolkit.i18nText("Fine-Design_Basic_Formula"), Toolkit.i18nText("Fine-Design_Basic_Actual_Value") ); + produceContent.setHoldObject(dictionary); + produceContent.setTag(SearchTag.DICT_PRODUCE); formulaInfos.add(new FormulaInfo(produceContent)); } } diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/js/SearchWebJSAction.java b/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/js/SearchWebJSAction.java index 0ceec53617..725d1280db 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/js/SearchWebJSAction.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/action/content/js/SearchWebJSAction.java @@ -4,6 +4,7 @@ import com.fr.design.actions.replace.info.JSInfo; import com.fr.design.actions.replace.info.base.ITContent; +import com.fr.design.actions.replace.info.base.SearchTag; import com.fr.design.actions.replace.utils.SearchJSUtils; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.JTemplate; @@ -19,6 +20,7 @@ import com.fr.report.web.util.ReportEngineEventMapping; import com.fr.web.attr.ReportWebAttr; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -86,12 +88,30 @@ public class SearchWebJSAction implements SearchJS { content.setTemplateName(jTemplate.getTemplateName()); content.setJumpAble(false); addWebContent2Array(webAttr); + //处理引用JS + dealImportJS(content,jsInfos,webAttr); for (int i = 0; i < arrayList.size(); i++) { addJSInfos2ListFromArray(content, jsInfos, arrayList.get(i)); } } } + private void dealImportJS(ITContent content, List jsInfos, ReportWebAttr webAttr) { + if (webAttr != null){ + for (String jsStr : webAttr.getJSImport()){ + ITContent jsContent = ITContent.copy(content); + jsContent.addOtherPos( + Toolkit.i18nText("Fine-Design_Basic_Report_Web_Attributes"), + Toolkit.i18nText("Fine-Design_Report_Import_JavaScript") + ); + jsContent.setReplaceObject(jsStr); + jsContent.setHoldObject(webAttr); + jsContent.setTag(SearchTag.IMPORT_JS); + jsInfos.add(new JSInfo(jsContent)); + } + } + } + private void addJSInfos2ListFromServerWebAttr(ITContent content, List jsInfos, WebContent webContent) { ITContent newContent = ITContent.copy(content); if (SERVER_MAP.containsKey(webContent.getClass().getSimpleName())) { diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/info/FormulaInfo.java b/designer-realize/src/main/java/com/fr/design/actions/replace/info/FormulaInfo.java index 73a0750cb8..ce2ecd36c6 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/info/FormulaInfo.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/info/FormulaInfo.java @@ -40,14 +40,7 @@ public class FormulaInfo implements Info { @Override public Map getValue(Object... o) { Map map = new HashMap<>(); - //这边比较特殊,存的都是FormulaDictionary ,特殊判断一下 - if (this.content.getOtherPos().contains(DISPLAY)) { - map.put("content", ((FormulaDictionary) this.getContent().getReplaceObject()).getExcuteFormula()); - } else if (this.content.getOtherPos().contains(ACTUAL)) { - map.put("content", ((FormulaDictionary) this.getContent().getReplaceObject()).getProduceFormula()); - } else { - map = getCommonValue(); - } + map = getCommonValue(); return map; } @@ -70,11 +63,8 @@ public class FormulaInfo implements Info { @Override public Boolean checkValid() { - FormulaReplaceObject formulaReplaceObject = FormulaReplaceObject.match(this.content.getReplaceObject().getClass().getSimpleName()); - if (formulaReplaceObject != null) { - return formulaReplaceObject.check(this); - } - return false; + //校验二期才完善,目前都给过 + return true; } private Map getCommonValue() { 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 3d615e18a9..53bd77a4d1 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 @@ -3,13 +3,16 @@ package com.fr.design.actions.replace.info; import com.fr.data.impl.DBTableData; import com.fr.design.actions.replace.utils.ShowValueUtils; import com.fr.form.event.Listener; +import com.fr.general.GeneralUtils; import com.fr.js.JavaScriptImpl; import com.fr.js.NameJavaScript; import com.fr.plugin.chart.base.VanChartHtmlLabel; import com.fr.stable.StringUtils; import com.fr.stable.collections.combination.Pair; +import com.fr.web.attr.ReportWebAttr; import org.jetbrains.annotations.Nullable; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -184,33 +187,71 @@ public enum ReplaceObject implements DealWithInfoValue { return StringUtils.equals(javaScript.getContent(), info.getContent().getOldShowStr()); } }, + /** + * 模板Web属性——引用JS + */ + IMPORT_JS("String") { + @Override + public Map getValue(Object... o) { + HashMap map = new HashMap<>(); + addValue2Map(contentKey, GeneralUtils.objectToString(o[0]), map); + return map; + } + + @Override + public void setValue(Info info, String findStr, String replaceStr, List> operatorArray) { + if (info.getContent().getHoldObject() instanceof ReportWebAttr) { + ReportWebAttr attr = (ReportWebAttr) info.getContent().getHoldObject(); + List jsImports = Arrays.asList(attr.getJSImport()); + String jsName = GeneralUtils.objectToString(info.getContent().getReplaceObject()); + for (int i = 0, len = jsImports.size(); i < len; i++) { + if (StringUtils.equals(jsImports.get(i), jsName)) { + jsImports.set(i, ShowValueUtils.replaceAll(jsName, findStr, replaceStr)); + } + } + attr.clearJSImportList(); + for (int i = 0, len = jsImports.size(); i < len; i++) { + attr.addJSImport(jsImports.get(i)); + } + } + } + + @Override + public String getInfoShowStr(Info info) { + return GeneralUtils.objectToString(info.getContent().getReplaceObject()); + } + + @Override + boolean check(Info info) { + return true; + } + }, /** * DBTableData——SQL */ DB_TABLE_DATA("DBTableData") { @Override - boolean check(Info info) { + boolean check (Info info){ DBTableData dbTableData = (DBTableData) info.getContent().getReplaceObject(); return StringUtils.equals(dbTableData.getQuery(), info.getContent().getOldShowStr()); } @Override - public Map getValue(Object... o) { + public Map getValue (Object...o){ HashMap map = new HashMap<>(); addValue2Map(contentKey, ((DBTableData) o[0]).getQuery(), map); return map; } @Override - public void setValue(Info info, String findStr, String replaceStr, List> operatorArray) { + public void setValue (Info info, String findStr, String replaceStr, List < Pair < Integer, Integer >> operatorArray){ DBTableData dbTableData = (DBTableData) info.getContent().getReplaceObject(); info.updateOldStr(dbTableData.getQuery(), findStr); dbTableData.setQuery(ShowValueUtils.replaceAll(dbTableData.getQuery(), findStr, replaceStr)); - //todo DesignTableDataManager } @Override - public String getInfoShowStr(Info info) { + public String getInfoShowStr (Info info){ return info.getInfoShowStr(info); } }; @@ -256,4 +297,4 @@ public enum ReplaceObject implements DealWithInfoValue { abstract boolean check(Info info); -} + } diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/info/base/SearchTag.java b/designer-realize/src/main/java/com/fr/design/actions/replace/info/base/SearchTag.java index 1bbba05b35..b5e202bcb1 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/info/base/SearchTag.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/info/base/SearchTag.java @@ -44,6 +44,18 @@ public class SearchTag { * 单元格属性-其他-内容提示 */ public static final int CELL_TOOL_TIP = 8; + /** + * 数据字典-公式-显示值 + */ + public static final int DICT_EXCUTE = 9; + /** + * 数据字典-公式-实际值 + */ + public static final int DICT_PRODUCE = 10; + /** + * 引用JS + */ + public static final int IMPORT_JS = 11; 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 96ee17b6cd..4843df57f4 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 @@ -9,6 +9,7 @@ import com.fr.design.actions.replace.utils.ShowValueUtils; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.dialog.UIDialog; import com.fr.design.file.HistoryTemplateListCache; +import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.DesignerContext; @@ -22,6 +23,7 @@ import com.fr.stable.StringUtils; import javax.swing.JOptionPane; import javax.swing.JPanel; import java.awt.BorderLayout; +import java.awt.Color; import java.awt.Dimension; import java.awt.Point; import java.awt.event.ActionEvent; @@ -117,8 +119,10 @@ public class ITReplaceMainDialog extends UIDialog { JPanel center = new JPanel(new BorderLayout()); + UIComboBox replaceComboBox = northPane.getReplaceInputCombobox(); northPane.getFindInputCombobox().setEditable(true); - northPane.getReplaceInputCombobox().setEditable(false); + replaceComboBox.setEnabled(false); + replaceComboBox.setEditable(true); northPane.getReplaceButton().setEnabled(false); ((UITextField) (northPane.getFindInputCombobox().getEditor().getEditorComponent())).setPlaceholder(Toolkit.i18nText("Fine-Design_Replace_Search_Input")); @@ -160,7 +164,8 @@ public class ITReplaceMainDialog extends UIDialog { private void replace() { String searchStr = ((UITextField) (northPane.getFindInputCombobox().getEditor().getEditorComponent())).getText(); String replaceStr = ((UITextField) (northPane.getReplaceInputCombobox().getEditor().getEditorComponent())).getText(); - if (StringUtils.equals(getSearchStr(), searchStr)) { + //替换内容为空需要触发搜索 + if (StringUtils.equals(getSearchStr(), searchStr) && StringUtils.isNotEmpty(replaceStr)) { if (isITReplaceValid() && checkTemplateChanged(searchResultList)) { for (Info info : searchResultList) { if (info.getContent().isSelected()) { @@ -298,7 +303,8 @@ public class ITReplaceMainDialog extends UIDialog { northPane.getResultLabel().setText("" + Toolkit.i18nText("Fine-Design_Replace_Search_Finish") + "" + searchResultList.size() + "" + Toolkit.i18nText("Fine-Design_Replace_Result")); } ITTableEditorPane.ITHeaderRenderer renderer = (ITTableEditorPane.ITHeaderRenderer) getEditTable().getTableHeader().getDefaultRenderer(); - renderer.refreshHeader(getEditTable()); + //刷新表头,并且重新勾选中表头全选框 + renderer.refreshHeader(getEditTable(), true); itTableEditor.fireTableDataChanged(); northPane.refreshFindInputComboBoxItems(); setSearchFlag(true); @@ -306,18 +312,17 @@ public class ITReplaceMainDialog extends UIDialog { //如果有结果,默认选中第一行 if (searchResultList.size() > 0){ getEditTable().addRowSelectionInterval(FIRST_ROW,FIRST_ROW); - northPane.getReplaceButton().setEnabled(true); } - - //设置替换输入框的可用性 - if (StringUtils.isNotEmpty(searchStr)) { - ((UITextField) (northPane.getReplaceInputCombobox().getEditor().getEditorComponent())).setEditable(true); - northPane.getReplaceInputCombobox().setEditable(true); + //更新替换按钮可用性 + if (StringUtils.isEmpty(searchStr) || searchResultList.size() == 0){ + northPane.getReplaceButton().setEnabled(false); } else { - ((UITextField) (northPane.getReplaceInputCombobox().getEditor().getEditorComponent())).setEditable(false); - northPane.getReplaceInputCombobox().setEditable(false); + northPane.getReplaceButton().setEnabled(true); } + + //设置替换输入框的可用性 + northPane.getReplaceInputCombobox().setEnabled(StringUtils.isNotEmpty(searchStr)); } else { //todo } diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITTableEditorPane.java b/designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITTableEditorPane.java index 4d2f39718d..0a743d34eb 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITTableEditorPane.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/ui/ITTableEditorPane.java @@ -72,17 +72,8 @@ public class ITTableEditorPane extends BasicPane { int col = ((JTable) e.getSource()).columnAtPoint(e.getPoint()); if (col == ITReplaceSouthPanel.CHECKBOX_INDEX) { ITContent content = (ITContent) editTable.getValueAt(row, ITReplaceSouthPanel.CONTENT_INDEX); - if (content.isSelected()) { - content.setSelected(false); - editTable.setValueAt(content.isSelected(), row, col); - ITReplaceMainDialog.selectCount--; - ITReplaceMainDialog.getInstance().getNorthPane().getReplaceButton().setEnabled(ITReplaceMainDialog.selectCount > 0); - } else { - content.setSelected(true); - editTable.setValueAt(content.isSelected(), row, col); - ITReplaceMainDialog.selectCount++; - ITReplaceMainDialog.getInstance().getNorthPane().getReplaceButton().setEnabled(true); - } + //改变面板的各个状态 + changeComponentStatus(content, row, col); } } @@ -90,10 +81,35 @@ public class ITTableEditorPane extends BasicPane { UIScrollPane scrollPane = new UIScrollPane(editTable); scrollPane.setBorder(new UIRoundedBorder(UIConstants.TITLED_BORDER_COLOR, 1, UIConstants.ARC)); pane.add(scrollPane, BorderLayout.CENTER); + } - + /** + * 改变面板的各个状态(替换按钮、表头勾选框) + * @param content + * @param row + * @param col + */ + public void changeComponentStatus(ITContent content, int row, int col) { + if (content.isSelected()) { + content.setSelected(false); + editTable.setValueAt(content.isSelected(), row, col); + ITReplaceMainDialog.selectCount--; + //如果没有选中,替换按钮需要置灰 + ITReplaceMainDialog.getInstance().getNorthPane().getReplaceButton().setEnabled(ITReplaceMainDialog.selectCount > 0); + } else { + content.setSelected(true); + editTable.setValueAt(content.isSelected(), row, col); + ITReplaceMainDialog.selectCount++; + ITReplaceMainDialog.getInstance().getNorthPane().getReplaceButton().setEnabled(true); + } + //更新表头的勾选框状态 + if (editTable.getTableHeader().getDefaultRenderer() instanceof ITHeaderRenderer) { + ITHeaderRenderer renderer = (ITHeaderRenderer) editTable.getTableHeader().getDefaultRenderer(); + renderer.refreshHeader(editTable, ITReplaceMainDialog.selectCount >= editTable.getRowCount()); + } } + public UITableModelAdapter getTableModel() { return tableModel; } @@ -142,8 +158,8 @@ public class ITTableEditorPane extends BasicPane { * * @param table */ - public void refreshHeader(JTable table) { - selectBox.setSelected(true); + public void refreshHeader(JTable table, boolean value) { + selectBox.setSelected(value); int rowHeight = table.getRowHeight(); table.updateUI(); table.setRowHeight(rowHeight);