Browse Source

Merge pull request #5316 in DESIGN/design from feature/10.0 to feature/big-screen

* commit 'b16be7bef1ba1539f2c6eb1f28fe49864db97b9e':
  REPORT-55795 【10.0.19】报错规范——设计器远程设计连接部分 fix 单元测试
  无jira 解决冲突 错误提交回退
  无jira 解决冲突 错误提交回退
  REPORT-55795 【10.0.19】报错规范——设计器远程设计连接部分
feature/big-screen
superman 3 years ago
parent
commit
2821612f9e
  1. 88
      designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java
  2. 239
      designer-base/src/main/java/com/fr/design/dialog/UIDetailErrorLinkDialog.java
  3. 2
      designer-base/src/main/java/com/fr/design/env/DesignerWorkspaceInfo.java
  4. 15
      designer-base/src/main/java/com/fr/design/env/RemoteDesignerWorkspaceInfo.java
  5. 32
      designer-base/src/main/java/com/fr/env/HelpLink.java
  6. 36
      designer-base/src/main/java/com/fr/env/RemoteDesignLocaleMark.java
  7. 48
      designer-base/src/main/java/com/fr/env/RemoteEnvPane.java
  8. 16
      designer-base/src/main/java/com/fr/env/handler/Handler.java
  9. 88
      designer-base/src/main/java/com/fr/env/handler/RemoteDesignExceptionHandler.java
  10. 30
      designer-base/src/main/java/com/fr/env/handler/ResultWrapper.java
  11. 18
      designer-base/src/main/java/com/fr/env/handler/impl/CancelHandler.java
  12. 48
      designer-base/src/main/java/com/fr/env/handler/impl/CommonHandler.java
  13. 21
      designer-base/src/main/java/com/fr/env/handler/impl/ExecutionHandler.java
  14. 24
      designer-base/src/main/java/com/fr/env/handler/impl/UnexpectedHandler.java
  15. 21
      designer-base/src/test/java/com/fr/design/env/RemoteDesignerWorkspaceInfoTest.java
  16. 14
      designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceProvider.java

88
designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java

