From bdb3e25edeb355538b396dfa94744504ce9351a4 Mon Sep 17 00:00:00 2001 From: "Destiny.Lin" Date: Thu, 27 Oct 2022 15:38:25 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-80695=20=E3=80=90=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E5=85=A8=E5=B1=80=E7=BA=A7=E5=88=AB=E6=9F=A5=E6=89=BE=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E4=BA=8C=E6=9C=9F=E3=80=91=E8=AE=BE=E7=BD=AE=E9=A1=B9?= =?UTF-8?q?=E4=B8=BB=E8=A6=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../actions/replace/action/ShowValue.java | 22 +- .../action/setting/CellFormatType.java | 257 ++++++++++++ .../replace/action/setting/CellGroupType.java | 246 ++++++++++++ .../action/setting/SettingContent.java | 72 ++++ .../action/setting/SettingController.java | 374 ++++++++++++++++++ .../action/SearchCellDSColumnAction.java | 82 ++++ .../action/SearchCellFormatAction.java | 92 +++++ .../action/SearchConnectionAction.java | 108 +++++ .../setting/action/SearchDSColumnAction.java | 87 ++++ 9 files changed, 1338 insertions(+), 2 deletions(-) create mode 100644 designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/CellFormatType.java create mode 100644 designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/CellGroupType.java create mode 100644 designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/SettingContent.java create mode 100644 designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/SettingController.java create mode 100644 designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/action/SearchCellDSColumnAction.java create mode 100644 designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/action/SearchCellFormatAction.java create mode 100644 designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/action/SearchConnectionAction.java create mode 100644 designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/action/SearchDSColumnAction.java diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/action/ShowValue.java b/designer-realize/src/main/java/com/fr/design/actions/replace/action/ShowValue.java index 02ded341eb..34211f1f8a 100644 --- a/designer-realize/src/main/java/com/fr/design/actions/replace/action/ShowValue.java +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/action/ShowValue.java @@ -3,6 +3,7 @@ package com.fr.design.actions.replace.action; import com.fr.design.actions.replace.info.Info; import com.fr.design.mainframe.JTemplate; +import java.util.ArrayList; import java.util.List; /** @@ -20,7 +21,9 @@ public interface ShowValue { * @param jTemplate * @return */ - List showSearchValue(JTemplate jTemplate); + default List showSearchValue(JTemplate jTemplate) { + return new ArrayList<>(); + } /** * 对搜索结果进行过滤 @@ -29,6 +32,21 @@ public interface ShowValue { * @param list * @return */ - List addMatchResult(String str, List list); + default List addMatchResult(String str, List list) { + return new ArrayList<>(); + } + + /** + * 对搜索结果进行过滤(多个过滤条件,主要针对设置项) + * + * @param list + * @param settingStr + * @param extraStr + * @return + */ + default List addMatchResult(List list, String settingStr, String extraStr) { + return new ArrayList<>(); + } + } diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/CellFormatType.java b/designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/CellFormatType.java new file mode 100644 index 0000000000..9f77d7d2b4 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/CellFormatType.java @@ -0,0 +1,257 @@ +package com.fr.design.actions.replace.action.setting; + +import com.fr.base.CoreDecimalFormat; +import com.fr.base.NameStyle; +import com.fr.base.TextFormat; +import com.fr.data.core.FormatField; +import com.fr.design.actions.replace.info.Info; +import com.fr.general.date.FineDateFormat; +import com.fr.report.cell.CellElement; +import com.fr.stable.StringUtils; +import org.jetbrains.annotations.Nullable; + +import java.text.Format; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * @author Destiny.Lin + * @version 11.0 + * created by Destiny.Lin on 2022-10-25 + */ +public enum CellFormatType { + + /** + * 单元格-格式-数字 + */ + CELL_FORMAT_NUMBER(SettingContent.FORMAT_NUMBER) { + @Override + public boolean hasExpand(String parentStr) { + return true; + } + + @Override + public List getItems() { + return Arrays.asList(FormatField.getInstance().getFormatArray(FormatField.getInstance().getContents(SettingContent.FORMAT_NUMBER))); + } + + @Override + public boolean isNeed(CellElement cellElement, String firstStr, String secondStr) { + Format format = cellElement.getStyle().getFormat(); + return format instanceof CoreDecimalFormat && StringUtils.equals(((CoreDecimalFormat) format).toPattern(), secondStr); + } + }, + /** + * 单元格-格式-常规 + */ + CELL_FORMAT_COMMON(SettingContent.FORMAT_COMMON) { + @Override + public List getItems() { + return super.getItems(); + } + + @Override + public boolean isNeed(CellElement cellElement, String firstStr, String secondStr) { + return cellElement.getStyle().getFormat() == null; + } + }, + /** + * 单元格-格式-货币 + */ + CELL_FORMAT_MONEY(SettingContent.FORMAT_MONEY) { + @Override + public boolean hasExpand(String parentStr) { + return true; + } + + @Override + public List getItems() { + return Arrays.asList(FormatField.getInstance().getFormatArray(FormatField.getInstance().getContents(SettingContent.FORMAT_MONEY))); + } + + @Override + public boolean isNeed(CellElement cellElement, String firstStr, String secondStr) { + Format format = cellElement.getStyle().getFormat(); + return format instanceof CoreDecimalFormat && StringUtils.equals(((CoreDecimalFormat) format).toPattern(), secondStr); + } + }, + /** + * 单元格-格式-日期 + */ + CELL_FORMAT_DATE(SettingContent.FORMAT_DATE) { + @Override + public boolean hasExpand(String parentStr) { + return true; + } + + @Override + public List getItems() { + return Arrays.asList(FormatField.getInstance().getFormatArray(FormatField.getInstance().getContents(SettingContent.FORMAT_DATE))); + } + + @Override + public boolean isNeed(CellElement cellElement, String firstStr, String secondStr) { + Format format = cellElement.getStyle().getFormat(); + return format instanceof FineDateFormat && StringUtils.equals(((FineDateFormat) format).toPattern(), secondStr); + } + }, + /** + * 单元格-格式-时间 + */ + CELL_FORMAT_TIME(SettingContent.FORMAT_TIME) { + @Override + public boolean hasExpand(String parentStr) { + return true; + } + + @Override + public List getItems() { + return Arrays.asList(FormatField.getInstance().getFormatArray(FormatField.getInstance().getContents(SettingContent.FORMAT_TIME))); + } + + @Override + public boolean isNeed(CellElement cellElement, String firstStr, String secondStr) { + Format format = cellElement.getStyle().getFormat(); + return format instanceof FineDateFormat && StringUtils.equals(((FineDateFormat) format).toPattern(), secondStr); + } + }, + /** + * 单元格-格式-科学计数 + */ + CELL_FORMAT_SCIENCE(SettingContent.FORMAT_SCIENCE) { + @Override + public boolean hasExpand(String parentStr) { + return true; + } + + @Override + public List getItems() { + return Arrays.asList(FormatField.getInstance().getFormatArray(FormatField.getInstance().getContents(SettingContent.FORMAT_SCIENCE))); + } + + @Override + public boolean isNeed(CellElement cellElement, String firstStr, String secondStr) { + Format format = cellElement.getStyle().getFormat(); + return format instanceof CoreDecimalFormat && StringUtils.equals(((CoreDecimalFormat) format).toPattern(), secondStr); + } + }, + /** + * 单元格-格式-百分比 + */ + CELL_FORMAT_PERCENT(SettingContent.FORMAT_PERCENT) { + @Override + public boolean hasExpand(String parentStr) { + return true; + } + + @Override + public List getItems() { + return Arrays.asList(FormatField.getInstance().getFormatArray(FormatField.getInstance().getContents(SettingContent.FORMAT_PERCENT))); + } + + @Override + public boolean isNeed(CellElement cellElement, String firstStr, String secondStr) { + Format format = cellElement.getStyle().getFormat(); + return format instanceof CoreDecimalFormat && StringUtils.equals(((CoreDecimalFormat) format).toPattern(), secondStr); + } + }, + /** + * 单元格-格式-千分比 + */ + CELL_FORMAT_PERMILLAGE(SettingContent.FORMAT_PERMILLAGE) { + @Override + public boolean hasExpand(String parentStr) { + return true; + } + + @Override + public List getItems() { + return Arrays.asList(FormatField.getInstance().getFormatArray(FormatField.getInstance().getContents(SettingContent.FORMAT_PERMILLAGE))); + } + + @Override + public boolean isNeed(CellElement cellElement, String firstStr, String secondStr) { + Format format = cellElement.getStyle().getFormat(); + return format instanceof CoreDecimalFormat && StringUtils.equals(((CoreDecimalFormat) format).toPattern(), secondStr); + } + }, + /** + * 单元格-格式-文本 + */ + CELL_FORMAT_TEXT(SettingContent.FORMAT_TEXT) { + @Override + public boolean isNeed(CellElement cellElement, String firstStr, String secondStr) { + Format format = cellElement.getStyle().getFormat(); + return format instanceof TextFormat; + } + }; + + + private String name; + + CellFormatType(String name) { + this.name = name; + } + + + /** + * 匹配 + * + * @param name + * @return + */ + @Nullable + public static CellFormatType match(String name) { + CellFormatType[] values = CellFormatType.values(); + for (CellFormatType value : values) { + if (StringUtils.equals(value.name, name)) { + return value; + } + } + return null; + } + + /** + * 是否能扩展选项 + * + * @return 能扩展则返回true + */ + public boolean hasExpand(String parentStr) { + return false; + } + + /** + * 获取界面数据 + */ + public List getItems() { + return new ArrayList<>(); + } + + /** + * 是否是要查找的内容 + * + * @param cellElement + * @param firstStr + * @param secondStr + * @return + */ + public boolean isNeed(CellElement cellElement, String firstStr, String secondStr) { + return false; + } + + /** + * 替换 + * + * @param info 存储信息的数据结构 + * @param firstStr 用户输入的第一级下拉框内容 + * @param secondStr 用户输入的第二级下拉框内容 + */ + public void replace(Info info, String firstStr, String secondStr) { + CellElement cellElement = (CellElement) info.getContent().getReplaceObject(); + cellElement.setStyle(cellElement.getStyle().deriveFormat(FormatField.getInstance().getFormat(FormatField.getInstance().getContents(firstStr), secondStr))); + if (cellElement.getStyle() instanceof NameStyle) { + ((NameStyle) cellElement.getStyle()).refreshStyle(); + } + } +} diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/CellGroupType.java b/designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/CellGroupType.java new file mode 100644 index 0000000000..8e769b4715 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/CellGroupType.java @@ -0,0 +1,246 @@ +package com.fr.design.actions.replace.action.setting; + + +import com.fr.data.util.function.AverageFunction; +import com.fr.data.util.function.CountFunction; +import com.fr.data.util.function.DataFunction; +import com.fr.data.util.function.MaxFunction; +import com.fr.data.util.function.MinFunction; +import com.fr.data.util.function.NoneFunction; +import com.fr.data.util.function.SumFunction; +import com.fr.design.actions.replace.info.Info; +import com.fr.report.cell.CellElement; +import com.fr.report.cell.cellattr.core.group.DSColumn; +import com.fr.report.cell.cellattr.core.group.FunctionGrouper; +import com.fr.report.cell.cellattr.core.group.RecordGrouper; +import com.fr.report.cell.cellattr.core.group.SummaryGrouper; +import com.fr.stable.StringUtils; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 处理单元格的格式(对于高级,由于需要自定义,不加入处理范围) + * + * @author Destiny.Lin + * @version 11.0 + * created by Destiny.Lin on 2022-10-26 + */ +public enum CellGroupType { + + /** + * 分组 + */ + GROUP(SettingContent.DIGIT_SETTING_GROUP) { + @Override + public List getItems() { + List items = new ArrayList() { + { + add(SettingContent.GROUP_COMMON); + add(SettingContent.GROUP_CONTINUUM); + } + }; + return items; + } + + + @Override + public boolean isNeed(CellElement cellElement, String firstStr, String secondStr) { + DSColumn column = (DSColumn) cellElement.getValue(); + RecordGrouper grouper = column.getGrouper(); + return grouper instanceof FunctionGrouper && grouper.getDivideMode() == getGroupType(secondStr); + } + + }, + /** + * 列表 + */ + LIST(SettingContent.DIGIT_SETTING_LIST) { + @Override + public boolean hasExpand(String parentStr) { + return false; + } + + + @Override + public boolean isNeed(CellElement cellElement, String firstStr, String secondStr) { + DSColumn column = (DSColumn) cellElement.getValue(); + RecordGrouper grouper = column.getGrouper(); + return grouper instanceof FunctionGrouper && grouper.getDivideMode() == getGroupType(firstStr); + } + }, + /** + * 汇总 + */ + SUM(SettingContent.DIGIT_SETTING_SUM) { + @Override + public List getItems() { + List items = new ArrayList() { + { + add(SettingContent.SUMMARY_SUM); + add(SettingContent.SUMMARY_AVERAGE); + add(SettingContent.SUMMARY_MAX); + add(SettingContent.SUMMARY_MIN); + add(SettingContent.SUMMARY_COUNT); + add(SettingContent.SUMMARY_NONE); + } + }; + return items; + } + + @Override + public boolean isNeed(CellElement cellElement, String firstStr, String secondStr) { + DSColumn column = (DSColumn) cellElement.getValue(); + RecordGrouper grouper = column.getGrouper(); + return grouper instanceof SummaryGrouper && ((SummaryGrouper) grouper).getFunction() != null && StringUtils.equals(((SummaryGrouper) grouper).getFunction().getClass().getSimpleName(), getSummaryType(secondStr)); + } + + @Override + public void replace(Info info, String firstStr, String secondStr) { + SummaryGrouper grouper = new SummaryGrouper(); + grouper.setFunction(createDataFunction(secondStr)); + CellElement cellElement = (CellElement) info.getContent().getReplaceObject(); + DSColumn column = (DSColumn) cellElement.getValue(); + column.setGrouper(grouper); + } + }; + + private String name; + + private Map groupMap = new HashMap() { + { + put(SettingContent.GROUP_COMMON, FunctionGrouper.GROUPING_MODE); + put(SettingContent.GROUP_CONTINUUM, FunctionGrouper.CONTINUUM_MODE); + put(SettingContent.DIGIT_LIST, FunctionGrouper.LIST_MODE); + } + }; + private Map summaryMap = new HashMap() { + { + put(SettingContent.SUMMARY_SUM, SUM_FUNCTION); + put(SettingContent.SUMMARY_AVERAGE, AVERAGE_FUNCTION); + put(SettingContent.SUMMARY_MAX, MAX_FUNCTION); + put(SettingContent.SUMMARY_MIN, MIN_FUNCTION); + put(SettingContent.SUMMARY_COUNT, COUNT_FUNCTION); + put(SettingContent.SUMMARY_NONE, NONE_FUNCTION); + } + }; + + public static final String SUM_FUNCTION = "SumFunction"; + public static final String AVERAGE_FUNCTION = "AverageFunction"; + public static final String MAX_FUNCTION = "MaxFunction"; + public static final String MIN_FUNCTION = "MinFunction"; + public static final String COUNT_FUNCTION = "CountFunction"; + public static final String NONE_FUNCTION = "NoneFunction"; + + + CellGroupType(String name) { + this.name = name; + } + + + /** + * 匹配 + * + * @param name + * @return + */ + @Nullable + public static CellGroupType match(String name) { + CellGroupType[] values = CellGroupType.values(); + for (CellGroupType value : values) { + if (StringUtils.equals(value.name, name)) { + return value; + } + } + return null; + } + + /** + * 是否是要查找的内容 + * + * @param cellElement + * @param firstStr + * @param secondStr + * @return + */ + public boolean isNeed(CellElement cellElement, String firstStr, String secondStr) { + DSColumn column = (DSColumn) cellElement.getValue(); + RecordGrouper recordGrouper = column.getGrouper(); + return recordGrouper instanceof FunctionGrouper && recordGrouper.getDivideMode() == getGroupType(secondStr); + } + + /** + * 匹配分组 + * + * @param str + * @return + */ + public Integer getGroupType(String str) { + return groupMap.getOrDefault(str, -1); + } + + /** + * 匹配汇总 + */ + public String getSummaryType(String str) { + return summaryMap.getOrDefault(str, StringUtils.EMPTY); + } + + /** + * 创建对应汇总的DataFunction + * + * @param str 汇总子级下拉框的内容 + * @return 指定类型的DataFunction + */ + public DataFunction createDataFunction(String str) { + switch (getSummaryType(str)) { + case SUM_FUNCTION: + return new SumFunction(); + case AVERAGE_FUNCTION: + return new AverageFunction(); + case MAX_FUNCTION: + return new MaxFunction(); + case MIN_FUNCTION: + return new MinFunction(); + case COUNT_FUNCTION: + return new CountFunction(); + case NONE_FUNCTION: + return new NoneFunction(); + } + return new NoneFunction(); + } + + /** + * 是否能扩展选项 + * + * @return 能扩展则返回true + */ + public boolean hasExpand(String parentStr) { + return true; + } + + /** + * 获取界面数据 + */ + public List getItems() { + return new ArrayList<>(); + } + + /** + * 替换 + * + * @param info 存储信息的数据结构 + * @param firstStr 用户输入的第一级下拉框 + * @param secondStr 用户输入的第二级下拉框 + */ + public void replace(Info info, String firstStr, String secondStr) { + FunctionGrouper grouper = new FunctionGrouper(); + grouper.setDivideMode(getGroupType(secondStr)); + CellElement cellElement = (CellElement) info.getContent().getReplaceObject(); + DSColumn column = (DSColumn) cellElement.getValue(); + column.setGrouper(grouper); + } +} diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/SettingContent.java b/designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/SettingContent.java new file mode 100644 index 0000000000..67211b77e9 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/SettingContent.java @@ -0,0 +1,72 @@ +package com.fr.design.actions.replace.action.setting; + +import com.fr.design.actions.replace.utils.ShowValueUtils; +import com.fr.design.i18n.Toolkit; + +/** + * @author Destiny.Lin + * @version 11.0 + * created by Destiny.Lin on 2022-10-24 + */ +public class SettingContent { + + public static final String CELL_FORMAT_NAME = ShowValueUtils.joinStr4Position(Toolkit.i18nText("Fine-Design_Basic_Cell"), Toolkit.i18nText("Fine-Design_Report_Base_Format")); + public static final String CELL_DATA_SETTING_NAME = ShowValueUtils.joinStr4Position(Toolkit.i18nText("Fine-Design_Basic_Cell"), Toolkit.i18nText("Fine-Design_Chart_Data_Setting")); + public static final String CELL_DS_COLUMN_NAME = ShowValueUtils.joinStr4Position(Toolkit.i18nText("Fine-Design_Basic_Cell"), Toolkit.i18nText("Fine-Design_Basic_DS_Column")); + public static final String DATASOURCE_CONNECTION_NAME = ShowValueUtils.joinStr4Position(Toolkit.i18nText("Fine-Design_Replace_Data_Source"), Toolkit.i18nText("Fine-Design_Replace_Data_Connection")); + public static final String DATASOURCE_COLLECT_NAME = ShowValueUtils.joinStr4Position(Toolkit.i18nText("Fine-Design_Replace_Data_Source"), Toolkit.i18nText("Fine-Design_Replace_Data_Collect")); + + /** + * 单元格-格式 + */ + public static final String FORMAT_COMMON = Toolkit.i18nText("Fine-Design_Replace_Common"); + public static final String FORMAT_NUMBER = Toolkit.i18nText("Fine-Design_Replace_Number"); + public static final String FORMAT_MONEY = Toolkit.i18nText("Fine-Design_Replace_Money"); + public static final String FORMAT_PERCENT = Toolkit.i18nText("Fine-Design_Replace_Percent"); + public static final String FORMAT_PERMILLAGE = Toolkit.i18nText("Fine-Design_Replace_Permillage"); + public static final String FORMAT_SCIENCE = Toolkit.i18nText("Fine-Design_Replace_Science"); + public static final String FORMAT_DATE = Toolkit.i18nText("Fine-Design_Replace_Date"); + public static final String FORMAT_TIME = Toolkit.i18nText("Fine-Design_Replace_Time"); + public static final String FORMAT_TEXT = Toolkit.i18nText("Fine-Design_Replace_Text"); + + + /** + * 单元格-数据设置 + */ + public static final String DIGIT_SETTING_GROUP = Toolkit.i18nText("Fine-Design_Replace_Group"); + public static final String DIGIT_SETTING_LIST = Toolkit.i18nText("Fine-Design_Replace_List"); + public static final String DIGIT_SETTING_SUM = Toolkit.i18nText("Fine-Design_Replace_Sum"); + + /** + * 单元格-数据设置-分组 + */ + public static final String GROUP_COMMON = Toolkit.i18nText("Fine-Design_Report_Common"); + public static final String GROUP_CONTINUUM = Toolkit.i18nText("Fine-Design_Report_Continuum"); + + /** + * 单元格-数据设置-列表 + */ + public static final String DIGIT_LIST = Toolkit.i18nText("Fine-Design_Report_Bind_Column_Select"); + + /** + * 单元格-数据设置-汇总 + */ + public static final String SUMMARY_SUM = Toolkit.i18nText("Fine-Design_DataFunction_Sum"); + public static final String SUMMARY_AVERAGE = Toolkit.i18nText("Fine-Design_DataFunction_Average"); + public static final String SUMMARY_MAX = Toolkit.i18nText("Fine-Design_DataFunction_Max"); + public static final String SUMMARY_MIN = Toolkit.i18nText("Fine-Design_DataFunction_Min"); + public static final String SUMMARY_COUNT = Toolkit.i18nText("Fine-Design_DataFunction_Count"); + public static final String SUMMARY_NONE = Toolkit.i18nText("Fine-Design_DataFunction_None"); + + /** + * 数据连接 + */ + public static final String CONNECTION_TEMPLATE = Toolkit.i18nText("Fine-Design_Basic_DS_Report_TableData"); + + /** + * 扩展出来的可能的选项 + */ + public static final String DS_COLUMN_EXPEND = "DS_COLUMN_EXPEND"; + + +} diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/SettingController.java b/designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/SettingController.java new file mode 100644 index 0000000000..fa7fcc0b09 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/SettingController.java @@ -0,0 +1,374 @@ +package com.fr.design.actions.replace.action.setting; + + +import com.fr.data.TableDataSource; +import com.fr.design.actions.replace.action.ShowValue; +import com.fr.design.actions.replace.action.setting.action.SearchCellDSColumnAction; +import com.fr.design.actions.replace.action.setting.action.SearchCellFormatAction; +import com.fr.design.actions.replace.action.setting.action.SearchConnectionAction; +import com.fr.design.actions.replace.action.setting.action.SearchDSColumnAction; +import com.fr.design.actions.replace.info.CellInfo; +import com.fr.design.actions.replace.info.ConnectionInfo; +import com.fr.design.actions.replace.info.Info; +import com.fr.design.actions.replace.ui.ITReplaceNorthPanel; +import com.fr.design.data.DesignTableDataManager; +import com.fr.design.file.HistoryTemplateListCache; +import com.fr.design.mainframe.JTemplate; +import com.fr.file.ConnectionConfig; +import com.fr.general.data.TableDataColumn; +import com.fr.report.cell.CellElement; +import com.fr.report.cell.cellattr.core.group.DSColumn; +import com.fr.stable.StringUtils; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +/** + * 设置项的查找内容 + * + * @author Destiny.Lin + * @version 11.0 + * created by Destiny.Lin on 2022-10-24 + */ +public enum SettingController implements ShowValue { + + /** + * 单元格-格式 + */ + CELL_FORMAT(SettingContent.CELL_FORMAT_NAME) { + @Override + public List getItems() { + return ITReplaceNorthPanel.formatItems; + } + + @Override + public List showSearchValue(JTemplate jTemplate) { + SearchCellFormatAction.getInstance().search4Infos(jTemplate); + return SearchCellFormatAction.getInstance().getCellInfos(); + } + + @Override + public List addMatchResult(List list, String settingStr, String extraStr) { + List cellInfos = new ArrayList<>(); + for (Info info : list) { + CellElement cellElement = (CellElement) info.getContent().getReplaceObject(); + CellFormatType type = CellFormatType.match(settingStr); + if (type != null && type.isNeed(cellElement, settingStr, extraStr)) { + cellInfos.add((CellInfo) info); + } + } + return cellInfos; + } + + @Override + public boolean hasExpand(String str, String parentStr) { + CellFormatType type = CellFormatType.match(parentStr); + if (type != null) { + return type.hasExpand(parentStr); + } + return false; + } + + @Override + public List getExtraItems(String str) { + CellFormatType type = CellFormatType.match(str); + if (type != null) { + return type.getItems(); + } + return new ArrayList<>(); + } + + @Override + public void replace(Info info, String firstStr, String secondStr) { + CellFormatType type = CellFormatType.match(firstStr); + if (type != null) { + type.replace(info, firstStr, secondStr); + } + } + }, + /** + * 单元格-数据设置 + */ + CELL_DATA_SETTING(SettingContent.CELL_DATA_SETTING_NAME) { + @Override + public List getItems() { + return ITReplaceNorthPanel.digitItems; + } + + @Override + public List showSearchValue(JTemplate jTemplate) { + SearchCellDSColumnAction.getInstance().search4Infos(jTemplate); + return SearchCellDSColumnAction.getInstance().getCellInfos(); + } + + @Override + public List addMatchResult(List list, String settingStr, String extraStr) { + List cellInfos = new ArrayList<>(); + for (Info info : list) { + CellElement cellElement = (CellElement) info.getContent().getReplaceObject(); + //能到这步说明单元格里是数据列 + CellGroupType cellGroupType = CellGroupType.match(settingStr); + if (cellGroupType != null && cellGroupType.isNeed(cellElement, settingStr, extraStr)) { + cellInfos.add((CellInfo) info); + } + } + return cellInfos; + } + + @Override + public List getExtraItems(String str) { + CellGroupType type = CellGroupType.match(str); + if (type != null) { + return type.getItems(); + } + return new ArrayList<>(); + } + + @Override + public boolean hasExpand(String str, String parentStr) { + CellGroupType type = CellGroupType.match(parentStr); + if (type != null) { + return type.hasExpand(parentStr); + } + return false; + } + + @Override + public void replace(Info info, String firstStr, String secondStr) { + CellGroupType type = CellGroupType.match(firstStr); + if (type != null) { + type.replace(info, firstStr, secondStr); + } + } + }, + /** + * 单元格-数据列 + */ + CELL_DS_COLUMN(SettingContent.CELL_DS_COLUMN_NAME) { + @Override + public List showSearchValue(JTemplate jTemplate) { + SearchCellDSColumnAction.getInstance().search4Infos(jTemplate); + return SearchCellDSColumnAction.getInstance().getCellInfos(); + } + + @Override + public List addMatchResult(List list, String settingStr, String extraStr) { + List cellInfos = new ArrayList<>(); + for (Info info : list) { + CellElement cellElement = (CellElement) info.getContent().getReplaceObject(); + //能到这步说明单元格里是数据列 + DSColumn dsColumn = (DSColumn) cellElement.getValue(); + if (isNeed(dsColumn, settingStr, extraStr)) { + cellInfos.add((CellInfo) info); + } + } + return cellInfos; + } + + public boolean isNeed(DSColumn dsColumn, String settingStr, String extraStr) { + return dsColumn != null && StringUtils.equals(settingStr, dsColumn.getDSName()) && dsColumn.getColumn() != null && StringUtils.equals(dsColumn.getColumnName(), extraStr); + } + + @Override + public List getItems() { + JTemplate jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + List tableDataArray = new ArrayList<>(); + if (jTemplate != null && jTemplate.getTarget() instanceof TableDataSource) { + TableDataSource source = (TableDataSource) jTemplate.getTarget(); + Iterator dataIterator = source.getTableDataNameIterator(); + while (dataIterator.hasNext()) { + String dataName = (String) dataIterator.next(); + tableDataArray.add(dataName); + } + } + return tableDataArray; + } + + @Override + public List getExtraItems(String str) { + JTemplate jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + List tableDataArray = new ArrayList<>(); + if (jTemplate != null) { + TableDataSource source = jTemplate.getTarget(); + tableDataArray = Arrays.asList(DesignTableDataManager.getSelectedColumnNames(source, str)); + } + return tableDataArray; + } + + @Override + public boolean hasExpand(String str, String parentStr) { + return true; + } + + @Override + public void replace(Info info, String firstStr, String secondStr) { + CellElement cellElement = (CellElement) info.getContent().getReplaceObject(); + DSColumn dsColumn = (DSColumn) cellElement.getValue(); + dsColumn.setDSName(firstStr); + dsColumn.setColumn(TableDataColumn.createColumn(secondStr)); + + } + }, + /** + * 数据源-数据连接 + */ + DATASOURCE_CONNECTION(SettingContent.DATASOURCE_CONNECTION_NAME) { + @Override + public List showSearchValue(JTemplate jTemplate) { + SearchConnectionAction.getInstance().search4Infos(jTemplate); + return SearchConnectionAction.getInstance().getConnectionInfos(); + } + + @Override + public List addMatchResult(List list, String settingStr, String extraStr) { + List connectionInfos = new ArrayList<>(); + for (Info info : list) { + if (StringUtils.equals(info.getContent().getShowStr(), settingStr)) { + connectionInfos.add((ConnectionInfo) info); + } + } + return connectionInfos; + + } + + @Override + public List getItems() { + List nameList = new ArrayList<>(); + for (String name : ConnectionConfig.getInstance().getConnections().keySet()) { + nameList.add(name); + } + return nameList; + } + + }, + /** + * 数据源-数据集 + */ + DATASOURCE_COLLECT(SettingContent.DATASOURCE_COLLECT_NAME) { + @Override + public List showSearchValue(JTemplate jTemplate) { + SearchDSColumnAction.getInstance().search4Infos(jTemplate); + return SearchDSColumnAction.getInstance().getDsColumnInfos(); + } + + + @Override + public List addMatchResult(List list, String settingStr, String extraStr) { + return list; + } + + @Override + public List getItems() { + return ITReplaceNorthPanel.dsColumnItems; + } + + + }; + + + private String name; + + SettingController(String name) { + this.name = name; + } + + + /** + * 匹配 + * + * @param name + * @return + */ + @Nullable + public static SettingController match(String name) { + SettingController[] values = SettingController.values(); + for (SettingController value : values) { + if (StringUtils.equals(value.name, name)) { + return value; + } + } + return null; + } + + /** + * 获取界面的数据,使之与选项匹配 + * + * @param name 选项 + */ + public static List getSettingRefreshItems(String name) { + SettingController[] values = SettingController.values(); + for (SettingController value : values) { + if (StringUtils.equals(value.name, name)) { + return value.getItems(); + } + } + return new ArrayList<>(); + } + + /** + * 获取界面的数据,使之与选项匹配 + * + * @param parentStr 选项 + */ + public static List getSettingExtraRefreshItems(String str, String parentStr) { + SettingController[] values = SettingController.values(); + for (SettingController value : values) { + if (StringUtils.equals(value.name, str)) { + return value.getExtraItems(parentStr); + } + } + return new ArrayList<>(); + } + + /** + * 获取界面数据 + */ + public List getItems() { + return new ArrayList<>(); + } + + /** + * 获取扩展数据 + * + * @param str 父类名称 + * @return 扩展的数据列表 + */ + public List getExtraItems(String str) { + return new ArrayList<>(); + } + + /** + * 是否能扩展选项 + * + * @return 能扩展则返回true + */ + public boolean hasExpand(String str, String parentStr) { + return false; + } + + /** + * 替换 + * + * @param info 存储信息的数据结构 + * @param firstStr 用户设定的第一级下拉框的内容 + * @param secondStr 用户设定的第二级下拉框的内容 + */ + public void replace(Info info, String firstStr, String secondStr) { + + } + + /** + * 是否修改过 + * + * @param info 存储信息的数据结构 + * @param inputStr 用户搜索的一级下拉框内容 + * @param extraStr 用户搜索的二级下拉框内容 + * @return 没修改过则返回false + */ + public boolean isEverChanged(Info info, String inputStr, String extraStr) { + return false; + } +} diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/action/SearchCellDSColumnAction.java b/designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/action/SearchCellDSColumnAction.java new file mode 100644 index 0000000000..3a79231867 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/action/SearchCellDSColumnAction.java @@ -0,0 +1,82 @@ +package com.fr.design.actions.replace.action.setting.action; + +import com.fr.design.actions.replace.action.SearchAction; +import com.fr.design.actions.replace.action.content.cell.SearchCellAction; +import com.fr.design.actions.replace.info.CellInfo; +import com.fr.design.mainframe.JTemplate; +import com.fr.general.GeneralUtils; +import com.fr.report.cell.CellElement; +import com.fr.report.cell.cellattr.core.group.DSColumn; + +import java.util.ArrayList; +import java.util.List; + +/** + * 存储单元格-数据列 + * + * @author Destiny.Lin + * @version 11.0 + * created by Destiny.Lin on 2022-10-26 + */ +public class SearchCellDSColumnAction implements SearchAction { + private List cellInfos = new ArrayList<>(); + + private SearchCellDSColumnAction() { + } + + @Override + public void search4Infos(JTemplate jTemplate) { + List cellInfos = new ArrayList<>(); + SearchCellAction.getInstance().search4Infos(jTemplate); + for (CellInfo info : SearchCellAction.getInstance().getCellInfos()) { + CellElement cellElement = (CellElement) info.getContent().getReplaceObject(); + if (cellElement.getValue() instanceof DSColumn) { + info.getContent().setShowStr(GeneralUtils.objectToString(cellElement.getValue())); + cellInfos.add(info); + } + } + setCellInfos(cellInfos); + } + + public List getCellInfos() { + return cellInfos; + } + + public void setCellInfos(List cellInfos) { + this.cellInfos = cellInfos; + } + + /** + * 对外开放的获取对象的方法 + * + * @return + */ + public static SearchCellDSColumnAction getInstance() { + return SearchCellDSColumnActionEnum.SINGLETON.getInstance(); + } + + /** + * 枚举实现单例 + */ + private enum SearchCellDSColumnActionEnum { + /** + * 单例 + */ + SINGLETON; + + private SearchCellDSColumnAction instance; + + SearchCellDSColumnActionEnum() { + instance = new SearchCellDSColumnAction(); + } + + /** + * 获取对象 + * + * @return + */ + public SearchCellDSColumnAction getInstance() { + return instance; + } + } +} diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/action/SearchCellFormatAction.java b/designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/action/SearchCellFormatAction.java new file mode 100644 index 0000000000..bd607c625b --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/action/SearchCellFormatAction.java @@ -0,0 +1,92 @@ +package com.fr.design.actions.replace.action.setting.action; + +import com.fr.base.Formula; +import com.fr.design.actions.replace.action.SearchAction; +import com.fr.design.actions.replace.action.content.cell.SearchCellAction; +import com.fr.design.actions.replace.info.CellInfo; +import com.fr.design.mainframe.JTemplate; +import com.fr.general.GeneralUtils; +import com.fr.report.cell.CellElement; +import com.fr.report.cell.cellattr.core.group.DSColumn; + +import java.util.ArrayList; +import java.util.List; + +/** + * 存储有格式的单元格 + * + * @author Destiny.Lin + * @version 11.0 + * created by Destiny.Lin on 2022-10-25 + */ +public class SearchCellFormatAction implements SearchAction { + private List cellInfos = new ArrayList<>(); + + private SearchCellFormatAction() { + } + + @Override + public void search4Infos(JTemplate jTemplate) { + List cellInfos = new ArrayList<>(); + SearchCellAction.getInstance().search4Infos(jTemplate); + for (CellInfo info : SearchCellAction.getInstance().getCellInfos()) { + CellElement cellElement = (CellElement) info.getContent().getReplaceObject(); + if (isFormatValid(cellElement)) { + info.getContent().setShowStr(GeneralUtils.objectToString(cellElement.getValue())); + cellInfos.add(info); + } + } + setCellInfos(cellInfos); + } + + public boolean isFormatValid(CellElement cellElement) { + return cellElement.getStyle() != null + && (cellElement.getValue() instanceof Formula + || cellElement.getValue() instanceof DSColumn + || cellElement.getValue() instanceof String + || cellElement.getValue() instanceof Integer); + } + + public List getCellInfos() { + return cellInfos; + } + + public void setCellInfos(List cellInfos) { + this.cellInfos = cellInfos; + } + + /** + * 对外开放的获取对象的方法 + * + * @return + */ + public static SearchCellFormatAction getInstance() { + return SearchCellFormatActionEnum.SINGLETON.getInstance(); + } + + /** + * 枚举实现单例 + */ + private enum SearchCellFormatActionEnum { + /** + * 单例 + */ + SINGLETON; + + private SearchCellFormatAction instance; + + SearchCellFormatActionEnum() { + instance = new SearchCellFormatAction(); + } + + /** + * 获取对象 + * + * @return + */ + public SearchCellFormatAction getInstance() { + return instance; + } + } + +} diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/action/SearchConnectionAction.java b/designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/action/SearchConnectionAction.java new file mode 100644 index 0000000000..199361fd7b --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/action/SearchConnectionAction.java @@ -0,0 +1,108 @@ +package com.fr.design.actions.replace.action.setting.action; + +import com.fr.base.TableData; +import com.fr.base.TableDataConnection; +import com.fr.data.TableDataSource; +import com.fr.data.impl.Connection; +import com.fr.data.impl.NameDatabaseConnection; +import com.fr.design.actions.replace.action.SearchAction; +import com.fr.design.actions.replace.info.ConnectionInfo; +import com.fr.design.actions.replace.info.base.ITContent; +import com.fr.design.mainframe.JTemplate; +import com.fr.file.ConnectionConfig; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +/** + * 存储数据连接信息 + * + * @author Destiny.Lin + * @version 11.0 + * created by Destiny.Lin on 2022-10-26 + */ +public class SearchConnectionAction implements SearchAction { + private List connectionInfos = new ArrayList<>(); + + + private SearchConnectionAction() { + + } + + @Override + public void search4Infos(JTemplate jTemplate) { + List connectionInfos = new ArrayList<>(); + Map map = ConnectionConfig.getInstance().getConnections(); + Map needMap = new HashMap<>(); + TableDataSource source = (TableDataSource) jTemplate.getTarget(); + Iterator dataIterator = source.getTableDataNameIterator(); + while (dataIterator.hasNext()) { + String dataName = (String) dataIterator.next(); + TableData data = source.getTableData(dataName); + if (isNameDataBaseConnectionValid(data)) { + NameDatabaseConnection connection = (NameDatabaseConnection) ((TableDataConnection) data).getDatabase(); + if (map.containsKey(connection.getName())) { + needMap.put(connection.getName(), connection); + } + } + } + for (String name : needMap.keySet()) { + ITContent content = new ITContent(); + content.setReplaceObject(needMap.get(name)); + content.setTemplateName(jTemplate.getTemplateName()); + content.setJumpAble(false); + content.setShowStr(name); + connectionInfos.add(new ConnectionInfo(content)); + } + setConnectionInfos(connectionInfos); + } + + public boolean isNameDataBaseConnectionValid(TableData data) { + return data instanceof TableDataConnection && ((TableDataConnection) data).getDatabase() instanceof NameDatabaseConnection; + } + + public List getConnectionInfos() { + return connectionInfos; + } + + public void setConnectionInfos(List connectionInfos) { + this.connectionInfos = connectionInfos; + } + + /** + * 对外开放的获取对象的方法 + * + * @return + */ + public static SearchConnectionAction getInstance() { + return SearchConnectionActionEnum.SINGLETON.getInstance(); + } + + /** + * 枚举实现单例 + */ + private enum SearchConnectionActionEnum { + /** + * 单例 + */ + SINGLETON; + + private SearchConnectionAction instance; + + SearchConnectionActionEnum() { + instance = new SearchConnectionAction(); + } + + /** + * 获取对象 + * + * @return + */ + public SearchConnectionAction getInstance() { + return instance; + } + } +} diff --git a/designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/action/SearchDSColumnAction.java b/designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/action/SearchDSColumnAction.java new file mode 100644 index 0000000000..1cba80902b --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/actions/replace/action/setting/action/SearchDSColumnAction.java @@ -0,0 +1,87 @@ +package com.fr.design.actions.replace.action.setting.action; + +import com.fr.base.TableData; +import com.fr.data.TableDataSource; +import com.fr.design.actions.replace.action.SearchAction; +import com.fr.design.actions.replace.info.DSColumnInfo; +import com.fr.design.actions.replace.info.base.ITContent; +import com.fr.design.mainframe.JTemplate; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * 搜索数据列 + * + * @author Destiny.Lin + * @version 11.0 + * created by Destiny.Lin on 2022-10-26 + */ +public class SearchDSColumnAction implements SearchAction { + private List dsColumnInfos = new ArrayList<>(); + + + private SearchDSColumnAction() { + } + + @Override + public void search4Infos(JTemplate jTemplate) { + List dsColumnInfos = new ArrayList<>(); + TableDataSource source = (TableDataSource) jTemplate.getTarget(); + Iterator dataIterator = source.getTableDataNameIterator(); + while (dataIterator.hasNext()) { + String dataName = (String) dataIterator.next(); + TableData data = source.getTableData(dataName); + ITContent content = new ITContent(); + content.setJumpAble(false); + content.setReplaceObject(data); + content.setShowStr(dataName); + content.setTemplateName(jTemplate.getTemplateName()); + dsColumnInfos.add(new DSColumnInfo(content)); + setDsColumnInfos(dsColumnInfos); + } + } + + public List getDsColumnInfos() { + return dsColumnInfos; + } + + public void setDsColumnInfos(List dsColumnInfos) { + this.dsColumnInfos = dsColumnInfos; + } + + /** + * 对外开放的获取对象的方法 + * + * @return + */ + public static SearchDSColumnAction getInstance() { + return SearchDSColumnActionEnum.SINGLETON.getInstance(); + } + + /** + * 枚举实现单例 + */ + private enum SearchDSColumnActionEnum { + /** + * 单例 + */ + SINGLETON; + + private SearchDSColumnAction instance; + + SearchDSColumnActionEnum() { + instance = new SearchDSColumnAction(); + } + + /** + * 获取对象 + * + * @return + */ + public SearchDSColumnAction getInstance() { + return instance; + } + } +}