From ba5b8fe1674e6edb30affd980001ab9254972092 Mon Sep 17 00:00:00 2001 From: Harrison Date: Fri, 21 Dec 2018 10:43:05 +0800 Subject: [PATCH 1/5] =?UTF-8?q?REPORT-13074=20=E8=BF=9C=E7=A8=8B=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E5=90=91=E4=B8=8B=E5=85=BC=E5=AE=B9=201.=20=E5=8A=A0?= =?UTF-8?q?=E5=85=A5=E5=BA=8F=E5=88=97=E5=8C=96=E5=BC=82=E5=B8=B8=20Serili?= =?UTF-8?q?zationException=20,=20WorkspaceNoteHitException=202.=20?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=E5=88=87=E6=8D=A2=E8=BF=9C=E7=A8=8B=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E7=9A=84=E6=A3=80=E6=B5=8B=EF=BC=8C=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=BF=9C=E7=A8=8B=E8=BF=9E=E6=8E=A5=E7=9A=84?= =?UTF-8?q?=E6=8F=90=E9=86=92=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/EnvChangeEntrance.java | 46 ++++++++++++++++ .../main/java/com/fr/env/RemoteEnvPane.java | 37 ++++++++----- .../java/com/fr/env/TestConnectionResult.java | 55 +++++++++++++++++++ 3 files changed, 125 insertions(+), 13 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/env/TestConnectionResult.java 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 76ae52894..725272a15 100644 --- a/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java +++ b/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java @@ -5,6 +5,7 @@ import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.env.DesignerWorkspaceGenerator; import com.fr.design.env.DesignerWorkspaceInfo; +import com.fr.design.env.DesignerWorkspaceType; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.TemplateTreePane; import com.fr.design.i18n.Toolkit; @@ -15,19 +16,25 @@ import com.fr.env.EnvListPane; import com.fr.general.GeneralContext; import com.fr.license.exception.RegistEditionException; import com.fr.log.FineLoggerFactory; +import com.fr.stable.AssistUtils; import com.fr.stable.EnvChangedListener; import com.fr.start.server.ServerTray; import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContextCallback; import com.fr.workspace.Workspace; import com.fr.workspace.connect.AuthException; +import com.fr.workspace.connect.WorkspaceConnectionInfo; +import com.fr.workspace.engine.channel.http.FunctionalHttpRequest; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; import javax.swing.UIManager; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import static javax.swing.JOptionPane.ERROR_MESSAGE; +import static javax.swing.JOptionPane.QUESTION_MESSAGE; public class EnvChangeEntrance { @@ -90,6 +97,11 @@ public class EnvChangeEntrance { }); return false; } + + if (versionCheck(selectedEnv)) { + return false; + } + WorkContext.switchTo(workspace, new WorkContextCallback() { @Override public void done() { @@ -138,6 +150,40 @@ public class EnvChangeEntrance { return true; } + /** + * 切换环境之前,进行版本检测,当版本不一致的时候,提示。 + * 当选择 ok 时,才继续。 + * + * @param selectedEnv 选择的环境 + * @return 是否一致 + * @throws Exception 异常 + */ + private boolean versionCheck(DesignerWorkspaceInfo selectedEnv) throws Exception { + + if (selectedEnv.getType() == DesignerWorkspaceType.Remote) { + + WorkspaceConnectionInfo info = selectedEnv.getConnection(); + String serverVersion = new FunctionalHttpRequest(info).getServerVersion(); + + if (!AssistUtils.equals(serverVersion, WorkContext.getVersion())) { + + final List result = new ArrayList<>(1); + PopTipStrategy.NOW.showTip(new PopTip() { + @Override + public void show() { + String[] option = {Toolkit.i18nText("Fine-Design_Report_Yes"), Toolkit.i18nText("Fine-Design_Report_No")}; + int choice = JOptionPane.showOptionDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Version_Inconsistency"), + UIManager.getString("OptionPane.messageDialogTitle"), JOptionPane.YES_NO_OPTION, QUESTION_MESSAGE, UIManager.getIcon("OptionPane.warningIcon"), option, 1); + result.add(choice); + } + }); + + return result.size() != 0 && result.get(0) == 1; + } + } + return false; + } + /** * 编辑items * diff --git a/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java b/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java index 769c843cc..21b5d2b2c 100644 --- a/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java +++ b/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java @@ -511,14 +511,14 @@ public class RemoteEnvPane extends BasicBeanPane { } private void tryConnectRemoteEnv() { + final RemoteDesignerWorkspaceInfo remoteEnv = updateBean(); + final WorkspaceConnectionInfo connection = remoteEnv.getConnection(); + final SwingWorker worker = new SwingWorker() { @Override protected Boolean doInBackground() throws Exception { - final RemoteDesignerWorkspaceInfo remoteEnv = updateBean(); - - WorkspaceConnectionInfo connection = remoteEnv.getConnection(); DesignerEnvManager.getEnvManager().setCertificatePath(connection.getCertPath()); DesignerEnvManager.getEnvManager().setCertificatePass(connection.getCertSecretKey()); try { @@ -532,23 +532,33 @@ public class RemoteEnvPane extends BasicBeanPane { protected void done() { okButton.setEnabled(true); try { - Boolean result = get(); - if (result == null) { + + TestConnectionResult result = TestConnectionResult.parse(get(), connection); + if (result == TestConnectionResult.Fully_Success) { + message.setText(Toolkit.i18nText("Fine-Design_Basic_Remote_Connect_Successful")); + uiLabel.setIcon(UIManager.getIcon("OptionPane.informationIcon")); + } + + if (result == TestConnectionResult.Partly_Sucess) { + message.setText(Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Version_Inconsistency")); + uiLabel.setIcon(UIManager.getIcon("OptionPane.informationIcon")); + } + + if (result == TestConnectionResult.Fully_Failed) { + message.setText(Toolkit.i18nText("Fine-Design_Basic_Remote_Connect_Failed")); + uiLabel.setIcon(UIManager.getIcon("OptionPane.errorIcon")); + } + + if (result == TestConnectionResult.Auth_Failed) { message.setText(Toolkit.i18nText("Fine-Design_Basic_Remote_Connect_Auth_Failed")); uiLabel.setIcon(UIManager.getIcon("OptionPane.errorIcon")); - } else { - if (result) { - message.setText(Toolkit.i18nText("Fine-Design_Basic_Remote_Connect_Successful")); - uiLabel.setIcon(UIManager.getIcon("OptionPane.informationIcon")); - } else { - message.setText(Toolkit.i18nText("Fine-Design_Basic_Remote_Connect_Failed")); - uiLabel.setIcon(UIManager.getIcon("OptionPane.errorIcon")); - } } } catch (InterruptedException | ExecutionException e) { FineLoggerFactory.getLogger().error(e, e.getMessage()); message.setText(Toolkit.i18nText("Fine-Design_Basic_Remote_Connect_Failed")); uiLabel.setIcon(UIManager.getIcon("OptionPane.errorIcon")); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage()); } dialogDownPane.remove(cancelButton); dialogDownPane.revalidate(); @@ -596,6 +606,7 @@ public class RemoteEnvPane extends BasicBeanPane { dialogDownPane = new JPanel(); uiLabel = new UILabel(UIManager.getIcon("OptionPane.informationIcon")); upPane.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10)); + //upPane.setLayout(new BorderLayout()); upPane.add(uiLabel); upPane.add(message); dialogDownPane.setLayout(new FlowLayout(FlowLayout.CENTER, 6, 0)); diff --git a/designer-base/src/main/java/com/fr/env/TestConnectionResult.java b/designer-base/src/main/java/com/fr/env/TestConnectionResult.java new file mode 100644 index 000000000..3aaf594ec --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/TestConnectionResult.java @@ -0,0 +1,55 @@ +package com.fr.env; + +import com.fr.stable.AssistUtils; +import com.fr.workspace.WorkContext; +import com.fr.workspace.connect.WorkspaceConnectionInfo; +import com.fr.workspace.engine.channel.http.FunctionalHttpRequest; + +/** + * created by Harrison on 2018/12/20 + **/ +public enum TestConnectionResult { + /** + * 完全成功, 版本匹配,测试连接成功。 + */ + Fully_Success(0), + + /** + * 不完全成功,版本不匹配,但测试连接成功。 + */ + Partly_Sucess(1), + + /** + * 完全失败,直接没连上 + */ + Fully_Failed(2), + + /** + * 验证 Token 失败 + */ + Auth_Failed(3); + + private int sign; + + TestConnectionResult(int i) { + this.sign = i; + } + + public static TestConnectionResult parse(Boolean value, WorkspaceConnectionInfo info) throws Exception { + if (value == null) { + return Auth_Failed; + } + + if (!value) { + return Fully_Failed; + } + + String serverVersion = new FunctionalHttpRequest(info).getServerVersion(); + + if (AssistUtils.equals(serverVersion, WorkContext.getVersion())) { + return Fully_Success; + } + + return Partly_Sucess; + } +} From 1380b31b6467f8f0c400e4af279227416df9de12 Mon Sep 17 00:00:00 2001 From: Harrison Date: Fri, 21 Dec 2018 10:58:13 +0800 Subject: [PATCH 2/5] =?UTF-8?q?REPORT-13074=20=E8=BF=9C=E7=A8=8B=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E5=90=91=E4=B8=8B=E5=85=BC=E5=AE=B9=201.=20=E8=A1=A5?= =?UTF-8?q?=E5=85=85=E4=B8=80=E4=BA=9B=E6=B3=A8=E9=87=8A=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/fr/env/RemoteEnvPane.java | 4 +- .../java/com/fr/env/TestConnectionResult.java | 37 +++++++++++-------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java b/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java index 21b5d2b2c..742b6cc16 100644 --- a/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java +++ b/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java @@ -541,7 +541,7 @@ public class RemoteEnvPane extends BasicBeanPane { if (result == TestConnectionResult.Partly_Sucess) { message.setText(Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Version_Inconsistency")); - uiLabel.setIcon(UIManager.getIcon("OptionPane.informationIcon")); + uiLabel.setIcon(UIManager.getIcon("OptionPane.warningIcon")); } if (result == TestConnectionResult.Fully_Failed) { @@ -557,8 +557,6 @@ public class RemoteEnvPane extends BasicBeanPane { FineLoggerFactory.getLogger().error(e, e.getMessage()); message.setText(Toolkit.i18nText("Fine-Design_Basic_Remote_Connect_Failed")); uiLabel.setIcon(UIManager.getIcon("OptionPane.errorIcon")); - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage()); } dialogDownPane.remove(cancelButton); dialogDownPane.revalidate(); diff --git a/designer-base/src/main/java/com/fr/env/TestConnectionResult.java b/designer-base/src/main/java/com/fr/env/TestConnectionResult.java index 3aaf594ec..357d4f38c 100644 --- a/designer-base/src/main/java/com/fr/env/TestConnectionResult.java +++ b/designer-base/src/main/java/com/fr/env/TestConnectionResult.java @@ -1,41 +1,40 @@ package com.fr.env; +import com.fr.log.FineLoggerFactory; import com.fr.stable.AssistUtils; import com.fr.workspace.WorkContext; import com.fr.workspace.connect.WorkspaceConnectionInfo; import com.fr.workspace.engine.channel.http.FunctionalHttpRequest; /** + * 测试连接的结果。 + * 不改变原有逻辑的情况下,加入一层转化。 + * 根据这里的转化结果,判断需要提示哪些内容。 + * * created by Harrison on 2018/12/20 **/ public enum TestConnectionResult { /** * 完全成功, 版本匹配,测试连接成功。 */ - Fully_Success(0), + Fully_Success, /** * 不完全成功,版本不匹配,但测试连接成功。 */ - Partly_Sucess(1), + Partly_Sucess, /** * 完全失败,直接没连上 */ - Fully_Failed(2), + Fully_Failed, /** * 验证 Token 失败 */ - Auth_Failed(3); + Auth_Failed; - private int sign; - - TestConnectionResult(int i) { - this.sign = i; - } - - public static TestConnectionResult parse(Boolean value, WorkspaceConnectionInfo info) throws Exception { + public static TestConnectionResult parse(Boolean value, WorkspaceConnectionInfo info) { if (value == null) { return Auth_Failed; } @@ -43,13 +42,21 @@ public enum TestConnectionResult { if (!value) { return Fully_Failed; } + try { - String serverVersion = new FunctionalHttpRequest(info).getServerVersion(); + String serverVersion = new FunctionalHttpRequest(info).getServerVersion(); + if (AssistUtils.equals(serverVersion, WorkContext.getVersion())) { + return Fully_Success; + } - if (AssistUtils.equals(serverVersion, WorkContext.getVersion())) { - return Fully_Success; + return Partly_Sucess; + } catch (Exception e) { + + // 发生异常,说明没连接上。返回完全失败。 + FineLoggerFactory.getLogger().error(e.getMessage()); + return Fully_Failed; } - return Partly_Sucess; + } } From fcdb68c2fcedd59e37749bef190d8341f640497e Mon Sep 17 00:00:00 2001 From: Harrison Date: Fri, 21 Dec 2018 11:24:24 +0800 Subject: [PATCH 3/5] =?UTF-8?q?REPORT-13074=20=E8=BF=9C=E7=A8=8B=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E5=90=91=E4=B8=8B=E5=85=BC=E5=AE=B9=201.=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E4=B8=80=E4=B8=8B=E9=80=BB=E8=BE=91=E3=80=82=20?= =?UTF-8?q?=E6=9B=B4=E6=96=B9=E4=BE=BF=E7=90=86=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/EnvChangeEntrance.java | 47 ++++++++++++------- 1 file changed, 29 insertions(+), 18 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 725272a15..58f22d1b6 100644 --- a/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java +++ b/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java @@ -98,7 +98,8 @@ public class EnvChangeEntrance { return false; } - if (versionCheck(selectedEnv)) { + // 如果版本不一致,且确认 不继续 连接,这里返回 false. + if (!versionCheckAndConfirm(selectedEnv)) { return false; } @@ -151,37 +152,47 @@ public class EnvChangeEntrance { } /** - * 切换环境之前,进行版本检测,当版本不一致的时候,提示。 - * 当选择 ok 时,才继续。 + * 切换远程环境之前,进行版本检测,当版本不一致的时候,提示。 + * 当用户确认选择 ok 时,才继续。 * * @param selectedEnv 选择的环境 * @return 是否一致 + * 1. 非远程环境 , 返回 true + * 2. 远程环境 + * 2.1 不匹配, + * 2.1.1 当选择 ok , 返回 true + * 2.1.2 当选择 no, 返回 false + * 2.2 匹配, 返回 true * @throws Exception 异常 */ - private boolean versionCheck(DesignerWorkspaceInfo selectedEnv) throws Exception { + private boolean versionCheckAndConfirm(DesignerWorkspaceInfo selectedEnv) throws Exception { if (selectedEnv.getType() == DesignerWorkspaceType.Remote) { WorkspaceConnectionInfo info = selectedEnv.getConnection(); String serverVersion = new FunctionalHttpRequest(info).getServerVersion(); - if (!AssistUtils.equals(serverVersion, WorkContext.getVersion())) { + if (AssistUtils.equals(serverVersion, WorkContext.getVersion())) { + return true; + } - final List result = new ArrayList<>(1); - PopTipStrategy.NOW.showTip(new PopTip() { - @Override - public void show() { - String[] option = {Toolkit.i18nText("Fine-Design_Report_Yes"), Toolkit.i18nText("Fine-Design_Report_No")}; - int choice = JOptionPane.showOptionDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Version_Inconsistency"), - UIManager.getString("OptionPane.messageDialogTitle"), JOptionPane.YES_NO_OPTION, QUESTION_MESSAGE, UIManager.getIcon("OptionPane.warningIcon"), option, 1); - result.add(choice); - } - }); + final List result = new ArrayList<>(1); + PopTipStrategy.NOW.showTip(new PopTip() { + @Override + public void show() { + String[] option = {Toolkit.i18nText("Fine-Design_Report_Yes"), Toolkit.i18nText("Fine-Design_Report_No")}; + int choice = JOptionPane.showOptionDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Version_Inconsistency"), + UIManager.getString("OptionPane.messageDialogTitle"), JOptionPane.YES_NO_OPTION, QUESTION_MESSAGE, UIManager.getIcon("OptionPane.warningIcon"), option, 1); + result.add(choice); + } + }); - return result.size() != 0 && result.get(0) == 1; - } + // 只有选择 yes , 这里的值才为 0, 返回 true + // 否着返回 false, 将不进行下面的连接操作。 + return result.size() != 0 && result.get(0) == 0; } - return false; + + return true; } /** From 02dd1b00793e08c381d26f541d47f7ce2e94aac8 Mon Sep 17 00:00:00 2001 From: Harrison Date: Fri, 21 Dec 2018 11:43:14 +0800 Subject: [PATCH 4/5] =?UTF-8?q?REPORT-13074=20=E8=BF=9C=E7=A8=8B=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E5=90=91=E4=B8=8B=E5=85=BC=E5=AE=B9=201.=20=E5=BF=98?= =?UTF-8?q?=E4=BA=86=E6=B3=A8=E9=87=8A=E6=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- designer-base/src/main/java/com/fr/env/RemoteEnvPane.java | 1 - 1 file changed, 1 deletion(-) diff --git a/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java b/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java index 742b6cc16..dc764153c 100644 --- a/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java +++ b/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java @@ -604,7 +604,6 @@ public class RemoteEnvPane extends BasicBeanPane { dialogDownPane = new JPanel(); uiLabel = new UILabel(UIManager.getIcon("OptionPane.informationIcon")); upPane.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10)); - //upPane.setLayout(new BorderLayout()); upPane.add(uiLabel); upPane.add(message); dialogDownPane.setLayout(new FlowLayout(FlowLayout.CENTER, 6, 0)); From 0fcdd85bdb2801154a85c4f1c6452df57663bedb Mon Sep 17 00:00:00 2001 From: Harrison Date: Fri, 21 Dec 2018 16:26:57 +0800 Subject: [PATCH 5/5] =?UTF-8?q?REPORT-13074=20=E8=BF=9C=E7=A8=8B=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E5=90=91=E4=B8=8B=E5=85=BC=E5=AE=B9=201.=20=E5=B0=86?= =?UTF-8?q?=E5=B0=9D=E8=AF=95=E8=BF=9E=E6=8E=A5=E5=92=8C=E6=AD=A3=E5=BC=8F?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E6=8F=90=E7=A4=BA=E5=88=86=E5=BC=80=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- designer-base/src/main/java/com/fr/env/RemoteEnvPane.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java b/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java index dc764153c..d2953eeb6 100644 --- a/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java +++ b/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java @@ -540,7 +540,7 @@ public class RemoteEnvPane extends BasicBeanPane { } if (result == TestConnectionResult.Partly_Sucess) { - message.setText(Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Version_Inconsistency")); + message.setText(Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Version_Inconsistence_Test")); uiLabel.setIcon(UIManager.getIcon("OptionPane.warningIcon")); }