@ -6,7 +6,6 @@ import com.fr.design.data.DesignTableDataManager;
import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.dialog.FineJOptionPane; import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.dialog.link.MessageWithLink;
import com.fr.design.env.DesignerWorkspaceGenerator; import com.fr.design.env.DesignerWorkspaceGenerator;
import com.fr.design.env.DesignerWorkspaceInfo; import com.fr.design.env.DesignerWorkspaceInfo;
import com.fr.design.env.DesignerWorkspaceType; import com.fr.design.env.DesignerWorkspaceType;
@ -21,14 +20,11 @@ import com.fr.design.notification.NotificationCenter;
import com.fr.design.utils.DesignUtils; import com.fr.design.utils.DesignUtils;
import com.fr.design.versioncheck.VersionCheckUtils; import com.fr.design.versioncheck.VersionCheckUtils;
import com.fr.env.EnvListPane; import com.fr.env.EnvListPane;
import com.fr.env.RemoteWorkspaceURL; import com.fr.env.handler.RemoteDesignExceptionHandler;
import com.fr.env.TestConnectionResult;
import com.fr.exit.DesignerExiter; import com.fr.exit.DesignerExiter;
import com.fr.general.ComparatorUtils;
import com.fr.general.GeneralUtils; import com.fr.general.GeneralUtils;
import com.fr.invoke.Reflect; import com.fr.invoke.Reflect;
import com.fr.json.JSONArray; import com.fr.json.JSONArray;
import com.fr.license.exception.RegistEditionException;
import com.fr.locale.InterProviderFactory; import com.fr.locale.InterProviderFactory;
import com.fr.log.FineLoggerFactory; import com.fr.log.FineLoggerFactory;
import com.fr.process.ProcessEventPipe; import com.fr.process.ProcessEventPipe;
@ -46,8 +42,6 @@ import com.fr.workspace.base.WorkspaceAPI;
import com.fr.workspace.connect.WorkspaceConnectionInfo; import com.fr.workspace.connect.WorkspaceConnectionInfo;
import com.fr.workspace.engine.base.FineObjectPool; import com.fr.workspace.engine.base.FineObjectPool;
import com.fr.workspace.engine.channel.http.FunctionalHttpRequest; 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.exception.WorkspaceConnectionException;
import com.fr.workspace.engine.rpc.WorkspaceProxyPool; import com.fr.workspace.engine.rpc.WorkspaceProxyPool;
@ -66,7 +60,6 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.HashSet; import java.util.HashSet;
import static javax.swing.JOptionPane.ERROR_MESSAGE;
import static javax.swing.JOptionPane.QUESTION_MESSAGE; import static javax.swing.JOptionPane.QUESTION_MESSAGE;
public class EnvChangeEntrance { public class EnvChangeEntrance {
@ -79,6 +72,8 @@ public class EnvChangeEntrance {
private static EnvChangeEntrance singleton = new EnvChangeEntrance(); private static EnvChangeEntrance singleton = new EnvChangeEntrance();
} }
private BasicDialog dialog;
private EnvChangeEntrance() { private EnvChangeEntrance() {
@ -116,13 +111,6 @@ public class EnvChangeEntrance {
Workspace workspace = DesignerWorkspaceGenerator.generate(selectedEnv); Workspace workspace = DesignerWorkspaceGenerator.generate(selectedEnv);
boolean checkValid = workspace != null && selectedEnv.checkValid(); boolean checkValid = workspace != null && selectedEnv.checkValid();
if (!checkValid) { if (!checkValid) {
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_Tool_Tips"), ERROR_MESSAGE, UIManager.getIcon("OptionPane.errorIcon"));
}
});
return false; return false;
} }
@ -149,34 +137,9 @@ public class EnvChangeEntrance {
template.refreshToolArea(); template.refreshToolArea();
} }
pluginErrorRemind(); pluginErrorRemind();
} catch (WorkspaceAuthException | 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");
strategy.showTip(new PopTip() {
@Override
public void show() {
FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(),
Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"),
Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"),
ERROR_MESSAGE,
UIManager.getIcon("OptionPane.errorIcon"));
}
});
return false;
} catch (WorkspaceCheckException e) {
handleWorkspaceCheckException(e, strategy, connectionInfo);
return false;
} catch (Exception exception) { } catch (Exception exception) {
if (exception.getCause() instanceof WorkspaceCheckException) { // 失败的处理
handleWorkspaceCheckException((WorkspaceCheckException) exception.getCause(), strategy, connectionInfo); RemoteDesignExceptionHandler.getInstance().handleInSwitch(exception, selectedEnv);
} 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_Tool_Tips"),
ERROR_MESSAGE,
UIManager.getIcon("OptionPane.errorIcon")));
}
return false; return false;
} }
TemplateTreePane.getInstance().refreshDockingView(); TemplateTreePane.getInstance().refreshDockingView();
@ -188,29 +151,6 @@ public class EnvChangeEntrance {
return true; return true;
} }
public 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_Tool_Tips"),
ERROR_MESSAGE,
UIManager.getIcon("OptionPane.errorIcon")));
} else {
if (result.isVerifyResult()) {
FineLoggerFactory.getLogger().error(result.getText().replaceAll(TestConnectionResult.WRAP, StringUtils.EMPTY) + Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Modify_PassWord"));
}
strategy.showTip(() -> FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(),
result.isVerifyResult()
? new MessageWithLink(result.getText(), Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Modify_PassWord"), info.getUrl() + RemoteWorkspaceURL.SYSTEM_LOGIN_PATH)
: result.getText(),
Toolkit.i18nText("Fine-Design_Basic_Error"),
ERROR_MESSAGE,
UIManager.getIcon("OptionPane.errorIcon")));
}
}
/** /**
* 这个功能留着可能会加回来先做注释处理 * 这个功能留着可能会加回来先做注释处理
* 切换远程环境之前进行版本检测当版本不一致的时候提示 * 切换远程环境之前进行版本检测当版本不一致的时候提示
@ -440,7 +380,7 @@ public class EnvChangeEntrance {
public void chooseEnv(final String envName) { public void chooseEnv(final String envName) {
final EnvListPane envListPane = new EnvListPane(); final EnvListPane envListPane = new EnvListPane();
final BasicDialog envListDialog = envListPane.showWindow(DesignerContext.getDesignerFrame()); final BasicDialog envListDialog = envListPane.showWindow(DesignerContext.getDesignerFrame());
dialog = envListDialog;
envListPane.populateEnvManager(envName); envListPane.populateEnvManager(envName);
envListDialog.addDialogActionListener(new DialogActionAdapter() { envListDialog.addDialogActionListener(new DialogActionAdapter() {
@ -457,6 +397,7 @@ public class EnvChangeEntrance {
@Override @Override
public void doCancel() { public void doCancel() {
envListDialog.dispose(); envListDialog.dispose();
dialog = null;
// todo 断开了但是没选择新的环境,那么尝试重连旧环境,等接口 // todo 断开了但是没选择新的环境,那么尝试重连旧环境,等接口
} }
}); });
@ -474,6 +415,7 @@ public class EnvChangeEntrance {
final EnvListPane envListPane = new EnvListPane(); final EnvListPane envListPane = new EnvListPane();
envListPane.populateEnvManager(DesignerEnvManager.getEnvManager().getCurEnvName()); envListPane.populateEnvManager(DesignerEnvManager.getEnvManager().getCurEnvName());
BasicDialog envListDialog = envListPane.showWindow(SwingUtilities.getWindowAncestor(DesignerContext.getDesignerFrame())); BasicDialog envListDialog = envListPane.showWindow(SwingUtilities.getWindowAncestor(DesignerContext.getDesignerFrame()));
dialog = envListDialog;
envListDialog.addDialogActionListener(new DialogActionAdapter() { envListDialog.addDialogActionListener(new DialogActionAdapter() {
@Override @Override
@ -489,6 +431,7 @@ public class EnvChangeEntrance {
@Override @Override
public void doCancel() { public void doCancel() {
dialog = null;
DesignerExiter.getInstance().execute(); DesignerExiter.getInstance().execute();
} }
}); });
@ -523,6 +466,9 @@ public class EnvChangeEntrance {
return false; return false;
} }
public BasicDialog getDialog() {
return dialog;
}
/** /**
* 提示显示策略 * 提示显示策略
@ -559,14 +505,4 @@ public class EnvChangeEntrance {
interface PopTip { interface PopTip {
void show(); void show();
} }
private static class SuccessPopTip implements PopTip {
@Override
public void show() {
FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(),
Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Success"),
Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"),
FineJOptionPane.INFORMATION_MESSAGE);
}
}
} }

239
designer-base/src/main/java/com/fr/design/dialog/UIDetailErrorLinkDialog.java

@ -0,0 +1,239 @@
package com.fr.design.dialog;
import com.fr.base.GraphHelper;
import com.fr.design.dialog.link.MessageWithLink;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextarea.UITextArea;
import com.fr.design.i18n.Toolkit;
import com.fr.design.utils.DesignUtils;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.IOUtils;
import com.fr.stable.StringUtils;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Point;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.PrintWriter;
import java.io.StringWriter;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
/**
* 带链接的错误详情弹窗
*
* @author hades
* @version 10.0
* Created by hades on 2021/8/2
*/
public class UIDetailErrorLinkDialog extends UIDialog {
private static final Color LINK_COLOR = new Color(51, 152, 253);
private static final int GAP_5 = 5;
private static final int GAP_10 = 10;
private static final String TAG_A_START = "<a>";
private static final String TAG_A_END = "</a>";
private final Dimension dimension = new Dimension(300, 180);
public static Builder newBuilder() {
return new Builder();
}
private UIDetailErrorLinkDialog(Frame parent, Builder builder) {
super(parent);
init(builder);
}
private UIDetailErrorLinkDialog(Dialog parent, Builder builder) {
super(parent);
init(builder);
}
private void init(Builder builder) {
this.setTitle(builder.title);
// 顶部 图标和提示
UILabel errorIcon = new UILabel(IOUtils.readIcon("com/fr/design/images/lookandfeel/Information_Icon_Error_32x32.png"));
UILabel errorInfo= new UILabel(builder.reason);
JPanel topPane = new JPanel(new FlowLayout(FlowLayout.LEFT, GAP_10, GAP_5));
topPane.add(errorIcon);
topPane.add(errorInfo);
// 中部 详细内容
JPanel contentPane = new JPanel(new BorderLayout());
contentPane.setBorder(BorderFactory.createEmptyBorder(0, GAP_5,0,0));
UILabel errorCodeLabel = new UILabel(Toolkit.i18nText("Fine_Design_Basic_Error_Code", builder.errorCode));
UILabel link = new UILabel(Toolkit.i18nText("Fine_Design_Basic_Show_Error_Stack"));
link.setForeground(LINK_COLOR);
link.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
StringWriter stackTraceWriter = new StringWriter();
builder.throwable.printStackTrace(new PrintWriter(stackTraceWriter));
StackPane stackPane = new StackPane(stackTraceWriter.toString());
BasicDialog dialog = stackPane.showLargeWindow(UIDetailErrorLinkDialog.this, null);
dialog.setVisible(true);
}
});
contentPane.add(errorCodeLabel, BorderLayout.NORTH);
contentPane.add(createComponent(builder), BorderLayout.CENTER);
contentPane.add(link, BorderLayout.SOUTH);
// 确定 + 取消
JPanel actionPane = new JPanel(new FlowLayout(FlowLayout.RIGHT, GAP_10, GAP_10));
actionPane.add(createButton(Toolkit.i18nText("Fine-Design_Report_OK")));
actionPane.add(createButton(Toolkit.i18nText("Fine-Design_Basic_Cancel")));
this.getContentPane().add(topPane, BorderLayout.NORTH);
this.getContentPane().add(contentPane, BorderLayout.CENTER);
this.getContentPane().add(actionPane, BorderLayout.SOUTH);
this.setSize(dimension);
this.setResizable(false);
GUICoreUtils.centerWindow(this);
}
private UIButton createButton(String content) {
UIButton button = new UIButton(content);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
UIDetailErrorLinkDialog.this.dispose();
}
});
return button;
}
private JComponent createComponent(Builder builder) {
JPanel panel = new JPanel(new BorderLayout());
boolean existDetailReason = StringUtils.isNotEmpty(builder.detailReason);
int maxWidth = dimension.width;
if (existDetailReason) {
String message = Toolkit.i18nText("Fine_Design_Basic_Detail_Error_Info", builder.detailReason);
UILabel label = new UILabel(message);
maxWidth = Math.max(maxWidth, GraphHelper.getWidth(message, label.getFont()));
panel.add(label, BorderLayout.NORTH);
}
String solution = existDetailReason ? builder.solution : Toolkit.i18nText("Fine_Design_Basic_Detail_Error_Info", builder.solution);
if (builder.solution.contains(TAG_A_START)) {
String[] solutionP1 = solution.split(TAG_A_START);
String[] solutionP2 = solutionP1[1].split(TAG_A_END);
MessageWithLink messageWithLink;
if (solutionP2.length == 2) {
messageWithLink = new MessageWithLink(solutionP1[0], solutionP2[0], builder.link, solutionP2[1]);
} else {
messageWithLink = new MessageWithLink(solutionP1[0], solutionP2[0], builder.link);
}
panel.add(messageWithLink, BorderLayout.CENTER);
} else {
UILabel solutionLabel = new UILabel(solution);
panel.add(solutionLabel, BorderLayout.CENTER);
}
dimension.width = Math.max(maxWidth, GraphHelper.getWidth(solution, DesignUtils.getDefaultGUIFont()));
return panel;
}
@Override
public void checkValid() throws Exception {
// do nothing
}
class StackPane extends BasicPane {
public StackPane(String stack) {
setLayout(new BorderLayout());
UITextArea textArea = new UITextArea();
textArea.setEditable(false);
textArea.setText(stack);
UIScrollPane scrollPane = new UIScrollPane(textArea);
add(scrollPane);
// 滚动条默认在顶部
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
scrollPane.getViewport().setViewPosition(new Point(0, 0));
}
});
}
@Override
protected String title4PopupWindow() {
return Toolkit.i18nText("Fine_Design_Basic_Error_Stack");
}
}
public static class Builder {
private Window window;
private String title;
private String reason;
private String errorCode;
private String detailReason;
private String solution;
private String link;
private Throwable throwable;
private Builder() {
}
public Builder setTitle(String title) {
this.title = title;
return this;
}
public Builder setReason(String reason) {
this.reason = reason;
return this;
}
public Builder setErrorCode(String errorCode) {
this.errorCode = errorCode;
return this;
}
public Builder setSolution(String solution) {
this.solution = solution;
return this;
}
public Builder setDetailReason(String detailReason) {
this.detailReason = detailReason;
return this;
}
public Builder setThrowable(Throwable throwable) {
this.throwable = throwable;
return this;
}
public Builder setWindow(Window window) {
this.window = window;
return this;
}
public Builder setLink(String link) {
this.link = link;
return this;
}
public UIDetailErrorLinkDialog build() {
if (this.window instanceof Frame) {
return new UIDetailErrorLinkDialog((Frame) window, this);
} else {
return new UIDetailErrorLinkDialog((Dialog) window, this);
}
}
}
}

