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 ce495cdb97..382709c92f 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.data.DesignTableDataManager; import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.dialog.FineJOptionPane; +import com.fr.design.dialog.link.MessageWithLink; import com.fr.design.env.DesignerWorkspaceGenerator; import com.fr.design.env.DesignerWorkspaceInfo; import com.fr.design.env.DesignerWorkspaceType; @@ -18,7 +19,10 @@ import com.fr.design.mainframe.JTemplate; import com.fr.design.utils.DesignUtils; import com.fr.env.CheckServiceDialog; import com.fr.env.EnvListPane; +import com.fr.env.RemoteWorkspaceURL; +import com.fr.env.TestConnectionResult; import com.fr.exit.DesignerExiter; +import com.fr.general.ComparatorUtils; import com.fr.general.GeneralUtils; import com.fr.invoke.Reflect; import com.fr.json.JSONArray; @@ -40,6 +44,7 @@ import com.fr.workspace.connect.WorkspaceConnectionInfo; import com.fr.workspace.engine.base.FineObjectPool; import com.fr.workspace.engine.channel.http.FunctionalHttpRequest; import com.fr.workspace.engine.exception.WorkspaceAuthException; +import com.fr.workspace.engine.exception.WorkspaceCheckException; import com.fr.workspace.engine.exception.WorkspaceConnectionException; import com.fr.workspace.engine.rpc.WorkspaceProxyPool; @@ -145,21 +150,28 @@ public class EnvChangeEntrance { strategy.showTip(new PopTip() { @Override public void show() { - FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"), - com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Error"), ERROR_MESSAGE, UIManager.getIcon("OptionPane.errorIcon")); + FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), + Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"), + Toolkit.i18nText("Fine-Design_Basic_Error"), + ERROR_MESSAGE, + UIManager.getIcon("OptionPane.errorIcon")); } }); return false; + } catch (WorkspaceCheckException e) { + handleWorkspaceCheckException(e, strategy, connectionInfo); + return false; } catch (Exception exception) { - FineLoggerFactory.getLogger().error(exception.getMessage(), exception); - strategy.showTip(new PopTip() { - @Override - public void show() { - FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"), - com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Error"), ERROR_MESSAGE, UIManager.getIcon("OptionPane.errorIcon")); - } - }); - + if (exception.getCause() instanceof WorkspaceCheckException) { + handleWorkspaceCheckException((WorkspaceCheckException) exception.getCause(), strategy, connectionInfo); + } else { + FineLoggerFactory.getLogger().error(exception.getMessage(), exception); + strategy.showTip(() -> FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), + Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"), + Toolkit.i18nText("Fine-Design_Basic_Error"), + ERROR_MESSAGE, + UIManager.getIcon("OptionPane.errorIcon"))); + } return false; } TemplateTreePane.getInstance().refreshDockingView(); @@ -170,6 +182,24 @@ public class EnvChangeEntrance { return true; } + private void handleWorkspaceCheckException(WorkspaceCheckException e, PopTipStrategy strategy, WorkspaceConnectionInfo info) { + TestConnectionResult result = TestConnectionResult.parseByException(e); + FineLoggerFactory.getLogger().error(e.getMessage(), e); + if (ComparatorUtils.equals(result, TestConnectionResult.AUTH_FAILED)) { + strategy.showTip(() -> FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), + Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"), + Toolkit.i18nText("Fine-Design_Basic_Error"), + ERROR_MESSAGE, + UIManager.getIcon("OptionPane.errorIcon"))); + } else { + strategy.showTip(() -> FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), + new MessageWithLink(result.getText(), Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Modify_PassWord"), info.getUrl() + RemoteWorkspaceURL.SYSTEM_LOGIN_PATH), + Toolkit.i18nText("Fine-Design_Basic_Error"), + ERROR_MESSAGE, + UIManager.getIcon("OptionPane.errorIcon"))); + } + } + /** * 这个功能留着,可能会加回来,先做注释处理 * 切换远程环境之前,进行版本检测,当版本不一致的时候,提示。 diff --git a/designer-base/src/main/java/com/fr/design/dialog/link/MessageWithLink.java b/designer-base/src/main/java/com/fr/design/dialog/link/MessageWithLink.java new file mode 100644 index 0000000000..8a1f55cbdf --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/dialog/link/MessageWithLink.java @@ -0,0 +1,55 @@ +package com.fr.design.dialog.link; + +import com.fr.design.gui.ilable.UILabel; +import com.fr.log.FineLoggerFactory; +import com.fr.stable.StringUtils; +import java.awt.Color; +import java.awt.Desktop; +import java.awt.Font; +import java.net.URI; +import javax.swing.JEditorPane; +import javax.swing.event.HyperlinkEvent; + +/** + * 用来构建JOptionPane带超链的消息提示 + * + * @author hades + * @version 10.0 + * Created by hades on 2020/10/23 + */ +public class MessageWithLink extends JEditorPane { + + public MessageWithLink(String message, String linkName, String link) { + super("text/html", "
" + message + "" + linkName + "" + ""); + addHyperlinkListener(e -> { + if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) { + try { + Desktop.getDesktop().browse(URI.create(link)); + } catch (Exception exception) { + FineLoggerFactory.getLogger().error(exception.getMessage(), exception); + } + } + }); + setEditable(false); + setBorder(null); + } + + public MessageWithLink(String linkName, String link ) { + this(StringUtils.EMPTY, linkName, link); + } + + private static StringBuilder getStyle() { + // 构建和相同风格样式 + UILabel label = new UILabel(); + Font font = label.getFont(); + Color color = label.getBackground(); + + StringBuilder style = new StringBuilder("font-family:" + font.getFamily() + ";"); + style.append("font-weight:").append(font.isBold() ? "bold" : "normal").append(";"); + style.append("font-size:").append(font.getSize()).append("pt;"); + style.append("background-color: rgb(").append(color.getRed()).append(",").append(color.getGreen()).append(",").append(color.getBlue()).append(");"); + + return style; + } + +} 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 5257e74f42..0b7d64ee1f 100644 --- a/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java +++ b/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java @@ -4,6 +4,8 @@ import com.fr.design.DesignerEnvManager; import com.fr.design.ExtraDesignClassManager; import com.fr.design.beans.BasicBeanPane; import com.fr.design.border.UITitledBorder; +import com.fr.design.dialog.FineJOptionPane; +import com.fr.design.dialog.link.MessageWithLink; import com.fr.design.env.RemoteDesignerWorkspaceInfo; import com.fr.design.fun.DesignerEnvProcessor; import com.fr.design.gui.ibutton.UIButton; @@ -16,6 +18,7 @@ import com.fr.design.gui.itextfield.UITextField; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayoutHelper; +import com.fr.design.mainframe.DesignerContext; import com.fr.design.scrollruler.ModLineBorder; import com.fr.license.exception.RegistEditionException; import com.fr.log.FineLoggerFactory; @@ -25,6 +28,7 @@ import com.fr.workspace.WorkContext; import com.fr.workspace.connect.WorkspaceConnectionInfo; import com.fr.workspace.engine.exception.WorkspaceAuthException; +import com.fr.workspace.engine.exception.WorkspaceCheckException; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JDialog; @@ -53,12 +57,13 @@ import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; -import java.util.function.Supplier; + import static com.fr.design.layout.TableLayout.FILL; import static com.fr.design.layout.TableLayout.PREFERRED; import static com.fr.env.TestConnectionResult.AUTH_FAILED; import static com.fr.third.guava.base.Optional.fromNullable; +import static javax.swing.JOptionPane.ERROR_MESSAGE; /** * @author yaohwu @@ -583,6 +588,8 @@ public class RemoteEnvPane extends BasicBeanPane