Browse Source

Merge pull request #52 in DESIGN/design from ~HZZZ/design-100000:env to feature/10.0

* commit '3838b06108bc132d2508c5bfb8023872cc9f7e40':
  check
  merge
  merge
  merge
  merge
  start designer socket client
  merge
  merge
  env..
master
superman 7 years ago
parent
commit
10dfb0293a
  1. 167
      designer-base/src/com/fr/design/DesignerEnvManager.java
  2. 29
      designer-base/src/com/fr/design/actions/file/SwitchExistEnv.java
  3. 47
      designer-base/src/com/fr/design/file/TemplateTreePane.java
  4. 8
      designer-base/src/com/fr/design/mainframe/DesignerFrame.java
  5. 32
      designer-base/src/com/fr/design/mainframe/DesignerFrameFileDealerPane.java
  6. 34
      designer-base/src/com/fr/design/mainframe/TemplatePane.java
  7. 5
      designer-base/src/com/fr/design/mainframe/loghandler/DesignerLogHandler.java
  8. 88
      designer-base/src/com/fr/design/mainframe/loghandler/socketio/DesignerSocketIO.java
  9. 11
      designer-base/src/com/fr/env/EnvListPane.java
  10. 9
      designer-base/src/com/fr/env/LocalEnvPane.java
  11. 1384
      designer-base/src/com/fr/env/RemoteEnv.java
  12. 22
      designer-base/src/com/fr/env/RemoteEnvPane.java
  13. 83
      designer-base/src/com/fr/env/RemoteEnvUtils.java
  14. 62
      designer-base/src/com/fr/env/SignIn.java
  15. 3
      designer-realize/src/com/fr/start/module/DesignerModuleActivator.java

167
designer-base/src/com/fr/design/DesignerEnvManager.java