2
designer-base/src/main/java/com/fr/design/env/DesignerWorkspaceInfo.java vendored

@ -15,5 +15,5 @@ public interface DesignerWorkspaceInfo extends XMLable {
WorkspaceConnectionInfo getConnection(); WorkspaceConnectionInfo getConnection();
boolean checkValid(); boolean checkValid() throws Exception;
} }

15
designer-base/src/main/java/com/fr/design/env/RemoteDesignerWorkspaceInfo.java vendored

@ -168,8 +168,7 @@ public class RemoteDesignerWorkspaceInfo implements DesignerWorkspaceInfo {
@Override @Override
public boolean checkValid() { public boolean checkValid() throws Exception {
boolean result = false;
String newPort = Integer.toString(DesignerEnvManager.getEnvManager().getEmbedServerPort()); String newPort = Integer.toString(DesignerEnvManager.getEnvManager().getEmbedServerPort());
if (!ComparatorUtils.equals(port, newPort)) { if (!ComparatorUtils.equals(port, newPort)) {
// 使用过程中 更改了内置服务器端口 重新初始化下 // 使用过程中 更改了内置服务器端口 重新初始化下
@ -177,15 +176,9 @@ public class RemoteDesignerWorkspaceInfo implements DesignerWorkspaceInfo {
} }
if (FILTER_SET.contains(connection.getUrl())) { if (FILTER_SET.contains(connection.getUrl())) {
FineLoggerFactory.getLogger().error("url is same with local designer"); FineLoggerFactory.getLogger().error("url is same with local designer");
return result; return false;
} }
try { WorkContext.getConnector().validateVT(connection);
WorkContext.getConnector().validateVT(connection); return true;
result = true;
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
return result;
}
return result;
} }
} }

