Browse Source

REPORT-75998 搜索JS

feature/x
Destiny.Lin 2 years ago
parent
commit
84e0de2183
  1. 123
      designer-realize/src/main/java/com/fr/design/actions/replace/action/content/js/SearchCellJSAction.java
  2. 65
      designer-realize/src/main/java/com/fr/design/actions/replace/action/content/js/SearchFloatJSAction.java
  3. 46
      designer-realize/src/main/java/com/fr/design/actions/replace/action/content/js/SearchJSAction.java
  4. 137
      designer-realize/src/main/java/com/fr/design/actions/replace/action/content/js/SearchWebJSAction.java
  5. 57
      designer-realize/src/main/java/com/fr/design/actions/replace/action/content/js/SearchWidgetJSAction.java

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

@ -0,0 +1,123 @@
package com.fr.design.actions.replace.action.content.js;
import com.fr.chart.chartattr.ChartCollection;
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.actions.replace.info.JSInfo;
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.JavaScriptImpl;
import com.fr.js.NameJavaScript;
import com.fr.js.NameJavaScriptGroup;
import com.fr.plugin.chart.base.VanChartHtmlLabel;
import com.fr.report.cell.CellElement;
import com.fr.report.cell.TemplateCellElement;
import com.fr.report.cell.cellattr.highlight.DefaultHighlight;
import com.fr.report.cell.cellattr.highlight.HighlightAction;
import com.fr.report.cell.cellattr.highlight.HyperlinkHighlightAction;
import javafx.util.Pair;
import java.util.ArrayList;
/**
* @author Destiny.Lin
* @version 11.0
* created by Destiny.Lin on 2022-08-13
*/
public class SearchCellJSAction implements SearchAction {
public SearchCellJSAction(JTemplate jTemplate, ArrayList<JSInfo> jsInfos) {
jsInfos.addAll(search4Infos(jTemplate));
}
@Override
public ArrayList<JSInfo> search4Infos(JTemplate jTemplate) {
ArrayList<JSInfo> jsInfos = new ArrayList<>();
addJSInfos2ListFromCell(jTemplate, jsInfos);
return jsInfos;
}
private void addJSInfos2ListFromCell(JTemplate jTemplate, ArrayList<JSInfo> jsInfos) {
SearchCellAction searchCellAction = new SearchCellAction(jTemplate);
for (CellInfo cellInfo : searchCellAction.getCellInfos()) {
CellElement cell = (CellElement) cellInfo.getContent().getReplaceObject();
ITContent newContent4Cell = cellInfo.getContent().copy();
ITContent newContent4CellCondition = cellInfo.getContent().copy();
ITContent newContent4CellWidgetCondition = cellInfo.getContent().copy();
//单元格的超级链接里面的JS
SearchJSUtils.addJSInfosFromHyperLink(cell, jsInfos, newContent4Cell);
//单元格条件属性里的JS
newContent4CellCondition.addOtherPos(Toolkit.i18nText("Fine-Design_Basic_Condition_Attributes"));
searchCellConditionJS(cell, jsInfos, newContent4CellCondition);
//单元格如果是图表还需要额外处理
if (cell.getValue() instanceof ChartCollection) {
ArrayList<Pair<VanChartHtmlLabel, String>> htmlLabels = SearchJSUtils.getHtmlLabel((ChartCollection) cell.getValue());
ArrayList<NameJavaScript> nameJavaScripts = SearchJSUtils.getNameJavaScript((ChartCollection) cell.getValue());
//图表-样式-标签以及图表-特效-条件显示
ITContent htmlITContent = cellInfo.getContent().copy();
htmlITContent.getContentObject().setCell(cell);
htmlITContent.addOtherPos(Toolkit.i18nText("Fine-Design_Chart_Chart"));
SearchJSUtils.addJSInfosFromHtmlLabel(htmlITContent, htmlLabels, jsInfos);
//图表-特效-交互属性
ITContent conditionContent = cellInfo.getContent().copy();
conditionContent.getContentObject().setCell(cell);
conditionContent.addOtherPos(
Toolkit.i18nText("Fine-Design_Chart_Interactive"),
Toolkit.i18nText("Fine-Design_Report_Hyperlink")
);
SearchJSUtils.addJSInfosFromNameJS(conditionContent, nameJavaScripts, jsInfos);
}
}
}
private void searchCellConditionJS(CellElement cell, ArrayList<JSInfo> jsInfos, ITContent content) {
if (((TemplateCellElement) cell).getHighlightGroup() != null) {
for (int i = 0; i < ((TemplateCellElement) cell).getHighlightGroup().size(); i++) {
NameJavaScriptGroup njsg = getJSFromAction(((DefaultHighlight) ((TemplateCellElement) cell).getHighlightGroup().getHighlight(i)));
getAllJSFromNameJavaScriptGroup(cell, jsInfos, njsg, content);
}
}
}
private void getAllJSFromNameJavaScriptGroup(CellElement cell, ArrayList<JSInfo> jsInfos, NameJavaScriptGroup njsg, ITContent content) {
if (isJSExist(njsg)) {
for (int i = 0; i < njsg.size(); i++) {
if (njsg.getNameHyperlink(i).getJavaScript() instanceof JavaScriptImpl) {
ITContent newContent = content.copy();
newContent.getContentObject().setCell(cell);
newContent.getContentObject().setNameJavaScript(njsg.getNameHyperlink(i));
newContent.setReplaceObject(njsg.getNameHyperlink(i));
SearchJSUtils.addJSInfos(jsInfos, new JSInfo(newContent));
}
}
}
}
private boolean isJSExist(NameJavaScriptGroup njsg) {
return njsg != null;
}
private NameJavaScriptGroup getJSFromAction(DefaultHighlight highlight) {
for (int i = 0; i < highlight.actionCount(); i++) {
if (isHighlightAction(highlight.getHighlightAction(i))) {
return ((HyperlinkHighlightAction) highlight.getHighlightAction(i)).getHperlink();
}
}
return null;
}
private boolean isHighlightAction(HighlightAction highlightAction) {
return highlightAction instanceof HyperlinkHighlightAction;
}
}

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

