From b74d96cf19681397ab4f2c056dabf7ead6af2e88 Mon Sep 17 00:00:00 2001 From: kerry Date: Wed, 31 May 2023 19:39:36 +0800 Subject: [PATCH 1/3] =?UTF-8?q?REPORT-95741=20=E5=85=B3=E9=97=AD=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E6=96=B0=E5=BB=BA=E7=9A=84cpt=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=EF=BC=8C=E5=9B=9E=E5=88=B0=E4=BA=86fvs-tab=EF=BC=9B=E9=A2=84?= =?UTF-8?q?=E6=9C=9F=E6=98=AF=E6=89=93=E5=BC=80=E4=B8=8B=E4=B8=80=E5=BC=A0?= =?UTF-8?q?cpt/frm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/file/MultiTemplateTabPane.java | 14 +- .../fr/design/file/MultiTemplateTabUtils.java | 36 +++ .../design/file/MultiTemplateTabPaneTest.java | 289 ++++++++++++++++++ 3 files changed, 327 insertions(+), 12 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/file/MultiTemplateTabUtils.java create mode 100644 designer-base/src/test/java/com/fr/design/file/MultiTemplateTabPaneTest.java diff --git a/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabPane.java b/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabPane.java index 9236deb4ad..6658fc6638 100644 --- a/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabPane.java +++ b/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()); } diff --git a/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabUtils.java b/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabUtils.java new file mode 100644 index 0000000000..5a8c504189 --- /dev/null +++ b/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> 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> openedTemplate, Predicate> 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()); + } +} diff --git a/designer-base/src/test/java/com/fr/design/file/MultiTemplateTabPaneTest.java b/designer-base/src/test/java/com/fr/design/file/MultiTemplateTabPaneTest.java new file mode 100644 index 0000000000..c00976abb3 --- /dev/null +++ b/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> 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> 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> 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> 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> 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) { + + } + + } +} From 4531ad7d5fd22a0ea979b7544bbbfdc23a892c08 Mon Sep 17 00:00:00 2001 From: kerry Date: Thu, 1 Jun 2023 12:00:33 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/file/MultiTemplateTabUtils.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabUtils.java b/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabUtils.java index 5a8c504189..e5883a3987 100644 --- a/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabUtils.java +++ b/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabUtils.java @@ -7,6 +7,13 @@ import java.util.List; import java.util.function.Predicate; public class MultiTemplateTabUtils { + /** + * 计算离currentIndex最近的相同模式的模板index值(优先左边) + * @param currentIndex 当前index + * @param openedTemplate 模板list + * @param type 当前显示模式 + * @return + */ public static int calShowTemplateIndex(int currentIndex, List> openedTemplate, String type) { if (currentIndex < 0 || currentIndex > openedTemplate.size() - 1) { return -1; @@ -16,6 +23,13 @@ public class MultiTemplateTabUtils { return getShowJTemplateTab(currentIndex, openedTemplate, template -> !showJTemplateTab(type, template)); } + /** + * 先从左找,再从右找离得最近的满足条件的模板 + * @param currentIndex 当前index + * @param openedTemplate 模板list + * @param predicate + * @return + */ private static int getShowJTemplateTab(int currentIndex, List> openedTemplate, Predicate> predicate) { for (int i = currentIndex; i >= 0; i--) { if (predicate.test(openedTemplate.get(i))) { @@ -30,6 +44,12 @@ public class MultiTemplateTabUtils { return -1; } + /** + * 是否显示模板 + * @param type 模板类型 + * @param jTemplate 模板 + * @return + */ private static boolean showJTemplateTab(String type, JTemplate jTemplate) { return ComparatorUtils.equals(type, jTemplate.getTemplateTabOperatorType()); } From c8b3cd6ce396bf9e09bfb8566575cbf54a189ad7 Mon Sep 17 00:00:00 2001 From: kerry Date: Thu, 1 Jun 2023 13:57:09 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/file/MultiTemplateTabUtils.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabUtils.java b/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabUtils.java index e5883a3987..344abe64f2 100644 --- a/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabUtils.java +++ b/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabUtils.java @@ -9,9 +9,10 @@ import java.util.function.Predicate; public class MultiTemplateTabUtils { /** * 计算离currentIndex最近的相同模式的模板index值(优先左边) - * @param currentIndex 当前index + * + * @param currentIndex 当前index * @param openedTemplate 模板list - * @param type 当前显示模式 + * @param type 当前显示模式 * @return */ public static int calShowTemplateIndex(int currentIndex, List> openedTemplate, String type) { @@ -25,7 +26,8 @@ public class MultiTemplateTabUtils { /** * 先从左找,再从右找离得最近的满足条件的模板 - * @param currentIndex 当前index + * + * @param currentIndex 当前index * @param openedTemplate 模板list * @param predicate * @return @@ -46,7 +48,8 @@ public class MultiTemplateTabUtils { /** * 是否显示模板 - * @param type 模板类型 + * + * @param type 模板类型 * @param jTemplate 模板 * @return */