From 84dae4884f1fcdefce4351a9b19530e2c237a478 Mon Sep 17 00:00:00 2001 From: "yaoh.wu" Date: Fri, 19 Jul 2019 13:49:53 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=97=A0=E4=BB=BB=E5=8A=A1=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=B0=E5=BB=BA=E6=9C=AC=E5=9C=B0=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8F=AF=E8=83=BD=E5=87=BA=E7=8E=B0=E7=9A=84npe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/gui/itree/filetree/JFileTree.java | 25 +++++++++++-------- .../main/java/com/fr/env/LocalEnvPane.java | 17 ++++++++----- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/gui/itree/filetree/JFileTree.java b/designer-base/src/main/java/com/fr/design/gui/itree/filetree/JFileTree.java index 69875a97f..3b37f4358 100644 --- a/designer-base/src/main/java/com/fr/design/gui/itree/filetree/JFileTree.java +++ b/designer-base/src/main/java/com/fr/design/gui/itree/filetree/JFileTree.java @@ -1,10 +1,11 @@ package com.fr.design.gui.itree.filetree; -import com.fr.base.BaseUtils; import com.fr.design.i18n.Toolkit; import com.fr.general.ComparatorUtils; +import com.fr.general.IOUtils; import com.fr.stable.ArrayUtils; import com.fr.stable.project.ProjectConstants; +import org.jetbrains.annotations.Nullable; import javax.swing.Icon; import javax.swing.JTree; @@ -29,7 +30,8 @@ import java.util.Stack; * File Tree. */ public class JFileTree extends AbstractFileTree { - protected FileFilter fileFilter; + + private FileFilter fileFilter; public JFileTree() { this(null); @@ -68,11 +70,11 @@ public class JFileTree extends AbstractFileTree { DefaultMutableTreeNode rootTreeNode = (DefaultMutableTreeNode) defaultTreeModel.getRoot(); rootTreeNode.removeAllChildren(); - for (int k = 0; k < rootFiles.length; k++) { - DefaultMutableTreeNode node = new DefaultMutableTreeNode(new RootFile(rootFiles[k])); + for (File rootFile : rootFiles) { + DefaultMutableTreeNode node = new DefaultMutableTreeNode(new RootFile(rootFile)); rootTreeNode.add(node); - if (rootFiles[k].isDirectory()) { + if (rootFile.isDirectory()) { node.add(new DefaultMutableTreeNode(Boolean.TRUE)); } } @@ -93,6 +95,7 @@ public class JFileTree extends AbstractFileTree { this.fileFilter = fileFilter; } + @Nullable public File getSelectedFile() { TreePath selectedTreePath = this.getSelectionPath(); if (selectedTreePath == null) { @@ -140,7 +143,7 @@ public class JFileTree extends AbstractFileTree { File rootFile = rootLocalFile.getFile(); // 是父子关系,开始找孩子. if (AbstractFileTree.isParentFile(rootFile, currentFile)) { - Stack nameStack = new Stack(); // 将所有的名字加入Stack. + Stack nameStack = new Stack<>(); // 将所有的名字加入Stack. while (true) { if (ComparatorUtils.equals(rootFile, currentFile)) { break; @@ -153,7 +156,7 @@ public class JFileTree extends AbstractFileTree { } DefaultMutableTreeNode curChildTreeNode = rootChildTreeNode; while (!nameStack.isEmpty()) { - String name = (String) nameStack.pop(); + String name = nameStack.pop(); this.expandTreeNode(curChildTreeNode); for (int j = 0; j < curChildTreeNode.getChildCount(); j++) { DefaultMutableTreeNode tmpChildTreeNode = @@ -198,9 +201,8 @@ public class JFileTree extends AbstractFileTree { if (files == null) { return new FileDirectoryNode[0]; } - List fileNodeList = new ArrayList(); - for (int k = 0; k < files.length; k++) { - File tmpFile = files[k]; + List fileNodeList = new ArrayList<>(); + for (File tmpFile : files) { // 文件属性为隐藏的话 不放入列表 if (tmpFile.isHidden()) { continue; @@ -256,7 +258,7 @@ public class JFileTree extends AbstractFileTree { // 得到本地tree图标 Icon tmpIcon = view.getSystemIcon(currentFile); if (currentFile.isDirectory() && fBuf.length() > 0) { - tmpIcon = BaseUtils.readIcon("/com/fr/design/images/gui/folder.png"); + tmpIcon = IOUtils.readIcon("/com/fr/design/images/gui/folder.png"); } this.setIcon(tmpIcon); this.setName(null); @@ -299,6 +301,7 @@ public class JFileTree extends AbstractFileTree { */ @Override public int compare(FileDirectoryNode v1, FileDirectoryNode v2) { + //noinspection Duplicates if (v1.isDirectory()) { if (v2.isDirectory()) { return v1.getName().toLowerCase().compareTo(v2.getName().toLowerCase()); diff --git a/designer-base/src/main/java/com/fr/env/LocalEnvPane.java b/designer-base/src/main/java/com/fr/env/LocalEnvPane.java index eaabd0a9a..6f191dd1e 100644 --- a/designer-base/src/main/java/com/fr/env/LocalEnvPane.java +++ b/designer-base/src/main/java/com/fr/env/LocalEnvPane.java @@ -6,9 +6,9 @@ import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itextarea.UITextArea; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.gui.itree.filetree.JFileTree; +import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.file.filter.OnlyShowDirectoryFileFilter; - import com.fr.stable.StringUtils; import javax.swing.JPanel; @@ -33,8 +33,9 @@ public class LocalEnvPane extends BasicBeanPane { JPanel northPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); this.add(northPane, BorderLayout.NORTH); - northPane.add(new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Location") + ":"), BorderLayout.WEST); - northPane.add(pathTextField = new UITextField(), BorderLayout.CENTER); + northPane.add(new UILabel(Toolkit.i18nText("Fine-Design_Basic_Location") + ":"), BorderLayout.WEST); + pathTextField = new UITextField(); + northPane.add(pathTextField, BorderLayout.CENTER); // 删除选择文件按钮 添加JFileTree @@ -54,19 +55,23 @@ public class LocalEnvPane extends BasicBeanPane { @Override public void valueChanged(TreeSelectionEvent e) { - pathTextField.setText(localEnvTree.getSelectedFile().getPath()); + File selectFile = localEnvTree.getSelectedFile(); + if (selectFile == null) { + return; + } + pathTextField.setText(selectFile.getPath()); } }); UITextArea description = new UITextArea(); centerPane.add(description, BorderLayout.SOUTH); - description.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Env_Des1")); + description.setText(Toolkit.i18nText("Fine-Design_Basic_Env_Des1")); description.setEditable(false); } @Override protected String title4PopupWindow() { - return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Location"); + return Toolkit.i18nText("Fine-Design_Basic_Location"); } @Override From f91fbdb59cd74defbefecab7744c86d1f5f5a44e Mon Sep 17 00:00:00 2001 From: Harrison Date: Mon, 22 Jul 2019 14:54:09 +0800 Subject: [PATCH 2/3] =?UTF-8?q?REPORT-17881=20=E6=96=87=E6=A1=A3=E5=9C=A8?= =?UTF-8?q?=E7=BA=BF=E9=A2=84=E8=A7=88=E6=8E=A7=E4=BB=B6=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E6=97=A0=E6=95=88-=E5=A4=96=E9=83=A8=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E8=80=85=E6=8F=92=E4=BB=B6=E9=97=AE=E9=A2=98=20=E8=BF=99?= =?UTF-8?q?=E9=87=8C=E4=BF=9D=E5=AD=98=E7=9A=84=E4=B8=8D=E6=98=AF=E5=AE=9E?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E4=BF=A1=E6=81=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../widget/WidgetDefinePaneFactory.java | 29 +++++--- .../widget/WidgetDefinePaneFactoryTest.java | 66 +++++++++++++++++++ 2 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 designer-realize/src/test/java/com/fr/design/widget/WidgetDefinePaneFactoryTest.java diff --git a/designer-realize/src/main/java/com/fr/design/widget/WidgetDefinePaneFactory.java b/designer-realize/src/main/java/com/fr/design/widget/WidgetDefinePaneFactory.java index 756b36ad2..2df2e9f2a 100644 --- a/designer-realize/src/main/java/com/fr/design/widget/WidgetDefinePaneFactory.java +++ b/designer-realize/src/main/java/com/fr/design/widget/WidgetDefinePaneFactory.java @@ -48,6 +48,7 @@ import com.fr.report.web.button.write.AppendRowButton; import com.fr.report.web.button.write.DeleteRowButton; import com.fr.stable.bridge.BridgeMark; import com.fr.stable.bridge.StableFactory; +import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; @@ -60,7 +61,9 @@ import java.util.Map; * Time : 上午11:17 */ public class WidgetDefinePaneFactory { + private static Map, Appearance> defineMap = new HashMap, Appearance>(); + private static Map, Appearance> pluginDefineMap = ExtraDesignClassManager.getInstance().getCellWidgetOptionsMap(); static { defineMap.put(NumberEditor.class, new Appearance(NumberEditorDefinePane.class, WidgetConstants.NUMBER + "")); @@ -91,24 +94,32 @@ public class WidgetDefinePaneFactory { defineMap.put(AppendRowButton.class, new Appearance(ButtonDefinePane.class, WidgetConstants.BUTTON + "")); defineMap.put(DeleteRowButton.class, new Appearance(ButtonDefinePane.class, WidgetConstants.BUTTON + "")); defineMap.put(TreeNodeToggleButton.class, new Appearance(ButtonDefinePane.class, WidgetConstants.BUTTON + "")); - defineMap.putAll(ExtraDesignClassManager.getInstance().getCellWidgetOptionsMap()); } private WidgetDefinePaneFactory() { } + @Nullable public static RN createWidgetDefinePane(Widget widget, Operator operator) { + Appearance dn = defineMap.get(widget.getClass()); - DataModify definePane = null; - try { - definePane = (DataModify) dn.getDefineClass().newInstance(); - definePane.populateBean(widget); - operator.did(definePane.dataUI(), dn.getDisplayName()); - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); + // 再走一遍插件。 + if (dn == null) { + dn = pluginDefineMap.get(widget.getClass()); } - return new RN(definePane, dn.getDisplayName()); + if (dn != null) { + DataModify definePane = null; + try { + definePane = (DataModify) dn.getDefineClass().newInstance(); + definePane.populateBean(widget); + operator.did(definePane.dataUI(), dn.getDisplayName()); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + } + return new RN(definePane, dn.getDisplayName()); + } + return null; } public static class RN { diff --git a/designer-realize/src/test/java/com/fr/design/widget/WidgetDefinePaneFactoryTest.java b/designer-realize/src/test/java/com/fr/design/widget/WidgetDefinePaneFactoryTest.java new file mode 100644 index 000000000..a7b0c46b6 --- /dev/null +++ b/designer-realize/src/test/java/com/fr/design/widget/WidgetDefinePaneFactoryTest.java @@ -0,0 +1,66 @@ +package com.fr.design.widget; + +import com.fr.design.ExtraDesignClassManager; +import com.fr.design.data.DataCreatorUI; +import com.fr.design.widget.ui.ButtonDefinePane; +import com.fr.form.ui.Button; +import com.fr.form.ui.Widget; +import org.easymock.EasyMock; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.api.easymock.PowerMock; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import java.util.HashMap; +import java.util.Map; + +@RunWith(PowerMockRunner.class) +@PowerMockIgnore("javax.swing.*") +public class WidgetDefinePaneFactoryTest { + + @Test + @PrepareForTest({ExtraDesignClassManager.class, WidgetDefinePaneFactory.class}) + public void testCreateWidgetDefinePane() throws Exception { + + Map, Appearance> map = new HashMap<>(); + ExtraDesignClassManager mockDesignManager = EasyMock.mock(ExtraDesignClassManager.class); + EasyMock.expect(mockDesignManager.getCellWidgetOptionsMap()).andReturn(map).anyTimes(); + EasyMock.replay(mockDesignManager); + + PowerMock.mockStatic(ExtraDesignClassManager.class); + EasyMock.expect(ExtraDesignClassManager.getInstance()).andReturn(mockDesignManager).anyTimes(); + PowerMock.replayAll(ExtraDesignClassManager.class); + + Button mockWidget = EasyMock.mock(Button.class); + EasyMock.replay(mockWidget); + + ButtonDefinePane mockPane = EasyMock.mock(ButtonDefinePane.class); + mockPane.populateBean(EasyMock.anyObject(Button.class)); + EasyMock.expectLastCall(); + EasyMock.replay(mockPane); + + + Operator mockOperator = EasyMock.mock(Operator.class); + mockOperator.did(EasyMock.anyObject(DataCreatorUI.class), EasyMock.anyString()); + EasyMock.replay(mockOperator); + + WidgetDefinePaneFactory.RN rn1 = WidgetDefinePaneFactory.createWidgetDefinePane(mockWidget, mockOperator); + Assert.assertNull(rn1); + + Appearance appearance = new Appearance(ButtonDefinePane.class, "test"); + map.put(mockWidget.getClass(), appearance); + + WidgetDefinePaneFactory.RN rn2 = WidgetDefinePaneFactory.createWidgetDefinePane(mockWidget, mockOperator); + Assert.assertNotNull(rn2); + + map.clear(); + + WidgetDefinePaneFactory.RN rn3 = WidgetDefinePaneFactory.createWidgetDefinePane(mockWidget, mockOperator); + Assert.assertNull(rn3); + } + + +} \ No newline at end of file From d5c31126decf371118dc61f590aed3439c042a3c Mon Sep 17 00:00:00 2001 From: Lanlan Date: Thu, 25 Jul 2019 11:28:10 +0800 Subject: [PATCH 3/3] =?UTF-8?q?REPORT-18362=20=E6=8F=92=E4=BB=B6=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E6=A0=B9=E6=8D=AElic=E6=98=BE=E7=A4=BA-=E5=89=8D?= =?UTF-8?q?=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/extra/PluginOperateUtils.java | 16 ++++++++++++++++ .../exe/callback/InstallFromDiskCallback.java | 6 ++++-- .../exe/callback/InstallOnlineCallback.java | 5 +++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/extra/PluginOperateUtils.java b/designer-base/src/main/java/com/fr/design/extra/PluginOperateUtils.java index 774578630..c7c503ff3 100644 --- a/designer-base/src/main/java/com/fr/design/extra/PluginOperateUtils.java +++ b/designer-base/src/main/java/com/fr/design/extra/PluginOperateUtils.java @@ -206,5 +206,21 @@ public class PluginOperateUtils { return pluginInfo.toString(); } + public static String getSwitchedInfo(PluginTaskResult result) { + StringBuilder pluginInfo = new StringBuilder(); + List pluginTaskResults = result.asList(); + for (PluginTaskResult pluginTaskResult : pluginTaskResults) { + PluginTask pluginTask = pluginTaskResult.getCurrentTask(); + if (pluginTask == null) { + continue; + } + PluginMarker pluginMarker = pluginTask.getToMarker(); + PluginContext pluginContext = PluginManager.getContext(pluginMarker); + if (pluginContext != null && pluginContext.getSelfState() == 1) { + pluginInfo.append("\n").append(pluginContext.getSwitchedReason()); + } + } + return pluginInfo.toString(); + } } diff --git a/designer-base/src/main/java/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java b/designer-base/src/main/java/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java index e8096efbf..59d5d6a08 100644 --- a/designer-base/src/main/java/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java +++ b/designer-base/src/main/java/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java @@ -36,10 +36,12 @@ public class InstallFromDiskCallback extends AbstractPluginTaskCallback { @Override public void done(PluginTaskResult result) { + String pluginInfo = PluginOperateUtils.getSuccessInfo(result); if (result.isSuccess()) { + String switchedInfo = PluginOperateUtils.getSwitchedInfo(result); jsCallback.execute("success"); - FineLoggerFactory.getLogger().info(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Install_Success")); - JOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Install_Success")); + FineLoggerFactory.getLogger().info(pluginInfo + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Install_Success") + switchedInfo); + JOptionPane.showMessageDialog(null, pluginInfo + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Install_Success") + switchedInfo); } else if (result.errorCode() == PluginErrorCode.NeedDealWithPluginDependency) { int rv = JOptionPane.showOptionDialog( null, diff --git a/designer-base/src/main/java/com/fr/design/extra/exe/callback/InstallOnlineCallback.java b/designer-base/src/main/java/com/fr/design/extra/exe/callback/InstallOnlineCallback.java index 23b6679b6..6e72c0478 100644 --- a/designer-base/src/main/java/com/fr/design/extra/exe/callback/InstallOnlineCallback.java +++ b/designer-base/src/main/java/com/fr/design/extra/exe/callback/InstallOnlineCallback.java @@ -35,9 +35,10 @@ public class InstallOnlineCallback extends AbstractDealPreTaskCallback { protected void allDone(PluginTaskResult result) { String pluginInfo = PluginOperateUtils.getSuccessInfo(result); if (result.isSuccess()) { + String switchedInfo = PluginOperateUtils.getSwitchedInfo(result); jsCallback.execute("success"); - FineLoggerFactory.getLogger().info(pluginInfo + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Install_Success")); - JOptionPane.showMessageDialog(null, pluginInfo + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Install_Success")); + FineLoggerFactory.getLogger().info(pluginInfo + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Install_Success") + switchedInfo); + JOptionPane.showMessageDialog(null, pluginInfo + com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Plugin_Install_Success") + switchedInfo); } else if(result.errorCode() == PluginErrorCode.HasLowerPluginWhenInstall){ int rv = JOptionPane.showOptionDialog( null,