From 9a68b44324045012480ccddcfa1785746f5acbb9 Mon Sep 17 00:00:00 2001 From: "Java.Edge" Date: Wed, 6 May 2020 16:18:15 +0800 Subject: [PATCH] REPORT-27998 bugfix --- .../datapane/TableDataNameObjectCreator.java | 19 +-------- .../data/datapane/TableDataPaneListPane.java | 39 ++++++++----------- 2 files changed, 17 insertions(+), 41 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataNameObjectCreator.java b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataNameObjectCreator.java index 3ff2ed51b3..5c32b3cb54 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataNameObjectCreator.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataNameObjectCreator.java @@ -183,29 +183,12 @@ public class TableDataNameObjectCreator extends NameObjectCreator { @Override public Nameable createNameable(UnrepeatedNameHelper helper) { try { - return new NameObject(this.createUnrepeatedName(this.getPrefix()), clazzOfInitCase.newInstance()); + return new NameObject(helper.createUnrepeatedName(this.getPrefix()), clazzOfInitCase.newInstance()); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } } - public String createUnrepeatedName(String prefix) { - int count = 1; - - while (isDsNameRepeated(prefix + count)) { - count++; - } - return prefix + count; - } - - private boolean isDsNameRepeated(String name) { - if (allDSNames == null) { - TableDataSource source = DesignTableDataManager.getEditingTableDataSource(); - allDSNames = DesignTableDataManager.getAllDSNames(source); - } - return ArrayUtils.contains(allDSNames, name); - } - @Override public int hashCode() { return menuName == null ? 0 : menuName.hashCode(); diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataPaneListPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataPaneListPane.java index d2fdc32291..35f6077b87 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataPaneListPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataPaneListPane.java @@ -14,6 +14,7 @@ import com.fr.file.ProcedureConfig; import com.fr.file.TableDataConfig; import com.fr.general.ComparatorUtils; import com.fr.general.NameObject; +import com.fr.stable.ArrayUtils; import com.fr.stable.Nameable; import com.fr.stable.StringUtils; import com.fr.stable.core.PropertyChangeAdapter; @@ -133,36 +134,28 @@ public class TableDataPaneListPane extends JListControlPane implements TableData return super.createUnrepeatedName(prefix); } String[] allDsNames = DesignTableDataManager.getAllDSNames(source); + + // richer:生成的名字从1开始. kunsnat: 添加属性从0开始. + int count = 1; + while (isDsNameRepeated(prefix + count, allDsNames)) { + count++; + } + return prefix + count; + } + + private boolean isDsNameRepeated(String name, String[] allDsNames) { DefaultListModel model = this.getModel(); Nameable[] all = new Nameable[model.getSize()]; for (int i = 0; i < model.size(); i++) { all[i] = ((ListModelElement) model.get(i)).wrapper; } - // richer:生成的名字从1开始. kunsnat: 添加属性从0开始. - int count = all.length + 1; - while (true) { - String name_test = prefix + count; - boolean repeated = false; - for (int i = 0, len = model.size(); i < len; i++) { - Nameable nameable = all[i]; - if (ComparatorUtils.equals(nameable.getName(), name_test)) { - repeated = true; - break; - } - } - for (String dsname : allDsNames) { - if (ComparatorUtils.equals(dsname, name_test)) { - repeated = true; - break; - } + for (int i = 0, len = model.size(); i < len; i++) { + Nameable nameable = all[i]; + if (ComparatorUtils.equals(nameable.getName(), name)) { + return true; } - - if (!repeated) { - return name_test; - } - - count++; } + return ArrayUtils.contains(allDsNames, name); } @Override