diff --git a/designer-base/src/com/fr/design/mainframe/DesignerFrame.java b/designer-base/src/com/fr/design/mainframe/DesignerFrame.java index 828c6623b2..7c1b0ba0c1 100644 --- a/designer-base/src/com/fr/design/mainframe/DesignerFrame.java +++ b/designer-base/src/com/fr/design/mainframe/DesignerFrame.java @@ -7,6 +7,7 @@ import com.fr.base.BaseUtils; 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.resource.EnvConfigUtils; import com.fr.design.DesignModelAdapter; import com.fr.design.DesignState; @@ -317,7 +318,7 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta public void on(PluginEvent event) { refreshNorthEastPane(northEastPane, ad); - DesignUtils.refreshDesignerFrame(FRContext.getCurrentEnv()); + DesignUtils.refreshDesignerFrame(); } }, new PluginFilter() { @@ -682,10 +683,8 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta /** * 报表运行环境改变时,需要刷新某些面板 - * - * @param env 环境 */ - public void refreshEnv(Env env) { + public void refreshEnv() { this.setTitle(); DesignerFrameFileDealerPane.getInstance().refreshDockingView(); @@ -965,14 +964,8 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta DesignerEnvManager.getEnvManager().saveXMLFile(); - Env currentEnv = FRContext.getCurrentEnv(); - try { - EventDispatcher.fire(BEFORE_SIGN_OUT); - currentEnv.signOut(); - EventDispatcher.fire(AFTER_SIGN_OUT); - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } + EnvContext.signOut(); + this.setVisible(false); this.dispose(); diff --git a/designer-base/src/com/fr/design/mainframe/loghandler/DesignerLogHandler.java b/designer-base/src/com/fr/design/mainframe/loghandler/DesignerLogHandler.java index 846583538b..ef53252154 100644 --- a/designer-base/src/com/fr/design/mainframe/loghandler/DesignerLogHandler.java +++ b/designer-base/src/com/fr/design/mainframe/loghandler/DesignerLogHandler.java @@ -1,7 +1,6 @@ package com.fr.design.mainframe.loghandler; import com.fr.base.BaseUtils; -import com.fr.base.ServerConfig; import com.fr.base.FRContext; import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.imenu.UIMenuItem; @@ -38,9 +37,9 @@ import java.util.logging.LogRecord; import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER; public class DesignerLogHandler { - protected static final int INFO_INT = com.fr.third.apache.log4j.Level.INFO.toInt(); - protected static final int ERROR_INT = com.fr.third.apache.log4j.Level.ERROR.toInt(); - protected static final int WARN_INT = com.fr.third.apache.log4j.Level.WARN.toInt(); + protected static final int INFO_INT = Level.INFO.intValue(); + protected static final int ERROR_INT = Level.SEVERE.intValue(); + protected static final int WARN_INT = Level.WARNING.intValue(); private static final int GAP_X = -150; private static final int INFO_GAP_Y = -60; private static final int ERRO_GAP_Y = -40; 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 23393dcb29..ac5a2ab018 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 @@ -10,7 +10,6 @@ import com.fr.design.mainframe.loghandler.DesignerLogHandler; import com.fr.event.Event; import com.fr.event.EventDispatcher; import com.fr.event.Listener; -import com.fr.event.Null; import com.fr.general.LogRecordTime; import com.fr.general.LogUtils; import com.fr.log.FineLoggerFactory; @@ -43,18 +42,18 @@ public class DesignerSocketIO { }; static { - EventDispatcher.listen(EnvEvent.AFTER_SIGN_OUT, new Listener() { + EventDispatcher.listen(EnvEvent.AFTER_SIGN_OUT, new Listener() { @Override - public void on(Event event, Null param) { + public void on(Event event, EnvConfig param) { if (socketIO.isPresent()) { socketIO.get().close(); socketIO = Optional.absent(); } } }); - EventDispatcher.listen(EnvEvent.AFTER_SIGN_IN, new Listener() { + EventDispatcher.listen(EnvEvent.AFTER_SIGN_IN, new Listener() { @Override - public void on(Event event, Null param) { + public void on(Event event, EnvConfig param) { updateSocket(); } }); diff --git a/designer-base/src/com/fr/design/utils/DesignUtils.java b/designer-base/src/com/fr/design/utils/DesignUtils.java index 10573dd0e2..22cf51abab 100644 --- a/designer-base/src/com/fr/design/utils/DesignUtils.java +++ b/designer-base/src/com/fr/design/utils/DesignUtils.java @@ -1,13 +1,14 @@ 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.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; @@ -30,8 +31,11 @@ import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; import com.fr.start.ServerStarter; -import javax.swing.*; -import java.awt.*; +import javax.swing.JOptionPane; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import java.awt.Desktop; +import java.awt.Font; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.ByteArrayInputStream; @@ -183,20 +187,16 @@ public class DesignUtils { }); } - /** * 当前的报表运行环境切换到env * * @param env 需要切换去的环境 */ - public static void switchToEnv(Env env) { + public static void switchToEnv(EnvConfig env) { if (env == null) { return; } - Env oldEnv = FRContext.getCurrentEnv(); - String oldEnvPath = oldEnv == null ? null : oldEnv.getPath(); - // 看一下这个env在DesignerEnvManager里面有没有对应的,有的话就setCurrentEnvName DesignerEnvManager envManager = DesignerEnvManager.getEnvManager(); java.util.Iterator nameIt = envManager.getEnvNameIterator(); @@ -207,14 +207,11 @@ public class DesignUtils { break; } } - // 更新CurrentEnv于FRContext & DesignerEnvManager - FRContext.setCurrentEnv(env); - refreshDesignerFrame(env); + EnvContext.signIn(env); + refreshDesignerFrame(); } - public static void refreshDesignerFrame(Env env) { - - final Env run_env = env; + public static void refreshDesignerFrame() { // 刷新DesignerFrame里面的面板 SwingUtilities.invokeLater(new Runnable() { @@ -223,7 +220,7 @@ public class DesignUtils { if (DesignerContext.getDesignerFrame() == null) { return; } - DesignerContext.getDesignerFrame().refreshEnv(run_env); + DesignerContext.getDesignerFrame().refreshEnv(); DesignerContext.getDesignerFrame().repaint();// kunsnat: 切换环境后 刷新下 报表. 比如图表某些风格改变. } }); @@ -517,4 +514,4 @@ public class DesignUtils { } -} \ No newline at end of file +} diff --git a/designer-base/src/com/fr/env/RemoteEnv.java b/designer-base/src/com/fr/env/RemoteEnv.java index 8e17a4e22b..318ee267a4 100644 --- a/designer-base/src/com/fr/env/RemoteEnv.java +++ b/designer-base/src/com/fr/env/RemoteEnv.java @@ -41,6 +41,7 @@ import com.fr.stable.SvgProvider; import com.fr.stable.file.XMLFileManagerProvider; import com.fr.stable.project.ProjectConstants; import com.fr.stable.xml.XMLTools; +import com.fr.third.guava.base.Strings; import com.fr.third.guava.collect.ImmutableMap; import com.fr.web.ResourceConstants; @@ -75,6 +76,7 @@ import static com.fr.third.guava.base.Preconditions.checkArgument; * @author null */ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurable { + private static final String CERT_KEY = "javax.net.ssl.trustStore"; private static final String PWD_KEY = "javax.net.ssl.trustStorePassword"; private static final String HTTPS_PREFIX = "https:"; @@ -138,7 +140,6 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl } - /** * nameValuePairs,这个参数要接着this.path,拼成一个URL,否则服务器端req.getParameter是无法得到的 * @@ -214,7 +215,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl EnvConstants.USERNAME, getUser(), EnvConstants.PWD, getPassword()); String res = HttpToolbox.post(url, params, headers); - if (res == null) { + if (Strings.isNullOrEmpty(res)) { if (needMessage) { JOptionPane.showMessageDialog(component, Inter.getLocText("Datasource-Connection_failed")); } @@ -237,7 +238,7 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl return false; } else { if (needMessage) { - JOptionPane.showMessageDialog(component, Inter.getLocText(new String[]{"Datasource-Connection_failed", "Version-does-not-support"}, new String[]{",", "!"})); + JOptionPane.showMessageDialog(component, Inter.getLocText("Datasource-Connection_failed")); } else { FineLoggerFactory.getLogger().info(Inter.getLocText(new String[]{"Datasource-Connection_failed", "Version-does-not-support"}, new String[]{",", "!"})); } @@ -818,7 +819,6 @@ public class RemoteEnv extends AbstractEnv implements DesignAuthorityConfigurabl } - /** * 获取当前env的build文件路径 */ diff --git a/designer-base/src/com/fr/env/SignIn.java b/designer-base/src/com/fr/env/SignIn.java index 1e31677945..faa2c584f9 100644 --- a/designer-base/src/com/fr/env/SignIn.java +++ b/designer-base/src/com/fr/env/SignIn.java @@ -1,13 +1,11 @@ package com.fr.env; -import com.fr.base.FRContext; import com.fr.core.env.EnvConfig; import com.fr.core.env.EnvContext; import com.fr.core.env.EnvEvent; -import com.fr.core.env.resource.EnvConfigUtils; -import com.fr.core.env.resource.RemoteEnvConfig; -import com.fr.dav.LocalEnv; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.DesignerFrame; import com.fr.design.utils.DesignUtils; import com.fr.event.Event; import com.fr.event.EventDispatcher; @@ -17,7 +15,6 @@ import com.fr.general.ComparatorUtils; import com.fr.general.Inter; import javax.swing.JOptionPane; -import javax.swing.UIManager; public class SignIn { @@ -26,20 +23,14 @@ public class SignIn { EventDispatcher.listen(EnvEvent.CONNECTION_ERROR, new Listener() { @Override public void on(Event event, Null param) { - if (JOptionPane.showConfirmDialog(null, Inter.getLocText("FR-Remote_Connect2Server_Again"), UIManager.getString("OptionPane.titleText"), JOptionPane.YES_NO_OPTION) - == JOptionPane.OK_OPTION) { - try { - EnvContext.signIn(EnvContext.currentEnv()); - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage()); - } - } + JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText("Datasource-Connection_failed")); } }); } /** * 注册入环境 + * * @param selectedEnv 选择的环境 * @throws Exception 异常 */ @@ -47,15 +38,7 @@ public class SignIn { if (EnvContext.currentEnv() != null && !ComparatorUtils.equals(EnvContext.currentEnv(), selectedEnv)) { EnvContext.signOut(); } - EnvContext.signIn(selectedEnv); - DesignUtils.switchToEnv(trans(selectedEnv)); - } - private static com.fr.base.Env trans(EnvConfig env) { - if (env instanceof RemoteEnvConfig) { - return new RemoteEnv(env.getPath(), EnvConfigUtils.getUsername(env), EnvConfigUtils.getPassword(env)); - } else { - return new LocalEnv(); - } + DesignUtils.switchToEnv(selectedEnv); } } \ No newline at end of file diff --git a/designer-realize/src/com/fr/start/module/DesignerEnvProvider.java b/designer-realize/src/com/fr/start/module/DesignerEnvProvider.java index d7b3c975c9..f15b0a42b6 100644 --- a/designer-realize/src/com/fr/start/module/DesignerEnvProvider.java +++ b/designer-realize/src/com/fr/start/module/DesignerEnvProvider.java @@ -1,20 +1,29 @@ package com.fr.start.module; +import com.fr.base.FRContext; 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.serializer.OldSerializerAdapter; import com.fr.base.env.serializer.ProcedureDataModelSerializer; -import com.fr.base.env.user.RemoteUserCenter; -import com.fr.core.env.operator.user.UserCenter; +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.event.Event; +import com.fr.event.EventDispatcher; +import com.fr.event.Listener; import com.fr.file.filetree.FileNode; import com.fr.general.ComparatorUtils; import com.fr.module.Activator; @@ -44,181 +53,190 @@ public class DesignerEnvProvider extends Activator { } } initDesignerEnv(); - + getRoot().setSingleton(EnvSwitcher.class, new EnvSwitcher()); //设置好环境即可,具体跟环境有关的模块会自动调用 getRoot().getSingleton(EnvSwitcher.class).switch2LastEnv(); } - + private void initDesignerEnv() { - addSerializers(); - EnvProxy.addRemoteService(UserCenter.class, new RemoteUserCenter()); + 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()); + } + } + }); } - - + + private void addSerializers() { - + EnvProxy.addSerializer(ProcedureDataModel[].class, new ProcedureDataModelSerializer()); - + EnvProxy.addSerializer(ModifiedTable.class, new OldSerializerAdapter( - new OldSerializerAdapter.OldSerializer() { - - @Override - public void serializer(ModifiedTable obj, OutputStream out) throws Exception { - - DavXMLUtils.writeXMLModifiedTables(obj, out); - } - }, - new OldSerializerAdapter.OldDeserializer() { - - @Override - public ModifiedTable deserializer(InputStream in) throws Exception { - - return DavXMLUtils.readXMLModifiedTables(in); + new OldSerializerAdapter.OldSerializer() { + + @Override + public void serializer(ModifiedTable obj, OutputStream out) throws Exception { + + DavXMLUtils.writeXMLModifiedTables(obj, out); + } + }, + new OldSerializerAdapter.OldDeserializer() { + + @Override + public ModifiedTable deserializer(InputStream in) throws Exception { + + return DavXMLUtils.readXMLModifiedTables(in); + } } - } )); - + EnvProxy.addSerializer(com.fr.data.impl.Connection.class, new OldSerializerAdapter( - new OldSerializerAdapter.OldSerializer() { - - @Override - public void serializer(Connection obj, OutputStream out) { - - DavXMLUtils.writeXMLFileDatabaseConnection(obj, out); - } - }, - new OldSerializerAdapter.OldDeserializer() { - - @Override - public Connection deserializer(InputStream in) throws Exception { - - return DavXMLUtils.readXMLDatabaseConnection(in); + new OldSerializerAdapter.OldSerializer() { + + @Override + public void serializer(Connection obj, OutputStream out) { + + DavXMLUtils.writeXMLFileDatabaseConnection(obj, out); + } + }, + new OldSerializerAdapter.OldDeserializer() { + + @Override + public Connection deserializer(InputStream in) throws Exception { + + return DavXMLUtils.readXMLDatabaseConnection(in); + } } - } )); - + EnvProxy.addSerializer(FileNode[].class, new OldSerializerAdapter( - new OldSerializerAdapter.OldSerializer() { - - @Override - public void serializer(FileNode[] obj, OutputStream out) { - - DavXMLUtils.writeXMLFileNodes(obj, out); - } - }, - new OldSerializerAdapter.OldDeserializer() { - - @Override - public FileNode[] deserializer(InputStream in) { - - return DavXMLUtils.readXMLFileNodes(in); + new OldSerializerAdapter.OldSerializer() { + + @Override + public void serializer(FileNode[] obj, OutputStream out) { + + DavXMLUtils.writeXMLFileNodes(obj, out); + } + }, + new OldSerializerAdapter.OldDeserializer() { + + @Override + public FileNode[] deserializer(InputStream in) { + + return DavXMLUtils.readXMLFileNodes(in); + } } - } )); - + EnvProxy.addSerializer(TableProcedure[].class, new OldSerializerAdapter( - new OldSerializerAdapter.OldSerializer() { - - @Override - public void serializer(TableProcedure[] obj, OutputStream out) { - - DavXMLUtils.writeXMLFileSQLTable(obj, out); - } - }, - new OldSerializerAdapter.OldDeserializer() { - - @Override - public TableProcedure[] deserializer(InputStream in) throws Exception { - - return DavXMLUtils.readXMLSQLTables(in); + new OldSerializerAdapter.OldSerializer() { + + @Override + public void serializer(TableProcedure[] obj, OutputStream out) { + + DavXMLUtils.writeXMLFileSQLTable(obj, out); + } + }, + new OldSerializerAdapter.OldDeserializer() { + + @Override + public TableProcedure[] deserializer(InputStream in) throws Exception { + + return DavXMLUtils.readXMLSQLTables(in); + } } - } )); - + EnvProxy.addSerializer(TableData.class, new OldSerializerAdapter( - new OldSerializerAdapter.OldSerializer() { - - @Override - public void serializer(TableData obj, OutputStream out) { - - DavXMLUtils.writeXMLFileTableData(obj, out); - } - }, - new OldSerializerAdapter.OldDeserializer() { - - @Override - public TableData deserializer(InputStream in) throws Exception { - - return DavXMLUtils.readXMLTableData(in); + new OldSerializerAdapter.OldSerializer() { + + @Override + public void serializer(TableData obj, OutputStream out) { + + DavXMLUtils.writeXMLFileTableData(obj, out); + } + }, + new OldSerializerAdapter.OldDeserializer() { + + @Override + public TableData deserializer(InputStream in) throws Exception { + + return DavXMLUtils.readXMLTableData(in); + } } - } )); - + EnvProxy.addSerializer(Parameter[].class, new OldSerializerAdapter( - new OldSerializerAdapter.OldSerializer() { - - @Override - public void serializer(Parameter[] obj, OutputStream out) { - - DavXMLUtils.writeXMLFileParameters(obj, out); - } - }, - new OldSerializerAdapter.OldDeserializer() { - - @Override - public Parameter[] deserializer(InputStream in) throws Exception { - - return DavXMLUtils.readXMLParameters(in); + new OldSerializerAdapter.OldSerializer() { + + @Override + public void serializer(Parameter[] obj, OutputStream out) { + + DavXMLUtils.writeXMLFileParameters(obj, out); + } + }, + new OldSerializerAdapter.OldDeserializer() { + + @Override + public Parameter[] deserializer(InputStream in) throws Exception { + + return DavXMLUtils.readXMLParameters(in); + } } - } )); - + EnvProxy.addSerializer(StoreProcedure.class, new OldSerializerAdapter( - new OldSerializerAdapter.OldSerializer() { - - @Override - public void serializer(StoreProcedure obj, OutputStream out) { - - DavXMLUtils.writeXMLFileStoreProcedure(obj, out); - } - }, - new OldSerializerAdapter.OldDeserializer() { - - @Override - public StoreProcedure deserializer(InputStream in) throws Exception { - - return DavXMLUtils.readXMLStoreProcedure(in); + new OldSerializerAdapter.OldSerializer() { + + @Override + public void serializer(StoreProcedure obj, OutputStream out) { + + DavXMLUtils.writeXMLFileStoreProcedure(obj, out); + } + }, + new OldSerializerAdapter.OldDeserializer() { + + @Override + public StoreProcedure deserializer(InputStream in) throws Exception { + + return DavXMLUtils.readXMLStoreProcedure(in); + } } - } )); - + EnvProxy.addSerializer(StoreProcedureParameter[].class, new OldSerializerAdapter( - new OldSerializerAdapter.OldSerializer() { - - @Override - public void serializer(StoreProcedureParameter[] obj, OutputStream out) { - - DavXMLUtils.writeXMLFileParameters(obj, out); - } - }, - new OldSerializerAdapter.OldDeserializer() { - - @Override - public StoreProcedureParameter[] deserializer(InputStream in) throws Exception { - - return DavXMLUtils.readXMLStoreProcedureParameters(in); + new OldSerializerAdapter.OldSerializer() { + + @Override + public void serializer(StoreProcedureParameter[] obj, OutputStream out) { + + DavXMLUtils.writeXMLFileParameters(obj, out); + } + }, + new OldSerializerAdapter.OldDeserializer() { + + @Override + public StoreProcedureParameter[] deserializer(InputStream in) throws Exception { + + return DavXMLUtils.readXMLStoreProcedureParameters(in); + } } - } )); } - + @Override public void stop() { //清空模块 getRoot().removeSingleton(EnvSwitcher.class); } - - + + } diff --git a/designer-realize/src/com/fr/start/module/DesignerModuleActivator.java b/designer-realize/src/com/fr/start/module/DesignerModuleActivator.java index b6abbdf85c..276c9de347 100644 --- a/designer-realize/src/com/fr/start/module/DesignerModuleActivator.java +++ b/designer-realize/src/com/fr/start/module/DesignerModuleActivator.java @@ -14,25 +14,25 @@ import com.fr.stable.module.ModuleListener; * 之后慢慢将DesignerModule拆成Activator */ public class DesignerModuleActivator extends Activator implements Prepare { - + @Override public void start() { - + ModuleContext.registerModuleListener(getModule().upFindSingleton(ModuleListener.class)); ModuleContext.startModule(DesignerModule.class.getName()); ModuleContext.clearModuleListener(); DesignerSocketIO.init(); } - + @Override public void stop() { - + } - + @Override public void prepare() { - + addMutable(InterMutableKey.Path, "com/fr/design/i18n/main", "com/fr/design/i18n/chart"); } }