From fe66bd8aa18b782327909e1e3641e928cfe280e5 Mon Sep 17 00:00:00 2001 From: "yaoh.wu" Date: Fri, 28 Sep 2018 12:38:58 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-11590=20=E7=8E=AF=E5=A2=83=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E6=89=A7=E8=A1=8C=E5=AE=8C=E6=AF=95=E5=90=8E=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E9=80=89=E6=8B=A9=E5=AF=B9=E8=AF=9D=E6=A1=86=EF=BC=8C?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E6=97=B6=E7=8E=AF=E5=A2=83=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E5=92=8C9=E4=BF=9D=E6=8C=81=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/EnvChangeEntrance.java | 87 +++++++++++++++---- 1 file changed, 72 insertions(+), 15 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java b/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java index 9ad3b4ab11..f75fb8b62b 100644 --- a/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java +++ b/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java @@ -51,19 +51,28 @@ public class EnvChangeEntrance { }); } - private boolean envListOkAction(EnvListPane envListPane) { + private boolean envListOkAction(EnvListPane envListPane, PopTipStrategy strategy) { final String selectedName = envListPane.updateEnvManager(); - return switch2Env(selectedName); + return switch2Env(selectedName, strategy); } + /** + * 切换到指定名称的工作目录 + * + * @param envName 目标工作目录名称 + */ + public void switch2Env(final String envName) { + switch2Env(envName, PopTipStrategy.LATER); + } + /** * 切换到新环境 * * @param envName 新工作环境名称 * @return 是否成功 */ - public boolean switch2Env(final String envName) { + private boolean switch2Env(final String envName, PopTipStrategy strategy) { DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); DesignerWorkspaceInfo selectedEnv = envManager.getWorkspaceInfo(envName); @@ -71,8 +80,13 @@ public class EnvChangeEntrance { Workspace workspace = DesignerWorkspaceGenerator.generate(selectedEnv); boolean checkValid = workspace != null && selectedEnv.checkValid(); if (!checkValid) { - JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"), - UIManager.getString("OptionPane.messageDialogTitle"), ERROR_MESSAGE, UIManager.getIcon("OptionPane.errorIcon")); + strategy.showTip(new PopTip() { + @Override + public void show() { + JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"), + UIManager.getString("OptionPane.messageDialogTitle"), ERROR_MESSAGE, UIManager.getIcon("OptionPane.errorIcon")); + } + }); return false; } WorkContext.switchTo(workspace, new WorkContextCallback() { @@ -91,13 +105,24 @@ public class EnvChangeEntrance { } catch (AuthException | RegistEditionException e) { // String title = Toolkit.i18nText("Fine-Design_Basic_Remote_Connect_Auth_Failed"); // String title = Toolkit.i18nText("Fine-Design_Basic_Lic_Does_Not_Support_Remote"); - JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"), - UIManager.getString("OptionPane.messageDialogTitle"), ERROR_MESSAGE, UIManager.getIcon("OptionPane.errorIcon")); + strategy.showTip(new PopTip() { + @Override + public void show() { + JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"), + UIManager.getString("OptionPane.messageDialogTitle"), ERROR_MESSAGE, UIManager.getIcon("OptionPane.errorIcon")); + } + }); return false; } catch (Exception exception) { FineLoggerFactory.getLogger().error(exception.getMessage(), exception); - JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"), - UIManager.getString("OptionPane.messageDialogTitle"), ERROR_MESSAGE, UIManager.getIcon("OptionPane.errorIcon")); + strategy.showTip(new PopTip() { + @Override + public void show() { + JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"), + UIManager.getString("OptionPane.messageDialogTitle"), ERROR_MESSAGE, UIManager.getIcon("OptionPane.errorIcon")); + } + }); + return false; } TemplateTreePane.getInstance().refreshDockingView(); @@ -131,13 +156,11 @@ public class EnvChangeEntrance { @Override public void doOk() { - envListDialog.dispose(); - envListOkAction(envListPane); + envListOkAction(envListPane, PopTipStrategy.LATER); } @Override public void doCancel() { - envListDialog.dispose(); } }); @@ -155,11 +178,9 @@ public class EnvChangeEntrance { @Override public void doOk() { - - if (!envListOkAction(envListPane)) { + if (!envListOkAction(envListPane, PopTipStrategy.NOW)) { System.exit(0); } - } @Override @@ -170,4 +191,40 @@ public class EnvChangeEntrance { envListDialog.setVisible(true); } + + /** + * 提示显示策略 + */ + enum PopTipStrategy { + + /** + * 切换失败,就马上提示失败,不关闭选择列表对话框 + */ + NOW { + @Override + void showTip(PopTip tip) { + tip.show(); + } + }, + /** + * 切换失败,自动关闭选择列表对话框,然后提示切换失败 + */ + LATER { + @Override + void showTip(final PopTip tip) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + tip.show(); + } + }); + } + }; + + abstract void showTip(PopTip tip); + } + + interface PopTip { + void show(); + } }