Browse Source

Merge pull request #15538 in DESIGN/design from release/11.0 to bugfix/11.0

* commit '02a7674d4160e44f8d13ed433341d8a443998612': (24 commits)
  REPORT-141350 【FVS数据集替换】表格-单元格-条件属性-条件是数据列,无法识别,看下这里要不要支持
  REPORT-141671 【数据集替换】组合图的数据集替换后,数据列没有替换成功
  REPORT-141247 【FVS数据集替换】公式ds1.select、group、find字段名不会被替换
  REPORT-141350 【FVS数据集替换】表格-单元格-条件属性-条件是数据列,无法识别
  REPORT-141350 【FVS数据集替换】表格-单元格-条件属性-条件是数据列,无法识别
  REPORT-141247 【FVS数据集替换】公式ds1.select、group、find字段名不会被替换
  REPORT-140743 【数据集替换】下拉树和视图树的数据集替换后,实际并未生效
  REPORT-140743 【数据集替换】下拉树和视图树的数据集替换后,实际并未生效
  REPORT-129009 fix:FR标题翻译修改
  REPORT-140678 公式使用ds.select,对ds替换数据集后公式没有更新
  REPORT-140524 【FVS数据集替换】x3.0.0.1做的看板,图表数据和标题使用的模板和数据集数据,都被识别未使用
  REPORT-140524 【FVS数据集替换】x3.0.0.1做的看板,图表数据和标题使用的模板和数据集数据,都被识别未使用
  REPORT-140743 【数据集替换】下拉树和视图树的数据集替换后,实际并未生效
  REPORT-140634 【数据集替换】下拉树和视图树的数据集替换都不行
  REPORT-140453 【数据集替换】自定义校验的属性公式没有替换成功
  REPORT-140299 【数据集替换】数据列-高级-自定义显示中,没有替换
  REPORT-140371 【数据集替换】条件属性的形态-数据字典的数据集没有替换
  REPORT-140563 【数据集替换】参数面板所有控件的控件值字段,都没有替换
  REPORT-140564 【数据集替换】参数面板所有控件的数据字典的数据集,都没有替换
  REPORT-140361 【数据集替换】图表的特效-图表超链悬浮图表的数据-数据集,没有替换
  ...
bugfix/11.0
superman 4 days ago
parent
commit
4b2086e60d
  1. 16
      designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java
  2. 2
      designer-base/src/main/java/com/fr/design/gui/frpane/CommitTabbedPane.java
  3. 3
      designer-realize/src/main/java/com/fr/design/actions/replace/action/content/formula/cell/SearchDSColumnFormulaAction.java
  4. 24
      designer-realize/src/main/java/com/fr/design/actions/replace/action/content/formula/chart/SearchChartCollectionFormulaAction.java
  5. 49
      designer-realize/src/main/java/com/fr/design/actions/replace/action/content/formula/template/SearchTemplateFormulaAction.java
  6. 13
      designer-realize/src/main/java/com/fr/design/actions/replace/action/content/js/SearchCellJSAction.java
  7. 2
      designer-realize/src/main/java/com/fr/design/actions/replace/action/content/js/SearchChartJSAction.java
  8. 12
      designer-realize/src/main/java/com/fr/design/actions/replace/action/content/js/SearchFloatJSAction.java
  9. 12
      designer-realize/src/main/java/com/fr/design/actions/replace/action/content/js/SearchJS.java
  10. 16
      designer-realize/src/main/java/com/fr/design/actions/replace/action/content/js/SearchJSManager.java
  11. 74
      designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtils.java
  12. 603
      designer-realize/src/main/java/com/fr/design/actions/replace/utils/ReplaceUtils.java
  13. 68
      designer-realize/src/main/java/com/fr/design/actions/replace/utils/SearchJSUtils.java
  14. 4
      designer-realize/src/test/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtilsTest.java

16
designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java