@ -0,0 +1,65 @@
package com.fr.design.actions.replace.action.content.js;
import com.fr.chart.chartattr.ChartCollection;
import com.fr.design.actions.replace.action.SearchAction;
import com.fr.design.actions.replace.action.content.floatelement.SearchFloatAction;
import com.fr.design.actions.replace.info.FloatInfo;
import com.fr.design.actions.replace.info.JSInfo;
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.NameJavaScript;
import com.fr.main.impl.WorkBook;
import com.fr.plugin.chart.base.VanChartHtmlLabel;
import com.fr.report.cell.FloatElement;
import com.fr.report.elementcase.ElementCase;
import com.fr.report.poly.PolyECBlock;
import com.fr.report.report.Report;
import javafx.util.Pair;
import java.util.*;
/**
* @author Destiny.Lin
* @version 11.0
* created by Destiny.Lin on 2022-08-15
*/
public class SearchFloatJSAction implements SearchAction {
public SearchFloatJSAction(JTemplate jTemplate, ArrayList<JSInfo> jsInfos) {
jsInfos.addAll(search4Infos(jTemplate));
}
@Override
public ArrayList<JSInfo> search4Infos(JTemplate jTemplate) {
ArrayList<JSInfo> jsInfos = new ArrayList<>();
addJSInfos2ListFromFloat(jTemplate, jsInfos);
return jsInfos;
}
private void addJSInfos2ListFromFloat(JTemplate jTemplate, ArrayList<JSInfo> jsInfos) {
SearchFloatAction searchFloatAction = new SearchFloatAction(jTemplate);
for (FloatInfo floatInfo : searchFloatAction.getFloatInfos()) {
FloatElement floatElement = (FloatElement) floatInfo.getContent().getReplaceObject();
ITContent content = floatInfo.getContent().copy();
//从超级链接搜索
SearchJSUtils.addJSInfosFromHyperLink(floatElement, jsInfos, content);
if (floatElement.getValue() instanceof ChartCollection) {
ArrayList<Pair<VanChartHtmlLabel, String>> htmlLabels = SearchJSUtils.getHtmlLabel((ChartCollection) floatElement.getValue());
ArrayList<NameJavaScript> nameJavaScripts = SearchJSUtils.getNameJavaScript((ChartCollection) floatElement.getValue());
//图表-样式-标签以及图表-特效-条件显示
SearchJSUtils.addJSInfosFromHtmlLabel(content, htmlLabels, jsInfos);
//图表-特效-交互属性
ITContent newContent = content.copy();
newContent.addOtherPos(
Toolkit.i18nText("Fine-Design_Chart_Animation_Special"),
Toolkit.i18nText("Fine-Design_Chart_Interactive")
);
SearchJSUtils.addJSInfosFromNameJS(newContent, nameJavaScripts, jsInfos);
}
}
}
}

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