32
designer-base/src/main/java/com/fr/env/HelpLink.java vendored

@ -0,0 +1,32 @@
package com.fr.env;
import com.fr.design.DesignerEnvManager;
import com.fr.design.env.DesignerWorkspaceInfo;
import com.fr.general.locale.LocaleCenter;
import com.fr.general.locale.LocaleMark;
import com.fr.locale.InterProviderFactory;
import java.util.HashMap;
import java.util.Map;
/**
* @author hades
* @version 10.0
* Created by hades on 2021/8/9
*/
public class HelpLink {
public static String getLink(String solution) {
Map<String, String> map = new HashMap<>();
String currentName = DesignerEnvManager.getEnvManager().getCurEnvName();
DesignerWorkspaceInfo workspaceInfo = DesignerEnvManager.getEnvManager().getWorkspaceInfo(currentName);
LocaleMark<String> linkMark = LocaleCenter.getMark(RemoteDesignLocaleMark.class);
String link = linkMark.getValue();
map.put(InterProviderFactory.getProvider().getLocText("Fine-Core_Remote_Design_Change_PassWord"), workspaceInfo.getConnection().getUrl() + RemoteWorkspaceURL.SYSTEM_LOGIN_PATH);
map.put(InterProviderFactory.getProvider().getLocText("Fine-Core_Remote_Design_Cert_Error_Solution"), link);
map.put(InterProviderFactory.getProvider().getLocText("Fine-Core_Remote_Design_Connection_Unknown_Error_Solution"), link);
map.put(InterProviderFactory.getProvider().getLocText("Fine-Core_Remote_Design_NetWork_Connection_Error_Solution"), link);
return map.get(solution);
}
}

