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 0a464aa6d9..1aa6008fe3 100644 --- a/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java +++ b/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java @@ -101,6 +101,29 @@ public class EnvChangeEntrance { } } + /** + * 插件进行用户名转换 + * + * @param workspaceInfo 环境信息 + */ + private DesignerWorkspaceInfo customUserName(DesignerWorkspaceInfo workspaceInfo) { + //本地环境直接返回 + if (workspaceInfo == null || workspaceInfo.getType() == DesignerWorkspaceType.Local) { + return workspaceInfo; + } + RemoteDesignerWorkspaceInfo.RemoteDesignerWorkspaceInfoProcessor processor = ExtraDesignClassManager.getInstance().getSingle(RemoteDesignerWorkspaceInfo.RemoteDesignerWorkspaceInfoProcessor.XML_TAG); + if (processor == null) { + return workspaceInfo; + } + try { + WorkspaceConnectionInfo workspaceConnectionInfo = processor.customUserName(workspaceInfo.getConnection()); + return (RemoteDesignerWorkspaceInfo) ((RemoteDesignerWorkspaceInfo) workspaceInfo).cloneWithConnectionInfo(workspaceConnectionInfo); + } catch (Exception e) { + FineLoggerFactory.getLogger().error(e.getMessage(), e); + return workspaceInfo; + } + } + /** * 切换到新环境 * @@ -109,7 +132,7 @@ public class EnvChangeEntrance { */ private boolean switch2Env(final String envName, PopTipStrategy strategy) { DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); - DesignerWorkspaceInfo selectedEnv = envManager.getWorkspaceInfo(envName); + DesignerWorkspaceInfo selectedEnv = customUserName(envManager.getWorkspaceInfo(envName)); DesignerWorkspaceInfoContext.setWorkspaceInfo(selectedEnv); WorkspaceConnectionInfo connectionInfo = selectedEnv.getConnection(); diff --git a/designer-base/src/main/java/com/fr/design/env/RemoteDesignerWorkspaceInfo.java b/designer-base/src/main/java/com/fr/design/env/RemoteDesignerWorkspaceInfo.java index 920a13dbfb..9041b1075a 100644 --- a/designer-base/src/main/java/com/fr/design/env/RemoteDesignerWorkspaceInfo.java +++ b/designer-base/src/main/java/com/fr/design/env/RemoteDesignerWorkspaceInfo.java @@ -6,6 +6,7 @@ import com.fr.log.FineLoggerFactory; import com.fr.security.SecurityToolbox; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; +import com.fr.stable.fun.mark.Immutable; import com.fr.stable.project.ProjectConstants; import com.fr.stable.xml.XMLPrintWriter; import com.fr.stable.xml.XMLableReader; @@ -166,6 +167,15 @@ public class RemoteDesignerWorkspaceInfo implements DesignerWorkspaceInfo { return object; } + /** + * clone一个自定义连接信息的RemoteDesignerWorkspaceInfo + */ + public Object cloneWithConnectionInfo(WorkspaceConnectionInfo workspaceConnectionInfo) throws CloneNotSupportedException { + RemoteDesignerWorkspaceInfo object = (RemoteDesignerWorkspaceInfo) super.clone(); + object.connection = workspaceConnectionInfo; + return object; + } + @Override public boolean checkValid() throws Exception { @@ -181,4 +191,24 @@ public class RemoteDesignerWorkspaceInfo implements DesignerWorkspaceInfo { WorkContext.getConnector().validateVT(connection); return true; } + + /** + * 远程设计自定义用户名接口 + * + * @author John.Ying + * @version 11.0 + * Created by John.Ying on 2023/5/17 + */ + public interface RemoteDesignerWorkspaceInfoProcessor extends Immutable { + + String XML_TAG = "RemoteDesignerWorkspaceInfoProcessor"; + + int CURRENT_LEVEL = 1; + + /** + * 返回一个新的自定义连接信息 + */ + WorkspaceConnectionInfo customUserName(WorkspaceConnectionInfo workspaceInfo); + + } } 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 31bdaa979b..cc721d5e12 100644 --- a/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java +++ b/designer-base/src/main/java/com/fr/env/RemoteEnvPane.java @@ -579,8 +579,14 @@ public class RemoteEnvPane extends BasicBeanPane { private void tryConnectRemoteEnv() { final RemoteDesignerWorkspaceInfo remoteEnv = updateBean(); - final WorkspaceConnectionInfo connection = remoteEnv.getConnection(); - + WorkspaceConnectionInfo originalConnection = remoteEnv.getConnection(); + final WorkspaceConnectionInfo connection; + RemoteDesignerWorkspaceInfo.RemoteDesignerWorkspaceInfoProcessor processor = ExtraDesignClassManager.getInstance().getSingle(RemoteDesignerWorkspaceInfo.RemoteDesignerWorkspaceInfoProcessor.XML_TAG); + if (processor != null) { + connection = processor.customUserName(originalConnection); + } else { + connection = remoteEnv.getConnection(); + } final SwingWorker worker = new SwingWorker() { @Override