@ -0,0 +1,46 @@
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 java.util.ArrayList;
/**
* @author Destiny.Lin
* @version 11.0
* created by Destiny.Lin on 2022-08-12
*/
public class SearchJSAction implements SearchAction {
private ArrayList<JSInfo> jsInfos;
public SearchJSAction(JTemplate jTemplate) {
setJsInfos(search4Infos(jTemplate));
}
@Override
public ArrayList<JSInfo> search4Infos(JTemplate jTemplate) {
ArrayList<JSInfo> jsInfos = new ArrayList<>();
//从单元格获取JS
new SearchCellJSAction(jTemplate, jsInfos);
//从参数面板控件
new SearchWidgetJSAction(jTemplate, jsInfos);
//从模板Web属性
new SearchWebJSAction(jTemplate, jsInfos);
//从悬浮元素
new SearchFloatJSAction(jTemplate, jsInfos);
return jsInfos;
}
public ArrayList<JSInfo> getJsInfos() {
return jsInfos;
}
public void setJsInfos(ArrayList<JSInfo> jsInfos) {
this.jsInfos = jsInfos;
}
}

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

@ -0,0 +1,137 @@
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.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.form.event.Listener;
import com.fr.form.ui.CustomToolBarButton;
import com.fr.form.ui.Widget;
import com.fr.js.JavaScriptImpl;
import com.fr.main.impl.WorkBook;
import com.fr.report.web.ToolBarManager;
import com.fr.report.web.WebContent;
import com.fr.web.attr.ReportWebAttr;
import java.util.ArrayList;
import java.util.HashMap;
/**
* @author Destiny.Lin
* @version 11.0
* created by Destiny.Lin on 2022-08-15
*/
public class SearchWebJSAction implements SearchAction {
private final static HashMap<String, String> map = new HashMap<>();
private ArrayList<WebContent> arrayList = new ArrayList<>();
static {
map.put("WebPage", Toolkit.i18nText("Fine-Design_Report_Pagination_Setting"));
map.put("WebWrite", Toolkit.i18nText("Fine-Design_Report_Write_Setting"));
map.put("WebView", Toolkit.i18nText("Fine-Design_Report_Data_Analysis_Settings"));
}
public SearchWebJSAction(JTemplate jTemplate, ArrayList<JSInfo> jsInfos) {
jsInfos.addAll(search4Infos(jTemplate));
}
@Override
public ArrayList<JSInfo> search4Infos(JTemplate jTemplate) {
ArrayList<JSInfo> jsInfos = new ArrayList<>();
addJSInfos2ListFromWeb(jTemplate, jsInfos);
return jsInfos;
}
private void addJSInfos2ListFromWeb(JTemplate jTemplate, ArrayList<JSInfo> jsInfos) {
if (jTemplate.getTarget() instanceof WorkBook) {
WorkBook workBook = (WorkBook) jTemplate.getTarget();
ReportWebAttr webAttr = workBook.getReportWebAttr();
ITContent content = new ITContent();
content.setTemplateName(jTemplate.getTemplateName());
addWebContent2Array(webAttr);
for (int i = 0; i < arrayList.size(); i++) {
addJSInfos2ListFromArray(content, jsInfos, arrayList.get(i));
}
}
}
private void addJSInfos2ListFromArray(ITContent content, ArrayList<JSInfo> jsInfos, WebContent webContent) {
ITContent newContent = content.copy();
if (map.containsKey(webContent.getClass().getSimpleName())) {
newContent.addOtherPos(map.get(webContent.getClass().getSimpleName()));
}
addJSInfos2ListFromWebButton(newContent, jsInfos, webContent);
addJSInfos2ListFromWebListener(newContent, jsInfos, webContent);
}
private void addJSInfos2ListFromWebListener(ITContent content, ArrayList<JSInfo> jsInfos, WebContent webContent) {
for (int i = 0; i < webContent.getListenerSize(); i++) {
Listener listener = webContent.getListener(i);
ITContent newContent = content.copy();
newContent.setReplaceObject(listener);
SearchJSUtils.searchJSFromListener(jsInfos, newContent);
}
}
private void addJSInfos2ListFromWebButton(ITContent content, ArrayList<JSInfo> jsInfos, WebContent webContent) {
if (hasToolBarManagers(webContent.getToolBarManagers())) {
for (ToolBarManager toolBarManager : webContent.getToolBarManagers()) {
dealWithCustonToolBarButtonImpl(content, jsInfos, toolBarManager);
}
}
}
private void addWebContent2Array(ReportWebAttr webAttr) {
if (webAttr != null) {
addContent(arrayList, webAttr.getWebWrite());
addContent(arrayList, webAttr.getWebPage());
addContent(arrayList, webAttr.getWebView());
}
}
private void addContent(ArrayList<WebContent> arrayList, WebContent webContent) {
if (webContent != null) {
arrayList.add(webContent);
}
}
private void dealWithCustonToolBarButtonImpl(ITContent content, ArrayList<JSInfo> jsInfos, ToolBarManager toolBarManager) {
for (int i = 0; i < toolBarManager.getToolBar().getWidgetSize(); i++) {
if (isWidgetIntanceofCustomToolBarButton(toolBarManager.getToolBar().getWidget(i))) {
ITContent newContent = content.copy();
newContent.getContentObject().setWidget(toolBarManager.getToolBar().getWidget(i));
addJSInfos2ListFromButtonImpl(newContent, jsInfos);
}
}
}
private void addJSInfos2ListFromButtonImpl(ITContent content, ArrayList<JSInfo> jsInfos) {
if (((CustomToolBarButton) content.getContentObject().getWidget()).getJSImpl() != null
&& ((CustomToolBarButton) content.getContentObject().getWidget()).getJSImpl() instanceof JavaScriptImpl) {
ITContent newContent = content.copy();
newContent.addOtherPos(Toolkit.i18nText("Fine-Design_Report_Custom_Form_Button"));
newContent.getContentObject().setJs(((CustomToolBarButton) content.getContentObject().getWidget()).getJSImpl());
newContent.setReplaceObject(((CustomToolBarButton) content.getContentObject().getWidget()).getJSImpl());
SearchJSUtils.addJSInfos(jsInfos, new JSInfo(newContent));
}
}
private boolean hasToolBarManagers(ToolBarManager[] toolBarManagers) {
return toolBarManagers.length > 0;
}
private boolean isWidgetIntanceofCustomToolBarButton(Widget widget) {
return widget instanceof CustomToolBarButton;
}
}

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

