Browse Source

Pull request #5819: REPORT-55243:cpt和cptx合并

Merge in DESIGN/design from ~FLY.LI/design:feature/x to feature/x

* commit 'e9eadf142317089a140821851b3d2e37c9d29b9a':
  REPORT-55243:可能存在的强转错误及方法名修改
  REPORT-55243:修改整型数字为常量,修改对cpt和cptx文件后缀的判断方式
  REPORT-55243:修改不合理的方法名 & 改变报表引擎属性界面对应的类名
  REPORT-55243:联动修改因为报表引擎属性中标识引擎的数据类型的改变所需要修改的代码,将其中关于cpt和cptx兼容的流程部分放入一个工具类中(放在CptCompileUtil中不合适)
research/11.0
Fly.Li 3 years ago
parent
commit
4f34c340d3
  1. 7
      designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java
  2. 88
      designer-base/src/main/java/com/fr/nx/app/designer/utils/CptAndCptxCompatibilityUtil.java
  3. 79
      designer-base/src/main/java/com/fr/nx/app/designer/utils/CptCompileUtil.java
  4. 6
      designer-realize/src/main/java/com/fr/design/actions/report/ReportEngineAttrAction.java
  5. 9
      designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java
  6. 15
      designer-realize/src/main/java/com/fr/design/report/ReportEnginePane.java

7
designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java