36
designer-base/src/main/java/com/fr/env/RemoteDesignLocaleMark.java vendored

@ -0,0 +1,36 @@
package com.fr.env;
import com.fr.general.CloudCenter;
import com.fr.general.GeneralContext;
import com.fr.general.locale.LocaleMark;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
/**
* @author hades
* @version 10.0
* Created by hades on 2021/8/9
*/
public class RemoteDesignLocaleMark implements LocaleMark<String> {
private Map<Locale, String> map = new HashMap<>();
private static final String REMOTE_DESIGN_CN = CloudCenter.getInstance().acquireUrlByKind("help.remote.design.zh_CN", "https://help.fanruan.com/finereport/doc-view-3925.html");
private static final String REMOTE_DESIGN_EN = CloudCenter.getInstance().acquireUrlByKind("help.remote.design.en_US", "https://help.fanruan.com/finereport-en/doc-view-3862.html");
public RemoteDesignLocaleMark() {
map.put(Locale.CHINA, REMOTE_DESIGN_CN);
map.put(Locale.KOREA, REMOTE_DESIGN_EN);
map.put(Locale.JAPAN, REMOTE_DESIGN_EN);
map.put(Locale.US, REMOTE_DESIGN_EN);
map.put(Locale.TAIWAN, REMOTE_DESIGN_CN);
}
@Override
public String getValue() {
String result = map.get(GeneralContext.getLocale());
return result == null ? REMOTE_DESIGN_CN : result;
}
}

48
designer-base/src/main/java/com/fr/env/RemoteEnvPane.java vendored

@ -4,8 +4,6 @@ import com.fr.design.DesignerEnvManager;
import com.fr.design.ExtraDesignClassManager; import com.fr.design.ExtraDesignClassManager;
import com.fr.design.beans.BasicBeanPane; import com.fr.design.beans.BasicBeanPane;
import com.fr.design.border.UITitledBorder; 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.env.RemoteDesignerWorkspaceInfo;
import com.fr.design.fun.DesignerEnvProcessor; import com.fr.design.fun.DesignerEnvProcessor;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
@ -22,17 +20,12 @@ import com.fr.design.i18n.DesignSizeI18nManager;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayoutHelper; import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.scrollruler.ModLineBorder; import com.fr.design.scrollruler.ModLineBorder;
import com.fr.license.exception.RegistEditionException; import com.fr.env.handler.RemoteDesignExceptionHandler;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.third.guava.base.Strings; import com.fr.third.guava.base.Strings;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import com.fr.workspace.connect.WorkspaceConnectionInfo; 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.BorderFactory;
import javax.swing.BoxLayout; import javax.swing.BoxLayout;
@ -66,9 +59,7 @@ import java.io.File;
import static com.fr.design.layout.TableLayout.FILL; import static com.fr.design.layout.TableLayout.FILL;
import static com.fr.design.layout.TableLayout.PREFERRED; 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 com.fr.third.guava.base.Optional.fromNullable;
import static javax.swing.JOptionPane.ERROR_MESSAGE;
/** /**
* @author yaohwu * @author yaohwu
@ -573,8 +564,7 @@ public class RemoteEnvPane extends BasicBeanPane<RemoteDesignerWorkspaceInfo> {
fileChooserButton.addActionListener(new ActionListener() { fileChooserButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent evt) { public void actionPerformed(ActionEvent evt) {
FileChooserProvider fileChooserProvider = new JavaFxNativeFileChooser.Builder(). FileChooserProvider fileChooserProvider = new JavaFxNativeFileChooser.Builder().fileSelectionMode(FileSelectionMode.FILE).build();
fileSelectionMode(FileSelectionMode.FILE).build();
int saveValue = fileChooserProvider.showDialog(SwingUtilities.getWindowAncestor(RemoteEnvPane.this)); int saveValue = fileChooserProvider.showDialog(SwingUtilities.getWindowAncestor(RemoteEnvPane.this));
if (saveValue == JFileChooser.APPROVE_OPTION) { if (saveValue == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooserProvider.getSelectedFile(); File selectedFile = fileChooserProvider.getSelectedFile();
@ -589,42 +579,24 @@ public class RemoteEnvPane extends BasicBeanPane<RemoteDesignerWorkspaceInfo> {
final RemoteDesignerWorkspaceInfo remoteEnv = updateBean(); final RemoteDesignerWorkspaceInfo remoteEnv = updateBean();
final WorkspaceConnectionInfo connection = remoteEnv.getConnection(); final WorkspaceConnectionInfo connection = remoteEnv.getConnection();
final SwingWorker<TestConnectionResult, Void> worker = new SwingWorker<TestConnectionResult, Void>() { final SwingWorker<Boolean, Void> worker = new SwingWorker<Boolean, Void>() {
@Override @Override
protected TestConnectionResult doInBackground() throws Exception { protected Boolean doInBackground() throws Exception {
try { return WorkContext.getConnector().testConnection(connection);
return TestConnectionResult.parse(WorkContext.getConnector().testConnection(connection), connection);
} catch (WorkspaceAuthException ignored) {
return AUTH_FAILED;
} catch (RegistEditionException e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
throw e;
} catch (WorkspaceCheckException e) {
return TestConnectionResult.parseByException(e);
}
} }
@Override @Override
protected void done() { protected void done() {
okButton.setEnabled(true); okButton.setEnabled(true);
try { try {
TestConnectionResult result = get(); if (get()) {
if (result.isVerifyResult()) { message.setText(Toolkit.i18nText("Fine-Design_Basic_Remote_Connect_Successful"));
dialog.dispose(); uiLabel.setIcon(UIManager.getIcon("OptionPane.informationIcon"));
FineLoggerFactory.getLogger().error(result.getText().replaceAll(TestConnectionResult.WRAP, StringUtils.EMPTY) + Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Modify_PassWord"));
FineJOptionPane.showMessageDialog(RemoteEnvPane.this,
new MessageWithLink(result.getText(), Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Modify_PassWord"), connection.getUrl() + RemoteWorkspaceURL.SYSTEM_LOGIN_PATH),
Toolkit.i18nText("Fine-Design_Basic_Dialog_Message_Title"),
ERROR_MESSAGE,
UIManager.getIcon("OptionPane.errorIcon"));
} }
message.setText(result.getText());
uiLabel.setIcon(result.getIcon());
} catch (Exception e) { } catch (Exception e) {
FineLoggerFactory.getLogger().error(e, e.getMessage()); dialog.dispose();
message.setText(Toolkit.i18nText("Fine-Design_Basic_Remote_Connect_Failed")); RemoteDesignExceptionHandler.getInstance().handleInTest(e);
uiLabel.setIcon(UIManager.getIcon("OptionPane.errorIcon"));
} }
dialogDownPane.remove(cancelButton); dialogDownPane.remove(cancelButton);
dialogDownPane.revalidate(); dialogDownPane.revalidate();

16
designer-base/src/main/java/com/fr/env/handler/Handler.java vendored

@ -0,0 +1,16 @@
package com.fr.env.handler;
/**
* @author hades
* @version 10.0
* Created by hades on 2021/8/5
*/
public interface Handler<T, R> {
/**
* @param t
* @return 是否需要继续处理
*/
R handle(T t);
}

