Browse Source

REPORT-95741 关闭自动新建的cpt模板,回到了fvs-tab;预期是打开下一张cpt/frm

release/11.0
kerry 1 year ago
parent
commit
b74d96cf19
  1. 14
      designer-base/src/main/java/com/fr/design/file/MultiTemplateTabPane.java
  2. 36
      designer-base/src/main/java/com/fr/design/file/MultiTemplateTabUtils.java
  3. 289
      designer-base/src/test/java/com/fr/design/file/MultiTemplateTabPaneTest.java

14
designer-base/src/main/java/com/fr/design/file/MultiTemplateTabPane.java

@ -1108,18 +1108,8 @@ public class MultiTemplateTabPane extends JComponent {
* @return
*/
public int calNextShowJTemplateIndex(int currentIndex) {
//先看是否有可以展示的模板
for (int i = currentIndex; i >= 0; i--) {
if (showJTemplateTab(openedTemplate.get(i))) {
return i;
}
}
for (int i = currentIndex; i >= 0; i--) {
if (!showJTemplateTab(openedTemplate.get(i))) {
return i;
}
}
return -1;
JTemplate jTemplate= HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
return MultiTemplateTabUtils.calShowTemplateIndex(currentIndex, openedTemplate, jTemplate.getTemplateTabOperatorType());
}

36
designer-base/src/main/java/com/fr/design/file/MultiTemplateTabUtils.java

@ -0,0 +1,36 @@
package com.fr.design.file;
import com.fr.design.mainframe.JTemplate;
import com.fr.general.ComparatorUtils;
import java.util.List;
import java.util.function.Predicate;
public class MultiTemplateTabUtils {
public static int calShowTemplateIndex(int currentIndex, List<JTemplate<?, ?>> openedTemplate, String type) {
if (currentIndex < 0 || currentIndex > openedTemplate.size() - 1) {
return -1;
}
int result = getShowJTemplateTab(currentIndex, openedTemplate, template -> showJTemplateTab(type, template));
if (result != -1) return result;
return getShowJTemplateTab(currentIndex, openedTemplate, template -> !showJTemplateTab(type, template));
}
private static int getShowJTemplateTab(int currentIndex, List<JTemplate<?, ?>> openedTemplate, Predicate<JTemplate<?, ?>> predicate) {
for (int i = currentIndex; i >= 0; i--) {
if (predicate.test(openedTemplate.get(i))) {
return i;
}
}
for (int i = currentIndex + 1; i < openedTemplate.size(); i++) {
if (predicate.test(openedTemplate.get(i))) {
return i;
}
}
return -1;
}
private static boolean showJTemplateTab(String type, JTemplate<?, ?> jTemplate) {
return ComparatorUtils.equals(type, jTemplate.getTemplateTabOperatorType());
}
}

289
designer-base/src/test/java/com/fr/design/file/MultiTemplateTabPaneTest.java

@ -0,0 +1,289 @@
package com.fr.design.file;
import com.fr.design.DesignModelAdapter;
import com.fr.design.ExtraDesignClassManager;
import com.fr.design.designer.TargetComponent;
import com.fr.design.gui.frpane.HyperlinkGroupPane;
import com.fr.design.gui.frpane.HyperlinkGroupPaneActionProvider;
import com.fr.design.gui.imenu.UIMenuItem;
import com.fr.design.mainframe.AuthorityEditPane;
import com.fr.design.mainframe.BaseUndoState;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.mainframe.template.info.TemplateProcessInfo;
import com.fr.design.menu.ShortCut;
import com.fr.design.menu.ToolBarDef;
import com.fr.plugin.injectable.PluginModule;
import junit.framework.TestCase;
import org.junit.Assert;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JPanel;
import java.util.ArrayList;
import java.util.List;
public class MultiTemplateTabPaneTest extends TestCase {
@Override
protected void setUp() throws Exception {
PluginModule.registerAgent(PluginModule.ExtraDesign, new ExtraDesignClassManager());
}
/**
* 当前显示模式A传入index左边(含当前)或右边有模式A的模板返回最近的模式A模板index优先左边
*/
public void test_index_left_has_same_mode_temp() {
//当前显示模式A,传入index左边(含当前)有模式A的模板,返回左边最近的模式A模板index
List<JTemplate<?, ?>> openedTemplateList = new ArrayList<>();
openedTemplateList.add(new A_Mode());
Assert.assertEquals(0, MultiTemplateTabUtils.calShowTemplateIndex(0, openedTemplateList, "A_Mode"));
openedTemplateList.add(new A_Mode());
Assert.assertEquals(1, MultiTemplateTabUtils.calShowTemplateIndex(1, openedTemplateList, "A_Mode"));
openedTemplateList.add(new B_Mode());
Assert.assertEquals(1, MultiTemplateTabUtils.calShowTemplateIndex(1, openedTemplateList, "A_Mode"));
}
public void test_index_left_has_not_but_right_has_same_mode_temp() {
//当前显示模式A,传入index左边没有但是右边有模式A的模板,返回右边最近的模式A模板index
List<JTemplate<?, ?>> openedTemplateList = new ArrayList<>();
openedTemplateList.add(new B_Mode());
openedTemplateList.add(new A_Mode());
Assert.assertEquals(1, MultiTemplateTabUtils.calShowTemplateIndex(0, openedTemplateList, "A_Mode"));
openedTemplateList.add(1, new B_Mode());
openedTemplateList.add(new A_Mode());
Assert.assertEquals(2, MultiTemplateTabUtils.calShowTemplateIndex(0, openedTemplateList, "A_Mode"));
openedTemplateList.add(new A_Mode());
Assert.assertEquals(2, MultiTemplateTabUtils.calShowTemplateIndex(0, openedTemplateList, "A_Mode"));
}
/**
* 当前显示模式A没有模式A的模板左边(含当前)或者右边有其他模式的模板返回最近的其他模式模式模板index优先左边
*/
public void test_no_same_mode_temp_but_index_left_has_other_mode_temp() {
//当前显示模式A,没有模式A的模板,左边(含当前)有其他模式模板,返回左边最近的其他模式模板index
List<JTemplate<?, ?>> openedTemplateList = new ArrayList<>();
openedTemplateList.add(new B_Mode());
Assert.assertEquals(0, MultiTemplateTabUtils.calShowTemplateIndex(0, openedTemplateList, "A_Mode"));
openedTemplateList.add(new B_Mode());
Assert.assertEquals(1, MultiTemplateTabUtils.calShowTemplateIndex(1, openedTemplateList, "A_Mode"));
}
public void test_has_no_temp() {
//当前显示模式A,没有模式A的模板,也没有其他模式的模板,返回-1
List<JTemplate<?, ?>> openedTemplateList = new ArrayList<>();
Assert.assertEquals(-1, MultiTemplateTabUtils.calShowTemplateIndex(0, openedTemplateList, "A_Mode"));
}
public void test_if_index_less_than_zero_or_more_than_open_temp_size() {
//index<0 或者超出openTemplateList.size时,返回-1
List<JTemplate<?, ?>> openedTemplateList = new ArrayList<>();
Assert.assertEquals(-1, MultiTemplateTabUtils.calShowTemplateIndex(-1, openedTemplateList, "A_Mode"));
Assert.assertEquals(-1, MultiTemplateTabUtils.calShowTemplateIndex(0, openedTemplateList, "A_Mode"));
openedTemplateList.add(new A_Mode());
Assert.assertEquals(-1, MultiTemplateTabUtils.calShowTemplateIndex(1, openedTemplateList, "A_Mode"));
}
private class A_Mode extends AbstractTestMode {
public String getTemplateTabOperatorType() {
return "A_Mode";
}
}
private class B_Mode extends AbstractTestMode {
public String getTemplateTabOperatorType() {
return "B_Mode";
}
}
private abstract class AbstractTestMode extends JTemplate {
public AbstractTestMode() {
}
@Override
public void copy() {
}
@Override
public boolean paste() {
return false;
}
@Override
public boolean cut() {
return false;
}
@Override
public AuthorityEditPane createAuthorityEditPane() {
return null;
}
@Override
public JPanel getEastUpPane() {
return null;
}
@Override
public JPanel getEastDownPane() {
return null;
}
@Override
public ToolBarDef[] toolbars4Target() {
return new ToolBarDef[0];
}
@Override
public JPanel[] toolbarPanes4Form() {
return new JPanel[0];
}
@Override
public JComponent[] toolBarButton4Form() {
return new JComponent[0];
}
@Override
public JComponent toolBar4Authority() {
return null;
}
@Override
public int getToolBarHeight() {
return 0;
}
@Override
public void refreshEastPropertiesPane() {
}
@Override
public TargetComponent getCurrentElementCasePane() {
return null;
}
@Override
public JComponent getCurrentReportComponentPane() {
return null;
}
@Override
public TemplateProcessInfo getProcessInfo() {
return null;
}
@Override
public void setJTemplateResolution(int resolution) {
}
@Override
public int getJTemplateResolution() {
return 0;
}
@Override
protected JComponent createCenterPane() {
return null;
}
@Override
public void removeTemplateSelection() {
}
@Override
public void refreshContainer() {
}
@Override
public void removeParameterPaneSelection() {
}
@Override
public void setScale(int resolution) {
}
@Override
public int getScale() {
return 0;
}
@Override
public int selfAdaptUpdate() {
return 0;
}
@Override
protected DesignModelAdapter createDesignModel() {
return null;
}
@Override
public UIMenuItem[] createMenuItem4Preview() {
return new UIMenuItem[0];
}
@Override
protected BaseUndoState<?> createUndoState() {
return null;
}
@Override
public String suffix() {
return null;
}
@Override
public ShortCut[] shortcut4TemplateMenu() {
return new ShortCut[0];
}
@Override
public ShortCut[] shortCuts4Authority() {
return new ShortCut[0];
}
@Override
public boolean isJWorkBook() {
return false;
}
@Override
public HyperlinkGroupPane getHyperLinkPane(HyperlinkGroupPaneActionProvider hyperlinkGroupPaneActionProvider) {
return null;
}
@Override
public HyperlinkGroupPane getHyperLinkPaneNoPop(HyperlinkGroupPaneActionProvider hyperlinkGroupPaneActionProvider) {
return null;
}
@Override
public void setAuthorityMode(boolean isUpMode) {
}
@Override
public Icon getIcon() {
return null;
}
@Override
public String route() {
return null;
}
@Override
protected void applyUndoState(BaseUndoState baseUndoState) {
}
}
}
Loading…
Cancel
Save