From d38aa7607be273eb241bff1ddc5bc6447aa15c94 Mon Sep 17 00:00:00 2001 From: Harrison Date: Thu, 16 Nov 2023 15:07:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20REPORT-106669=20=E6=8A=A5=E8=A1=A8?= =?UTF-8?q?=E5=9F=8B=E7=82=B9=E8=A1=A5=E5=85=85=20-=20=E5=B0=86=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E6=93=8D=E4=BD=9C=E5=8C=85=E4=B8=8A=E4=B8=80=E5=B1=82?= =?UTF-8?q?=EF=BC=8C=E7=84=B6=E5=90=8E=E5=9C=A8=E5=A4=96=E5=B1=82=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E8=AE=B0=E5=BD=95=E5=92=8C=E8=A7=A6=E5=8F=91=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E3=80=82=E4=B8=8D=E7=84=B6=E6=8F=92=E4=BB=B6=E6=9C=89?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E8=AE=B0=E5=BD=95=E4=B8=8D=E5=88=B0=E5=9F=8B?= =?UTF-8?q?=E7=82=B9=E4=BF=A1=E6=81=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/EnvChangeEntrance.java | 109 +++++++++++++----- 1 file changed, 79 insertions(+), 30 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 090a0bd639..91b23007ef 100644 --- a/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java +++ b/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java @@ -127,53 +127,105 @@ public class EnvChangeEntrance { } } + /** * 切换到新环境 * * @param envName 新工作环境名称 + * @param strategy 提示策略 * @return 是否成功 */ private boolean switch2Env(final String envName, PopTipStrategy strategy) { PerformancePoint performancePoint = PerformancePoint.create(); + boolean switchStatus = doSwitch2Env(envName, strategy); + // 记录切换耗时 + recordSwitchElapsed(performancePoint); + // 触发切换埋点 + triggerSwitchMetric(switchStatus); + return switchStatus; + } - DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); - DesignerWorkspaceInfo selectedEnv = customUserName(envManager.getWorkspaceInfo(envName)); - DesignerWorkspaceInfoContext.setWorkspaceInfo(selectedEnv); - WorkspaceConnectionInfo connectionInfo = selectedEnv.getConnection(); + /** + * 由云端运维,触发切换埋点 + * 内部空实现 + * + * @param switchStatus 切换状态 + */ + private void triggerSwitchMetric(boolean switchStatus) { + } + /** + * 切换到新环境 + * 1. 先获取选中的环境 + * 2. 生成工作目录 + * 3. 验证工作目录 + * 4. 触发切换操作 + * 5. 触发可能存在异常的切换后动作 + * 6. 触发切换后动作 + * + * @param envName 新工作环境名称 + * @return 是否成功 + */ + private boolean doSwitch2Env(final String envName, PopTipStrategy strategy) { + + DesignerWorkspaceInfo selectedEnv = getSelectedEnv(envName); try { Workspace workspace = DesignerWorkspaceGenerator.generate(selectedEnv); - boolean checkValid = workspace != null && selectedEnv.checkValid(); - if (!checkValid) { + if (notValid(workspace, selectedEnv)) { return false; } - //如果是相同环境 - if (isSameEnv(workspace)) { - //目前切换到相同环境需要更新一下名字,后续如果有别的操作直接往里面加就行了 - switch2SameEnv(envName); - } else { - //切换到新环境,做下封装 - switch2OtherEnv(workspace, envName); - } - // REPORT-25688如果是war包部署的服务器,给与提示 - if (WorkContext.getCurrent().isWarDeploy()) { - FineJOptionPane.showMessageDialog(null, Toolkit.i18nText("Fine-Design_Basic_War_Deploy_Tip"), - Toolkit.i18nText("Fine-Design_Basic_Message"), JOptionPane.INFORMATION_MESSAGE); - } - //REPORT-13810如果只是添加了工作目录,没有切换,这里ToolArea也是要显示新建的工作目录 - JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); - if (JTemplate.isValid(template)) { - template.refreshToolArea(); - } - PluginErrorDesignReminder.getInstance().remindStartFailedPlugins(); + doSwitchAction(envName, workspace); + afterSwitchWithEx(); } catch (Exception exception) { // 失败的处理 WorkspaceExceptionHandler.getInstance().handleInSwitch(exception, selectedEnv); - // 记录切换耗时 - recordSwitchElapsed(performancePoint); return false; } + afterSwitch(); + return true; + } + + private DesignerWorkspaceInfo getSelectedEnv(String envName) { + + DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); + DesignerWorkspaceInfo selectedEnv = customUserName(envManager.getWorkspaceInfo(envName)); + DesignerWorkspaceInfoContext.setWorkspaceInfo(selectedEnv); + return selectedEnv; + } + + private static boolean notValid(Workspace workspace, DesignerWorkspaceInfo selectedEnv) throws Exception { + boolean checkValid = workspace != null && selectedEnv.checkValid(); + return !checkValid; + } + + private void doSwitchAction(String envName, Workspace workspace) { + + //如果是相同环境 + if (isSameEnv(workspace)) { + //目前切换到相同环境需要更新一下名字,后续如果有别的操作直接往里面加就行了 + switch2SameEnv(envName); + } else { + //切换到新环境,做下封装 + switch2OtherEnv(workspace, envName); + } + } + + private static void afterSwitchWithEx() { + // REPORT-25688如果是war包部署的服务器,给与提示 + if (WorkContext.getCurrent().isWarDeploy()) { + FineJOptionPane.showMessageDialog(null, Toolkit.i18nText("Fine-Design_Basic_War_Deploy_Tip"), + Toolkit.i18nText("Fine-Design_Basic_Message"), JOptionPane.INFORMATION_MESSAGE); + } + //REPORT-13810如果只是添加了工作目录,没有切换,这里ToolArea也是要显示新建的工作目录 + JTemplate template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + if (JTemplate.isValid(template)) { + template.refreshToolArea(); + } + PluginErrorDesignReminder.getInstance().remindStartFailedPlugins(); + } + + private static void afterSwitch() { TemplateTreePane.getInstance().refreshDockingView(); DesignModelAdapter model = DesignModelAdapter.getCurrentModelAdapter(); if (model != null) { @@ -182,9 +234,6 @@ public class EnvChangeEntrance { NotificationCenter.getInstance().clearAllNotifications(); //切换环境后,清空粘贴板里面的内容 TemplateTreeClipboard.getInstance().reset(); - // 记录切换耗时 - recordSwitchElapsed(performancePoint); - return true; } private static void recordSwitchElapsed(PerformancePoint performancePoint) {