@ -0,0 +1,57 @@
package com.fr.design.actions.replace.action.content.js;
import com.fr.base.parameter.ParameterUI;
import com.fr.design.actions.replace.action.SearchAction;
import com.fr.design.actions.replace.action.content.component.SearchComponentAction;
import com.fr.design.actions.replace.action.content.widget.SearchWidgetAction;
import com.fr.design.actions.replace.info.ComponentInfo;
import com.fr.design.actions.replace.info.JSInfo;
import com.fr.design.actions.replace.info.WidgetInfo;
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.form.ui.Widget;
import com.fr.main.impl.WorkBook;
import com.fr.main.parameter.ReportParameterAttr;
import java.util.ArrayList;
/**
* @author Destiny.Lin
* @version 11.0
* created by Destiny.Lin on 2022-08-13
*/
public class SearchWidgetJSAction implements SearchAction {
public SearchWidgetJSAction(JTemplate jTemplate,ArrayList<JSInfo> jsInfos){
jsInfos.addAll(search4Infos(jTemplate));
}
@Override
public ArrayList<JSInfo> search4Infos(JTemplate jTemplate) {
ArrayList<JSInfo> jsInfos = new ArrayList<>();
addJSInfos2ListFromWidget(jTemplate,jsInfos);
return jsInfos;
}
private void addJSInfos2ListFromWidget(JTemplate jTemplate, ArrayList<JSInfo> jsInfos) {
if (jTemplate.getTarget() instanceof WorkBook){
SearchWidgetAction searchWidgetAction = new SearchWidgetAction(jTemplate);
for (WidgetInfo widgetInfo : searchWidgetAction.getWidgetInfos()){
ITContent content = widgetInfo.getContent().copy();
content.addOtherPos(Toolkit.i18nText("Fine-Design_Report_Event"));
SearchJSUtils.selectJSAction(jsInfos,content);
}
} else {
SearchComponentAction searchComponentAction = new SearchComponentAction(jTemplate);
for (ComponentInfo componentInfo : searchComponentAction.getComponentInfos()){
ITContent content = componentInfo.getContent().copy();
content.addOtherPos(Toolkit.i18nText("Fine-Design_Report_Event"));
SearchJSUtils.selectJSAction(jsInfos,content);
}
}
}
}
Loading…
Cancel
Save