@ -69,7 +69,7 @@ import com.fr.general.ComparatorUtils;
import com.fr.general.IOUtils;
import com.fr.locale.InterProviderFactory;
import com.fr.log.FineLoggerFactory;
import com.fr.main.impl.WorkBook;
import com.fr.nx.app.designer.utils.CptAndCptxCompatibilityUtil;
import com.fr.nx.app.designer.utils.CptCompileUtil;
import com.fr.nx.cptx.entry.metadata.CptxMetadata;
import com.fr.nx.cptx.utils.CptxFileUtils;
@ -1470,7 +1470,7 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
* 设置新引擎后有不支持的功能时设计器中模板的标题需要加上兼容模式或者不支持分页引擎来提示用户
* */
private String compatibilityTip() {
if (!CptCompileUtil.isNewEngine(this.getTarget(), getEditingFILE().getPath())){
if (!CptAndCptxCompatibilityUtil.isEngineXEnable(this.getTarget(), getEditingFILE().getPath())){
return StringUtils.EMPTY;
}
String path = this.getEditingFILE().getPath();
@ -1686,8 +1686,7 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
* 2.在这三种情况下1.cptx文件另存为cpt文件 2.cptx另存为cptx文件 3.设置了新引擎的cpt文件另存为cpt文件
* 因为文件的编译目录改变了需要重新预编译因此设置jTemplate的保存状态为false
* */
boolean hasChanged = CptCompileUtil.hasChanged(oldName, this);
if (hasChanged){
if (CptAndCptxCompatibilityUtil.needRecompile(oldName, this)){
this.saved = false;
}
result = this.saveRealFile();

88
designer-base/src/main/java/com/fr/nx/app/designer/utils/CptAndCptxCompatibilityUtil.java

@ -0,0 +1,88 @@
package com.fr.nx.app.designer.utils;
import com.fr.base.extension.FileExtension;
import com.fr.design.mainframe.JTemplate;
import com.fr.file.FILE;
import com.fr.main.TemplateWorkBook;
import com.fr.report.report.Report;
import com.fr.report.stable.LayerReportAttr;
import com.fr.report.worksheet.WorkSheet;
/**
* @author fly.li
* @version 10.0
* Created on 2021/09/12
*/
public class CptAndCptxCompatibilityUtil {
/**
* 判断是否需要重新编译
**/
public static boolean needRecompile(String oldName, JTemplate jTemplate){
FILE editingFILE = jTemplate.getEditingFILE();
String path = editingFILE.getPath();
//只有在旧文件是cptx文件并且新文件是cpt文件时才会改变报表引擎属性
boolean isCptxConvertToCpt = FileExtension.CPTX.matchExtension(oldName) && FileExtension.CPT.matchExtension(path);
if (isCptxConvertToCpt && !setFrEngineAttr(jTemplate)){
isCptxConvertToCpt = false;
}
return (isCptxConvertToCpt || isSaveAs(jTemplate, oldName, path));
}
/**
* 判断是不是cptx模板或者开启了的新引擎的cpt模板的另存为操作
**/
private static boolean isSaveAs(JTemplate jTemplate, String oldName, String newName){
return isEngineXEnable(jTemplate.getTarget(), newName) && ((FileExtension.CPTX.matchExtension(oldName) && FileExtension.CPTX.matchExtension(newName)) || (FileExtension.CPT.matchExtension(oldName) && FileExtension.CPT.matchExtension(newName)));
}
/**
* cptx另存为cpt需要修改报表引擎属性
**/
private static boolean setFrEngineAttr(JTemplate jTemplate){
WorkSheet workSheet = gainWorkSheet(jTemplate.getTarget());
if (workSheet == null){
return false;
}else {
LayerReportAttr layerReportAttr = workSheet.getLayerReportAttr();
if (layerReportAttr == null){
layerReportAttr = new LayerReportAttr();
workSheet.setLayerReportAttr(layerReportAttr);
}
layerReportAttr.setClientPaging(true);
layerReportAttr.setEngineState(0);
return true;
}
}
/**
* 是否启用了新引擎的判断
* cptx自动走新引擎非兼容模式cpt需要进行设置
* */
public static boolean isEngineXEnable(Object workBook, String fileName){
WorkSheet workSheet = gainWorkSheet(workBook);
LayerReportAttr layerReportAttr = gainLayerReportAttr(workSheet);
return isEngineXEnable(layerReportAttr, fileName);
}
private static LayerReportAttr gainLayerReportAttr(WorkSheet workSheet){
if (workSheet != null){
LayerReportAttr layerReportAttr = workSheet.getLayerReportAttr();
return layerReportAttr;
} else {
return null;
}
}
private static WorkSheet gainWorkSheet(Object workBook){
if (workBook == null || !(workBook instanceof TemplateWorkBook)){
return null;
}
Report report = ((TemplateWorkBook) workBook).getReport(0);
return report instanceof WorkSheet ? (WorkSheet)report : null;
}
private static boolean isEngineXEnable(LayerReportAttr layerReportAttr, String fileName){
return (layerReportAttr!= null && layerReportAttr.isClientPaging() && layerReportAttr.getEngineState() == LayerReportAttr.ENGINE_X) || FileExtension.CPTX.matchExtension(fileName);
}
}

79
designer-base/src/main/java/com/fr/nx/app/designer/utils/CptCompileUtil.java

@ -6,7 +6,6 @@ import com.fr.file.FILE;
import com.fr.file.FileNodeFILE;
import com.fr.general.ComparatorUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.main.TemplateWorkBook;
import com.fr.main.impl.WorkBook;
import com.fr.nx.app.designer.cptx.io.DesignReadWritableProvider;
import com.fr.nx.app.designer.monitor.DesignerMetricRecorder;
@ -25,9 +24,6 @@ import com.fr.nx.cptx.utils.CptxFileUtils;
import com.fr.nx.data.layer.LayerItem;
import com.fr.nx.data.layer.LayerProps;
import com.fr.nx.template.compile.CompiledReport;
import com.fr.report.report.Report;
import com.fr.report.stable.LayerReportAttr;
import com.fr.report.worksheet.WorkSheet;
import java.io.OutputStream;
@ -39,15 +35,18 @@ public class CptCompileUtil {
}
FILE file = jtemplate.getEditingFILE();
String path = file.getPath();
WorkBook workbook = (WorkBook) jtemplate.getTarget();
Object target = jtemplate.getTarget();
/*
* 如果是cpt并且引擎设置正确执行预编译如果是cptx文件也执行预编译在JStreamWork中保存和另存为流程都进行了重新编译
* 但是由于之前的DefaultTemplateResource.saveTemplate的原因导致JStreamWork::saveFile()不能执行--cptx的保存不能进行预编译
* 应该是流程的误改动这里改回来保存时仍然执行预编译
* 预编译本不应该受引擎模式的影响但是cpt文件在设置为新引擎后是需要进行编译的
* */
if (!isNewEngine(workbook, path)){
if (!CptAndCptxCompatibilityUtil.isEngineXEnable(target, path)){
return;
}
WorkBook workbook = (WorkBook) jtemplate.getTarget();
TransformResultInfo resultInfo = compile0(workbook, file);
unSupportLog(resultInfo);
@ -140,70 +139,6 @@ public class CptCompileUtil {
|| ComparatorUtils.equals(TransformResult.UNSUPPORT, result);
}
/*
* 该另存为流程会改变文件内容现在作为兼容的流程以后可以随时删除该流程
* */
public static boolean hasChanged(String oldName, JTemplate jTemplate){
FILE editingFILE = jTemplate.getEditingFILE();
String path = editingFILE.getPath();
//只有在旧文件是cptx文件并且新文件是cpt文件时才会改变报表引擎属性
boolean isChange = oldName.endsWith(".cptx") && path.endsWith(".cpt");
if (isChange && !changeFrEngineAttr(jTemplate)){
isChange = false;
}
//合并JStreamWork中另存为流程,cptx的另存为也需要重新预编译
return (isChange || isSaveAs(jTemplate, oldName, path));
}
//cptx和设置了新引擎的cpt的另存也需要进行预编译
private static boolean isSaveAs(JTemplate jTemplate, String oldName, String newName){
return isNewEngine(jTemplate.getTarget(), newName) && ((FileExtension.CPTX.matchExtension(oldName) && FileExtension.CPTX.matchExtension(newName)) || (FileExtension.CPT.matchExtension(oldName) && FileExtension.CPT.matchExtension(newName)));
}
private static boolean changeFrEngineAttr(JTemplate jTemplate){
WorkSheet workSheet = gainWorkSheet(jTemplate);
if (workSheet == null){
return false;
}else {
LayerReportAttr layerReportAttr = workSheet.getLayerReportAttr();
if (layerReportAttr == null){
layerReportAttr = new LayerReportAttr();
workSheet.setLayerReportAttr(layerReportAttr);
}
layerReportAttr.setClientPaging(true);
layerReportAttr.setNewEngine(true);
return true;
}
}
public static boolean isNewEngine(Object workBook, String fileName){
WorkSheet workSheet = gainWorkSheet(workBook);
LayerReportAttr layerReportAttr = gainLayerReportAttr(workSheet);
return isNewEngine(layerReportAttr, fileName);
}
private static LayerReportAttr gainLayerReportAttr(WorkSheet workSheet){
if (workSheet != null){
LayerReportAttr layerReportAttr = workSheet.getLayerReportAttr();
return layerReportAttr;
} else {
return null;
}
}
private static WorkSheet gainWorkSheet(Object workBook){
if (workBook == null || !(workBook instanceof TemplateWorkBook)){
return null;
}
Report report = ((TemplateWorkBook) workBook).getReport(0);
return report instanceof WorkSheet ? (WorkSheet)report : null;
}
private static boolean isNewEngine(LayerReportAttr layerReportAttr, String fileName){
return (layerReportAttr!= null && layerReportAttr.isClientPaging() && layerReportAttr.isNewEngine()) || FileExtension.CPTX.matchExtension(fileName);
}
private static void unSupportLog(TransformResultInfo transformResultInfo){
TransformResult result = transformResultInfo.getResult();
//这里只打印模板转换不支持的信息,没有打印模板转换失败的信息
@ -212,5 +147,7 @@ public class CptCompileUtil {
}
}
private static boolean isUnSupportFileType(String path){
return FileExtension.CPT.matchExtension(path) || FileExtension.CPTX.matchExtension(path);
}
}

6
designer-realize/src/main/java/com/fr/design/actions/report/ReportEngineAttrAction.java

@ -7,7 +7,7 @@ import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.WorkSheetDesigner;
import com.fr.design.menu.KeySetUtils;
import com.fr.design.report.LayerReportEnginePane;
import com.fr.design.report.ReportEnginePane;
import com.fr.report.worksheet.WorkSheet;
public class ReportEngineAttrAction extends ReportComponentAction<WorkSheetDesigner> {
@ -18,7 +18,7 @@ public class ReportEngineAttrAction extends ReportComponentAction<WorkSheetDesig
this.setName(getMenuKeySet().getMenuKeySetName() + "...");
this.setMnemonic(getMenuKeySet().getMnemonic());
this.setSmallIcon("/com/fr/design/images/m_report/reportEngineAttr");
this.generateAndSetSearchText(LayerReportEnginePane.class.getName());
this.generateAndSetSearchText(ReportEnginePane.class.getName());
}
@ -35,7 +35,7 @@ public class ReportEngineAttrAction extends ReportComponentAction<WorkSheetDesig
return false;
}
final WorkSheet tplEC = jws.getTemplateReport();
final LayerReportEnginePane layerReportEnginePane = new LayerReportEnginePane(tplEC);
final ReportEnginePane layerReportEnginePane = new ReportEnginePane(tplEC);
layerReportEnginePane.populateBean(tplEC.getLayerReportAttr());
BasicDialog dialog = layerReportEnginePane.showWindow(DesignerContext.getDesignerFrame());
isChange = false;

9
designer-realize/src/main/java/com/fr/design/mainframe/JWorkBook.java

@ -5,7 +5,6 @@ import com.fr.base.DynamicUnitList;
import com.fr.base.Parameter;
import com.fr.base.ScreenResolution;
import com.fr.base.extension.FileExtension;
import com.fr.base.theme.FormTheme;
import com.fr.base.theme.TemplateThemeCompatible;
import com.fr.base.vcs.DesignerMode;
import com.fr.base.theme.ReportTheme;
@ -90,7 +89,7 @@ import com.fr.main.impl.WorkBookAdapter;
import com.fr.main.impl.WorkBookX;
import com.fr.main.parameter.ReportParameterAttr;
import com.fr.nx.app.designer.menu.CalculateAttrAction;
import com.fr.nx.app.designer.utils.CptCompileUtil;
import com.fr.nx.app.designer.utils.CptAndCptxCompatibilityUtil;
import com.fr.poly.PolyDesigner;
import com.fr.poly.creator.BlockCreator;
import com.fr.privilege.finegrain.WorkSheetPrivilegeControl;
@ -719,7 +718,7 @@ public class JWorkBook extends JTemplate<WorkBook, WorkBookUndoState> {
}
protected void addShortCut(MenuDef exportMenuDef, MenuDef excelExportMenuDef) {
if (CptCompileUtil.isNewEngine(this.getTarget(), getEditingFILE().getPath())){
if (CptAndCptxCompatibilityUtil.isEngineXEnable(this.getTarget(), getEditingFILE().getPath())){
exportMenuDef.addShortCut(excelExportMenuDef, new PDFExportAction(this), new WordExportAction(this), new SVGExportAction(this),
new CSVExportAction(this), new TextExportAction(this));
}else {
@ -749,7 +748,7 @@ public class JWorkBook extends JTemplate<WorkBook, WorkBookUndoState> {
*/
@Override
public ShortCut[] shortcut4TemplateMenu() {
boolean isNewEngine = CptCompileUtil.isNewEngine(this.getTarget(), getEditingFILE().getPath());
boolean enableNewEngine = CptAndCptxCompatibilityUtil.isEngineXEnable(this.getTarget(), getEditingFILE().getPath());
ShortCut[] commonShortCut = ArrayUtils.addAll(new ShortCut[]{
new ReportWebAttrAction(this),
new ReportExportAttrAction(this),
@ -760,7 +759,7 @@ public class JWorkBook extends JTemplate<WorkBook, WorkBookUndoState> {
new ReportWatermarkAction(this),
new NameSeparator(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Utils_Current_Sheet")),
}, this.reportComposite.getEditingReportComponent().shortcut4TemplateMenu());
if (isNewEngine){
if (enableNewEngine){
return ArraysUtil.insert(commonShortCut, new CalculateAttrAction(this), 5);
}else {
return commonShortCut;

15
designer-realize/src/main/java/com/fr/design/report/LayerReportEnginePane.java → designer-realize/src/main/java/com/fr/design/report/ReportEnginePane.java

@ -11,17 +11,14 @@ import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.DesignerContext;
import com.fr.locale.InterProviderFactory;
import com.fr.report.core.ReportUtils;
import com.fr.report.stable.LayerReportAttr;
import com.fr.report.worksheet.WorkSheet;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import java.awt.CardLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
@ -34,7 +31,7 @@ import java.util.List;
* @version 10.0
* Created on 2021/08/22
*/
public class LayerReportEnginePane extends BasicBeanPane<LayerReportAttr> {
public class ReportEnginePane extends BasicBeanPane<LayerReportAttr> {
private static final int LABEL_HEIGHT = 55;
private UICheckBox isClientPaging;
private UICheckBox isShowDataNumber;
@ -43,12 +40,12 @@ public class LayerReportEnginePane extends BasicBeanPane<LayerReportAttr> {
private WorkSheet worksheet;
private List<JRadioButton> radioButtons = new ArrayList<>(2);
public LayerReportEnginePane(WorkSheet worksheet) {
public ReportEnginePane(WorkSheet worksheet) {
this.worksheet = worksheet;
this.initComponents();
}
public LayerReportEnginePane() {
public ReportEnginePane() {
this(null);
}
@ -165,8 +162,8 @@ public class LayerReportEnginePane extends BasicBeanPane<LayerReportAttr> {
isPageQueryBox.setSelected(false);
countPerPageEditor.setEnabled(false);
}
radioButtons.get(0).setSelected(ob.isNewEngine());
radioButtons.get(1).setSelected(!ob.isNewEngine());
radioButtons.get(0).setSelected(ob.getEngineState() == LayerReportAttr.ENGINE_X ? true : false);
radioButtons.get(1).setSelected(ob.getEngineState() == LayerReportAttr.LINE_ENGINE ? true : false);
}
@Override
@ -179,7 +176,7 @@ public class LayerReportEnginePane extends BasicBeanPane<LayerReportAttr> {
attr.setShowDataNumber(isShowDataNumber.isSelected());
for (int i = 0; i < radioButtons.size(); i++){
if (radioButtons.get(i).isSelected()){
attr.setNewEngine((i == 0));
attr.setEngineState(i);
}
}
return attr;
Loading…
Cancel
Save