88
designer-base/src/main/java/com/fr/env/handler/RemoteDesignExceptionHandler.java vendored

@ -0,0 +1,88 @@
package com.fr.env.handler;
import com.fr.design.EnvChangeEntrance;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.env.DesignerWorkspaceInfo;
import com.fr.design.env.DesignerWorkspaceType;
import com.fr.design.i18n.Toolkit;
import com.fr.env.handler.impl.CancelHandler;
import com.fr.env.handler.impl.CommonHandler;
import com.fr.env.handler.impl.ExecutionHandler;
import com.fr.env.handler.impl.UnexpectedHandler;
import com.fr.log.FineLoggerFactory;
import java.util.ArrayList;
import java.util.List;
import javax.swing.UIManager;
import static javax.swing.JOptionPane.ERROR_MESSAGE;
/**
* @author hades
* @version 10.0
* Created by hades on 2021/8/5
*/
public class RemoteDesignExceptionHandler {
private static final RemoteDesignExceptionHandler INSTANCE = new RemoteDesignExceptionHandler();
public static RemoteDesignExceptionHandler getInstance() {
return INSTANCE;
}
private final List<Handler<Throwable, ResultWrapper>> testList = new ArrayList<>();
private final List<Handler<Throwable, ResultWrapper>> switchList = new ArrayList<>();
private RemoteDesignExceptionHandler() {
// 要保证顺序
testList.add(new CancelHandler());
testList.add(new ExecutionHandler());
testList.add(new UnexpectedHandler());
testList.add(new CommonHandler(false));
switchList.add(new CancelHandler());
switchList.add(new ExecutionHandler());
switchList.add(new UnexpectedHandler());
switchList.add(new CommonHandler(true));
}
public void handle(Throwable e, List<Handler<Throwable, ResultWrapper>> list) {
Throwable throwable = e;
ResultWrapper wrapper;
for (Handler<Throwable, ResultWrapper> handler : list) {
wrapper = handler.handle(throwable);
throwable = wrapper.getThrowable();
if (!wrapper.isNext()) {
break;
}
}
FineLoggerFactory.getLogger().error(throwable.getMessage(), throwable);
}
public void handleInSwitch(Throwable e, DesignerWorkspaceInfo workspaceInfo) {
if (workspaceInfo == null || workspaceInfo.getType() == DesignerWorkspaceType.Local) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
FineJOptionPane.showMessageDialog(EnvChangeEntrance.getInstance().getDialog(),
Toolkit.i18nText("Fine-Design_Basic_Switch_Workspace_Failed"),
Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"),
ERROR_MESSAGE,
UIManager.getIcon("OptionPane.errorIcon"));
return;
}
handle(e, switchList);
}
public void handleInStart(Throwable e, DesignerWorkspaceInfo workspaceInfo) {
if (workspaceInfo == null || workspaceInfo.getType() == DesignerWorkspaceType.Local) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
return;
}
handle(e, testList);
}
public void handleInTest(Throwable e) {
handle(e, testList);
}
}

30
designer-base/src/main/java/com/fr/env/handler/ResultWrapper.java vendored

