Browse Source

CHART-18790 design new template name

feature/big-screen
shine 4 years ago
parent
commit
823755386c
  1. 3
      designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java
  2. 43
      designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java
  3. 55
      designer-base/src/main/java/com/fr/design/mainframe/JTemplateNameHelper.java

3
designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java

@ -829,6 +829,9 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta
if (east != null) { if (east != null) {
basePane.add(east, BorderLayout.EAST); basePane.add(east, BorderLayout.EAST);
} }
layeredPane.repaint();
layeredPane.revalidate();
} }
/** /**

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

@ -24,7 +24,6 @@ import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.dialog.InformationWarnPane; import com.fr.design.dialog.InformationWarnPane;
import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.file.TemplateResourceManager; import com.fr.design.file.TemplateResourceManager;
import com.fr.design.file.TemplateTreePane;
import com.fr.design.fun.DesignerFrameUpButtonProvider; import com.fr.design.fun.DesignerFrameUpButtonProvider;
import com.fr.design.fun.MenuHandler; import com.fr.design.fun.MenuHandler;
import com.fr.design.fun.PreviewProvider; import com.fr.design.fun.PreviewProvider;
@ -34,7 +33,6 @@ import com.fr.design.gui.frpane.HyperlinkGroupPane;
import com.fr.design.gui.frpane.HyperlinkGroupPaneActionProvider; import com.fr.design.gui.frpane.HyperlinkGroupPaneActionProvider;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.imenu.UIMenuItem; import com.fr.design.gui.imenu.UIMenuItem;
import com.fr.design.gui.itree.filetree.TemplateFileTree;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.chart.info.ChartInfoCollector; import com.fr.design.mainframe.chart.info.ChartInfoCollector;
@ -80,20 +78,15 @@ import javax.swing.BorderFactory;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.undo.UndoManager; import javax.swing.undo.UndoManager;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern;
/** /**
* 报表设计和表单设计的编辑区域(设计器编辑的IO文件) * 报表设计和表单设计的编辑区域(设计器编辑的IO文件)
*/ */
public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>> extends TargetComponent<T> implements ToolBarMenuDockPlus, DesignerProxy { public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>> extends TargetComponent<T> implements ToolBarMenuDockPlus, DesignerProxy {
// TODO ALEX_SEP editingFILE这个属性一定要吗?如果非要不可,有没有可能保证不为null // TODO ALEX_SEP editingFILE这个属性一定要吗?如果非要不可,有没有可能保证不为null
private static final int PREFIX_NUM = 3000;
private FILE editingFILE = null; private FILE editingFILE = null;
// alex:初始状态为saved,这样不管是新建模板,还是打开模板,如果未做任何操作直接关闭,不提示保存 // alex:初始状态为saved,这样不管是新建模板,还是打开模板,如果未做任何操作直接关闭,不提示保存
private boolean saved = true; private boolean saved = true;
@ -105,7 +98,6 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
protected T template; // 当前模板 protected T template; // 当前模板
protected TemplateProcessInfo<T> processInfo; // 模板过程的相关信息 protected TemplateProcessInfo<T> processInfo; // 模板过程的相关信息
private JComponent centerPane; private JComponent centerPane;
private static short currentIndex = 0;// 此变量用于多次新建模板时,让名字不重复
private DesignModelAdapter<T, ?> designModel; private DesignModelAdapter<T, ?> designModel;
private PreviewProvider previewType; private PreviewProvider previewType;
protected TimeConsumeTimer consumeTimer = new TimeConsumeTimer(); protected TimeConsumeTimer consumeTimer = new TimeConsumeTimer();
@ -117,7 +109,7 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
} }
public JTemplate(T t, String defaultFileName) { public JTemplate(T t, String defaultFileName) {
this(t, new MemFILE(newTemplateNameByIndex(defaultFileName)), true); this(t, new MemFILE(JTemplateNameHelper.newTemplateNameByIndex(defaultFileName)), true);
} }
public JTemplate(T t, FILE file) { public JTemplate(T t, FILE file) {
@ -840,39 +832,6 @@ public abstract class JTemplate<T extends BaseBook, U extends BaseUndoState<?>>
return true; return true;
} }
private static String newTemplateNameByIndex(String prefix) {
// 用于获取左侧模板的文件名,如左侧已包含"WorkBook1.cpt, WorkBook12.cpt, WorkBook177.cpt"
// 那么新建的文件名将被命名为"WorkBook178.cpt",即取最大数+1
TemplateFileTree tt = TemplateTreePane.getInstance().getTemplateFileTree();
DefaultMutableTreeNode gen = (DefaultMutableTreeNode) tt.getModel().getRoot();
String[] str = new String[gen.getChildCount()];
ArrayList<String> al = new ArrayList<String>();
for (int j = 0; j < gen.getChildCount(); j++) {
str[j] = gen.getChildAt(j).toString();
if (str[j].contains(prefix) && str[j].contains(".")) {
for (int i = 0; i < PREFIX_NUM; i++) {
if (ComparatorUtils.equals(str[j].split("[.]")[0], (prefix + i))) {
al.add(str[j]);
}
}
}
}
int[] reportNum = new int[al.size()];
for (int i = 0; i < al.size(); i++) {
Pattern pattern = Pattern.compile("[" + prefix + ".]+");
String[] strs = pattern.split(al.get(i).toString());
reportNum[i] = Integer.parseInt(strs[1]);
}
Arrays.sort(reportNum);
int idx = reportNum.length > 0 ? reportNum[reportNum.length - 1] + 1 : 1;
idx = idx + currentIndex;
currentIndex++;
return prefix + idx;
}
// /////////////////////////////toolbarMenuDock////////////////////////////////// // /////////////////////////////toolbarMenuDock//////////////////////////////////
/** /**

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

@ -0,0 +1,55 @@
package com.fr.design.mainframe;
import com.fr.design.file.TemplateTreePane;
import com.fr.design.gui.itree.filetree.TemplateFileTree;
import com.fr.general.ComparatorUtils;
import javax.swing.tree.DefaultMutableTreeNode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.regex.Pattern;
/**
* @author shine
* @version 10.0
* Created by shine on 2021/5/7
*/
public class JTemplateNameHelper {
private static final int PREFIX_NUM = 3000;
private static short currentIndex = 0;// 此变量用于多次新建模板时,让名字不重复
public static String newTemplateNameByIndex(String prefix) {
// 用于获取左侧模板的文件名,如左侧已包含"WorkBook1.cpt, WorkBook12.cpt, WorkBook177.cpt"
// 那么新建的文件名将被命名为"WorkBook178.cpt",即取最大数+1
TemplateFileTree tt = TemplateTreePane.getInstance().getTemplateFileTree();
DefaultMutableTreeNode gen = (DefaultMutableTreeNode) tt.getModel().getRoot();
String[] str = new String[gen.getChildCount()];
ArrayList<String> al = new ArrayList<String>();
for (int j = 0; j < gen.getChildCount(); j++) {
str[j] = gen.getChildAt(j).toString();
if (str[j].contains(prefix) && str[j].contains(".")) {
for (int i = 0; i < PREFIX_NUM; i++) {
if (ComparatorUtils.equals(str[j].split("[.]")[0], (prefix + i))) {
al.add(str[j]);
}
}
}
}
int[] reportNum = new int[al.size()];
for (int i = 0; i < al.size(); i++) {
Pattern pattern = Pattern.compile("[" + prefix + ".]+");
String[] strs = pattern.split(al.get(i).toString());
reportNum[i] = Integer.parseInt(strs[1]);
}
Arrays.sort(reportNum);
int idx = reportNum.length > 0 ? reportNum[reportNum.length - 1] + 1 : 1;
idx = idx + currentIndex;
currentIndex++;
return prefix + idx;
}
}
Loading…
Cancel
Save