Browse Source

Merge pull request #9978 in DESIGN/design from bugfix/11.0 to feature/x

* commit '222a7eaaa506b46a8d8e99fc1425cf989bf5494c':
  REPORT-79909 补充注释
  重构getFileNameIndex
  REPORT-79909 设计器启动失败,有模板名称叫WorkBook88888888888888.cpt导致
  REPORT-79909 设计器启动失败,有模板名称叫WorkBook88888888888888.cpt导致
  REPORT-79111 数据集分组插件-安装之后,复制决策报表的报表块,数据查询无法一起复制 【问题原因】粘贴的逻辑里将BasicTableDataTreePane强转成了TableDataTreePane,导致插件里实现的BasicTableDataTreePane的子类对象强转失败报错 【改动思路】删掉强转的逻辑,后续的调用也均为抽象类中的抽象方法,可以保证不影响插件 【review建议】
feature/x
superman 2 years ago
parent
commit
df46cff279
  1. 4
      designer-base/src/main/java/com/fr/design/data/tabledata/paste/TableDataFollowingPasteUtils.java
  2. 73
      designer-base/src/main/java/com/fr/design/mainframe/JTemplateNameHelper.java
  3. 23
      designer-base/src/test/java/com/fr/design/mainframe/JTemplateNameHelperTest.java

4
designer-base/src/main/java/com/fr/design/data/tabledata/paste/TableDataFollowingPasteUtils.java

@ -5,6 +5,7 @@ import com.fr.base.chart.BaseChartCollection;
import com.fr.data.TableDataSource; import com.fr.data.TableDataSource;
import com.fr.data.impl.storeproc.StoreProcedure; import com.fr.data.impl.storeproc.StoreProcedure;
import com.fr.design.DesignModelAdapter; import com.fr.design.DesignModelAdapter;
import com.fr.design.data.BasicTableDataTreePane;
import com.fr.design.data.DesignTableDataManager; import com.fr.design.data.DesignTableDataManager;
import com.fr.design.data.datapane.TableDataTreePane; import com.fr.design.data.datapane.TableDataTreePane;
import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane; import com.fr.design.data.tabledata.tabledatapane.AbstractTableDataPane;
@ -22,7 +23,6 @@ import com.fr.form.ui.DictionaryContainer;
import com.fr.form.ui.ElementCaseEditor; import com.fr.form.ui.ElementCaseEditor;
import com.fr.form.ui.Widget; import com.fr.form.ui.Widget;
import com.fr.form.ui.concept.data.ValueInitializer; import com.fr.form.ui.concept.data.ValueInitializer;
import com.fr.general.ComparatorUtils;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.report.cell.FloatElement; import com.fr.report.cell.FloatElement;
import com.fr.report.cell.tabledata.ElementUsedTableDataProvider; import com.fr.report.cell.tabledata.ElementUsedTableDataProvider;
@ -57,7 +57,7 @@ public class TableDataFollowingPasteUtils {
} }
// 获取当前的TableDataTreePane // 获取当前的TableDataTreePane
DesignModelAdapter<?, ?> currentModelAdapter = DesignModelAdapter.getCurrentModelAdapter(); DesignModelAdapter<?, ?> currentModelAdapter = DesignModelAdapter.getCurrentModelAdapter();
TableDataTreePane tableDataTreePane = (TableDataTreePane) TableDataTreePane.getInstanceWithoutRefreshEverytime(currentModelAdapter); BasicTableDataTreePane tableDataTreePane = TableDataTreePane.getInstanceWithoutRefreshEverytime(currentModelAdapter);
// 粘贴(添加)数据集 // 粘贴(添加)数据集
for (Map.Entry<String, TableData> dataWrapperEntry : tableDataWrapperMap.entrySet()) { for (Map.Entry<String, TableData> dataWrapperEntry : tableDataWrapperMap.entrySet()) {
String dsName = dataWrapperEntry.getKey(); String dsName = dataWrapperEntry.getKey();

73
designer-base/src/main/java/com/fr/design/mainframe/JTemplateNameHelper.java

@ -5,6 +5,7 @@ import com.fr.design.gui.itree.filetree.TemplateFileTree;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultMutableTreeNode;
import java.math.BigInteger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -27,19 +28,18 @@ public class JTemplateNameHelper {
DefaultMutableTreeNode gen = (DefaultMutableTreeNode) tt.getModel().getRoot(); DefaultMutableTreeNode gen = (DefaultMutableTreeNode) tt.getModel().getRoot();
String[] str = new String[gen.getChildCount()]; String[] str = new String[gen.getChildCount()];
List<Integer> reportNum = new ArrayList<>(); List<BigInteger> reportNum = new ArrayList<>();
for (int j = 0; j < gen.getChildCount(); j++) { for (int j = 0; j < gen.getChildCount(); j++) {
str[j] = gen.getChildAt(j).toString(); str[j] = gen.getChildAt(j).toString();
//返回文件名中的index(算法中没有再匹配文件后缀了,因为DefaultMutableTreeNode中已经匹配过了) //返回文件名中的index(算法中没有再匹配文件后缀了,因为DefaultMutableTreeNode中已经匹配过了)
Integer index = getFileNameIndex(prefix, str[j]); BigInteger index = getFileNameIndex(prefix, str[j]);
if (index != null) { if (index != null) {
reportNum.add(index); reportNum.add(index);
} }
} }
Collections.sort(reportNum); Collections.sort(reportNum);
int idx = reportNum.size() > 0 ? reportNum.get(reportNum.size() - 1) + 1 : 1; BigInteger idx = reportNum.size() > 0 ? reportNum.get(reportNum.size() - 1).add(BigInteger.valueOf(1)) : BigInteger.valueOf(1);
idx = idx.add(BigInteger.valueOf(currentIndex));
idx = idx + currentIndex;
currentIndex++; currentIndex++;
return prefix + idx; return prefix + idx;
} }
@ -52,35 +52,56 @@ public class JTemplateNameHelper {
* @Author Henry.Wang * @Author Henry.Wang
* @Date 2021/4/9 11:13 * @Date 2021/4/9 11:13
**/ **/
private static Integer getFileNameIndex(String prefix, String fileName) { private static BigInteger getFileNameIndex(String prefix, String fileName) {
if (fileName.length() <= prefix.length()) { //如果文件名长度小于等于前缀长度或者匹配前缀失败,直接返回就可以了
if ((prefix.length() >= fileName.length()) || (!StringUtils.equals(prefix, fileName.substring(0, prefix.length())))) {
return null; return null;
} }
char[] chars = new char[fileName.length()]; BigInteger integer = null;
int i = 0; integer = matchFileNameIndex(prefix, fileName);
for (; i < fileName.length(); i++) { return integer;
}
/**
* 匹配文件名称的数字后缀Index
* @param prefix 前缀
* @param fileName 文件名称全名
* @return 返回对应的数字后缀Index
*/
private static BigInteger matchFileNameIndex(String prefix, String fileName) {
StringBuilder result = new StringBuilder();
for (int i = prefix.length(); i < fileName.length(); i++) {
char c = fileName.charAt(i); char c = fileName.charAt(i);
//匹配前缀 if (isDot(c)) {
if (i < prefix.length()) { break;
if (c != prefix.charAt(i)) {
return null;
}
} else { } else {
if (c == '.') { if (isNotNumber(c)) {
break; return null;
} else {
//匹配0~9
if (c < 48 || c > 57) {
return null;
}
chars[i - prefix.length()] = c;
} }
result.append(c);
} }
} }
String s = new String(chars).substring(0, i - prefix.length()); if (StringUtils.isBlank(result.toString())) {
if (StringUtils.isBlank(s)) {
return null; return null;
} }
return Integer.valueOf(s); return new BigInteger(result.toString(), 10);
}
/**
* 是否不属于数字0-9
* @param c 用于判断的char
* @return 返回对应判断结果
*/
private static boolean isNotNumber(char c) {
return c < 48 || c > 57;
}
/**
* 是否属于'.'
* @param c 用于判断的char
* @return 返回对应判断结果
*/
private static boolean isDot(char c) {
return c == '.';
} }
} }