@ -0,0 +1,30 @@
package com.fr.env.handler;
/**
* @author hades
* @version 10.0
* Created by hades on 2021/8/5
*/
public class ResultWrapper {
private final boolean next;
private final Throwable throwable;
public ResultWrapper(Throwable throwable) {
this(true, throwable);
}
public ResultWrapper(boolean next, Throwable e) {
this.next = next;
this.throwable = e;
}
public boolean isNext() {
return next;
}
public Throwable getThrowable() {
return throwable;
}
}

18
designer-base/src/main/java/com/fr/env/handler/impl/CancelHandler.java vendored

@ -0,0 +1,18 @@
package com.fr.env.handler.impl;
import com.fr.env.handler.Handler;
import com.fr.env.handler.ResultWrapper;
import java.util.concurrent.CancellationException;
/**
* @author hades
* @version 10.0
* Created by hades on 2021/8/5
*/
public class CancelHandler implements Handler<Throwable, ResultWrapper> {
@Override
public ResultWrapper handle(Throwable e) {
return new ResultWrapper(!(e instanceof CancellationException), e);
}
}

48
designer-base/src/main/java/com/fr/env/handler/impl/CommonHandler.java vendored

@ -0,0 +1,48 @@
package com.fr.env.handler.impl;
import com.fr.base.exception.ExceptionDescriptor;
import com.fr.design.EnvChangeEntrance;
import com.fr.design.dialog.UIDetailErrorLinkDialog;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.DesignerContext;
import com.fr.env.HelpLink;
import com.fr.env.handler.Handler;
import com.fr.env.handler.ResultWrapper;
import javax.swing.SwingUtilities;
/**
* @author hades
* @version 10.0
* Created by hades on 2021/8/5
*/
public class CommonHandler implements Handler<Throwable, ResultWrapper> {
private final boolean onSwitch;
public CommonHandler(boolean onSwitch) {
this.onSwitch = onSwitch;
}
@Override
public ResultWrapper handle(Throwable e) {
if (e instanceof ExceptionDescriptor) {
ExceptionDescriptor exceptionDescriptor = (ExceptionDescriptor) e;
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
UIDetailErrorLinkDialog detailErrorLinkDialog = UIDetailErrorLinkDialog.newBuilder().
setWindow(onSwitch ? DesignerContext.getDesignerFrame() : EnvChangeEntrance.getInstance().getDialog()).
setErrorCode(exceptionDescriptor.errorCode()).
setReason(exceptionDescriptor.reason()).
setSolution(exceptionDescriptor.solution()).
setDetailReason(exceptionDescriptor.detailReason()).
setTitle(Toolkit.i18nText("Fine-Design_Basic_Connection_Failed")).
setLink(HelpLink.getLink(exceptionDescriptor.solution())).
setThrowable(e).build();
detailErrorLinkDialog.setVisible(true);
}
});
}
return new ResultWrapper(e);
}
}

21
designer-base/src/main/java/com/fr/env/handler/impl/ExecutionHandler.java vendored

@ -0,0 +1,21 @@
package com.fr.env.handler.impl;
import com.fr.env.handler.Handler;
import com.fr.env.handler.ResultWrapper;
import java.util.concurrent.ExecutionException;
/**
* @author hades
* @version 10.0
* Created by hades on 2021/8/5
*/
public class ExecutionHandler implements Handler<Throwable, ResultWrapper> {
@Override
public ResultWrapper handle(Throwable e) {
if (e instanceof ExecutionException) {
return new ResultWrapper(e.getCause());
}
return new ResultWrapper(e.getCause());
}
}

24
designer-base/src/main/java/com/fr/env/handler/impl/UnexpectedHandler.java vendored

@ -0,0 +1,24 @@
package com.fr.env.handler.impl;
import com.fr.base.exception.ExceptionDescriptor;
import com.fr.env.handler.Handler;
import com.fr.env.handler.ResultWrapper;
import com.fr.workspace.engine.convert.ExceptionConverter;
/**
* 出现预料之外的情况异常处理器
*
* @author hades
* @version 10.0
* Created by hades on 2021/8/5
*/
public class UnexpectedHandler implements Handler<Throwable, ResultWrapper> {
@Override
public ResultWrapper handle(Throwable e) {
if (!(e instanceof ExceptionDescriptor)) {
return new ResultWrapper(ExceptionConverter.getInstance().convert(e)) ;
}
return new ResultWrapper(e);
}
}

21
designer-base/src/test/java/com/fr/design/env/RemoteDesignerWorkspaceInfoTest.java vendored