@ -4,13 +4,14 @@
package com.fr.design;
import com.fr.base.BaseXMLUtils;
import com.fr.base.Env;
import com.fr.base.FRContext;
import com.fr.base.Utils;
import com.fr.dav.LocalEnv;
import com.fr.base.env.resource.EnvConfigUtils;
import com.fr.base.env.resource.LocalEnvConfig;
import com.fr.base.env.resource.RemoteEnvConfig;
import com.fr.core.env.EnvConfig;
import com.fr.design.actions.help.alphafine.AlphaFineConfigManager;
import com.fr.design.constants.UIConstants;
import com.fr.env.RemoteEnv;
import com.fr.env.SignIn;
import com.fr.file.FILEFactory;
import com.fr.general.ComparatorUtils;
@ -72,7 +73,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
private boolean showPaintToolBar = true;
private int maxNumberOrPreviewRow = 200;
// name和Env的键值对
private Map<String, Env> nameEnvMap = new ListMap();
private Map<String, EnvConfig> nameEnvMap = new ListMap();
// marks: 当前报表服务器名字
private String curEnvName = null;
private boolean showProjectPane = true;
@ -191,7 +192,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
if (installHome != null) {
String name = Inter.getLocText("FR-Engine_DEFAULT");
String envPath = StableUtils.pathJoin(new String[]{installHome, ProjectConstants.WEBAPP_NAME, ProjectConstants.WEBINF_NAME});
designerEnvManager.putEnv(name, LocalEnv.createEnv(envPath));
designerEnvManager.putEnv(name, new LocalEnvConfig(envPath));
designerEnvManager.setCurEnvName(name);
}
}
@ -323,7 +324,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
FRContext.getLogger().error(e.getMessage(), e);
}
// 清空前一个版本中的工作目录和最近打开
nameEnvMap = new ListMap<String, Env>();
nameEnvMap = new ListMap<String, EnvConfig>();
recentOpenedFilePathList = new ArrayList<String>();
curEnvName = null;
designerEnvManager.saveXMLFile();
@ -470,7 +471,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
* @return 是默认则返回true
*/
public boolean isCurrentEnvDefault() {
Env currentEnv = this.getEnv(curEnvName);
EnvConfig currentEnv = this.getEnv(curEnvName);
String defaultEnvPath = StableUtils.pathJoin(new String[]{StableUtils.getInstallHome(), ProjectConstants.WEBAPP_NAME, ProjectConstants.WEBINF_NAME});
return ComparatorUtils.equals(new File(defaultEnvPath).getPath(), currentEnv.getPath());
}
@ -478,21 +479,19 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
/**
* 返回默认环境
*/
public Env getDefaultEnv() {
public EnvConfig getDefaultEnv() {
String installHome = StableUtils.getInstallHome();
String defaultenvPath = StableUtils.pathJoin(new String[]{installHome, ProjectConstants.WEBAPP_NAME, ProjectConstants.WEBINF_NAME});
String defaultenvPath = StableUtils.pathJoin(installHome, ProjectConstants.WEBAPP_NAME, ProjectConstants.WEBINF_NAME);
defaultenvPath = new File(defaultenvPath).getPath();
if (nameEnvMap.size() >= 0) {
Iterator<Entry<String, Env>> entryIt = nameEnvMap.entrySet().iterator();
while (entryIt.hasNext()) {
Entry<String, Env> entry = entryIt.next();
Env env = entry.getValue();
if (ComparatorUtils.equals(defaultenvPath, env.getPath())) {
return env;
}
Iterator<Entry<String, EnvConfig>> entryIt = nameEnvMap.entrySet().iterator();
while (entryIt.hasNext()) {
Entry<String, EnvConfig> entry = entryIt.next();
EnvConfig env = entry.getValue();
if (ComparatorUtils.equals(defaultenvPath, env.getPath())) {
return env;
}
}
Env newDefaultEnv = LocalEnv.createEnv(defaultenvPath);
EnvConfig newDefaultEnv = new LocalEnvConfig(defaultenvPath);
this.putEnv(Inter.getLocText(new String[]{"Default", "Utils-Report_Runtime_Env"}), newDefaultEnv);
return newDefaultEnv;
}
@ -505,10 +504,10 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
String defaultenvPath = StableUtils.pathJoin(new String[]{installHome, ProjectConstants.WEBAPP_NAME, ProjectConstants.WEBINF_NAME});
defaultenvPath = new File(defaultenvPath).getPath();
if (nameEnvMap.size() >= 0) {
Iterator<Entry<String, Env>> entryIt = nameEnvMap.entrySet().iterator();
Iterator<Entry<String, EnvConfig>> entryIt = nameEnvMap.entrySet().iterator();
while (entryIt.hasNext()) {
Entry<String, Env> entry = entryIt.next();
Env env = entry.getValue();
Entry<String, EnvConfig> entry = entryIt.next();
EnvConfig env = entry.getValue();
if (ComparatorUtils.equals(defaultenvPath, env.getPath())) {
return entry.getKey();
}
@ -680,7 +679,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
/**
* 根据名称返回环境
*/
public Env getEnv(String name) {
public EnvConfig getEnv(String name) {
return this.nameEnvMap.get(name);
}
@ -690,7 +689,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
* @param name 名称
* @param env 对应的环境
*/
public void putEnv(String name, Env env) {
public void putEnv(String name, EnvConfig env) {
this.nameEnvMap.put(name, env);
}
@ -1401,7 +1400,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
if ((tmpVal = reader.getAttrAsString("webinfLocation", null)) != null) {
// marks:兼容6.1的
// marks:设置默认的目录.
Env reportServer = LocalEnv.createEnv(tmpVal);
EnvConfig reportServer = new LocalEnvConfig(tmpVal);
String curReportServerName = Inter.getLocText("Server-Embedded_Server");
this.putEnv(curReportServerName, reportServer);
@ -1454,11 +1453,11 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
}
if (reader.isChildNode()) {
if (reader.getTagName().equals("Env")) { // description.
if (reader.getTagName().contains("Env")) { // description.
// marks:获取名字
String reportServerName = reader.getAttrAsString("name", null);
Env env = readEnv(reader);
EnvConfig env = readEnv(reader);
if (env == null) {
return;
}
@ -1584,7 +1583,7 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
Iterator<String> nameIt = this.getEnvNameIterator();
while (nameIt.hasNext()) {
String envName = nameIt.next();
Env env = this.getEnv(envName);
EnvConfig env = this.getEnv(envName);
writeEnv(writer, envName, env);
}
@ -1743,44 +1742,44 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
}
/*
* 写Env为xml
*/
private static void writeEnv(XMLPrintWriter writer, String name, Env env) {
* 写Env为xml
*/
private static void writeEnv(XMLPrintWriter writer, String name, EnvConfig env) {
if (env == null) {
return;
}
writer.startTAG("Env");
writer.startTAG("EnvConfig");
writer.classAttr(env.getClass());
writer.attr("name", name);
env.writeXML(writer);
EnvConfigXMLAdapter xmlAdapter = env instanceof RemoteEnvConfig
? new RemoteEnvConfigXMLAdapter()
: new LocalEnvConfigXMLAdapter();
xmlAdapter.fromEnvConfig(env).writeXML(writer);
writer.end();
}
/*
* 从xml读Env
*/
private static Env readEnv(XMLableReader reader) {
Env env = null;
* 从xml读Env
*/
private static EnvConfig readEnv(XMLableReader reader) {
EnvConfigXMLAdapter xmlAdapter = null;
String tmpVal; //temp value
if ((tmpVal = reader.getAttrAsString("class", null)) != null) {
if (tmpVal.endsWith(".LocalEnv")) {
env = LocalEnv.createEnv();
} else if (tmpVal.endsWith(".RemoteEnv")) {
env = new RemoteEnv();
if (tmpVal.contains(".LocalEnv")) {
xmlAdapter = new LocalEnvConfigXMLAdapter();
} else if (tmpVal.contains(".RemoteEnv")) {
xmlAdapter = new RemoteEnvConfigXMLAdapter();
}
}
if (env == null) {
return env;
if (xmlAdapter == null) {
return null;
}
reader.readXMLObject(env);
return env;
reader.readXMLObject(xmlAdapter);
return xmlAdapter.toEnvConfig();
}
public AlphaFineConfigManager getAlphaFineConfigManager() {
@ -1790,4 +1789,78 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
public void setAlphaFineConfigManager(AlphaFineConfigManager alphaFineConfigManager) {
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;
}
}
}

29
designer-base/src/com/fr/design/actions/file/SwitchExistEnv.java

@ -1,14 +1,14 @@
package com.fr.design.actions.file;
import com.fr.base.BaseUtils;
import com.fr.base.Env;
import com.fr.base.FRContext;
import com.fr.dav.LocalEnv;
import com.fr.base.env.resource.LocalEnvConfig;
import com.fr.base.env.resource.RemoteEnvConfig;
import com.fr.core.env.EnvConfig;
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.dialog.InformationWarnPane;
import com.fr.design.file.HistoryTemplateListPane;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.JTemplate;
@ -18,20 +18,15 @@ 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.ComparatorUtils;
import com.fr.general.FRLogger;
import com.fr.general.GeneralContext;
import com.fr.general.Inter;
import com.fr.stable.EnvChangedListener;
import com.fr.stable.ProductConstants;
import com.fr.stable.StringUtils;
import javax.swing.*;
import javax.swing.JOptionPane;
import java.awt.event.ActionEvent;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.logging.Level;
public class SwitchExistEnv extends MenuDef {
@ -71,10 +66,10 @@ public class SwitchExistEnv extends MenuDef {
public GetExistEnvAction(String envName) {
this.setName(envName);
Env env = DesignerEnvManager.getEnvManager().getEnv(envName);
if (env instanceof LocalEnv) {
EnvConfig env = DesignerEnvManager.getEnvManager().getEnv(envName);
if (env instanceof LocalEnvConfig) {
this.setSmallIcon(BaseUtils.readIcon("com/fr/design/images/data/bind/localconnect.png"));
} else if (env instanceof RemoteEnv) {
} else if (env instanceof RemoteEnvConfig) {
this.setSmallIcon(BaseUtils.readIcon("com/fr/design/images/data/bind/distanceconnect.png"));
}
}
@ -102,20 +97,12 @@ public class SwitchExistEnv extends MenuDef {
*/
public void actionPerformed(ActionEvent e) {
DesignerEnvManager envManager = DesignerEnvManager.getEnvManager();
Env selectedEnv = envManager.getEnv(this.getName());
EnvConfig selectedEnv = envManager.getEnv(this.getName());
try {
if (selectedEnv instanceof RemoteEnv && !((RemoteEnv) selectedEnv).testServerConnection()) {
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText(new String[]{"M-SwitchWorkspace", "Failed"}));
return;
}
String remoteVersion = selectedEnv.getDesignerVersion();
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");
FRLogger.getLogger().log(Level.WARNING, infor);
new InformationWarnPane(infor, moreInfo, Inter.getLocText("Tooltips")).show();
return;
}
SignIn.signIn(selectedEnv);
HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().refreshToolArea();
fireDSChanged();

47
designer-base/src/com/fr/design/file/TemplateTreePane.java

@ -143,7 +143,7 @@ public class TemplateTreePane extends JPanel implements FileOperations {
public void openContainerFolder() {
FileNode fn = TemplateTreePane.this.reportletsTree.getSelectedFileNode();
LocalEnv localEnv = (LocalEnv) FRContext.getCurrentEnv();
String filePath = StableUtils.pathJoin(localEnv.path, fn.getEnvPath());
String filePath = StableUtils.pathJoin(localEnv.getPath(), fn.getEnvPath());
filePath = filePath.substring(0, filePath.lastIndexOf(CoreConstants.SEPARATOR));
try {
Desktop.getDesktop().open(new File(filePath));
@ -193,6 +193,16 @@ public class TemplateTreePane extends JPanel implements FileOperations {
reportletsTree.refresh();
}
@Override
public void lockFile() {
throw new UnsupportedOperationException("unsupport now");
}
@Override
public void unLockFile() {
throw new UnsupportedOperationException("unsupport now");
}
private void deleteHistory(String fileName) {
int index = HistoryTemplateListPane.getInstance().contains(fileName);
int size = HistoryTemplateListPane.getInstance().getHistoryCount();
@ -218,41 +228,6 @@ public class TemplateTreePane extends JPanel implements FileOperations {
MutilTempalteTabPane.getInstance().repaint();
}
/**
* 加上文件锁
*/
public void lockFile() {
FileNode fn = reportletsTree.getSelectedFileNode();
RemoteEnv remoteEnv = (RemoteEnv) FRContext.getCurrentEnv();
if (fn == null) {
return;
}
try {
remoteEnv.getLock(new String[]{fn.getEnvPath()});
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), e.getMessage());
}
reportletsTree.refresh();
}
/**
* 文件解锁
*/
public void unLockFile() {
FileNode fn = reportletsTree.getSelectedFileNode();
if (fn == null) {
return;
}
RemoteEnv remoteEnv = (RemoteEnv) FRContext.getCurrentEnv();
try {
remoteEnv.releaseLock(new String[]{fn.getEnvPath()});
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), e.getMessage());
}
reportletsTree.refresh();
}
public String getSelectedTemplatePath() {
return reportletsTree.getSelectedTemplatePath();

8
designer-base/src/com/fr/design/mainframe/DesignerFrame.java

@ -6,6 +6,8 @@ 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.resource.EnvConfigUtils;
import com.fr.core.env.EnvConfig;
import com.fr.design.DesignModelAdapter;
import com.fr.design.DesignState;
import com.fr.design.DesignerEnvManager;
@ -640,10 +642,10 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta
defaultTitleSB.append(ProductConstants.BRANCH);
// james:标识登录的用户和登录的ENV
String envName = DesignerEnvManager.getEnvManager().getCurEnvName();
Env env = DesignerEnvManager.getEnvManager().getEnv(envName);
EnvConfig env = DesignerEnvManager.getEnvManager().getEnv(envName);
if (env != null) {
defaultTitleSB.append(env.getUser()).append('@').append(envName).append('[');
defaultTitleSB.append(env.getEnvDescription());
defaultTitleSB.append(EnvConfigUtils.getUsername(env)).append('@').append(envName).append('[');
defaultTitleSB.append(Inter.getLocText("Env-Remote_Server"));
defaultTitleSB.append(']');
if (editingTemplate != null) {
String path = editingTemplate.getEditingFILE().getPath();

32
designer-base/src/com/fr/design/mainframe/DesignerFrameFileDealerPane.java

@ -249,38 +249,6 @@ public class DesignerFrameFileDealerPane extends JPanel implements FileToolbarSt
}
}
/*
* 加锁
*/
private class GetLockAction extends UpdateAction {
public GetLockAction() {
this.setName(Inter.getLocText("FR-Designer_Get_Lock"));
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/control/lock.png"));
}
@Override
public void actionPerformed(ActionEvent evt) {
selectedOperation.lockFile();
}
}
/*
* 解锁
*/
private class ReleaseLockAction extends UpdateAction {
public ReleaseLockAction() {
this.setName(Inter.getLocText("FR-Designer_Release_Lock"));
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/control/unlock.png"));
}
@Override
public void actionPerformed(ActionEvent evt) {
selectedOperation.unLockFile();
}
}
/**
* 按钮状态改变
*/

34
designer-base/src/com/fr/design/mainframe/TemplatePane.java

@ -1,7 +1,7 @@
package com.fr.design.mainframe;
import com.fr.base.BaseUtils;
import com.fr.base.Env;
import com.fr.core.env.EnvConfig;
import com.fr.dav.LocalEnv;
import com.fr.design.DesignModelAdapter;
import com.fr.design.DesignerEnvManager;
@ -22,8 +22,19 @@ import com.fr.stable.EnvChangedListener;
import com.fr.stable.ProductConstants;
import com.fr.stable.StringUtils;
import javax.swing.*;
import java.awt.*;
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 java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
@ -97,6 +108,7 @@ public class TemplatePane extends JPanel implements MouseListener {
/**
* 是否可扩展
*
* @return 同上
*/
public boolean IsExpanded() {
@ -111,7 +123,7 @@ public class TemplatePane extends JPanel implements MouseListener {
private boolean envListOkAction(EnvListPane envListPane) {
String selectedName = envListPane.updateEnvManager();
DesignerEnvManager envManager = DesignerEnvManager.getEnvManager();
Env selectedEnv = envManager.getEnv(selectedName);
EnvConfig selectedEnv = envManager.getEnv(selectedName);
GeneralContext.fireEnvWillChangeListener();
try {
//如果是远程的还要先测试下,如果失败就不切换
@ -120,7 +132,7 @@ public class TemplatePane extends JPanel implements MouseListener {
JOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(), Inter.getLocText(new String[]{"M-SwitchWorkspace", "Failed"}));
return false;
} else {
String remoteVersion = selectedEnv.getDesignerVersion();
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");
@ -147,6 +159,11 @@ public class TemplatePane extends JPanel implements MouseListener {
return true;
}
private String getDesignerVersion(EnvConfig selectedEnv) {
// return selectedEnv.getDesignerVersion();
throw new UnsupportedOperationException("unsupport now");
}
/**
* 编辑items
*/
@ -161,7 +178,7 @@ public class TemplatePane extends JPanel implements MouseListener {
}
public void doCancel() {
envListDialog.setVisible(false);
envListDialog.setVisible(false);
}
});
envListDialog.setVisible(true);
@ -209,6 +226,7 @@ public class TemplatePane extends JPanel implements MouseListener {
/**
* 鼠标点击
*
* @param e 事件
*/
@Override
@ -217,6 +235,7 @@ public class TemplatePane extends JPanel implements MouseListener {
/**
* 鼠标按下
*
* @param e 事件
*/
@Override
@ -231,6 +250,7 @@ public class TemplatePane extends JPanel implements MouseListener {
/**
* 鼠标放开
*
* @param e 事件
*/
@Override
@ -239,6 +259,7 @@ public class TemplatePane extends JPanel implements MouseListener {
/**
* 鼠标进入
*
* @param e 事件
*/
@Override
@ -247,6 +268,7 @@ public class TemplatePane extends JPanel implements MouseListener {
/**
* 鼠标离开
*
* @param e 事件
*/
@Override

5
designer-base/src/com/fr/design/mainframe/loghandler/DesignerLogHandler.java

@ -11,6 +11,7 @@ import com.fr.general.FRLogLevel;
import com.fr.general.FRLogger;
import com.fr.general.GeneralContext;
import com.fr.general.Inter;
import com.fr.general.LogRecordTime;
import com.fr.log.LogHandler;
import com.fr.stable.EnvChangedListener;
import com.fr.stable.xml.LogRecordTimeProvider;
@ -149,6 +150,10 @@ public class DesignerLogHandler {
logHandlerArea.printStackTrace(message, level, date);
}
public void printRemoteLog(LogRecordTime logRecordTime) {
logHandlerArea.printStackTrace(logRecordTime);
}
private class LogHandlerArea extends JPanel {
private static final long serialVersionUID = 8215630927304621660L;

88
designer-base/src/com/fr/design/mainframe/loghandler/socketio/DesignerSocketIO.java

@ -0,0 +1,88 @@
package com.fr.design.mainframe.loghandler.socketio;
import com.fr.base.env.EnvContext;
import com.fr.base.env.resource.LocalEnvConfig;
import com.fr.core.env.EnvConfig;
import com.fr.core.env.EnvConstants;
import com.fr.core.env.EnvEvents;
import com.fr.decision.webservice.utils.DecisionServiceConstants;
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;
import com.fr.third.guava.base.Optional;
import com.fr.web.WebSocketConfig;
import io.socket.client.IO;
import io.socket.client.Socket;
import io.socket.emitter.Emitter;
import java.io.ByteArrayInputStream;
import java.net.URI;
import java.net.URL;
public class DesignerSocketIO {
private static Optional<Socket> socketIO = Optional.absent();
private static final Emitter.Listener printLog = new Emitter.Listener() {
@Override
public void call(Object... objects) {
try {
LogRecordTime[] logRecordTimes = LogUtils.readXMLLogRecords(new ByteArrayInputStream((byte[]) objects[0]));
for (LogRecordTime logRecordTime : logRecordTimes) {
DesignerLogHandler.getInstance().printRemoteLog(logRecordTime);
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
};
static {
EventDispatcher.listen(EnvEvents.AFTER_SIGN_OUT, new Listener<Null>() {
@Override
public void on(Event event, Null param) {
if (socketIO.isPresent()) {
socketIO.get().close();
socketIO = Optional.absent();
}
}
});
EventDispatcher.listen(EnvEvents.AFTER_SIGN_IN, new Listener<Null>() {
@Override
public void on(Event event, Null param) {
updateSocket();
}
});
}
public static void init() {
updateSocket();
}
private static void updateSocket() {
EnvConfig env = EnvContext.currentEnv();
if (env instanceof LocalEnvConfig) {
return;
}
try {
String uri = String.format("http://%s:%s%s?%s=%s",
new URL(env.getPath()).getHost(),
WebSocketConfig.getInstance().getPort(),
EnvConstants.WS_NAMESPACE,
DecisionServiceConstants.WEB_SOCKET_TOKEN_NAME,
EnvContext.currentToken());
socketIO = Optional.of(IO.socket(new URI(uri)));
socketIO.get().on(EnvConstants.WS_LOGRECORD, printLog);
socketIO.get().connect();
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
}
}

11
designer-base/src/com/fr/env/EnvListPane.java vendored

@ -1,7 +1,8 @@
package com.fr.env;
import com.fr.base.Env;
import com.fr.dav.LocalEnv;
import com.fr.base.env.resource.LocalEnvConfig;
import com.fr.base.env.resource.RemoteEnvConfig;
import com.fr.core.env.EnvConfig;
import com.fr.design.DesignerEnvManager;
import com.fr.design.gui.controlpane.JListControlPane;
import com.fr.design.gui.controlpane.NameObjectCreator;
@ -59,9 +60,9 @@ public class EnvListPane extends JListControlPane {
@Override
public NameableCreator[] createNameableCreators() {
NameableCreator local = new NameObjectCreator(Inter.getLocText("Env-Local_Directory"), "com/fr/design/images/data/bind/localconnect.png",
LocalEnv.class, LocalEnvPane.class);
LocalEnvConfig.class, LocalEnvPane.class);
NameableCreator remote = new NameObjectCreator(Inter.getLocText("Env-Remote_Server"), "com/fr/design/images/data/bind/distanceconnect.png",
RemoteEnv.class, RemoteEnvPane.class);
RemoteEnvConfig.class, RemoteEnvPane.class);
return new NameableCreator[]{local, remote};
}
@ -104,7 +105,7 @@ public class EnvListPane extends JListControlPane {
Nameable[] res = this.update();
for (Nameable re : res) {
NameObject nameObject = (NameObject) re;
mgr.putEnv(nameObject.getName(), (Env) nameObject.getObject());
mgr.putEnv(nameObject.getName(), (EnvConfig) nameObject.getObject());
}
return this.getSelectedName();
}

9
designer-base/src/com/fr/env/LocalEnvPane.java vendored

@ -1,5 +1,6 @@
package com.fr.env;
import com.fr.base.env.resource.LocalEnvConfig;
import com.fr.dav.LocalEnv;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.gui.ilable.UILabel;
@ -21,7 +22,7 @@ import java.io.File;
/**
* @author yaohwu
*/
public class LocalEnvPane extends BasicBeanPane<LocalEnv> {
public class LocalEnvPane extends BasicBeanPane<LocalEnvConfig> {
private UITextField pathTextField;
private JFileTree localEnvTree;
@ -70,9 +71,9 @@ public class LocalEnvPane extends BasicBeanPane<LocalEnv> {
}
@Override
public LocalEnv updateBean() {
public LocalEnvConfig updateBean() {
String path = pathTextField.getText();
return LocalEnv.createEnv(path);
return new LocalEnvConfig(path);
}
public String getPath() {
@ -80,7 +81,7 @@ public class LocalEnvPane extends BasicBeanPane<LocalEnv> {
}
@Override
public void populateBean(LocalEnv ob) {
public void populateBean(LocalEnvConfig ob) {
if (StringUtils.isBlank(ob.getPath())) {
return;
}

1384
designer-base/src/com/fr/env/RemoteEnv.java vendored

File diff suppressed because it is too large Load Diff

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

@ -1,6 +1,8 @@
package com.fr.env;
import com.fr.base.FRContext;
import com.fr.base.env.resource.EnvConfigUtils;
import com.fr.base.env.resource.RemoteEnvConfig;
import com.fr.design.DesignerEnvManager;
import com.fr.design.beans.BasicBeanPane;
import com.fr.design.border.UITitledBorder;
@ -49,7 +51,7 @@ import static com.fr.design.layout.TableLayout.PREFERRED;
/**
* @author yaohwu
*/
public class RemoteEnvPane extends BasicBeanPane<RemoteEnv> {
public class RemoteEnvPane extends BasicBeanPane<RemoteEnvConfig> {
private static final Color TIPS_FONT_COLOR = new Color(0x8f8f92);
@ -100,7 +102,7 @@ public class RemoteEnvPane extends BasicBeanPane<RemoteEnv> {
/**
* 主机位置
*/
private RemoteEnvURL remoteEnvURL;
private RemoteEnvURL remoteEnvURL = new RemoteEnvURL("");
/**
* https 配置面板
*/
@ -151,6 +153,7 @@ public class RemoteEnvPane extends BasicBeanPane<RemoteEnv> {
@Override
public void removeUpdate(DocumentEvent e) {
actionURLInputChange();
}
@ -250,7 +253,7 @@ public class RemoteEnvPane extends BasicBeanPane<RemoteEnv> {
}
@Override
public void populateBean(RemoteEnv ob) {
public void populateBean(RemoteEnvConfig ob) {
if (StringUtils.isEmpty(ob.getPath())) {
remoteEnvURL = RemoteEnvURL.createDefaultURL();
@ -265,18 +268,20 @@ public class RemoteEnvPane extends BasicBeanPane<RemoteEnv> {
fileChooserButton.setEnabled(remoteEnvURL.getHttps());
updateHttpsConfigPanel();
this.usernameInput.setText(ob.getUser() == null ? StringUtils.EMPTY : ob.getUser());
String username = EnvConfigUtils.getUsername(ob);
String pwd = EnvConfigUtils.getPassword(ob);
this.usernameInput.setText(username == null ? StringUtils.EMPTY : pwd);
this.passwordInput.setText(ob.getPassword() == null ? StringUtils.EMPTY : ob.getPassword());
}
@Override
public RemoteEnv updateBean() {
public RemoteEnvConfig updateBean() {
String path = remoteEnvURL.getURL();
String user = this.usernameInput.getText();
String password = new String(this.passwordInput.getPassword());
return new RemoteEnv(path, user, password);
return new RemoteEnvConfig(path, user, password);
}
@Override
@ -465,11 +470,8 @@ public class RemoteEnvPane extends BasicBeanPane<RemoteEnv> {
}
private boolean testConnection() {
RemoteEnv env = new RemoteEnv();
String url = remoteEnvURL.getURL();
env.setPath(url);
env.setUser(usernameInput.getText());
env.setPassword(new String(passwordInput.getPassword()));
RemoteEnv env = new RemoteEnv(url, usernameInput.getText(), new String(passwordInput.getPassword()));
boolean connect = false;
try {
if (StringUtils.isNotEmpty(url)) {

83
designer-base/src/com/fr/env/RemoteEnvUtils.java vendored

@ -57,7 +57,7 @@ public class RemoteEnvUtils {
builder.addParameter(entry.getKey(), entry.getValue());
}
if (!isSignIn) {
builder.addParameter("id", env.getValidUserID());
builder.addParameter("id", env.getUserID());
}
InputStreamEntity reqEntity = new InputStreamEntity(new ByteArrayInputStream(bytes));
@ -82,7 +82,7 @@ public class RemoteEnvUtils {
builder.addParameter(entry.getKey(), entry.getValue());
}
if (!isSignIn) {
builder.addParameter("id", env.getValidUserID());
builder.addParameter("id", env.getUserID());
}
try (CloseableHttpClient httpClient = HttpClients.createSystem()) {
@ -105,7 +105,7 @@ public class RemoteEnvUtils {
builder.addParameter(entry.getKey(), entry.getValue());
}
if (!isSignIn) {
builder.addParameter("id", env.getValidUserID());
builder.addParameter("id", env.getUserID());
}
try (CloseableHttpClient httpClient = HttpClients.createSystem()) {
HttpUriRequest request = builder.build();
@ -118,57 +118,10 @@ public class RemoteEnvUtils {
}
public static InputStream headBeatConnection(RemoteEnv env) {
String path = env.getPath();
String username = env.getUser();
InputStream inputStream = null;
try (CloseableHttpClient httpClient = HttpClients.createSystem()) {
HttpUriRequest request = RequestBuilder.get(path)
.addParameter("op", "fr_remote_design")
.addParameter("cmd", "heart_beat")
.addParameter("user", username)
.addParameter("id", env.getValidUserID())
.build();
inputStream = httpClient.execute(request, responseHandler);
} catch (IOException | EnvException e) {
FRContext.getLogger().error(e.getMessage());
}
return inputStream;
}
public static InputStream testConnection(boolean isSignIn, RemoteEnv env) throws EnvException {
String username = env.getUser();
String path = env.getPath();
String password = env.getPassword();
InputStream inputStream = null;
try (CloseableHttpClient httpClient = HttpClients.createSystem()) {
RequestBuilder builder = RequestBuilder.get(path);
if (!isSignIn) {
builder.addParameter("id", env.getValidUserID());
}
HttpUriRequest request = builder
.addParameter("op", "fr_remote_design")
.addParameter("cmd", "test_server_connection")
.addParameter("user", username)
.addParameter("password", URLEncoder.encode(password, EncodeConstants.ENCODING_UTF_8))
.build();
inputStream = httpClient.execute(request, responseHandler);
} catch (IOException e) {
FRContext.getLogger().error(e.getMessage());
}
return inputStream;
}
public static InputStream updateAuthorities(DesignAuthority[] authorities, RemoteEnv env) throws EnvException {
public static InputStream updateAuthorities(DesignAuthority[] authorities, RemoteEnv env) {
String path = env.getPath();
// 远程设计临时用户id
String userID = env.getValidUserID();
String userID = env.getUserID();
InputStream inputStream = null;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
@ -194,7 +147,7 @@ public class RemoteEnvUtils {
public static InputStream getAuthorities(RemoteEnv env) throws EnvException {
String path = env.getPath();
// 远程设计临时用户id
String userID = env.getValidUserID();
String userID = env.getUserID();
InputStream inputStream = null;
try (CloseableHttpClient httpClient = HttpClients.createSystem();) {
@ -211,28 +164,4 @@ public class RemoteEnvUtils {
}
public static InputStream listFile(String pFilePath, boolean isWebReport, RemoteEnv env) throws EnvException {
String path = env.getPath();
// 远程设计临时用户id
String userID = env.getValidUserID();
String username = env.getUser();
InputStream inputStream = null;
try (CloseableHttpClient httpClient = HttpClients.createSystem()) {
HttpUriRequest request = RequestBuilder.get(path)
.addParameter("op", "fs_remote_design")
.addParameter("cmd", "design_list_file")
.addParameter("file_path", pFilePath)
.addParameter("currentUserName", username)
.addParameter("currentUserId", userID)
.addParameter("id", userID)
.addParameter("isWebReport", Boolean.toString(isWebReport))
.build();
inputStream = httpClient.execute(request, responseHandler);
} catch (IOException e) {
FRContext.getLogger().error(e.getMessage());
}
return inputStream;
}
}

62
designer-base/src/com/fr/env/SignIn.java vendored

@ -1,43 +1,61 @@
package com.fr.env;
import com.fr.base.Env;
import com.fr.base.FRContext;
import com.fr.base.env.EnvContext;
import com.fr.base.env.resource.EnvConfigUtils;
import com.fr.base.env.resource.RemoteEnvConfig;
import com.fr.core.env.EnvConfig;
import com.fr.core.env.EnvEvents;
import com.fr.dav.LocalEnv;
import com.fr.design.utils.DesignUtils;
import com.fr.event.Event;
import com.fr.event.EventDispatcher;
import com.fr.event.Listener;
import com.fr.event.Null;
import com.fr.general.ComparatorUtils;
import com.fr.general.env.EnvContext;
import com.fr.general.Inter;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
public class SignIn {
public static Env lastSelectedEnv;// 记录最后登录的Env
static {
EventDispatcher.listen(EnvEvents.CONNECTION_ERROR, new Listener<Null>() {
@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());
}
}
}
});
}
/**
* 注册入环境
* @param selectedEnv 选择的环境
* @throws Exception 异常
*/
public static void signIn(Env selectedEnv) throws Exception {
boolean validServer;
signOutOldEnv(selectedEnv);
selectedEnv.signIn();
validServer = true;
if (validServer) {
DesignUtils.switchToEnv(selectedEnv);
lastSelectedEnv = selectedEnv;
public static void signIn(EnvConfig selectedEnv) throws Exception {
if (EnvContext.currentEnv() != null && !ComparatorUtils.equals(EnvContext.currentEnv(), selectedEnv)) {
EnvContext.signOut();
}
EnvContext.signIn(selectedEnv);
DesignUtils.switchToEnv(trans(selectedEnv));
}
private static void signOutOldEnv(Env newEnv) {
// 环境相同直接返回,避免浪费过多时间
if (lastSelectedEnv == null || ComparatorUtils.equals(lastSelectedEnv, newEnv)) {
return;
}
try {
EnvContext.fireBeforeSignOut();
lastSelectedEnv.signOut();
EnvContext.fireAfterSignOut();
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
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();
}
}
}

3
designer-realize/src/com/fr/start/module/DesignerModuleActivator.java

@ -1,5 +1,6 @@
package com.fr.start.module;
import com.fr.design.mainframe.loghandler.socketio.DesignerSocketIO;
import com.fr.design.module.DesignerModule;
import com.fr.general.ModuleContext;
import com.fr.locale.InterMutableKey;
@ -20,6 +21,8 @@ public class DesignerModuleActivator extends Activator implements Prepare {
ModuleContext.registerModuleListener(getModule().upFindSingleton(ModuleListener.class));
ModuleContext.startModule(DesignerModule.class.getName());
ModuleContext.clearModuleListener();
DesignerSocketIO.init();
}
@Override

Loading…
Cancel
Save