@ -92,15 +92,13 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
public class TableDataTreePane extends BasicTableDataTreePane {
private static Set<AbstractExtraAction> extraActions = new HashSet<>();
private static Map<String, AbstractExtraAction> extraActions = new HashMap<>();
private static final TableDataTreePane singleton = new TableDataTreePane();
public static final int PLUGIN_LISTENER_PRIORITY = 1;
@ -226,7 +224,7 @@ public class TableDataTreePane extends BasicTableDataTreePane {
popupMenu.add(pasteAction.createMenuItem());
popupMenu.add(removeAction.createMenuItem());
popupMenu.addSeparator();
for (AbstractExtraAction action : extraActions) {
for (AbstractExtraAction action : extraActions.values()) {
try {
popupMenu.add(action.createMenuItem());
} catch (Exception e) {
@ -275,7 +273,7 @@ public class TableDataTreePane extends BasicTableDataTreePane {
}
private void initExtraAction() {
for (AbstractExtraAction action: extraActions) {
for (AbstractExtraAction action: extraActions.values()) {
try {
toolbarDef.addShortCut(action);
} catch (Exception e) {
@ -290,7 +288,7 @@ public class TableDataTreePane extends BasicTableDataTreePane {
* @param extraAction TableDataTree工具栏的扩展接口Action
*/
public static void registerExtraAction(AbstractExtraAction extraAction) {
extraActions.add(extraAction);
extraActions.put(extraAction.getClass().getSimpleName(), extraAction);
}
/**
@ -299,7 +297,7 @@ public class TableDataTreePane extends BasicTableDataTreePane {
* @param extraAction TableDataTree工具栏的扩展接口Action
*/
public static void removeExtraAction(AbstractExtraAction extraAction) {
extraActions.remove(extraAction);
extraActions.remove(extraAction.getClass().getSimpleName());
}
/**
@ -729,7 +727,7 @@ public class TableDataTreePane extends BasicTableDataTreePane {
pasteAction.setEnabled(false);
removeAction.setEnabled(false);
previewTableDataAction.setEnabled(false);
for (AbstractExtraAction action : extraActions) {
for (AbstractExtraAction action : extraActions.values()) {
action.setEnabled(false);
}
if (op == null || op.interceptButtonEnabled()) {
@ -766,7 +764,7 @@ public class TableDataTreePane extends BasicTableDataTreePane {
}
private void checkExtraActionEnable(int dataMode, int selectioncount, boolean hasSelectedIndependentColumns) {
for (AbstractExtraAction action : extraActions) {
for (AbstractExtraAction action : extraActions.values()) {
action.setEnabled(action.checkEnable(dataMode, selectioncount, hasSelectedIndependentColumns));
}
}

2
designer-base/src/main/java/com/fr/design/gui/frpane/CommitTabbedPane.java

@ -409,7 +409,7 @@ public class CommitTabbedPane extends JComponent implements MouseListener, Mous
selectedIndex = dbManipulationPaneList.size()-1;
commit2DBJavaScriptPane.updateCardPane();
} else if (isOverCloseIcon(x)){
int re = FineJOptionPane.showConfirmDialog(SwingUtilities.getWindowAncestor(this), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_CommitTab_Sure_To_Delete")+ "?", com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_CommitTab_Remove")
int re = FineJOptionPane.showConfirmDialog(SwingUtilities.getWindowAncestor(this), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_CommitTab_Sure_To_Delete")+ "?", com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Tool_Tips")
, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (re == JOptionPane.OK_OPTION) {
dbManipulationPaneList.remove(getTabIndex(x));

3
designer-realize/src/main/java/com/fr/design/actions/replace/action/content/formula/cell/SearchDSColumnFormulaAction.java

@ -58,8 +58,7 @@ public class SearchDSColumnFormulaAction implements SearchCellFormula {
}
private void addFormulaInfos2ArrayFromResult(ITContent content, DSColumn dsColumn, List<FormulaInfo> formulaInfos) {
char formulaLabel = '=';
if (dsColumn.getResult() != null && dsColumn.getResult().length() > 0 && dsColumn.getResult().charAt(0) == formulaLabel) {
if (dsColumn.getResult() != null && dsColumn.getResult().length() > 0) {
ITContent newContent = ITContent.copy(content);
newContent.setReplaceObject(dsColumn);
//高级-显示值

24
designer-realize/src/main/java/com/fr/design/actions/replace/action/content/formula/chart/SearchChartCollectionFormulaAction.java

@ -63,29 +63,33 @@ public class SearchChartCollectionFormulaAction {
public void searchChartCollectionFormula(List<FormulaInfo> formulaInfos, ITContent content, ChartCollection chartCollection) {
for (int i = 0; i < chartCollection.getChartCount(); i++) {
ITContent chartContent = ITContent.copy(content);
searchChartPatternFormula(formulaInfos, chartContent, chartCollection.getChart(i));
Chart chart = chartCollection.getChart(i);
if (chart == null) {
continue;
}
searchChartPatternFormula(formulaInfos, chartContent, chart);
if (isChangeConfigAttrValid(chartCollection.getChangeConfigAttr())) {
//图表切换属性
dealChangeConfig(formulaInfos, chartContent, chartCollection.getChart(i));
dealChangeConfig(formulaInfos, chartContent, chart);
}
//图表-交互属性-超级链接
dealChartHyperLink(formulaInfos, chartContent, chartCollection.getChart(i));
dealChartHyperLink(formulaInfos, chartContent, chart);
//数据-单元格数据-分类名&系列名&值
SearchChartDataFormulaManager searchChartDataFormulaManager = SearchChartDataFormulaManager.getInstance();
Map<String, SearchChartDataFormula> type = searchChartDataFormulaManager.getChartDataType();
if (isDefinitionValid(chartCollection.getChart(i).getFilterDefinition())) {
String name = chartCollection.getChart(i).getFilterDefinition().getClass().getSimpleName();
if (isDefinitionValid(chart.getFilterDefinition())) {
String name = chart.getFilterDefinition().getClass().getSimpleName();
SearchChartDataFormula searchChartDataFormula = type.get(name);
TopDefinitionProvider provider = chartCollection.getChart(i).getFilterDefinition();
TopDefinitionProvider provider = chart.getFilterDefinition();
ITContent dataContent = ITContent.copy(content);
dataContent.addOtherPos(chartCollection.getChart(i).getChartName(), Toolkit.i18nText("Fine-Design_Basic_Data"));
dataContent.addOtherPos(chart.getChartName(), Toolkit.i18nText("Fine-Design_Basic_Data"));
searchChartDataFormula.searchChartDataFormula(formulaInfos, dataContent, provider);
}
//数据-形态
if (chartCollection.getChart(i).getFilterDefinition() != null) {
if (chart.getFilterDefinition() != null) {
ITContent presentContent = ITContent.copy(content);
presentContent.addOtherPos(chartCollection.getChart(i).getChartName(), Toolkit.i18nText("Fine-Design_Basic_Data"));
searchFormulaFromChartPresent(formulaInfos, presentContent, chartCollection.getChart(i).getFilterDefinition());
presentContent.addOtherPos(chart.getChartName(), Toolkit.i18nText("Fine-Design_Basic_Data"));
searchFormulaFromChartPresent(formulaInfos, presentContent, chart.getFilterDefinition());
}
}
}

49
designer-realize/src/main/java/com/fr/design/actions/replace/action/content/formula/template/SearchTemplateFormulaAction.java

@ -2,21 +2,17 @@ package com.fr.design.actions.replace.action.content.formula.template;
import com.fr.base.Formula;
import com.fr.base.Parameter;
import com.fr.base.ParameterConfig;
import com.fr.base.io.AttrMark;
import com.fr.base.iofile.attr.WatermarkAttr;
import com.fr.data.ClassSubmitJob;
import com.fr.data.Verifier;
import com.fr.data.VerifyItem;
import com.fr.design.actions.replace.action.content.formula.highlight.javascript.SearchCommit2DBJSFormulaAction;
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.file.HistoryTemplateListCache;
import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.mainframe.ReportComponentComposite;
import com.fr.design.mainframe.SheetNameTabPane;
import com.fr.main.impl.WorkBook;
import com.fr.report.core.ReportUtils;
import com.fr.report.report.Report;
@ -25,8 +21,10 @@ import com.fr.report.write.BuiltInSQLSubmiter;
import com.fr.report.write.ReportWriteAttr;
import com.fr.report.write.SubmitVisitor;
import com.fr.report.write.ValueVerifier;
import com.fr.report.write.WClassSubmiter;
import com.fr.report.write.WClassVerifier;
import com.fr.stable.CommonUtils;
import com.fr.stable.ListMap;
import java.util.List;
@ -109,16 +107,31 @@ public class SearchTemplateFormulaAction implements SearchTemplateFormula {
//数据校验
for (int i = 0, len = attr.getVerifierCount(); i < len; i++) {
Verifier verifier = attr.getVerifier(i);
ITContent content = ITContent.copy(sheetContent);
content.addOtherPos(Toolkit.i18nText("Fine-Design_Report_Verify_Data_Verify"));
if (verifier instanceof ValueVerifier) {
ITContent content = ITContent.copy(sheetContent);
content.addOtherPos(Toolkit.i18nText("Fine-Design_Report_Verify_Data_Verify"));
dealValueVerifier4Formula(formulaInfos, content, (ValueVerifier) verifier);
} else if (verifier instanceof WClassVerifier) {
dealWClassVerifier(formulaInfos, content, (WClassVerifier)verifier);
}
}
}
}
private void dealWClassVerifier(List<FormulaInfo> formulaInfos, ITContent content, WClassVerifier verifier) {
if (verifier.getClassVerifyJob() != null) {
ListMap map = verifier.getClassVerifyJob().getPropertyMap();
for (Object value : map.values()) {
if (value instanceof Formula) {
ITContent formulaContent = ITContent.copy(content);
formulaContent.setReplaceObject(value);
formulaInfos.add(new FormulaInfo(formulaContent));
}
}
}
}
private void dealValueVerifier4Formula(List<FormulaInfo> formulaInfos, ITContent content, ValueVerifier verifier) {
ITContent verifyContent = ITContent.copy(content);
verifyContent.addOtherPos(verifier.getName());
@ -133,6 +146,7 @@ public class SearchTemplateFormulaAction implements SearchTemplateFormula {
ITContent messageContent = ITContent.copy(verifyContent);
messageContent.setReplaceObject(item.getMessage());
messageContent.setHoldObject(item);
messageContent.setTag(SearchTag.WRITE_ATTR_MESSAGE);
formulaInfos.add(new FormulaInfo(messageContent));
}
}
@ -144,6 +158,25 @@ public class SearchTemplateFormulaAction implements SearchTemplateFormula {
ITContent content = ITContent.copy(submitContent);
content.addOtherPos(submiter.getName());
SearchCommit2DBJSFormulaAction.getInstance().dealWithDBManipulation(formulaInfos, content, submiter.getDBManipulation());
} else if (visitor instanceof WClassSubmiter) {
WClassSubmiter submiter = (WClassSubmiter) visitor;
ITContent content = ITContent.copy(submitContent);
content.addOtherPos(submiter.getName());
if (submiter.getSubmitJob() instanceof ClassSubmitJob) {
ClassSubmitJob job = (ClassSubmitJob) submiter.getSubmitJob();
dealClassSubmitJob(formulaInfos, job, content);
}
}
}
private void dealClassSubmitJob(List<FormulaInfo> formulaInfos, ClassSubmitJob job, ITContent content) {
ListMap map = job.getPropertyMap();
for (Object value : map.values()) {
if (value instanceof Formula) {
ITContent formulaContent = ITContent.copy(content);
formulaContent.setReplaceObject(value);
formulaInfos.add(new FormulaInfo(formulaContent));
}
}
}

13
designer-realize/src/main/java/com/fr/design/actions/replace/action/content/js/SearchCellJSAction.java

@ -9,6 +9,7 @@ import com.fr.design.actions.replace.info.base.ITContent;
import com.fr.design.actions.replace.utils.SearchJSUtils;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.JTemplate;
import com.fr.js.JavaScript;
import com.fr.js.JavaScriptImpl;
import com.fr.js.NameJavaScriptGroup;
@ -42,6 +43,18 @@ public class SearchCellJSAction implements SearchJS {
jsInfos.addAll(CellJSInfos);
}
@Override
public List<JavaScript> getTemplateJSDependenceTables(JTemplate jTemplate) {
List<JavaScript> scripts = new ArrayList<>();
SearchCellAction searchCellAction = SearchCellAction.getInstance();
searchCellAction.search4Infos(jTemplate);
for (CellInfo cellInfo : searchCellAction.getCellInfos()) {
CellElement cell = (CellElement) cellInfo.getContent().getReplaceObject();
scripts.addAll(SearchJSUtils.getJSDependenceTables(cell));
}
return scripts;
}
private void addJSInfos2ListFromCell(JTemplate jTemplate, List<JSInfo> jsInfos) {
SearchCellAction searchCellAction = SearchCellAction.getInstance();
searchCellAction.search4Infos(jTemplate);

2
designer-realize/src/main/java/com/fr/design/actions/replace/action/content/js/SearchChartJSAction.java

@ -9,7 +9,6 @@ import com.fr.design.actions.replace.utils.SearchJSUtils;
import com.fr.design.i18n.Toolkit;
import com.fr.js.JavaScriptImpl;
import com.fr.js.NameJavaScript;
import com.fr.js.NameJavaScriptGroup;
import com.fr.plugin.chart.attr.axis.VanChartAxis;
import com.fr.plugin.chart.attr.plot.VanChartPlot;
@ -21,7 +20,6 @@ import com.fr.plugin.chart.custom.VanChartCustomPlot;
import com.fr.plugin.chart.vanchart.VanChart;
import com.fr.stable.collections.combination.Pair;
import java.util.ArrayList;
import java.util.List;
/**

12
designer-realize/src/main/java/com/fr/design/actions/replace/action/content/js/SearchFloatJSAction.java

@ -11,6 +11,7 @@ import com.fr.design.actions.replace.utils.SearchJSUtils;
import com.fr.design.mainframe.JTemplate;
import com.fr.js.JavaScript;
import com.fr.report.cell.FloatElement;
@ -37,6 +38,17 @@ public class SearchFloatJSAction implements SearchJS {
jsInfos.addAll(floatJSInfos);
}
@Override
public List<JavaScript> getTemplateJSDependenceTables(JTemplate jTemplate) {
List<JavaScript> scripts = new ArrayList<>();
SearchFloatAction searchFloatAction = SearchFloatAction.getInstance();
searchFloatAction.search4Infos(jTemplate);
for (FloatInfo floatInfo : searchFloatAction.getFloatInfos()) {
FloatElement floatElement = (FloatElement) floatInfo.getContent().getReplaceObject();
scripts.addAll(SearchJSUtils.getJSDependenceTables(floatElement));
}
return scripts;
}
private void addJSInfos2ListFromFloat(JTemplate jTemplate, List<JSInfo> jsInfos) {
SearchFloatAction searchFloatAction = SearchFloatAction.getInstance();

12
designer-realize/src/main/java/com/fr/design/actions/replace/action/content/js/SearchJS.java

@ -3,7 +3,9 @@ package com.fr.design.actions.replace.action.content.js;
import com.fr.design.actions.replace.action.SearchAction;
import com.fr.design.actions.replace.info.JSInfo;
import com.fr.design.mainframe.JTemplate;
import com.fr.js.JavaScript;
import java.util.ArrayList;
import java.util.List;
/**
@ -23,4 +25,14 @@ public interface SearchJS extends SearchAction {
*/
default void searchJSFromObject(JTemplate jTemplate, List<JSInfo> jsInfos) {
}
/**
* 获取模板中的涉及数据集的所有超链
*
* @param jTemplate 模板
* @return 超链集合
*/
default List<JavaScript> getTemplateJSDependenceTables(JTemplate jTemplate) {
return new ArrayList<>();
}
}

16
designer-realize/src/main/java/com/fr/design/actions/replace/action/content/js/SearchJSManager.java

@ -5,6 +5,7 @@ import com.fr.design.actions.replace.action.SearchManager;
import com.fr.design.actions.replace.info.JSInfo;
import com.fr.design.mainframe.JTemplate;
import com.fr.js.JavaScript;
import java.util.ArrayList;
import java.util.HashSet;
@ -45,6 +46,21 @@ public class SearchJSManager implements SearchAction, SearchManager {
setJsInfos(jsInfos);
}
/**
* 查找超链
*
* @param jTemplate 模板
* @return 超链集合
*/
public List<JavaScript> getTemplateJSDependenceTables(JTemplate jTemplate) {
List<JavaScript> javaScripts = new ArrayList<>();
for (SearchJS searchJS : searchJSSet) {
javaScripts.addAll(searchJS.getTemplateJSDependenceTables(jTemplate));
}
return javaScripts;
}
public List<JSInfo> getJsInfos() {
return jsInfos;
}

74
designer-realize/src/main/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtils.java

@ -3,9 +3,11 @@ package com.fr.design.actions.replace.action.content.tabledata;
import com.fr.data.TableReplacementEntity;
import com.fr.invoke.Reflect;
import com.fr.log.FineLoggerFactory;
import com.fr.parser.Ambiguity;
import com.fr.parser.BinaryExpression;
import com.fr.parser.DatasetFunctionCall;
import com.fr.parser.FunctionCall;
import com.fr.parser.RelationExpression;
import com.fr.parser.StringLiteral;
import com.fr.script.Calculator;
import com.fr.stable.StringUtils;
@ -107,18 +109,7 @@ public class TableDataFormulaUtils {
// 数据集名称
StringBuilder parent = new StringBuilder(datasetFunctionCall.getSourceName());
for (Node subNode : subNodes) {
// 嵌套普通公式
if (subNode instanceof FunctionCall) {
replaceArgument4FunctionCall((FunctionCall) subNode, entities);
} else if (subNode instanceof StringLiteral) {
// 无嵌套,可以根据传进来的datasetFunctionCall进行替换
StringLiteral stringLiteral = (StringLiteral) subNode;
replaceDatasetFunctionCall0(stringLiteral, datasetFunctionCall, entities, parent);
} else if (subNode instanceof DatasetFunctionCall) {
// 嵌套datasetFunctionCall,递归回来该方法继续往下
DatasetFunctionCall datasetFunctionCall1 = (DatasetFunctionCall) subNode;
replaceArgument4DatasetFunctionCall(datasetFunctionCall1, entities);
}
replaceNode4DatasetFunctionCall(subNode, datasetFunctionCall, entities, parent);
}
for (TableReplacementEntity entity : entities) {
if (StringUtils.equals(parent.toString(), entity.getOldName())) {
@ -130,17 +121,40 @@ public class TableDataFormulaUtils {
}
}
private static void replaceDatasetFunctionCall0(StringLiteral stringLiteral, DatasetFunctionCall datasetFunctionCall, List<TableReplacementEntity> entities, StringBuilder parent) {
private static void replaceNode4DatasetFunctionCall(Node subNode, DatasetFunctionCall datasetFunctionCall, List<TableReplacementEntity> entities, StringBuilder parent) {
// 嵌套普通公式
if (subNode instanceof FunctionCall) {
replaceArgument4FunctionCall((FunctionCall) subNode, entities);
} else if (subNode instanceof Ambiguity) {
// 无嵌套,可以根据传进来的datasetFunctionCall进行替换
// 这边产品确认只能替换无双引号的字段,因此是ambiguity而不是StringLiteral
Ambiguity ambiguity = (Ambiguity) subNode;
replaceDatasetFunctionCall0(ambiguity, datasetFunctionCall, entities, parent);
} else if (subNode instanceof DatasetFunctionCall) {
// 嵌套datasetFunctionCall,递归回来该方法继续往下
DatasetFunctionCall datasetFunctionCall1 = (DatasetFunctionCall) subNode;
replaceArgument4DatasetFunctionCall(datasetFunctionCall1, entities);
} else if (subNode instanceof RelationExpression) {
Node left = ((RelationExpression) subNode).getLeft();
Node right = ((RelationExpression) subNode).getRight();
replaceNode4DatasetFunctionCall(left, datasetFunctionCall, entities, parent);
replaceNode4DatasetFunctionCall(right, datasetFunctionCall, entities, parent);
}
}
private static void replaceDatasetFunctionCall0(Ambiguity ambiguity, DatasetFunctionCall datasetFunctionCall, List<TableReplacementEntity> entities, StringBuilder parent) {
try {
TableDataFormulaType type = TableDataFormulaType.get(datasetFunctionCall.getFnName());
if (type != null) {
String name = stringLiteral.eval(Calculator.createCalculator()).toString();
String name = ambiguity.toString();
for (TableReplacementEntity entity : entities) {
if (StringUtils.equals(parent.toString(), entity.getOldName())) {
// 如果是要替换的数据集
String field = entity.getTargetField(name);
// 替换成匹配后的字段
Reflect.on(stringLiteral).set(STATEMENT, field);
if (StringUtils.isNotEmpty(field)) {
// 替换成匹配后的字段
Reflect.on(ambiguity).set(STATEMENT, field);
}
break;
}
}
@ -173,12 +187,18 @@ public class TableDataFormulaUtils {
if (subNode instanceof FunctionCall) {
FunctionCall functionCall = (FunctionCall) subNode;
result.addAll(TableDataFormulaUtils.fetchArgument(functionCall, functionName, argumentIndex));
} else if (subNode instanceof DatasetFunctionCall) {
DatasetFunctionCall datasetFunctionCall = (DatasetFunctionCall) subNode;
result.addAll(TableDataFormulaUtils.fetchArgument(datasetFunctionCall, functionName));
}
}
}
} else if (node instanceof FunctionCall) {
FunctionCall functionCall = (FunctionCall) node;
result.addAll(TableDataFormulaUtils.fetchArgument(functionCall, functionName, argumentIndex));
} else if (node instanceof DatasetFunctionCall) {
DatasetFunctionCall datasetFunctionCall = (DatasetFunctionCall) node;
result.addAll(TableDataFormulaUtils.fetchArgument(datasetFunctionCall, functionName));
}
}
@ -188,6 +208,28 @@ public class TableDataFormulaUtils {
return result;
}
private static List<String> fetchArgument(DatasetFunctionCall datasetFunctionCall, String functionName) {
List<String> result = new ArrayList<>();
Node[] subNodes = datasetFunctionCall.getArguments();
String sourceName = datasetFunctionCall.getSourceName();
if (StringUtils.isNotEmpty(functionName)) {
result.add(sourceName);
}
if (subNodes != null) {
// 遍历子公式
for (Object subNode : subNodes) {
if (subNode instanceof FunctionCall) {
for (TableDataFormulaType tableDataFormulaType : TableDataFormulaType.values()) {
result.addAll(TableDataFormulaUtils.fetchArgument((FunctionCall) subNode, tableDataFormulaType.name(), tableDataFormulaType.getArgumentIndex()));
}
} else if (subNode instanceof DatasetFunctionCall) {
result.addAll(fetchArgument((DatasetFunctionCall) subNode, functionName));
}
}
}
return result;
}
private static void replaceArgument4FunctionCall(FunctionCall functionCall, List<TableReplacementEntity> entities) {
Node[] subNodes = functionCall.getArguments();
if (subNodes != null) {

603
designer-realize/src/main/java/com/fr/design/actions/replace/utils/ReplaceUtils.java

@ -1,13 +1,27 @@
package com.fr.design.actions.replace.utils;
import com.fr.base.Formula;
import com.fr.base.present.DictPresent;
import com.fr.base.present.Present;
import com.fr.chart.chartattr.ChartCollection;
import com.fr.chart.web.ChartHyperPoplink;
import com.fr.data.SimpleDSColumn;
import com.fr.data.TableReplacementEntity;
import com.fr.data.condition.CommonCondition;
import com.fr.data.condition.JoinCondition;
import com.fr.data.condition.ListCondition;
import com.fr.data.condition.ObjectCondition;
import com.fr.data.core.Compare;
import com.fr.data.impl.NameTableData;
import com.fr.data.impl.TableDataDictionary;
import com.fr.data.impl.TreeNodeAttr;
import com.fr.data.impl.TreeNodeWrapper;
import com.fr.design.actions.replace.action.content.cell.SearchCellAction;
import com.fr.design.actions.replace.action.content.formula.SearchFormulaManager;
import com.fr.design.actions.replace.action.content.formula.cell.SearchCellFormulaAction;
import com.fr.design.actions.replace.action.content.formula.chart.SearchChartCollectionFormulaAction;
import com.fr.design.actions.replace.action.content.formula.widget.SearchWidgetFormulaAction;
import com.fr.design.actions.replace.action.content.js.SearchJSManager;
import com.fr.design.actions.replace.action.content.tabledata.TableDataFormulaType;
import com.fr.design.actions.replace.action.content.tabledata.TableDataFormulaUtils;
import com.fr.design.actions.replace.action.content.widget.SearchWidgetAction;
@ -17,8 +31,32 @@ import com.fr.design.actions.replace.info.WidgetInfo;
import com.fr.design.actions.replace.info.base.ITContent;
import com.fr.design.mainframe.JTemplate;
import com.fr.form.FormElementCaseProvider;
import com.fr.form.data.DataBinding;
import com.fr.form.ui.DataControl;
import com.fr.form.ui.DictionaryContainer;
import com.fr.form.ui.ElementCaseEditor;
import com.fr.form.ui.TreeEditor;
import com.fr.form.ui.Widget;
import com.fr.form.ui.concept.data.ValueInitializer;
import com.fr.form.ui.tree.LayerConfig;
import com.fr.general.ComparatorUtils;
import com.fr.general.data.Condition;
import com.fr.general.data.TableDataColumn;
import com.fr.js.JavaScript;
import com.fr.js.NameJavaScript;
import com.fr.js.NameJavaScriptGroup;
import com.fr.main.impl.WorkBook;
import com.fr.main.parameter.ReportParameterAttr;
import com.fr.report.cell.CellElement;
import com.fr.report.cell.FloatElement;
import com.fr.report.cell.TemplateCellElement;
import com.fr.report.cell.cellattr.core.group.DSColumn;
import com.fr.report.cell.cellattr.highlight.DefaultHighlight;
import com.fr.report.cell.cellattr.highlight.Highlight;
import com.fr.report.cell.cellattr.highlight.HighlightGroup;
import com.fr.report.cell.cellattr.highlight.HyperlinkHighlightAction;
import com.fr.report.cell.cellattr.highlight.PresentHighlightAction;
import com.fr.report.cell.cellattr.highlight.WidgetHighlightAction;
import com.fr.report.elementcase.ElementCase;
import com.fr.report.report.Report;
import com.fr.report.utils.ElementCaseHelper;
@ -86,8 +124,18 @@ public class ReplaceUtils {
* @return 报表块使用的数据集
*/
public static Set<String> getElementCaseDependenceTables(ElementCaseEditor elementCaseEditor) {
FormElementCaseProvider elementCase = elementCaseEditor.getElementCase();
return elementCase.getCellTableDataSet();
Set<String> ans = new HashSet<>();
FormElementCaseProvider provider = elementCaseEditor.getElementCase();
if (provider instanceof ElementCase) {
// 非公式部分
ans.addAll(searchTableDataWithOutFormula((ElementCase)provider));
// 公式部分——理论上就只有单元格和控件(超链那些都包含)
List<FormulaInfo> formulaInfos = getElementCaseFormulas((ElementCase) provider);
ans.addAll(searchFormulaInfos(formulaInfos));
// 超链部分
ans.addAll(searchElementCasJs((ElementCase)provider));
}
return ans;
}
/**
@ -180,6 +228,8 @@ public class ReplaceUtils {
List<FormulaInfo> formulaInfos = new ArrayList<>();
SearchChartCollectionFormulaAction.getInstance().searchChartCollectionFormula(formulaInfos, new ITContent(), chartCollection);
replaceFormulaInfos(formulaInfos, entities);
// 超链部分
replaceChartJs(chartCollection, entities);
}
/**
@ -190,13 +240,16 @@ public class ReplaceUtils {
*/
public static void replaceElementCase(ElementCase elementCase, List<TableReplacementEntity> entities) {
// 非公式部分
ElementCaseHelper.replaceTableDataWithOutFormula(elementCase, entities);
replaceTableDataWithOutFormula(elementCase, entities);
// 公式部分——理论上就只有单元格和控件(超链那些都包含)
List<FormulaInfo> formulaInfos = getElementCaseFormulas(elementCase);
replaceFormulaInfos(formulaInfos, entities);
// 超链部分
replaceElementCasJs(elementCase, entities);
}
/**
* 替换CPT使用的数据集(包含公式里的)
*
@ -206,18 +259,130 @@ public class ReplaceUtils {
public static void replaceCpt(JTemplate template, List<TableReplacementEntity> entity) {
if (template.getTarget() instanceof WorkBook) {
WorkBook workBook = (WorkBook) template.getTarget();
// 非公式部分替换
// 参数面板
replaceWorkBookPara(workBook, entity);
// 主体非公式部分替换
replaceWorkBook(workBook, entity);
// 公式部分
SearchFormulaManager.getInstance().search4Infos(template);
List<FormulaInfo> formulaInfos = SearchFormulaManager.getInstance().getFormulaInfos();
replaceFormulaInfos(formulaInfos, entity);
// 超链部分
replaceTemplateJs(template, entity);
// 触发响应
template.fireTargetModified();
}
}
/**
* ----------------------------------------------private--------------------------------------------------
*/
private static void replaceWorkBookPara(WorkBook workBook, List<TableReplacementEntity> entity) {
ReportParameterAttr attr = workBook.getReportParameterAttr();
if (attr != null && attr.getParameterUI() != null) {
Widget[] widgets = attr.getParameterUI().getAllWidgets();
for (Widget widget : widgets) {
replaceWidget(widget, entity);
}
}
}
private static void replaceTemplateJs(JTemplate template, List<TableReplacementEntity> entity) {
List<JavaScript> javaScripts = SearchJSManager.getInstance().getTemplateJSDependenceTables(template);
replaceJs(javaScripts, entity);
}
private static void replaceChartJs(ChartCollection chartCollection, List<TableReplacementEntity> entities) {
List<JavaScript> scripts = new ArrayList<>();
List<NameJavaScript> nameJavaScripts = SearchJSUtils.getChartJavaScript(chartCollection);
for(NameJavaScript javaScript : nameJavaScripts) {
if (javaScript.getJavaScript() instanceof ChartHyperPoplink) {
scripts.add(javaScript.getJavaScript());
}
}
replaceJs(scripts, entities);
}
private static void replaceElementCasJs(ElementCase elementCase, List<TableReplacementEntity> entities) {
if (elementCase == null) {
return;
}
List<JavaScript> javaScripts = new ArrayList<>();
// 替换悬浮元素
Iterator floatIterator = elementCase.floatIterator();
while (floatIterator.hasNext()) {
FloatElement floatCell = (FloatElement) floatIterator.next();
javaScripts.addAll(SearchJSUtils.getJSDependenceTables(floatCell));
}
// 替换通用元素
Iterator cellIterator = elementCase.cellIterator();
while (cellIterator.hasNext()) {
CellElement cell = (CellElement) cellIterator.next();
javaScripts.addAll(SearchJSUtils.getJSDependenceTables(cell));
}
replaceJs(javaScripts, entities);
}
private static void replaceCellHighlight(CellElement cell, List<TableReplacementEntity> entities) {
if (cell instanceof TemplateCellElement) {
HighlightGroup group = ((TemplateCellElement) cell).getHighlightGroup();
if (group != null) {
for (int i = 0 ; i < group.size(); i++) {
Highlight highlight = group.getHighlight(i);
replaceHighlight(highlight, entities);
}
}
}
}
private static void replaceHighlight(Highlight highlight, List<TableReplacementEntity> entities) {
if (highlight instanceof DefaultHighlight) {
DefaultHighlight defaultHighlight = (DefaultHighlight) highlight;
replaceCondition(defaultHighlight.getCondition(), entities);
for (int i = 0 ; i < defaultHighlight.actionCount() ; i++) {
if (defaultHighlight.getHighlightAction(i) instanceof PresentHighlightAction) {
PresentHighlightAction action = (PresentHighlightAction) defaultHighlight.getHighlightAction(i);
ElementCaseHelper.replacePresent(action.getPresent(), entities);
} else if (defaultHighlight.getHighlightAction(i) instanceof WidgetHighlightAction) {
WidgetHighlightAction action = (WidgetHighlightAction) defaultHighlight.getHighlightAction(i);
replaceWidget(action.getWidget(), entities);
} else if (defaultHighlight.getHighlightAction(i) instanceof HyperlinkHighlightAction) {
HyperlinkHighlightAction action = (HyperlinkHighlightAction) defaultHighlight.getHighlightAction(i);
NameJavaScriptGroup group = action.getHperlink();
dealNameJavaScriptGroup(group, entities);
}
}
}
}
private static void dealNameJavaScriptGroup(NameJavaScriptGroup group, List<TableReplacementEntity> entities) {
if (group != null) {
for (int i = 0 ; i < group.size(); i++) {
NameJavaScript javaScript = group.getNameHyperlink(i);
if (javaScript.getJavaScript() instanceof ChartHyperPoplink) {
if (((ChartHyperPoplink) javaScript.getJavaScript()).getChartCollection() instanceof ChartCollection) {
replaceChart((ChartCollection) ((ChartHyperPoplink) javaScript.getJavaScript()).getChartCollection(), entities);
}
}
}
}
}
private static void replaceJs(List<JavaScript> javaScripts, List<TableReplacementEntity> entity) {
for (JavaScript javaScript : javaScripts) {
if (javaScript instanceof ChartHyperPoplink) {
ChartHyperPoplink chartHyperPoplink = (ChartHyperPoplink) javaScript;
if (chartHyperPoplink.getChartCollection() instanceof ChartCollection) {
replaceChart((ChartCollection) chartHyperPoplink.getChartCollection(), entity);
}
}
}
}
private static void replaceWorkBook(WorkBook workBook, List<TableReplacementEntity> entity) {
if (acceptTableReplacement(entity)) {
for (int i = 0; i < workBook.getReportCount(); i++) {
@ -226,7 +391,7 @@ public class ReplaceUtils {
Iterator it = report.iteratorOfElementCase();
while (it.hasNext()) {
ElementCase elementCase = (ElementCase) it.next();
ElementCaseHelper.replaceTableDataWithOutFormula(elementCase, entity);
replaceTableDataWithOutFormula(elementCase, entity);
}
}
}
@ -270,4 +435,430 @@ public class ReplaceUtils {
}
return formulaInfos;
}
/**
* 替换数据集
*
* @param elementCase 可以是报表块组件WorkBook...
* @param entity 数据集替换信息
*/
private static void replaceTableDataWithOutFormula(ElementCase elementCase, List<TableReplacementEntity> entity) {
if (elementCase == null) {
return;
}
// -------非公式部分-------
// 替换悬浮元素
replaceFloatCell(elementCase, entity);
// 替换通用元素
replaceNormalCell(elementCase, entity);
}
/**
* 替换通用元素,主要是单元格的各个地方
*
* <li>单元格形态</li>
* <li>单元格控件</li>
* <li>单元格数据字典</li>
* <li>单元格值</li>
*
* @param elementCase
* @param entity
*/
private static void replaceNormalCell(ElementCase elementCase, List<TableReplacementEntity> entity) {
Iterator cellIterator = elementCase.cellIterator();
while (cellIterator.hasNext()) {
CellElement cell = (CellElement) cellIterator.next();
// 处理【形态、控件、数据字典】
replacePresentAndDictionary(cell, entity);
// 处理【单元格值】
replaceCellValue(cell, entity);
// 处理【条件属性】
replaceCellHighlight(cell, entity);
}
}
private static void replaceCellValue(CellElement cell, List<TableReplacementEntity> entity) {
Object value = cell.getValue();
if (value instanceof DSColumn) {
// 替换【数据列】
replaceDSColumn( (DSColumn) value, entity);
// 替换【条件属性】
replaceCondition(((DSColumn) value).getCondition(), entity);
} else if (value instanceof ChartCollection) {
((ChartCollection) value).replaceTableData(entity);
replaceChartJs((ChartCollection) value, entity);
}
}
private static void replaceCondition(Condition condition, List<TableReplacementEntity> entity) {
if (condition != null) {
//公式条件不需要修改,里面不会涉及到,有问题再加
//普通条件
//1条条件
replaceSingleCondition(condition, entity);
//N条条件
if (condition instanceof ListCondition) {
for (int k = 0; k < ((ListCondition) condition).getJoinConditionCount(); k++) {
JoinCondition joinCondition = ((ListCondition) condition).getJoinCondition(k);
Condition obCondition = joinCondition.getCondition();
if (obCondition != null) {
replaceSingleCondition(obCondition, entity);
}
}
}
}
}
private static void replaceSingleCondition(Condition condition, List<TableReplacementEntity> entity) {
if (condition instanceof CommonCondition) {
dealWithTableDataNameChange((CommonCondition) condition, entity);
}
if (condition instanceof ObjectCondition) {
dealWithCompare(((ObjectCondition) condition).getCompare(), entity);
}
}
private static void dealWithTableDataNameChange(CommonCondition condition, List<TableReplacementEntity> entities) {
Compare compare = condition.getCompare();
dealWithCompare(compare, entities);
}
private static void dealWithCompare(Compare compare, List<TableReplacementEntity> entities) {
if (compare != null) {
Object ob = compare.getValue();
if (ob instanceof SimpleDSColumn) {
for (TableReplacementEntity entity : entities) {
if (ComparatorUtils.equals(((SimpleDSColumn) ob).getDsName(), entity.getOldName())) {
((SimpleDSColumn) ob).setDsName(entity.getNewName());
((SimpleDSColumn) ob).setColumn(TableDataColumn.createColumn(entity.getTargetField(TableDataColumn.getColumnName(((SimpleDSColumn) ob).getColumn()))));
}
}
}
}
}
private static void replaceDSColumn(DSColumn dsColumn, List<TableReplacementEntity> entities) {
for (TableReplacementEntity entity : entities) {
if (ComparatorUtils.equals(dsColumn.getDSName(), entity.getOldName())) {
// 数据集替换
dsColumn.setDSName(entity.getNewName());
// 数据集字段替换
dsColumn.setColumn(TableDataColumn.createColumn(entity.getTargetField(dsColumn.getColumnName())));
}
}
}
private static void replacePresentAndDictionary(CellElement cell, List<TableReplacementEntity> entities) {
TemplateCellElement cellElement = (TemplateCellElement) cell;
// 处理单元格的控件
replaceWidget(cellElement.getWidget(), entities);
// 处理形态
ElementCaseHelper.replacePresent(cellElement.getPresent(), entities);
}
/**
* 处理控件
*
* @param widget 控件
* @param entities 替换信息
*/
private static void replaceWidget(Widget widget, List<TableReplacementEntity> entities) {
if (widget instanceof DictionaryContainer) {
DictionaryContainer db = (DictionaryContainer) widget;
if (widget instanceof TreeEditor) {
Object config = ((TreeEditor) widget).getBuildModelConfig();
replaceTreeConfig(config, entities);
((TreeEditor) widget).setBuildModelConfig(config);
}
if (db.getDictionary() instanceof TableDataDictionary) {
TableDataDictionary tdd = (TableDataDictionary) db.getDictionary();
NameTableData ndd = (NameTableData) tdd.getTableData();
// 控件持有的数据字典也得处理
ElementCaseHelper.replaceTableDataDictionary(tdd, ndd, entities);
}
}
if (widget instanceof DataControl) {
ValueInitializer value = ((DataControl) widget).getWidgetValue();
if (value != null && value.getValue() instanceof DataBinding) {
DataBinding binding = (DataBinding) value.getValue();
for (TableReplacementEntity entity : entities) {
if (StringUtils.equals(entity.getOldName(), binding.getDataSourceName())) {
value.setValue(new DataBinding(entity.getNewName(), entity.getTargetField(binding.getDataBindingKey())));
break;
}
}
}
}
}
/**
* 处理树结构的config
*
* @param config 树结构配置
* @param entities 替换信息
*/
public static void replaceTreeConfig(Object config, List<TableReplacementEntity> entities) {
if (config instanceof LayerConfig[]) {
LayerConfig[] layerConfigs = (LayerConfig[]) config;
dealWithLayerConfigs(layerConfigs, entities);
} else if (config instanceof TreeNodeWrapper) {
TreeNodeWrapper wrapper = (TreeNodeWrapper) config;
dealWithTreeNodeWrapper(wrapper, entities);
} else if (config instanceof TableDataDictionary) {
TableDataDictionary tableDataDictionary = (TableDataDictionary) config;
ElementCaseHelper.replaceTableDataDictionary(tableDataDictionary, (NameTableData) tableDataDictionary.getTableData(), entities);
}
}
private static void dealWithTreeNodeWrapper(TreeNodeWrapper wrapper, List<TableReplacementEntity> entities) {
for (TreeNodeAttr attr : wrapper.getTreeNodeAttrs()) {
if (attr.getDictionary() instanceof TableDataDictionary) {
TableDataDictionary tableDataDictionary = (TableDataDictionary) attr.getDictionary();
ElementCaseHelper.replaceTableDataDictionary(tableDataDictionary, (NameTableData) tableDataDictionary.getTableData(), entities);
}
}
}
private static void dealWithLayerConfigs(LayerConfig[] layerConfigs, List<TableReplacementEntity> entities) {
for (LayerConfig layerConfig : layerConfigs) {
if (layerConfig.getDictionary() != null ) {
for (TableReplacementEntity entity : entities) {
if (layerConfig.getTableData() instanceof NameTableData && StringUtils.equals(layerConfig.getTableData().getName(), entity.getOldName())) {
layerConfig.setTableData(new NameTableData(entity.getNewName()));
layerConfig.setViewColumn(entity.getTargetIndex(layerConfig.getViewColumn()));
layerConfig.setModelColumn(entity.getTargetIndex(layerConfig.getModelColumn()));
}
}
ElementCaseHelper.replaceTableDataDictionary(layerConfig.getDictionary(), (NameTableData) layerConfig.getDictionary().getTableData(), entities);
}
}
}
/**
* 替换悬浮元素中的数据集
*
* @param elementCase 组件
* @param entities 替换信息
*/
private static void replaceFloatCell(ElementCase elementCase, List<TableReplacementEntity> entities) {
Iterator floatIterator = elementCase.floatIterator();
while (floatIterator.hasNext()) {
FloatElement floatCell = (FloatElement) floatIterator.next();
Object value = floatCell.getValue();
if (value instanceof ChartCollection) {
((ChartCollection) value).replaceTableData(entities);
replaceChartJs((ChartCollection) value, entities);
}
}
}
/**
* ------------------------private search-----------------------------------
*/
private static Set<String> searchElementCasJs(ElementCase elementCase) {
Set<String> ans = new HashSet<>();
List<JavaScript> javaScripts = new ArrayList<>();
// 替换通用元素
Iterator cellIterator = elementCase.cellIterator();
while (cellIterator.hasNext()) {
CellElement cell = (CellElement) cellIterator.next();
javaScripts.addAll(SearchJSUtils.getJSDependenceTables(cell));
}
ans.addAll(searchJs(javaScripts));
return ans;
}
private static Set<String> searchJs(List<JavaScript> javaScripts) {
Set<String> ans = new HashSet<>();
for (JavaScript javaScript : javaScripts) {
if (javaScript instanceof ChartHyperPoplink) {
ChartHyperPoplink chartHyperPoplink = (ChartHyperPoplink) javaScript;
if (chartHyperPoplink.getChartCollection() instanceof ChartCollection) {
ans.addAll((chartHyperPoplink.getChartCollection().getDataSetNames()));
}
}
}
return ans;
}
private static Set<String> searchFormulaInfos(List<FormulaInfo> formulaInfos) {
Set<String> ans = new HashSet<>();
for (FormulaInfo formulaInfo : formulaInfos) {
ans.addAll(TableDataFormulaUtils.search4TableData(formulaInfo.getPureValue()));
}
return ans;
}
private static Set<String> searchTableDataWithOutFormula(ElementCase elementCase) {
Set<String> ans = new HashSet<>();
Iterator cellIterator = elementCase.cellIterator();
while (cellIterator.hasNext()) {
CellElement cell = (CellElement) cellIterator.next();
// 处理【形态、控件、数据字典】
ans.addAll(searchPresentAndDictionary(cell));
// 处理【单元格值】
ans.addAll(searchCellValue(cell));
// 处理【条件属性】
ans.addAll(searchCellHighlight(cell));
}
return ans;
}
private static Set<String> searchCellHighlight(CellElement cell) {
Set<String> ans = new HashSet<>();
if (cell instanceof TemplateCellElement) {
HighlightGroup group = ((TemplateCellElement) cell).getHighlightGroup();
if (group != null) {
for (int i = 0 ; i < group.size(); i++) {
Highlight highlight = group.getHighlight(i);
ans.addAll(searchHighlight(highlight));
}
}
}
return ans;
}
private static Set<String> searchHighlight(Highlight highlight) {
Set<String> ans = new HashSet<>();
if (highlight instanceof DefaultHighlight) {
DefaultHighlight defaultHighlight = (DefaultHighlight) highlight;
for (int i = 0 ; i < defaultHighlight.actionCount() ; i++) {
if (defaultHighlight.getHighlightAction(i) instanceof PresentHighlightAction) {
PresentHighlightAction action = (PresentHighlightAction) defaultHighlight.getHighlightAction(i);
ans.addAll(searchPresent(action.getPresent()));
} else if (defaultHighlight.getHighlightAction(i) instanceof WidgetHighlightAction) {
WidgetHighlightAction action = (WidgetHighlightAction) defaultHighlight.getHighlightAction(i);
ans.addAll(searchWidget(action.getWidget()));
} else if (defaultHighlight.getHighlightAction(i) instanceof HyperlinkHighlightAction) {
HyperlinkHighlightAction action = (HyperlinkHighlightAction) defaultHighlight.getHighlightAction(i);
NameJavaScriptGroup group = action.getHperlink();
ans.addAll(searchNameJavaScriptGroup(group));
}
}
}
return ans;
}
private static Set<String> searchNameJavaScriptGroup(NameJavaScriptGroup group) {
Set<String> ans = new HashSet<>();
if (group != null) {
for (int i = 0 ; i < group.size(); i++) {
NameJavaScript javaScript = group.getNameHyperlink(i);
if (javaScript.getJavaScript() instanceof ChartHyperPoplink) {
if (((ChartHyperPoplink) javaScript.getJavaScript()).getChartCollection() instanceof ChartCollection) {
ans.addAll((((ChartHyperPoplink) javaScript.getJavaScript()).getChartCollection().getDataSetNames()));
}
}
}
}
return ans;
}
private static Set<String> searchCellValue(CellElement cell) {
Set<String> ans = new HashSet<>();
Object value = cell.getValue();
if (value instanceof DSColumn) {
// 查找【数据列】
ans.add(((DSColumn) value).getDSName());
// 查找【条件属性】
ans.addAll(searchCondition(((DSColumn) value).getCondition()));
} else if (value instanceof ChartCollection) {
ans.addAll(((ChartCollection) value).getDataSetNames());
}
return ans;
}
private static Set<String> searchCondition(Condition condition) {
Set<String> ans = new HashSet<>();
if (condition != null) {
//普通条件
//1条条件
if (condition instanceof CommonCondition) {
ans.addAll(searchCondition0((CommonCondition) condition));
}
//N条条件
if (condition instanceof ListCondition) {
for (int k = 0; k < ((ListCondition) condition).getJoinConditionCount(); k++) {
JoinCondition joinCondition = ((ListCondition) condition).getJoinCondition(k);
Condition obCondition = joinCondition.getCondition();
if (obCondition instanceof CommonCondition) {
ans.addAll(searchCondition0((CommonCondition) obCondition));
}
}
}
}
return ans;
}
private static Set<String> searchCondition0(CommonCondition condition) {
Set<String> ans = new HashSet<>();
Compare compare = condition.getCompare();
Object ob = compare.getValue();
if (ob instanceof SimpleDSColumn) {
ans.add(((SimpleDSColumn) ob).getDsName());
}
return ans;
}
private static Set<String> searchPresentAndDictionary(CellElement cell) {
Set<String> ans = new HashSet<>();
TemplateCellElement cellElement = (TemplateCellElement) cell;
// 处理单元格的控件
ans.addAll(searchWidget(cellElement.getWidget()));
// 处理形态
ans.addAll(searchPresent(cellElement.getPresent()));
return ans;
}
private static Set<String> searchPresent(Present p) {
Set<String> ans = new HashSet<>();
if (!(p instanceof DictPresent)) {
return ans;
}
DictPresent dp = (DictPresent) p;
if (!(dp.getDictionary() instanceof TableDataDictionary)) {
return ans;
}
TableDataDictionary td = (TableDataDictionary) dp.getDictionary();
if (!(td.getTableData() instanceof NameTableData)) {
return ans;
}
NameTableData nd = (NameTableData) td.getTableData();
ans.add(nd.getName());
return ans;
}
private static Set<String> searchWidget(Widget widget) {
Set<String> ans = new HashSet<>();
if (widget instanceof DictionaryContainer) {
DictionaryContainer db = (DictionaryContainer) widget;
if (db.getDictionary() instanceof TableDataDictionary) {
TableDataDictionary tdd = (TableDataDictionary) db.getDictionary();
NameTableData ndd = (NameTableData) tdd.getTableData();
if (ndd != null) {
ans.add(ndd.getName());
}
}
}
if (widget instanceof DataControl) {
ValueInitializer value = ((DataControl) widget).getWidgetValue();
if (value != null && value.getValue() instanceof DataBinding) {
DataBinding binding = (DataBinding) value.getValue();
ans.add(binding.getDataSourceName());
}
}
return ans;
}
}

68
designer-realize/src/main/java/com/fr/design/actions/replace/utils/SearchJSUtils.java

@ -36,7 +36,6 @@ import com.fr.report.cell.Elem;
import com.fr.stable.StringUtils;
import com.fr.stable.collections.combination.Pair;
import java.util.ArrayList;
import java.util.List;
@ -379,6 +378,38 @@ public class SearchJSUtils {
}
/**
* 获取图表-特效-交互属性中的JS
*/
public static List<NameJavaScript> getChartJavaScript(ChartCollection chartCollection) {
ArrayList<NameJavaScript> nameJavaScriptArrayList = new ArrayList<>();
for (int i = 0; i < chartCollection.getChartCount(); i++) {
if (chartCollection.getChart(i) instanceof VanChart) {
VanChart chart = ((VanChart) chartCollection.getChart(i));
if (chart.getPlot() != null) {
if (chart.getPlot() instanceof VanChartCustomPlot) {
VanChartCustomPlot plot = chart.getPlot();
for (Plot customPlot : plot.getCustomPlotList()) {
getChartJavaScriptFromGroup(customPlot.getHotHyperLink(), nameJavaScriptArrayList);
}
} else {
NameJavaScriptGroup nameJavaScriptGroup = chart.getPlot().getHotHyperLink();
getChartJavaScriptFromGroup(nameJavaScriptGroup, nameJavaScriptArrayList);
}
}
}
}
return nameJavaScriptArrayList;
}
private static void getChartJavaScriptFromGroup(NameJavaScriptGroup nameJavaScriptGroup, ArrayList<NameJavaScript> nameJavaScriptArrayList) {
if (isNameJavaScriptGroupExist(nameJavaScriptGroup)) {
for (int j = 0; j < nameJavaScriptGroup.size(); j++) {
nameJavaScriptArrayList.add(nameJavaScriptGroup.getNameHyperlink(j));
}
}
}
/**
* 处理图表的交互属性可能存在多种地图
* @param content 存储信息的数据结构
@ -493,6 +524,41 @@ public class SearchJSUtils {
}
}
/**
* 获取涉及数据集的超链
*
* @param elem 单元对象
* @return 超链集合
*/
public static List<JavaScript> getJSDependenceTables(Elem elem) {
List<JavaScript> scripts = new ArrayList<>();
if (elem.getNameHyperlinkGroup() != null) {
for (int j = 0; j < elem.getNameHyperlinkGroup().size(); j++) {
NameJavaScript nameJavaScript = elem.getNameHyperlinkGroup().getNameHyperlink(j);
JavaScript javaScript = nameJavaScript.getJavaScript();
if (isChartHyperPopLinkValid(javaScript)) {
ChartHyperPoplink chartHyperPoplink = (ChartHyperPoplink) javaScript;
scripts.add(javaScript);
dealWithChartHyperPoplink(chartHyperPoplink, scripts);
}
}
}
return scripts;
}
private static void dealWithChartHyperPoplink(ChartHyperPoplink chartHyperPoplink, List<JavaScript> scripts) {
if (chartHyperPoplink.getChartCollection() instanceof ChartCollection) {
List<NameJavaScript> nameJavaScripts = getNameJavaScript((ChartCollection) chartHyperPoplink.getChartCollection(), new ITContent(), new ArrayList<>());
for(NameJavaScript javaScript : nameJavaScripts) {
if (javaScript.getJavaScript() instanceof ChartHyperPoplink) {
scripts.add(javaScript.getJavaScript());
}
}
}
}
/**
* 是否图表悬浮超链且内部图表是否可用
*

4
designer-realize/src/test/java/com/fr/design/actions/replace/action/content/tabledata/TableDataFormulaUtilsTest.java

@ -42,6 +42,10 @@ public class TableDataFormulaUtilsTest extends TestCase {
Assert.assertTrue(qiantao2.contains("test-测试7"));
Assert.assertTrue(qiantao2.contains("test-测试8"));
String str3 = "TEST_TABLE.select(INNER.select(glbName,\"6\"),\"6\")";
Set<String> result = TableDataFormulaUtils.search4TableData(str3);
Assert.assertTrue(result.contains("TEST_TABLE"));
Assert.assertTrue(result.contains("INNER"));
}
public void testReplace() {

Loading…
Cancel
Save