From 8b153a0fbbc94a37910228fe7aa010510490bb4f Mon Sep 17 00:00:00 2001 From: richie Date: Fri, 8 Jun 2018 10:02:17 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=97=A0JIRA=E4=BB=BB=E5=8A=A1=20=E8=BF=9C?= =?UTF-8?q?=E7=A8=8B=E8=AE=BE=E8=AE=A1=E7=99=BB=E5=BD=95=E7=99=BB=E5=87=BA?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=88=E9=83=A8=E5=88=86=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/fr/design/DesignerEnvManager.java | 193 ++++-------------- .../design/actions/file/SwitchExistEnv.java | 11 +- .../src/com/fr/design/env/EnvGenerator.java | 22 ++ .../com/fr/design/env/RemoteEnvConfig.java | 124 +++++++++++ .../fr/design/mainframe/DesignerFrame.java | 17 +- .../com/fr/design/mainframe/TemplatePane.java | 5 +- .../loghandler/socketio/DesignerSocketIO.java | 14 +- .../src/com/fr/design/utils/DesignUtils.java | 22 +- designer-base/src/com/fr/env/EnvListPane.java | 4 +- .../src/com/fr/env/LocalEnvPane.java | 2 +- designer-base/src/com/fr/env/RemoteEnv.java | 18 +- .../src/com/fr/env/RemoteEnvPane.java | 8 +- .../src/com/fr/env/RemoteEnvPane2.java | 88 +++++--- designer-base/src/com/fr/env/SignIn.java | 9 +- .../src/com/fr/start/ServerStarter.java | 6 +- .../src/com/fr/start/EnvSwitcher.java | 12 +- .../fr/start/module/DesignerEnvProvider.java | 18 +- 17 files changed, 319 insertions(+), 254 deletions(-) create mode 100644 designer-base/src/com/fr/design/env/EnvGenerator.java create mode 100644 designer-base/src/com/fr/design/env/RemoteEnvConfig.java diff --git a/designer-base/src/com/fr/design/DesignerEnvManager.java b/designer-base/src/com/fr/design/DesignerEnvManager.java index 6517e705e2..956871424d 100644 --- a/designer-base/src/com/fr/design/DesignerEnvManager.java +++ b/designer-base/src/com/fr/design/DesignerEnvManager.java @@ -6,19 +6,19 @@ package com.fr.design; import com.fr.base.BaseXMLUtils; import com.fr.base.FRContext; import com.fr.base.Utils; +import com.fr.base.env.EnvUpdater; import com.fr.core.env.EnvConfig; -import com.fr.core.env.resource.EnvConfigUtils; -import com.fr.core.env.resource.LocalEnvConfig; -import com.fr.core.env.resource.RemoteEnvConfig; +import com.fr.core.env.impl.LocalEnvConfig; import com.fr.design.actions.help.alphafine.AlphaFineConfigManager; import com.fr.design.constants.UIConstants; -import com.fr.env.SignIn; +import com.fr.design.env.EnvGenerator; import com.fr.file.FILEFactory; import com.fr.general.ComparatorUtils; import com.fr.general.FRLogFormatter; import com.fr.general.GeneralContext; import com.fr.general.IOUtils; import com.fr.general.Inter; +import com.fr.general.xml.GeneralXMLTools; import com.fr.log.FineLoggerFactory; import com.fr.stable.Constants; import com.fr.stable.EnvChangedListener; @@ -73,7 +73,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { private boolean showPaintToolBar = true; private int maxNumberOrPreviewRow = 200; // name和Env的键值对 - private Map nameEnvMap = new ListMap(); + private Map nameEnvMap = new ListMap<>(); // marks: 当前报表服务器名字 private String curEnvName = null; private boolean showProjectPane = true; @@ -526,11 +526,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { if (isCurrentEnvDefault()) { return; } - try { - SignIn.signIn(getDefaultEnv()); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); - } + EnvUpdater.updateEnv(EnvGenerator.generate(getDefaultEnv())); } /** @@ -1311,8 +1307,8 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { this.readReportPaneAttributions(reader); } else if ("RecentOpenedFilePathList".equals(name) || "ResentOpenedFilePathList".equals(name)) { this.readRecentOpenFileList(reader); - } else if ("Envs".equals(name) || name.equals("ReportServerMap")) { - this.readCurEnv(reader); + } else if ("EnvConfigMap".equals(name)) { + this.readEnvConfigMap(reader); } else if (name.equals("ActivationKey")) { readActiveKey(reader); } else if ("LogLocation".equals(name)) { @@ -1457,32 +1453,30 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { } } - private void readCurEnv(XMLableReader reader) { - String tmpVal; - // marks:设置默认的webInf名字 - if ((tmpVal = reader.getAttrAsString("currentEnv", null)) != null) { - this.setCurEnvName(tmpVal); - } - + private void readEnvConfigMap(XMLableReader reader) { + String currentEnv = reader.getAttrAsString("currentEnv", StringUtils.EMPTY); + this.setCurEnvName(currentEnv); reader.readXMLObject(new XMLReadable() { - @Override public void readXML(XMLableReader reader) { if (reader.isAttr()) { - DesignerEnvManager.this.clearAllEnv(); - } - - if (reader.isChildNode()) { - if (reader.getTagName().contains("Env")) { // description. - // marks:获取名字 - String reportServerName = reader.getAttrAsString("name", null); - - EnvConfig env = readEnv(reader); - if (env == null) { - return; - } - - DesignerEnvManager.this.putEnv(reportServerName, env); + clearAllEnv(); + } else if (reader.isChildNode()) { + String tagName = reader.getTagName(); + if ("EnvConfigElement".equals(tagName)) { + final String name = reader.getAttrAsString("name", StringUtils.EMPTY); + reader.readXMLObject(new XMLReadable() { + @Override + public void readXML(XMLableReader reader) { + if (reader.isChildNode()) { + String tagName = reader.getTagName(); + if (EnvConfig.XML_TAG.equals(tagName)) { + EnvConfig envConfig = (EnvConfig) GeneralXMLTools.readXMLable(reader); + putEnv(name, envConfig); + } + } + } + }); } } } @@ -1524,7 +1518,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { public void writeXML(XMLPrintWriter writer) { writer.startTAG("Designer"); - writeAttrues(writer); + writeAttributes(writer); writeReportPaneAttributions(writer); writeRecentOpenFileAndEnvList(writer); writeSomeAttr(writer); @@ -1596,22 +1590,20 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { } writer.end(); - writer.startTAG("Envs"); + writer.startTAG("EnvConfigMap"); if (this.curEnvName != null) { writer.attr("currentEnv", this.curEnvName); } - Iterator nameIt = this.getEnvNameIterator(); - while (nameIt.hasNext()) { - String envName = nameIt.next(); - EnvConfig env = this.getEnv(envName); - - writeEnv(writer, envName, env); + for (Entry entry : nameEnvMap.entrySet()) { + writer.startTAG("EnvConfigElement").attr("name", entry.getKey()); + EnvConfig envConfig = entry.getValue(); + GeneralXMLTools.writeXMLable(writer, envConfig, EnvConfig.XML_TAG); + writer.end(); } - writer.end(); } - private void writeAttrues(XMLPrintWriter writer) { + private void writeAttributes(XMLPrintWriter writer) { writer.startTAG("Attributes"); if (this.getWindowBounds() != null) { writer.attr("windowBounds", BaseXMLUtils.getRectangleText(this.getWindowBounds())); @@ -1767,46 +1759,6 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { .end(); } - /* - * 写Env为xml - */ - private static void writeEnv(XMLPrintWriter writer, String name, EnvConfig env) { - if (env == null) { - return; - } - - writer.startTAG("EnvConfig"); - writer.classAttr(env.getClass()); - writer.attr("name", name); - - EnvConfigXMLAdapter xmlAdapter = env instanceof RemoteEnvConfig - ? new RemoteEnvConfigXMLAdapter() - : new LocalEnvConfigXMLAdapter(); - xmlAdapter.fromEnvConfig(env).writeXML(writer); - writer.end(); - } - - /* - * 从xml读Env - */ - private static EnvConfig readEnv(XMLableReader reader) { - EnvConfigXMLAdapter xmlAdapter = null; - String tmpVal; //temp value - if ((tmpVal = reader.getAttrAsString("class", null)) != null) { - if (tmpVal.contains(".LocalEnv")) { - xmlAdapter = new LocalEnvConfigXMLAdapter(); - } else if (tmpVal.contains(".RemoteEnv")) { - xmlAdapter = new RemoteEnvConfigXMLAdapter(); - } - } - - if (xmlAdapter == null) { - return null; - } - - reader.readXMLObject(xmlAdapter); - return xmlAdapter.toEnvConfig(); - } public AlphaFineConfigManager getAlphaFineConfigManager() { return alphaFineConfigManager; @@ -1816,79 +1768,6 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter { this.alphaFineConfigManager = alphaFineConfigManager; } - private interface EnvConfigXMLAdapter extends XMLReadable, XMLWriter { - EnvConfig toEnvConfig(); - - EnvConfigXMLAdapter fromEnvConfig(EnvConfig envConfig); - } - - private static class LocalEnvConfigXMLAdapter implements EnvConfigXMLAdapter { - private String path; - - public void readXML(XMLableReader reader) { - if (reader.isChildNode()) { - if ("DIR".equals(reader.getTagName())) { - this.path = reader.getElementValue(); - } - } - } - - public void writeXML(XMLPrintWriter writer) { - writer.startTAG("DIR").textNode(this.path).end(); - } - - public EnvConfig toEnvConfig() { - return new LocalEnvConfig(path); - } - - public EnvConfigXMLAdapter fromEnvConfig(EnvConfig envConfig) { - this.path = envConfig.getPath(); - return this; - } - - } - - private static class RemoteEnvConfigXMLAdapter implements EnvConfigXMLAdapter { - private String path; - private String username; - private String password; - - public void readXML(XMLableReader reader) { - if (reader.isChildNode()) { - String tmpVal; - if ("DIR".equals(reader.getTagName())) { - if ((tmpVal = reader.getAttrAsString("path", null)) != null) { - this.path = tmpVal; - } - if ((tmpVal = reader.getAttrAsString("user", null)) != null) { - this.username = tmpVal; - } - if ((tmpVal = reader.getAttrAsString("password", null)) != null) { - this.password = tmpVal; - } - } - } - } - - public void writeXML(XMLPrintWriter writer) { - writer.startTAG("DIR") - .attr("path", this.path) - .attr("user", this.username) - .attr("password", this.password) - .end(); - } - - public EnvConfig toEnvConfig() { - return new RemoteEnvConfig(path, username, password); - } - - public EnvConfigXMLAdapter fromEnvConfig(EnvConfig envConfig) { - this.path = envConfig.getPath(); - this.username = EnvConfigUtils.getUsername(envConfig); - this.password = EnvConfigUtils.getPassword(envConfig); - return this; - } - } public boolean isImageCompress() { return imageCompress; } diff --git a/designer-base/src/com/fr/design/actions/file/SwitchExistEnv.java b/designer-base/src/com/fr/design/actions/file/SwitchExistEnv.java index 838fce4e00..decc72daac 100644 --- a/designer-base/src/com/fr/design/actions/file/SwitchExistEnv.java +++ b/designer-base/src/com/fr/design/actions/file/SwitchExistEnv.java @@ -1,13 +1,15 @@ package com.fr.design.actions.file; import com.fr.base.BaseUtils; +import com.fr.base.env.EnvUpdater; import com.fr.core.env.EnvConfig; -import com.fr.core.env.resource.LocalEnvConfig; -import com.fr.core.env.resource.RemoteEnvConfig; +import com.fr.core.env.impl.LocalEnvConfig; import com.fr.design.DesignerEnvManager; import com.fr.design.actions.UpdateAction; import com.fr.design.data.DesignTableDataManager; import com.fr.design.data.tabledata.ResponseDataSourceChange; +import com.fr.design.env.EnvGenerator; +import com.fr.design.env.RemoteEnvConfig; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.JTemplate; @@ -16,13 +18,12 @@ import com.fr.design.menu.KeySetUtils; import com.fr.design.menu.MenuDef; import com.fr.design.menu.SeparatorDef; import com.fr.env.RemoteEnv; -import com.fr.env.SignIn; import com.fr.general.GeneralContext; import com.fr.general.Inter; import com.fr.log.FineLoggerFactory; import com.fr.stable.EnvChangedListener; -import javax.swing.JOptionPane; +import javax.swing.*; import java.awt.event.ActionEvent; import java.util.HashMap; import java.util.Iterator; @@ -105,7 +106,7 @@ public class SwitchExistEnv extends MenuDef { Inter.getLocText(new String[]{"M-SwitchWorkspace", "Failed"})); return; } - SignIn.signIn(selectedEnv); + EnvUpdater.updateEnv(EnvGenerator.generate(selectedEnv)); HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().refreshToolArea(); fireDSChanged(); } catch (Exception em) { diff --git a/designer-base/src/com/fr/design/env/EnvGenerator.java b/designer-base/src/com/fr/design/env/EnvGenerator.java new file mode 100644 index 0000000000..c56ab92956 --- /dev/null +++ b/designer-base/src/com/fr/design/env/EnvGenerator.java @@ -0,0 +1,22 @@ +package com.fr.design.env; + +import com.fr.base.Env; +import com.fr.core.env.EnvConfig; +import com.fr.core.env.impl.LocalEnvConfig; +import com.fr.dav.LocalEnv; +import com.fr.env.RemoteEnv; + +/** + * 根据配置生成运行环境 + */ +public class EnvGenerator { + public static Env generate(EnvConfig config) { + Env env = null; + if (config instanceof LocalEnvConfig) { + env = new LocalEnv((LocalEnvConfig)config); + } else if (config instanceof RemoteEnvConfig) { + env = new RemoteEnv((RemoteEnvConfig) config); + } + return env; + } +} diff --git a/designer-base/src/com/fr/design/env/RemoteEnvConfig.java b/designer-base/src/com/fr/design/env/RemoteEnvConfig.java new file mode 100644 index 0000000000..bb5f0ba107 --- /dev/null +++ b/designer-base/src/com/fr/design/env/RemoteEnvConfig.java @@ -0,0 +1,124 @@ +package com.fr.design.env; + +import com.fr.core.env.impl.AbstractEnvConfig; +import com.fr.general.Inter; +import com.fr.security.SecurityToolbox; +import com.fr.stable.AssistUtils; +import com.fr.stable.StableUtils; +import com.fr.stable.StringUtils; +import com.fr.stable.xml.XMLPrintWriter; +import com.fr.stable.xml.XMLableReader; + + +public class RemoteEnvConfig extends AbstractEnvConfig { + + public static final int DEFAULT_RPC_PORT = 39999; + + private String host; + private int port; + private String username; + private String password; + + public RemoteEnvConfig() { + + } + + public RemoteEnvConfig(String host, int port, String username, String password) { + this.host = host; + this.port = port; + this.username = username; + this.password = password; + } + + @Override + public String getPath() { + return StableUtils.join(new Object[]{host, port}, ":"); + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + @Override + public String getDescription(String name) { + return username + "@" + name + "[" + Inter.getLocText("") + "]"; + } + + @Override + public void readXML(XMLableReader reader) { + super.readXML(reader); + if (reader.isChildNode()) { + String tagName = reader.getTagName(); + if ("Attr".equals(tagName)) { + this.host = reader.getAttrAsString("host", StringUtils.EMPTY); + this.port = reader.getAttrAsInt("port", DEFAULT_RPC_PORT); + this.username = reader.getAttrAsString("username", StringUtils.EMPTY); + this.password = SecurityToolbox.decrypt(reader.getAttrAsString("password", StringUtils.EMPTY)); + } + } + } + + @Override + public void writeXML(XMLPrintWriter writer) { + super.writeXML(writer); + writer.startTAG("Attr") + .attr("host", host) + .attr("port", port) + .attr("username", username) + .attr("password", SecurityToolbox.encrypt(password)) + .end(); + + } + + @Override + public boolean equals(Object o) { + return o instanceof RemoteEnvConfig + && AssistUtils.equals(((RemoteEnvConfig) o).host, host) + && AssistUtils.equals(((RemoteEnvConfig) o).port, port) + && AssistUtils.equals(((RemoteEnvConfig) o).username, username) + && AssistUtils.equals(((RemoteEnvConfig) o).password, password); + } + + @Override + public int hashCode() { + return AssistUtils.hashCode(host, port, username, password); + } + + @Override + public Object clone() throws CloneNotSupportedException { + RemoteEnvConfig cloned = (RemoteEnvConfig) super.clone(); + cloned.host = host; + cloned.port = port; + cloned.username = username; + cloned.password = password; + return cloned; + } +} diff --git a/designer-base/src/com/fr/design/mainframe/DesignerFrame.java b/designer-base/src/com/fr/design/mainframe/DesignerFrame.java index 628bf85710..706ae7575b 100644 --- a/designer-base/src/com/fr/design/mainframe/DesignerFrame.java +++ b/designer-base/src/com/fr/design/mainframe/DesignerFrame.java @@ -4,11 +4,9 @@ package com.fr.design.mainframe; import com.fr.base.BaseUtils; -import com.fr.base.Env; import com.fr.base.FRContext; +import com.fr.base.env.EnvUpdater; import com.fr.core.env.EnvConfig; -import com.fr.core.env.EnvContext; -import com.fr.core.env.resource.EnvConfigUtils; import com.fr.design.DesignModelAdapter; import com.fr.design.DesignState; import com.fr.design.DesignerEnvManager; @@ -37,15 +35,14 @@ import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus; import com.fr.design.menu.MenuManager; import com.fr.design.utils.DesignUtils; import com.fr.design.utils.gui.GUICoreUtils; -import com.fr.event.EventDispatcher; import com.fr.file.FILE; import com.fr.file.FILEFactory; import com.fr.file.FileFILE; import com.fr.file.FileNodeFILE; import com.fr.general.ComparatorUtils; -import com.fr.log.FineLoggerFactory; import com.fr.general.GeneralContext; import com.fr.general.Inter; +import com.fr.log.FineLoggerFactory; import com.fr.plugin.context.PluginContext; import com.fr.plugin.injectable.PluginModule; import com.fr.plugin.manage.PluginFilter; @@ -84,9 +81,6 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import static com.fr.core.env.EnvEvent.AFTER_SIGN_OUT; -import static com.fr.core.env.EnvEvent.BEFORE_SIGN_OUT; - public class DesignerFrame extends JFrame implements JTemplateActionListener, TargetModifiedListener { public static final String DESIGNER_FRAME_NAME = "designer_frame"; public static final Dimension MIN_SIZE = new Dimension(100, 100); @@ -648,13 +642,12 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta defaultTitleSB.append(ProductConstants.PRODUCT_NAME); defaultTitleSB.append(" "); defaultTitleSB.append(ProductConstants.BRANCH); + defaultTitleSB.append(" "); // james:标识登录的用户和登录的ENV String envName = DesignerEnvManager.getEnvManager().getCurEnvName(); EnvConfig env = DesignerEnvManager.getEnvManager().getEnv(envName); if (env != null) { - defaultTitleSB.append(EnvConfigUtils.getUsername(env)).append('@').append(envName).append('['); - defaultTitleSB.append(Inter.getLocText("Env-Remote_Server")); - defaultTitleSB.append(']'); + defaultTitleSB.append(env.getDescription(envName)); if (editingTemplate != null) { String path = editingTemplate.getEditingFILE().getPath(); if (!editingTemplate.getEditingFILE().exists()) { @@ -981,7 +974,7 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta DesignerEnvManager.getEnvManager().saveXMLFile(); - EnvContext.signOut(); + EnvUpdater.disconnect(); this.setVisible(false); this.dispose(); diff --git a/designer-base/src/com/fr/design/mainframe/TemplatePane.java b/designer-base/src/com/fr/design/mainframe/TemplatePane.java index 8d128ce5e3..79904a90ee 100644 --- a/designer-base/src/com/fr/design/mainframe/TemplatePane.java +++ b/designer-base/src/com/fr/design/mainframe/TemplatePane.java @@ -1,6 +1,7 @@ package com.fr.design.mainframe; import com.fr.base.BaseUtils; +import com.fr.base.env.EnvUpdater; import com.fr.core.env.EnvConfig; import com.fr.dav.LocalEnv; import com.fr.design.DesignModelAdapter; @@ -8,13 +9,13 @@ import com.fr.design.DesignerEnvManager; import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.dialog.InformationWarnPane; +import com.fr.design.env.EnvGenerator; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.file.TemplateTreePane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ilable.UILabel; import com.fr.env.EnvListPane; import com.fr.env.RemoteEnv; -import com.fr.env.SignIn; import com.fr.general.ComparatorUtils; import com.fr.general.GeneralContext; import com.fr.general.Inter; @@ -141,7 +142,7 @@ public class TemplatePane extends JPanel implements MouseListener { } } } - SignIn.signIn(selectedEnv); + EnvUpdater.updateEnv(EnvGenerator.generate(selectedEnv)); JTemplate template = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); if (template != null) { template.refreshToolArea(); diff --git a/designer-base/src/com/fr/design/mainframe/loghandler/socketio/DesignerSocketIO.java b/designer-base/src/com/fr/design/mainframe/loghandler/socketio/DesignerSocketIO.java index 2da090c1ee..957d9f83ac 100644 --- a/designer-base/src/com/fr/design/mainframe/loghandler/socketio/DesignerSocketIO.java +++ b/designer-base/src/com/fr/design/mainframe/loghandler/socketio/DesignerSocketIO.java @@ -1,14 +1,18 @@ package com.fr.design.mainframe.loghandler.socketio; +import com.fr.base.Env; +import com.fr.base.FRContext; import com.fr.config.ConfigEvent; import com.fr.config.Configuration; import com.fr.core.env.EnvConfig; import com.fr.core.env.EnvConstants; import com.fr.core.env.EnvContext; import com.fr.core.env.EnvEvent; -import com.fr.core.env.resource.LocalEnvConfig; +import com.fr.core.env.impl.LocalEnvConfig; import com.fr.decision.webservice.utils.DecisionServiceConstants; +import com.fr.design.env.RemoteEnvConfig; import com.fr.design.mainframe.loghandler.DesignerLogHandler; +import com.fr.env.RemoteEnv; import com.fr.event.Event; import com.fr.event.EventDispatcher; import com.fr.event.Listener; @@ -66,14 +70,14 @@ public class DesignerSocketIO { } private static void updateSocket() { - EnvConfig env = EnvContext.currentEnv(); - if (env instanceof LocalEnvConfig) { + Env env = FRContext.getCurrentEnv(); + if (env.isLocalEnv()) { return; } - try { + RemoteEnvConfig config = ((RemoteEnv)env).getEnvConfig(); String uri = String.format("http://%s:%s%s?%s=%s", - new URL(env.getPath()).getHost(), + config.getHost(), WebSocketConfig.getInstance().getPort(), EnvConstants.WS_NAMESPACE, DecisionServiceConstants.WEB_SOCKET_TOKEN_NAME, diff --git a/designer-base/src/com/fr/design/utils/DesignUtils.java b/designer-base/src/com/fr/design/utils/DesignUtils.java index 22cf51abab..889e52dd61 100644 --- a/designer-base/src/com/fr/design/utils/DesignUtils.java +++ b/designer-base/src/com/fr/design/utils/DesignUtils.java @@ -1,17 +1,19 @@ package com.fr.design.utils; import com.fr.base.BaseUtils; +import com.fr.base.Env; import com.fr.base.EnvException; import com.fr.base.FRContext; import com.fr.base.FeedBackInfo; import com.fr.base.ServerConfig; import com.fr.base.Utils; +import com.fr.base.env.EnvUpdater; import com.fr.base.remote.RemoteDeziConstants; import com.fr.core.env.EnvConfig; -import com.fr.core.env.EnvContext; import com.fr.dav.DavXMLUtils; import com.fr.design.DesignerEnvManager; import com.fr.design.ExtraDesignClassManager; +import com.fr.design.env.EnvGenerator; import com.fr.design.fun.DesignerEnvProcessor; import com.fr.design.gui.UILookAndFeel; import com.fr.design.mainframe.DesignerContext; @@ -31,11 +33,8 @@ import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; import com.fr.start.ServerStarter; -import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; -import javax.swing.UIManager; -import java.awt.Desktop; -import java.awt.Font; +import javax.swing.*; +import java.awt.*; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.ByteArrayInputStream; @@ -190,10 +189,10 @@ public class DesignUtils { /** * 当前的报表运行环境切换到env * - * @param env 需要切换去的环境 + * @param config 需要切换去的环境 */ - public static void switchToEnv(EnvConfig env) { - if (env == null) { + public static void switchToEnv(EnvConfig config) { + if (config == null) { return; } @@ -202,12 +201,13 @@ public class DesignUtils { java.util.Iterator nameIt = envManager.getEnvNameIterator(); while (nameIt.hasNext()) { String name = nameIt.next(); - if (ComparatorUtils.equals(envManager.getEnv(name), env)) { + if (ComparatorUtils.equals(envManager.getEnv(name), config)) { envManager.setCurEnvName(name); break; } } - EnvContext.signIn(env); + Env env = EnvGenerator.generate(config); + EnvUpdater.updateEnv(env); refreshDesignerFrame(); } diff --git a/designer-base/src/com/fr/env/EnvListPane.java b/designer-base/src/com/fr/env/EnvListPane.java index 92bab2929e..6146b5d5d5 100644 --- a/designer-base/src/com/fr/env/EnvListPane.java +++ b/designer-base/src/com/fr/env/EnvListPane.java @@ -1,8 +1,8 @@ package com.fr.env; import com.fr.core.env.EnvConfig; -import com.fr.core.env.resource.LocalEnvConfig; -import com.fr.core.env.resource.RemoteEnvConfig; +import com.fr.core.env.impl.LocalEnvConfig; +import com.fr.design.env.RemoteEnvConfig; import com.fr.design.DesignerEnvManager; import com.fr.design.gui.controlpane.JListControlPane; import com.fr.design.gui.controlpane.NameObjectCreator; diff --git a/designer-base/src/com/fr/env/LocalEnvPane.java b/designer-base/src/com/fr/env/LocalEnvPane.java index 57f37d1cd3..d5dce6a1a3 100644 --- a/designer-base/src/com/fr/env/LocalEnvPane.java +++ b/designer-base/src/com/fr/env/LocalEnvPane.java @@ -1,6 +1,6 @@ package com.fr.env; -import com.fr.core.env.resource.LocalEnvConfig; +import com.fr.core.env.impl.LocalEnvConfig; import com.fr.design.beans.BasicBeanPane; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.itextarea.UITextArea; diff --git a/designer-base/src/com/fr/env/RemoteEnv.java b/designer-base/src/com/fr/env/RemoteEnv.java index ffb42c122b..07e9274ed9 100644 --- a/designer-base/src/com/fr/env/RemoteEnv.java +++ b/designer-base/src/com/fr/env/RemoteEnv.java @@ -10,7 +10,7 @@ import com.fr.common.rpc.netty.MessageSendExecutor; import com.fr.common.rpc.netty.RemoteCallClient; import com.fr.core.env.EnvConstants; import com.fr.core.env.EnvContext; -import com.fr.core.env.resource.RemoteEnvConfig; +import com.fr.design.env.RemoteEnvConfig; import com.fr.data.TableDataSource; import com.fr.data.impl.EmbeddedTableData; import com.fr.data.impl.storeproc.StoreProcedure; @@ -93,13 +93,9 @@ public class RemoteEnv extends AbstractEnv implements DesignAut this.config = config; } - public RemoteEnv(String path, String userName, String password) { - config = new RemoteEnvConfig(path, userName, password); - } - @Override public void connect() throws Exception { - + RemoteCallClient.getInstance().load(config.getHost(), config.getPort(), RemoteCallServerConfig.getInstance().getSerializeProtocol()); } @Override @@ -128,6 +124,11 @@ public class RemoteEnv extends AbstractEnv implements DesignAut return MessageSendExecutor.getInstance().execute(FileOperator.class); } + @Override + public RemoteEnvConfig getEnvConfig() { + return config; + } + @Override public String getPath() { return config.getPath(); @@ -147,6 +148,11 @@ public class RemoteEnv extends AbstractEnv implements DesignAut return EnvContext.currentToken(); } + @Override + public boolean isLocalEnv() { + return false; + } + /** * execute method之后,取返回的 InputStream */ diff --git a/designer-base/src/com/fr/env/RemoteEnvPane.java b/designer-base/src/com/fr/env/RemoteEnvPane.java index 1e13d7e4b5..6028dc6eee 100644 --- a/designer-base/src/com/fr/env/RemoteEnvPane.java +++ b/designer-base/src/com/fr/env/RemoteEnvPane.java @@ -2,7 +2,7 @@ package com.fr.env; import com.fr.base.FRContext; import com.fr.core.env.resource.EnvConfigUtils; -import com.fr.core.env.resource.RemoteEnvConfig; +import com.fr.design.env.RemoteEnvConfig; import com.fr.design.DesignerEnvManager; import com.fr.design.beans.BasicBeanPane; import com.fr.design.border.UITitledBorder; @@ -280,8 +280,9 @@ public class RemoteEnvPane extends BasicBeanPane { String path = remoteEnvURL.getURL(); String user = this.usernameInput.getText(); String password = new String(this.passwordInput.getPassword()); + return null; - return new RemoteEnvConfig(path, user, password); + //return new RemoteEnvConfig(path, user, password); } @Override @@ -471,7 +472,8 @@ public class RemoteEnvPane extends BasicBeanPane { private boolean testConnection() { String url = remoteEnvURL.getURL(); - RemoteEnv env = new RemoteEnv(url, usernameInput.getText(), new String(passwordInput.getPassword())); + //RemoteEnv env = new RemoteEnv(url, usernameInput.getText(), new String(passwordInput.getPassword())); + RemoteEnv env = null; boolean connect = false; try { if (StringUtils.isNotEmpty(url)) { diff --git a/designer-base/src/com/fr/env/RemoteEnvPane2.java b/designer-base/src/com/fr/env/RemoteEnvPane2.java index 11bd73cef2..6263969e0e 100644 --- a/designer-base/src/com/fr/env/RemoteEnvPane2.java +++ b/designer-base/src/com/fr/env/RemoteEnvPane2.java @@ -1,6 +1,6 @@ package com.fr.env; -import com.fr.core.env.resource.RemoteEnvConfig; +import com.fr.design.env.RemoteEnvConfig; import com.fr.design.beans.BasicBeanPane; import com.fr.design.border.UITitledBorder; import com.fr.design.gui.ibutton.UIButton; @@ -12,14 +12,14 @@ import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.Inter; -import com.fr.log.FineLoggerFactory; import javax.swing.*; import javax.swing.border.EmptyBorder; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.concurrent.ExecutionException; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; /** * 远程环境设置界面,暂时命名为2,待做完功能直接替代掉老的RemoteEnvPane @@ -30,6 +30,10 @@ public class RemoteEnvPane2 extends BasicBeanPane { private UIIntNumberField portTextField; private UITextField usernameTextField; private UIPassWordField passwordTextField; + private JDialog dialog; + private UILabel message; + private UIButton okButton; + private UIButton cancelButton; public RemoteEnvPane2() { initComponents(); @@ -73,46 +77,82 @@ public class RemoteEnvPane2 extends BasicBeanPane { } }); contentPanel.add(valuePane, BorderLayout.CENTER); + + message = new UILabel(); + okButton = new UIButton(Inter.getLocText("OK")); + cancelButton = new UIButton(Inter.getLocText("Cancel")); } private void tryConnectRemoteEnv() { - final RemoteEnv remoteEnv = new RemoteEnv(this.updateBean()); - new SwingWorker() { + final SwingWorker worker = new SwingWorker() { @Override protected Void doInBackground() throws Exception { + final RemoteEnv remoteEnv = new RemoteEnv(updateBean()); remoteEnv.connectOnce(); return null; } @Override protected void done() { + okButton.setEnabled(true); try { get(); - showConnectMessage(); + message.setText(Inter.getLocText("Fine-Designer_Basic_Remote_Connect_Successful")); } catch (Exception e) { - showCannotConnectMessage(); + message.setText(Inter.getLocText("Fine-Designer_Basic_Remote_Connect_Failed")); } } - }.execute(); - } + }; + worker.execute(); + initMessageDialog(); + okButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + dialog.dispose(); + } + }); + cancelButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + dialog.dispose(); + worker.cancel(true); + } + }); - private void showCannotConnectMessage() { - JOptionPane.showMessageDialog( - this, - Inter.getLocText("Fine-Designer_Basic_Remote_Connect_Failed"), - UIManager.getString("OptionPane.messageDialogTitle", this.getLocale()), - JOptionPane.ERROR_MESSAGE - ); + dialog.addWindowListener(new WindowAdapter() { + public void windowClosed(WindowEvent e) { + worker.cancel(true); + } + }); + + dialog.setVisible(true); + dialog.dispose(); } - private void showConnectMessage() { - JOptionPane.showMessageDialog( - this, - Inter.getLocText("Fine-Designer_Basic_Remote_Connect_Successful"), - UIManager.getString("OptionPane.messageDialogTitle", this.getLocale()), - JOptionPane.INFORMATION_MESSAGE - ); + private void initMessageDialog() { + message.setText(Inter.getLocText("Fine-Designer_Basic_Remote_Env_Try") + "..."); + message.setBorder(BorderFactory.createEmptyBorder(8, 5, 0, 0)); + okButton.setEnabled(false); + + dialog = new JDialog((Dialog) SwingUtilities.getWindowAncestor(RemoteEnvPane2.this), Inter.getLocText("Datasource-Test_Connection"), true); + + dialog.setSize(new Dimension(268, 118)); + okButton.setEnabled(false); + JPanel jp = new JPanel(); + JPanel upPane = new JPanel(); + JPanel downPane = new JPanel(); + UILabel uiLabel = new UILabel(UIManager.getIcon("OptionPane.informationIcon")); + upPane.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10)); + upPane.add(uiLabel); + upPane.add(message); + downPane.setLayout(new FlowLayout(FlowLayout.CENTER, 6, 0)); + downPane.add(okButton); + downPane.add(cancelButton); + jp.setLayout(new BoxLayout(jp, BoxLayout.Y_AXIS)); + jp.add(upPane); + jp.add(downPane); + dialog.add(jp); + dialog.setResizable(false); + dialog.setLocationRelativeTo(SwingUtilities.getWindowAncestor(RemoteEnvPane2.this)); } @Override @@ -125,7 +165,7 @@ public class RemoteEnvPane2 extends BasicBeanPane { if (config == null) { return; } - hostTextField.setText(config.getPath()); + hostTextField.setText(config.getHost()); if (config.getPort() != 0) { portTextField.setValue(config.getPort()); } diff --git a/designer-base/src/com/fr/env/SignIn.java b/designer-base/src/com/fr/env/SignIn.java index 902acdaf19..c93338b23d 100644 --- a/designer-base/src/com/fr/env/SignIn.java +++ b/designer-base/src/com/fr/env/SignIn.java @@ -1,6 +1,8 @@ package com.fr.env; +import com.fr.base.Env; +import com.fr.base.FRContext; import com.fr.core.env.EnvConfig; import com.fr.core.env.EnvContext; import com.fr.core.env.EnvEvent; @@ -12,6 +14,7 @@ import com.fr.event.Listener; import com.fr.event.Null; import com.fr.general.ComparatorUtils; import com.fr.general.Inter; +import com.fr.stable.AssistUtils; import javax.swing.*; @@ -34,9 +37,9 @@ public class SignIn { * @throws Exception 异常 */ public static void signIn(EnvConfig selectedEnv) throws Exception { - - if (EnvContext.currentEnv() != null && !ComparatorUtils.equals(EnvContext.currentEnv(), selectedEnv)) { - EnvContext.signOut(); + Env env = FRContext.getCurrentEnv(); + if (env != null && AssistUtils.equals(env.getEnvConfig(), selectedEnv)) { + env.disconnect(); } DesignUtils.switchToEnv(selectedEnv); } diff --git a/designer-base/src/com/fr/start/ServerStarter.java b/designer-base/src/com/fr/start/ServerStarter.java index 027c1fdba3..1dc8cf8f14 100644 --- a/designer-base/src/com/fr/start/ServerStarter.java +++ b/designer-base/src/com/fr/start/ServerStarter.java @@ -2,16 +2,17 @@ package com.fr.start; import com.fr.base.FRContext; import com.fr.base.ServerConfig; +import com.fr.base.env.EnvUpdater; import com.fr.design.DesignModelAdapter; import com.fr.design.DesignerEnvManager; import com.fr.design.data.datapane.TableDataTreePane; import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.DialogActionAdapter; +import com.fr.design.env.EnvGenerator; import com.fr.design.file.TemplateTreePane; import com.fr.design.gui.itextarea.UITextArea; import com.fr.design.mainframe.DesignerContext; import com.fr.env.RemoteEnv; -import com.fr.env.SignIn; import com.fr.general.ComparatorUtils; import com.fr.general.GeneralContext; import com.fr.general.Inter; @@ -52,9 +53,8 @@ public class ServerStarter { @Override public void doOk() { - try { - SignIn.signIn(DesignerEnvManager.getEnvManager().getDefaultEnv()); + EnvUpdater.updateEnv(EnvGenerator.generate(DesignerEnvManager.getEnvManager().getDefaultEnv())); TemplateTreePane.getInstance().refreshDockingView(); TableDataTreePane.getInstance(DesignModelAdapter.getCurrentModelAdapter()); } catch (Exception e) { diff --git a/designer-realize/src/com/fr/start/EnvSwitcher.java b/designer-realize/src/com/fr/start/EnvSwitcher.java index 800466a466..5dffc028ab 100644 --- a/designer-realize/src/com/fr/start/EnvSwitcher.java +++ b/designer-realize/src/com/fr/start/EnvSwitcher.java @@ -1,10 +1,10 @@ package com.fr.start; -import com.fr.base.FRContext; +import com.fr.base.Env; +import com.fr.base.env.EnvUpdater; import com.fr.design.DesignerEnvManager; +import com.fr.design.env.EnvGenerator; import com.fr.design.mainframe.TemplatePane; -import com.fr.env.SignIn; -import com.fr.general.Inter; /** * Created by juhaoyu on 2018/1/31. @@ -16,10 +16,8 @@ public class EnvSwitcher { try { String current = DesignerEnvManager.getEnvManager().getCurEnvName(); - SignIn.signIn(DesignerEnvManager.getEnvManager().getEnv(current)); - if (!FRContext.getCurrentEnv().testServerConnectionWithOutShowMessagePane()) { - throw new Exception(Inter.getLocText("Datasource-Connection_failed")); - } + Env env = EnvGenerator.generate(DesignerEnvManager.getEnvManager().getEnv(current)); + EnvUpdater.updateEnv(env); } catch (Exception e) { TemplatePane.getInstance().dealEvnExceptionWhenStartDesigner(); } diff --git a/designer-realize/src/com/fr/start/module/DesignerEnvProvider.java b/designer-realize/src/com/fr/start/module/DesignerEnvProvider.java index f15b0a42b6..0615d7774a 100644 --- a/designer-realize/src/com/fr/start/module/DesignerEnvProvider.java +++ b/designer-realize/src/com/fr/start/module/DesignerEnvProvider.java @@ -1,26 +1,23 @@ package com.fr.start.module; -import com.fr.base.FRContext; +import com.fr.base.Env; import com.fr.base.ModifiedTable; import com.fr.base.Parameter; import com.fr.base.StoreProcedureParameter; import com.fr.base.TableData; +import com.fr.base.env.EnvUpdater; import com.fr.base.env.serializer.OldSerializerAdapter; import com.fr.base.env.serializer.ProcedureDataModelSerializer; import com.fr.core.env.EnvConfig; import com.fr.core.env.EnvEvent; import com.fr.core.env.proxy.EnvProxy; -import com.fr.core.env.resource.EnvConfigUtils; -import com.fr.core.env.resource.LocalEnvConfig; -import com.fr.core.env.resource.RemoteEnvConfig; import com.fr.data.core.db.TableProcedure; import com.fr.data.impl.Connection; import com.fr.data.impl.storeproc.ProcedureDataModel; import com.fr.data.impl.storeproc.StoreProcedure; import com.fr.dav.DavXMLUtils; -import com.fr.dav.LocalEnv; import com.fr.design.DesignerEnvManager; -import com.fr.env.RemoteEnv; +import com.fr.design.env.EnvGenerator; import com.fr.event.Event; import com.fr.event.EventDispatcher; import com.fr.event.Listener; @@ -64,17 +61,12 @@ public class DesignerEnvProvider extends Activator { EventDispatcher.listen(EnvEvent.BEFORE_SIGN_IN, new Listener() { @Override public void on(Event event, EnvConfig envConfig) { - if (envConfig instanceof RemoteEnvConfig) { - RemoteEnv remoteEnv = new RemoteEnv(envConfig.getPath(), EnvConfigUtils.getUsername(envConfig), EnvConfigUtils.getPassword(envConfig)); - FRContext.setCurrentEnv(remoteEnv); - } else if (envConfig instanceof LocalEnvConfig) { - FRContext.setCurrentEnv(new LocalEnv()); - } + Env env = EnvGenerator.generate(envConfig); + EnvUpdater.updateEnv(env); } }); } - private void addSerializers() { EnvProxy.addSerializer(ProcedureDataModel[].class, new ProcedureDataModelSerializer()); From c5bea16bc81a37f96c3be70bd69ace9a6ac5a525 Mon Sep 17 00:00:00 2001 From: richie Date: Fri, 8 Jun 2018 10:32:06 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=97=A0JIRA=E4=BB=BB=E5=8A=A1=20=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E5=8A=A0=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/fr/design/env/RemoteEnvConfig.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/designer-base/src/com/fr/design/env/RemoteEnvConfig.java b/designer-base/src/com/fr/design/env/RemoteEnvConfig.java index bb5f0ba107..5f6b763dfa 100644 --- a/designer-base/src/com/fr/design/env/RemoteEnvConfig.java +++ b/designer-base/src/com/fr/design/env/RemoteEnvConfig.java @@ -81,7 +81,10 @@ public class RemoteEnvConfig extends AbstractEnvConfig { this.host = reader.getAttrAsString("host", StringUtils.EMPTY); this.port = reader.getAttrAsInt("port", DEFAULT_RPC_PORT); this.username = reader.getAttrAsString("username", StringUtils.EMPTY); - this.password = SecurityToolbox.decrypt(reader.getAttrAsString("password", StringUtils.EMPTY)); + String password = reader.getAttrAsString("password", StringUtils.EMPTY); + if (StringUtils.isNotEmpty(password)) { + this.password = SecurityToolbox.decrypt(password); + } } } } @@ -92,9 +95,12 @@ public class RemoteEnvConfig extends AbstractEnvConfig { writer.startTAG("Attr") .attr("host", host) .attr("port", port) - .attr("username", username) - .attr("password", SecurityToolbox.encrypt(password)) - .end(); + .attr("username", username); + if (StringUtils.isNotEmpty(password)) { + writer.attr("password", SecurityToolbox.encrypt(password)); + } + + writer.end(); } From 20d7b397a669155720bdade84e1db6fca190d38c Mon Sep 17 00:00:00 2001 From: richie Date: Fri, 8 Jun 2018 12:22:24 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=97=A0JIRA=E4=BB=BB=E5=8A=A1=20=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E8=B5=84=E6=BA=90=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/actions/file/SwitchExistEnv.java | 31 +++++----- .../com/fr/design/env/RemoteEnvConfig.java | 16 ++++-- .../gui/itree/filetree/TemplateFileTree.java | 5 +- .../com/fr/design/mainframe/TemplatePane.java | 56 ++++++++----------- .../src/com/fr/design/utils/DesignUtils.java | 29 ---------- designer-base/src/com/fr/env/RemoteEnv.java | 6 ++ designer-base/src/com/fr/env/SignIn.java | 2 +- 7 files changed, 60 insertions(+), 85 deletions(-) diff --git a/designer-base/src/com/fr/design/actions/file/SwitchExistEnv.java b/designer-base/src/com/fr/design/actions/file/SwitchExistEnv.java index decc72daac..c956670576 100644 --- a/designer-base/src/com/fr/design/actions/file/SwitchExistEnv.java +++ b/designer-base/src/com/fr/design/actions/file/SwitchExistEnv.java @@ -1,6 +1,7 @@ package com.fr.design.actions.file; import com.fr.base.BaseUtils; +import com.fr.base.env.Callback; import com.fr.base.env.EnvUpdater; import com.fr.core.env.EnvConfig; import com.fr.core.env.impl.LocalEnvConfig; @@ -17,6 +18,7 @@ import com.fr.design.mainframe.TemplatePane; import com.fr.design.menu.KeySetUtils; import com.fr.design.menu.MenuDef; import com.fr.design.menu.SeparatorDef; +import com.fr.design.utils.DesignUtils; import com.fr.env.RemoteEnv; import com.fr.general.GeneralContext; import com.fr.general.Inter; @@ -98,24 +100,25 @@ public class SwitchExistEnv extends MenuDef { */ public void actionPerformed(ActionEvent e) { DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); - EnvConfig selectedEnv = envManager.getEnv(this.getName()); - try { - if (selectedEnv instanceof RemoteEnv && !((RemoteEnv) selectedEnv).testServerConnection()) { + final String envName = getName(); + EnvConfig selectedEnv = envManager.getEnv(envName); + EnvUpdater.updateEnv(EnvGenerator.generate(selectedEnv), new Callback() { + @Override + public void success() { + DesignerEnvManager.getEnvManager().setCurEnvName(envName); + DesignUtils.refreshDesignerFrame(); + HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().refreshToolArea(); + fireDSChanged(); + } + + @Override + public void fail() { + TemplatePane.getInstance().editItems(); JOptionPane.showMessageDialog( DesignerContext.getDesignerFrame(), Inter.getLocText(new String[]{"M-SwitchWorkspace", "Failed"})); - return; } - EnvUpdater.updateEnv(EnvGenerator.generate(selectedEnv)); - HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().refreshToolArea(); - fireDSChanged(); - } catch (Exception em) { - FineLoggerFactory.getLogger().error(em.getMessage(), em); - JOptionPane.showMessageDialog( - DesignerContext.getDesignerFrame(), - Inter.getLocText(new String[]{"M-SwitchWorkspace", "Failed"})); - TemplatePane.getInstance().editItems(); - } + }); } } } diff --git a/designer-base/src/com/fr/design/env/RemoteEnvConfig.java b/designer-base/src/com/fr/design/env/RemoteEnvConfig.java index 5f6b763dfa..fc701d8ca7 100644 --- a/designer-base/src/com/fr/design/env/RemoteEnvConfig.java +++ b/designer-base/src/com/fr/design/env/RemoteEnvConfig.java @@ -69,7 +69,7 @@ public class RemoteEnvConfig extends AbstractEnvConfig { @Override public String getDescription(String name) { - return username + "@" + name + "[" + Inter.getLocText("") + "]"; + return username + "@" + name + "[" + Inter.getLocText("Fine-Designer_Basic_Remote_Env") + "]"; } @Override @@ -85,6 +85,11 @@ public class RemoteEnvConfig extends AbstractEnvConfig { if (StringUtils.isNotEmpty(password)) { this.password = SecurityToolbox.decrypt(password); } + } else if ("Username".equals(tagName)) { + this.username = reader.getElementValue(); + } else if ("Password".equals(tagName)) { + String txt = reader.getElementValue(); + this.password = SecurityToolbox.decrypt(txt); } } } @@ -94,14 +99,13 @@ public class RemoteEnvConfig extends AbstractEnvConfig { super.writeXML(writer); writer.startTAG("Attr") .attr("host", host) - .attr("port", port) - .attr("username", username); + .attr("port", port); + writer.end(); + writer.startTAG("Username").textNode(username).end(); if (StringUtils.isNotEmpty(password)) { - writer.attr("password", SecurityToolbox.encrypt(password)); + writer.startTAG("Password").textNode(SecurityToolbox.encrypt(password)).end(); } - writer.end(); - } @Override diff --git a/designer-base/src/com/fr/design/gui/itree/filetree/TemplateFileTree.java b/designer-base/src/com/fr/design/gui/itree/filetree/TemplateFileTree.java index 650712bb0f..32c95f672f 100644 --- a/designer-base/src/com/fr/design/gui/itree/filetree/TemplateFileTree.java +++ b/designer-base/src/com/fr/design/gui/itree/filetree/TemplateFileTree.java @@ -1,10 +1,12 @@ package com.fr.design.gui.itree.filetree; import com.fr.base.Env; +import com.fr.base.FRContext; import com.fr.base.operator.file.FileOperator; import com.fr.core.env.proxy.EnvProxy; import com.fr.design.gui.itree.refreshabletree.ExpandMutableTreeNode; import com.fr.file.filetree.FileNode; +import com.fr.general.web.ParameterConstants; import com.fr.log.FineLoggerFactory; import com.fr.stable.ArrayUtils; import com.fr.stable.StableUtils; @@ -102,8 +104,7 @@ public class TemplateFileTree extends EnvFileTree { } public FileNode[] listFile(String path) throws Exception { - String extra = EnvProxy.get(FileOperator.class).readExtraResourcePath(path); - return EnvProxy.get(FileOperator.class).list(extra, path); + return FRContext.getCurrentEnv().getFileOperator().list("reportlets", path); } /* diff --git a/designer-base/src/com/fr/design/mainframe/TemplatePane.java b/designer-base/src/com/fr/design/mainframe/TemplatePane.java index 79904a90ee..5c539cd9bf 100644 --- a/designer-base/src/com/fr/design/mainframe/TemplatePane.java +++ b/designer-base/src/com/fr/design/mainframe/TemplatePane.java @@ -1,41 +1,34 @@ package com.fr.design.mainframe; import com.fr.base.BaseUtils; +import com.fr.base.env.Callback; import com.fr.base.env.EnvUpdater; import com.fr.core.env.EnvConfig; -import com.fr.dav.LocalEnv; +import com.fr.core.env.impl.LocalEnvConfig; import com.fr.design.DesignModelAdapter; import com.fr.design.DesignerEnvManager; import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.dialog.InformationWarnPane; import com.fr.design.env.EnvGenerator; +import com.fr.design.env.RemoteEnvConfig; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.file.TemplateTreePane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ilable.UILabel; +import com.fr.design.utils.DesignUtils; import com.fr.env.EnvListPane; import com.fr.env.RemoteEnv; import com.fr.general.ComparatorUtils; import com.fr.general.GeneralContext; +import com.fr.general.IOUtils; import com.fr.general.Inter; import com.fr.stable.EnvChangedListener; import com.fr.stable.ProductConstants; import com.fr.stable.StringUtils; -import javax.swing.BorderFactory; -import javax.swing.Icon; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.SwingUtilities; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Cursor; -import java.awt.Dimension; -import java.awt.GradientPaint; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Point; +import javax.swing.*; +import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; @@ -122,27 +115,23 @@ public class TemplatePane extends JPanel implements MouseListener { } private boolean envListOkAction(EnvListPane envListPane) { - String selectedName = envListPane.updateEnvManager(); + final String selectedName = envListPane.updateEnvManager(); DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); EnvConfig selectedEnv = envManager.getEnv(selectedName); GeneralContext.fireEnvWillChangeListener(); try { - //如果是远程的还要先测试下,如果失败就不切换 - if (selectedEnv instanceof RemoteEnv) { - if (!((RemoteEnv) selectedEnv).testServerConnection()) { + EnvUpdater.updateEnv(EnvGenerator.generate(selectedEnv), new Callback() { + @Override + public void fail() { JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText(new String[]{"M-SwitchWorkspace", "Failed"})); - return false; - } else { - String remoteVersion = getDesignerVersion(selectedEnv); - if (StringUtils.isBlank(remoteVersion) || ComparatorUtils.compare(remoteVersion, ProductConstants.DESIGNER_VERSION) < 0) { - String infor = Inter.getLocText("Server-version-tip"); - String moreInfo = Inter.getLocText("Server-version-tip-moreInfo"); - new InformationWarnPane(infor, moreInfo, Inter.getLocText("Tooltips")).show(); - return false; - } } - } - EnvUpdater.updateEnv(EnvGenerator.generate(selectedEnv)); + + @Override + public void success() { + DesignerEnvManager.getEnvManager().setCurEnvName(selectedName); + DesignUtils.refreshDesignerFrame(); + } + }); JTemplate template = HistoryTemplateListPane.getInstance().getCurrentEditingTemplate(); if (template != null) { template.refreshToolArea(); @@ -186,11 +175,12 @@ public class TemplatePane extends JPanel implements MouseListener { } private void setJLabel(String name) { - if (DesignerEnvManager.getEnvManager().getEnv(name) instanceof LocalEnv) { - envLabel.setIcon(BaseUtils.readIcon("com/fr/design/images/data/bind/localconnect.png")); + EnvConfig config = DesignerEnvManager.getEnvManager().getEnv(name); + if (config instanceof LocalEnvConfig) { + envLabel.setIcon(IOUtils.readIcon("com/fr/design/images/data/bind/localconnect.png")); - } else if (DesignerEnvManager.getEnvManager().getEnv(name) instanceof RemoteEnv) { - envLabel.setIcon(BaseUtils.readIcon("com/fr/design/images/data/bind/distanceconnect.png")); + } else if (config instanceof RemoteEnvConfig) { + envLabel.setIcon(IOUtils.readIcon("com/fr/design/images/data/bind/distanceconnect.png")); } envLabel.setText(name); envLabel.repaint(); diff --git a/designer-base/src/com/fr/design/utils/DesignUtils.java b/designer-base/src/com/fr/design/utils/DesignUtils.java index 889e52dd61..60b010b4c4 100644 --- a/designer-base/src/com/fr/design/utils/DesignUtils.java +++ b/designer-base/src/com/fr/design/utils/DesignUtils.java @@ -1,19 +1,15 @@ package com.fr.design.utils; import com.fr.base.BaseUtils; -import com.fr.base.Env; import com.fr.base.EnvException; import com.fr.base.FRContext; import com.fr.base.FeedBackInfo; import com.fr.base.ServerConfig; import com.fr.base.Utils; -import com.fr.base.env.EnvUpdater; import com.fr.base.remote.RemoteDeziConstants; -import com.fr.core.env.EnvConfig; import com.fr.dav.DavXMLUtils; import com.fr.design.DesignerEnvManager; import com.fr.design.ExtraDesignClassManager; -import com.fr.design.env.EnvGenerator; import com.fr.design.fun.DesignerEnvProcessor; import com.fr.design.gui.UILookAndFeel; import com.fr.design.mainframe.DesignerContext; @@ -186,31 +182,6 @@ public class DesignUtils { }); } - /** - * 当前的报表运行环境切换到env - * - * @param config 需要切换去的环境 - */ - public static void switchToEnv(EnvConfig config) { - if (config == null) { - return; - } - - // 看一下这个env在DesignerEnvManager里面有没有对应的,有的话就setCurrentEnvName - DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); - java.util.Iterator nameIt = envManager.getEnvNameIterator(); - while (nameIt.hasNext()) { - String name = nameIt.next(); - if (ComparatorUtils.equals(envManager.getEnv(name), config)) { - envManager.setCurEnvName(name); - break; - } - } - Env env = EnvGenerator.generate(config); - EnvUpdater.updateEnv(env); - refreshDesignerFrame(); - } - public static void refreshDesignerFrame() { // 刷新DesignerFrame里面的面板 diff --git a/designer-base/src/com/fr/env/RemoteEnv.java b/designer-base/src/com/fr/env/RemoteEnv.java index 07e9274ed9..eae3d57149 100644 --- a/designer-base/src/com/fr/env/RemoteEnv.java +++ b/designer-base/src/com/fr/env/RemoteEnv.java @@ -2,6 +2,7 @@ package com.fr.env; import com.fr.base.EnvException; import com.fr.base.TableData; +import com.fr.base.operator.common.CommonOperator; import com.fr.base.operator.connect.ConnectOperator; import com.fr.base.operator.file.FileOperator; import com.fr.base.remote.RemoteDeziConstants; @@ -124,6 +125,11 @@ public class RemoteEnv extends AbstractEnv implements DesignAut return MessageSendExecutor.getInstance().execute(FileOperator.class); } + @Override + public CommonOperator getCommonOperator() throws Exception { + return MessageSendExecutor.getInstance().execute(CommonOperator.class); + } + @Override public RemoteEnvConfig getEnvConfig() { return config; diff --git a/designer-base/src/com/fr/env/SignIn.java b/designer-base/src/com/fr/env/SignIn.java index c93338b23d..bca04d2484 100644 --- a/designer-base/src/com/fr/env/SignIn.java +++ b/designer-base/src/com/fr/env/SignIn.java @@ -41,6 +41,6 @@ public class SignIn { if (env != null && AssistUtils.equals(env.getEnvConfig(), selectedEnv)) { env.disconnect(); } - DesignUtils.switchToEnv(selectedEnv); + //DesignUtils.switchToEnv(selectedEnv); } } \ No newline at end of file