diff --git a/designer-base/src/main/java/com/fr/design/data/BasicTableDataTreePane.java b/designer-base/src/main/java/com/fr/design/data/BasicTableDataTreePane.java index 3dbcf81873..fa1fe545ed 100644 --- a/designer-base/src/main/java/com/fr/design/data/BasicTableDataTreePane.java +++ b/designer-base/src/main/java/com/fr/design/data/BasicTableDataTreePane.java @@ -444,7 +444,7 @@ public abstract class BasicTableDataTreePane extends DockingView implements Resp ((MultiResultTableData) (((TableDataWrapper) data).getTableData())).resetDataModelList(); if (data instanceof MultiResultTableDataWrapper) { MultiResultTableDataWrapper oldSdw = ((MultiResultTableDataWrapper) data); - MultiResultTableDataWrapper newSdw = new MultiResultTableDataWrapper((MultiResultTableData) oldSdw.getTableData(), oldSdw.getTableDataName(), oldSdw.getDataModelName()); + MultiResultTableDataWrapper newSdw = new MultiResultTableDataWrapper((MultiResultTableData) oldSdw.getTableData(), oldSdw.getMultiResultTableDataName(), oldSdw.getTableDataName()); newSdw.previewData(MultiResultTableDataWrapper.PREVIEW_ONE); } else { MultiResultTableData tableData = (MultiResultTableData) ((TableDataWrapper) data).getTableData(); diff --git a/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/ProcedureDataPane.java b/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/ProcedureDataPane.java index b57ca864fd..ad07f9b6fb 100644 --- a/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/ProcedureDataPane.java +++ b/designer-base/src/main/java/com/fr/design/data/tabledata/tabledatapane/ProcedureDataPane.java @@ -289,16 +289,16 @@ public class ProcedureDataPane extends AbstractTableDataPane imp @Override protected Void doInBackground() throws Exception { DesignTableDataManager.setThreadLocal(DesignTableDataManager.NO_PARAMETER); - // sp.setCalculating(true); + sp.setCalculating(true); ProcedureDataModel[] dataModels = (ProcedureDataModel[]) DesignTableDataManager.createLazyDataModel(sp, false); - //sp.refreshDataModelListAndResultNames(dataModels); + sp.refreshResults(dataModels); return null; } @Override public void done() { DesignTableDataManager.setThreadLocal(DesignTableDataManager.NO_PARAMETER); - // sp.setCalculating(false); + sp.setCalculating(false); doAfterProcudureDone(); fireDSChanged(); TableDataTreePane.getInstance(DesignModelAdapter.getCurrentModelAdapter()); diff --git a/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataNameWrapper.java b/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataNameWrapper.java index 610aac3c58..97bf701a62 100644 --- a/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataNameWrapper.java +++ b/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataNameWrapper.java @@ -4,11 +4,8 @@ import com.fr.base.TableData; import com.fr.data.MultiResultTableData; import com.fr.data.impl.NameDataModel; import com.fr.design.data.DesignTableDataManager; -import com.fr.design.data.datapane.TableDataCreatorProducer; -import com.fr.design.data.datapane.TableDataNameObjectCreator; import com.fr.design.data.datapane.preview.PreviewTablePane; import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; -import com.fr.general.IOUtils; import com.fr.log.FineLoggerFactory; import com.fr.workspace.WorkContext; @@ -68,12 +65,7 @@ public final class MultiResultTableDataNameWrapper implements TableDataWrapper { @Override public Icon getIcon() { - for (TableDataNameObjectCreator creator : TableDataCreatorProducer.getInstance().createReportTableDataCreator()) { - if (creator.createObject().getClass().isAssignableFrom(this.tableData.getClass())) { - return IOUtils.readIcon(creator.getIconPath()); - } - } - return IOUtils.readIcon("/com/fr/design/images/data/multi.png"); + return MultiResultTableDataWrapperHelper.getIcon(this.tableData.getClass()); } private void createResult(boolean needLoadingBar) { diff --git a/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataWrapper.java b/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataWrapper.java index 6cce86fd20..ae68bd112b 100644 --- a/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataWrapper.java +++ b/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataWrapper.java @@ -6,8 +6,6 @@ import com.fr.data.impl.NameDataModel; import com.fr.data.impl.storeproc.StoreProcedure; import com.fr.data.operator.DataOperator; import com.fr.design.data.DesignTableDataManager; -import com.fr.design.data.datapane.TableDataCreatorProducer; -import com.fr.design.data.datapane.TableDataNameObjectCreator; import com.fr.design.data.datapane.preview.PreviewTablePane; import com.fr.design.dialog.FineJOptionPane; import com.fr.design.gui.iprogressbar.AutoProgressBar; @@ -15,7 +13,6 @@ import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.DesignerContext; import com.fr.general.ComparatorUtils; -import com.fr.general.IOUtils; import com.fr.log.FineLoggerFactory; import javax.swing.Icon; @@ -163,12 +160,7 @@ public final class MultiResultTableDataWrapper implements TableDataWrapper { @Override public Icon getIcon() { - for (TableDataNameObjectCreator creator : TableDataCreatorProducer.getInstance().createReportTableDataCreator()) { - if (creator.createObject().getClass().isAssignableFrom(this.tableData.getClass())) { - return IOUtils.readIcon(creator.getIconPath()); - } - } - return IOUtils.readIcon("/com/fr/design/images/data/multi.png"); + return MultiResultTableDataWrapperHelper.getIcon(this.tableData.getClass()); } /** @@ -287,7 +279,8 @@ public final class MultiResultTableDataWrapper implements TableDataWrapper { @Override public String getTableDataName() { - return tableDataName; + // todo 这里返回数据集结果名称,带_的 + return dataModelName; } public String getDataModelName() { @@ -299,6 +292,16 @@ public final class MultiResultTableDataWrapper implements TableDataWrapper { return tableData; } + + /** + * 获取当前节点所属可编辑的数据集名称 + * + * @return + */ + public String getMultiResultTableDataName() { + return tableDataName; + } + /** * 是否异常 * @@ -312,9 +315,10 @@ public final class MultiResultTableDataWrapper implements TableDataWrapper { @Override public boolean equals(Object obj) { return obj instanceof MultiResultTableDataWrapper - && ComparatorUtils.equals(this.dataModelName, ((MultiResultTableDataWrapper) obj).getTableDataName()) - && ComparatorUtils.equals(this.tableData, ((MultiResultTableDataWrapper) obj).getTableData()) - && ComparatorUtils.equals(this.tableDataName, ((MultiResultTableDataWrapper) obj).getTableDataName()); + && ComparatorUtils.equals(this.getDataModelName(), ((MultiResultTableDataWrapper) obj).getDataModelName()) + && ComparatorUtils.equals(this.getTableData(), ((MultiResultTableDataWrapper) obj).getTableData()) + && ComparatorUtils.equals(this.getMultiResultTableDataName(), ((MultiResultTableDataWrapper) obj).getMultiResultTableDataName()) + && ComparatorUtils.equals(this.getTableDataName(), ((MultiResultTableDataWrapper) obj).getTableDataName()); } diff --git a/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataWrapperHelper.java b/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataWrapperHelper.java new file mode 100644 index 0000000000..91ca35d7fb --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/data/tabledata/wrapper/MultiResultTableDataWrapperHelper.java @@ -0,0 +1,54 @@ +package com.fr.design.data.tabledata.wrapper; + +import com.fr.base.TableData; +import com.fr.design.data.datapane.TableDataCreatorProducer; +import com.fr.design.data.datapane.TableDataNameObjectCreator; +import com.fr.design.fun.ServerTableDataDefineProvider; +import com.fr.design.fun.TableDataDefineProvider; +import com.fr.event.Event; +import com.fr.event.EventDispatcher; +import com.fr.event.Listener; +import com.fr.general.IOUtils; +import com.fr.plugin.context.PluginContext; +import com.fr.plugin.observer.PluginEventType; +import com.fr.stable.Filter; +import org.jetbrains.annotations.NotNull; + +import javax.swing.Icon; +import java.util.HashMap; +import java.util.Map; + +/** + * @author rinoux + * @version 11.0 + * Created by rinoux on 2022/9/7 + */ +class MultiResultTableDataWrapperHelper { + private static final Map, Icon> TABLE_DATA_ICON_PATHS = new HashMap<>(); + private static final String DEFAULT_MULTI_RESULT_TD_ICON = "/com/fr/design/images/data/multi.png"; + + + static { + Listener listener = new Listener() { + @Override + public void on(Event event, PluginContext param) { + TABLE_DATA_ICON_PATHS.clear(); + } + }; + Filter filter = pluginContext -> pluginContext.contain(TableDataDefineProvider.XML_TAG) || pluginContext.contain(ServerTableDataDefineProvider.XML_TAG); + EventDispatcher.listen(PluginEventType.AfterRun, listener, filter); + EventDispatcher.listen(PluginEventType.BeforeStop, listener, filter); + } + + + public static @NotNull Icon getIcon(@NotNull Class tableDataClass) { + return TABLE_DATA_ICON_PATHS.computeIfAbsent(tableDataClass, cls -> { + for (TableDataNameObjectCreator creator : TableDataCreatorProducer.getInstance().createReportTableDataCreator()) { + if (creator.createObject().getClass().isAssignableFrom(tableDataClass)) { + return IOUtils.readIcon(creator.getIconPath()); + } + } + return IOUtils.readIcon(DEFAULT_MULTI_RESULT_TD_ICON); + }); + } +} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplateNameHelper.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplateNameHelper.java index 22d5985ba9..96ca5b4843 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplateNameHelper.java +++ b/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 javax.swing.tree.DefaultMutableTreeNode; +import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -27,19 +28,18 @@ public class JTemplateNameHelper { DefaultMutableTreeNode gen = (DefaultMutableTreeNode) tt.getModel().getRoot(); String[] str = new String[gen.getChildCount()]; - List reportNum = new ArrayList<>(); + List reportNum = new ArrayList<>(); for (int j = 0; j < gen.getChildCount(); j++) { str[j] = gen.getChildAt(j).toString(); //返回文件名中的index(算法中没有再匹配文件后缀了,因为DefaultMutableTreeNode中已经匹配过了) - Integer index = getFileNameIndex(prefix, str[j]); + BigInteger index = getFileNameIndex(prefix, str[j]); if (index != null) { reportNum.add(index); } } Collections.sort(reportNum); - int idx = reportNum.size() > 0 ? reportNum.get(reportNum.size() - 1) + 1 : 1; - - idx = idx + currentIndex; + BigInteger idx = reportNum.size() > 0 ? reportNum.get(reportNum.size() - 1).add(BigInteger.valueOf(1)) : BigInteger.valueOf(1); + idx = idx.add(BigInteger.valueOf(currentIndex)); currentIndex++; return prefix + idx; } @@ -52,35 +52,56 @@ public class JTemplateNameHelper { * @Author Henry.Wang * @Date 2021/4/9 11:13 **/ - private static Integer getFileNameIndex(String prefix, String fileName) { - if (fileName.length() <= prefix.length()) { + private static BigInteger getFileNameIndex(String prefix, String fileName) { + //如果文件名长度小于等于前缀长度或者匹配前缀失败,直接返回就可以了 + if ((prefix.length() >= fileName.length()) || (!StringUtils.equals(prefix, fileName.substring(0, prefix.length())))) { return null; } - char[] chars = new char[fileName.length()]; - int i = 0; - for (; i < fileName.length(); i++) { + BigInteger integer = null; + integer = matchFileNameIndex(prefix, fileName); + 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); - //匹配前缀 - if (i < prefix.length()) { - if (c != prefix.charAt(i)) { - return null; - } + if (isDot(c)) { + break; } else { - if (c == '.') { - break; - } else { - //匹配0~9 - if (c < 48 || c > 57) { - return null; - } - chars[i - prefix.length()] = c; + if (isNotNumber(c)) { + return null; } + result.append(c); } } - String s = new String(chars).substring(0, i - prefix.length()); - if (StringUtils.isBlank(s)) { + if (StringUtils.isBlank(result.toString())) { 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 == '.'; } } diff --git a/designer-base/src/test/java/com/fr/design/mainframe/JTemplateNameHelperTest.java b/designer-base/src/test/java/com/fr/design/mainframe/JTemplateNameHelperTest.java index 032e715f60..0202028480 100644 --- a/designer-base/src/test/java/com/fr/design/mainframe/JTemplateNameHelperTest.java +++ b/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 com.fr.invoke.Reflect; + /** * @author shine * @version 10.0 @@ -18,6 +20,27 @@ public class JTemplateNameHelperTest extends TestCase { String name1 = JTemplateNameHelper.newTemplateNameByIndex("TEST"); 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()); + } }