23
designer-base/src/test/java/com/fr/design/mainframe/JTemplateNameHelperTest.java

@ -2,6 +2,8 @@ package com.fr.design.mainframe;
import junit.framework.TestCase; import junit.framework.TestCase;
import com.fr.invoke.Reflect;
/** /**
* @author shine * @author shine
* @version 10.0 * @version 10.0
@ -18,6 +20,27 @@ public class JTemplateNameHelperTest extends TestCase {
String name1 = JTemplateNameHelper.newTemplateNameByIndex("TEST"); String name1 = JTemplateNameHelper.newTemplateNameByIndex("TEST");
assertEquals("TEST2", name1); assertEquals("TEST2", name1);
}
public void testGetFileNameIndex() {
//正常情况
assertEquals("1", Reflect.on(JTemplateNameHelper.class).call("getFileNameIndex", "WorkBook", "WorkBook1").toString());
//正常情况
assertEquals("8888888888", Reflect.on(JTemplateNameHelper.class).call("getFileNameIndex", "WorkBook", "WorkBook8888888888").toString());
//正常情况
assertEquals("88812214128888881231238123123", Reflect.on(JTemplateNameHelper.class).call("getFileNameIndex", "WorkBook", "WorkBook88812214128888881231238123123").toString());
//前缀不匹配
assertNull(Reflect.on(JTemplateNameHelper.class).call("getFileNameIndex", "Work123", "WorkBook8888888888").get());
//前缀为空
assertNull(Reflect.on(JTemplateNameHelper.class).call("getFileNameIndex", "", "WorkBook8888888888").get());
//文件长度小于前缀
assertNull(Reflect.on(JTemplateNameHelper.class).call("getFileNameIndex", "WorkBook", "").get());
} }
} }

Loading…
Cancel
Save