@ -4,7 +4,10 @@ import com.fr.invoke.Reflect;
import com.fr.stable.xml.XMLPrintWriter; import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLReaderHelper; import com.fr.stable.xml.XMLReaderHelper;
import com.fr.stable.xml.XMLableReader; import com.fr.stable.xml.XMLableReader;
import com.fr.workspace.WorkContext;
import com.fr.workspace.connect.WorkspaceClient;
import com.fr.workspace.connect.WorkspaceConnectionInfo; import com.fr.workspace.connect.WorkspaceConnectionInfo;
import com.fr.workspace.connect.WorkspaceConnector;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.junit.Assert; import org.junit.Assert;
@ -18,15 +21,31 @@ import java.io.ByteArrayOutputStream;
*/ */
public class RemoteDesignerWorkspaceInfoTest extends TestCase { public class RemoteDesignerWorkspaceInfoTest extends TestCase {
public void testCheckValid() { public void testCheckValid() throws Exception {
RemoteDesignerWorkspaceInfo workspaceInfo0 = RemoteDesignerWorkspaceInfo.create(new WorkspaceConnectionInfo("http://localhost:8075/webroot/decision", "admin", "123", "", "", true)); RemoteDesignerWorkspaceInfo workspaceInfo0 = RemoteDesignerWorkspaceInfo.create(new WorkspaceConnectionInfo("http://localhost:8075/webroot/decision", "admin", "123", "", "", true));
RemoteDesignerWorkspaceInfo workspaceInfo1 = RemoteDesignerWorkspaceInfo.create(new WorkspaceConnectionInfo("http://127.0.0.1:8075/webroot/decision", "admin", "123", "", "", true)); RemoteDesignerWorkspaceInfo workspaceInfo1 = RemoteDesignerWorkspaceInfo.create(new WorkspaceConnectionInfo("http://127.0.0.1:8075/webroot/decision", "admin", "123", "", "", true));
RemoteDesignerWorkspaceInfo workspaceInfo2 = RemoteDesignerWorkspaceInfo.create(new WorkspaceConnectionInfo("https://127.0.0.1:8075/webroot/decision", "admin", "123", "", "", true)); RemoteDesignerWorkspaceInfo workspaceInfo2 = RemoteDesignerWorkspaceInfo.create(new WorkspaceConnectionInfo("https://127.0.0.1:8075/webroot/decision", "admin", "123", "", "", true));
RemoteDesignerWorkspaceInfo workspaceInfo3 = RemoteDesignerWorkspaceInfo.create(new WorkspaceConnectionInfo("https://localhost:8075/webroot/decision", "admin", "123", "", "", true)); RemoteDesignerWorkspaceInfo workspaceInfo3 = RemoteDesignerWorkspaceInfo.create(new WorkspaceConnectionInfo("https://localhost:8075/webroot/decision", "admin", "123", "", "", true));
WorkspaceConnector connector = WorkContext.getConnector();
WorkspaceConnector workspaceConnector = new WorkspaceConnector() {
@Override
public boolean testConnection(WorkspaceConnectionInfo connection) throws Exception {
return false;
}
@Override
public WorkspaceClient connect(WorkspaceConnectionInfo connection) throws Exception {
return null;
}
};
WorkContext.setConnector(workspaceConnector);
Assert.assertFalse(workspaceInfo0.checkValid()); Assert.assertFalse(workspaceInfo0.checkValid());
Assert.assertFalse(workspaceInfo1.checkValid()); Assert.assertFalse(workspaceInfo1.checkValid());
Assert.assertFalse(workspaceInfo2.checkValid()); Assert.assertFalse(workspaceInfo2.checkValid());
Assert.assertFalse(workspaceInfo3.checkValid()); Assert.assertFalse(workspaceInfo3.checkValid());
WorkContext.setConnector(connector);
} }
public void testReadXml() { public void testReadXml() {

14
designer-realize/src/main/java/com/fr/start/module/DesignerWorkspaceProvider.java

@ -8,9 +8,8 @@ import com.fr.design.editlock.ServerTableDataLockChangeChecker;
import com.fr.design.env.DesignerWorkspaceGenerator; import com.fr.design.env.DesignerWorkspaceGenerator;
import com.fr.design.env.DesignerWorkspaceInfo; import com.fr.design.env.DesignerWorkspaceInfo;
import com.fr.design.env.LocalDesignerWorkspaceInfo; import com.fr.design.env.LocalDesignerWorkspaceInfo;
import com.fr.design.i18n.Toolkit;
import com.fr.design.versioncheck.VersionCheckUtils; import com.fr.design.versioncheck.VersionCheckUtils;
import com.fr.env.TestConnectionResult; import com.fr.env.handler.RemoteDesignExceptionHandler;
import com.fr.event.Event; import com.fr.event.Event;
import com.fr.event.EventDispatcher; import com.fr.event.EventDispatcher;
import com.fr.event.Listener; import com.fr.event.Listener;
@ -21,7 +20,6 @@ import com.fr.stable.StringUtils;
import com.fr.value.NotNullLazyValue; import com.fr.value.NotNullLazyValue;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import com.fr.workspace.Workspace; import com.fr.workspace.Workspace;
import com.fr.workspace.engine.exception.WorkspaceCheckException;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -78,15 +76,7 @@ public class DesignerWorkspaceProvider extends Activator {
}); });
} }
} catch (Throwable e) { } catch (Throwable e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e); RemoteDesignExceptionHandler.getInstance().handleInStart(e, workspaceInfo);
if (e.getCause() instanceof WorkspaceCheckException) {
WorkspaceCheckException exception = (WorkspaceCheckException) e.getCause();
// 输出标准详情
TestConnectionResult result = TestConnectionResult.parseByException(exception);
if (result.isVerifyResult()) {
FineLoggerFactory.getLogger().error(result.getText().replaceAll(TestConnectionResult.WRAP, StringUtils.EMPTY) + Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Modify_PassWord"));
}
}
EnvChangeEntrance.getInstance().dealEvnExceptionWhenStartDesigner(); EnvChangeEntrance.getInstance().dealEvnExceptionWhenStartDesigner();
} }
} }

Loading…
Cancel
Save