XiaXiang 8 years ago
parent
commit
2cea885f4b
  1. 3
      designer/src/com/fr/design/mainframe/alphafine/AlphaFineHelper.java
  2. 42
      designer/src/com/fr/design/mainframe/alphafine/cell/CellModelHelper.java
  3. 46
      designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/ActionModel.java
  4. 12
      designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/AlphaCellModel.java
  5. 37
      designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/DocumentModel.java
  6. 36
      designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/FileModel.java
  7. 13
      designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/ModelHandel.java
  8. 59
      designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/PluginModel.java
  9. 42
      designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java
  10. 294
      designer/src/com/fr/design/mainframe/alphafine/recentSearch/RecentSearchManager.java
  11. 4
      designer/src/com/fr/design/mainframe/alphafine/searchManager/LatestSearchManager.java
  12. 2
      designer/src/com/fr/design/mainframe/alphafine/searchManager/PluginSearchManager.java
  13. 194
      designer/src/com/fr/design/mainframe/alphafine/xmlManager/RecentSearchManager.java
  14. 12
      designer_base/src/com/fr/design/utils/DesignUtils.java

3
designer/src/com/fr/design/mainframe/alphafine/AlphaFineHelper.java

@ -2,6 +2,7 @@ package com.fr.design.mainframe.alphafine;
import com.fr.base.FRContext; import com.fr.base.FRContext;
import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.alphafine.cell.cellModel.*;
import com.fr.design.mainframe.alphafine.component.AlphaFineDialog; import com.fr.design.mainframe.alphafine.component.AlphaFineDialog;
import com.fr.stable.StableUtils; import com.fr.stable.StableUtils;
@ -31,4 +32,6 @@ public class AlphaFineHelper {
} }
} }

42
designer/src/com/fr/design/mainframe/alphafine/cell/CellModelHelper.java

@ -0,0 +1,42 @@
package com.fr.design.mainframe.alphafine.cell;
import com.fr.design.mainframe.alphafine.CellType;
import com.fr.design.mainframe.alphafine.cell.cellModel.*;
import com.fr.json.JSONObject;
/**
* Created by XiaXiang on 2017/5/17.
*/
public class CellModelHelper {
public static AlphaCellModel jsonToModel(JSONObject object) {
int cellType = object.optInt("cellType");
switch (CellType.parse(cellType)) {
case ACTION:
return ActionModel.jsonToModel(object);
case DOCUMENT:
return DocumentModel.jsonToModel(object);
case FILE:
return FileModel.jsonToModel(object);
case PLUGIN:
case REUSE:
return PluginModel.jsonToModel(object);
}
return null;
}
public static String getResultValueFromModel(AlphaCellModel cellModel) {
switch (cellModel.getType()) {
case ACTION:
return cellModel.getName();
case DOCUMENT:
return ((DocumentModel)cellModel).getDocumentUrl();
case FILE:
return ((FileModel)cellModel).getFilePath();
case REUSE:
case PLUGIN:
return ((PluginModel)cellModel).getPluginUrl();
}
return null;
}
}

46
designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/ActionModel.java

@ -1,6 +1,9 @@
package com.fr.design.mainframe.alphafine.cell.cellModel; package com.fr.design.mainframe.alphafine.cell.cellModel;
import com.fr.design.mainframe.alphafine.CellType; import com.fr.design.mainframe.alphafine.CellType;
import com.fr.general.FRLogger;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import javax.swing.*; import javax.swing.*;
import java.io.Serializable; import java.io.Serializable;
@ -15,6 +18,21 @@ public class ActionModel extends AlphaCellModel implements Serializable {
super(name, content, type); super(name, content, type);
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ActionModel)) return false;
ActionModel that = (ActionModel) o;
return action != null ? action.equals(that.action) : that.action == null;
}
@Override
public int hashCode() {
return action != null ? action.hashCode() : 0;
}
public ActionModel(String name, Action action) { public ActionModel(String name, Action action) {
super(name, null, CellType.ACTION); super(name, null, CellType.ACTION);
this.action = action; this.action = action;
@ -27,4 +45,32 @@ public class ActionModel extends AlphaCellModel implements Serializable {
public void setAction(Action action) { public void setAction(Action action) {
this.action = action; this.action = action;
} }
@Override
public JSONObject ModelToJson() {
JSONObject object = JSONObject.create();
try {
object.put("name", getName()).put("action", getAction().getClass().getName()).put("cellType", getType().getCellType());
} catch (JSONException e) {
FRLogger.getLogger().error(e.getMessage());
}
return object;
}
public static ActionModel jsonToModel(JSONObject object ) {
String name = object.optString("name");
String actionName = object.optString("action");
Action action = null;
try {
Class<?> className = Class.forName(actionName);
action = (Action) className.newInstance();
} catch (ClassNotFoundException e) {
FRLogger.getLogger().error(e.getMessage());
} catch (IllegalAccessException e) {
FRLogger.getLogger().error(e.getMessage());
} catch (InstantiationException e) {
FRLogger.getLogger().error(e.getMessage());
}
return new ActionModel(name, action);
}
} }

12
designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/AlphaCellModel.java

@ -1,13 +1,14 @@
package com.fr.design.mainframe.alphafine.cell.cellModel; package com.fr.design.mainframe.alphafine.cell.cellModel;
import com.fr.design.mainframe.alphafine.CellType; import com.fr.design.mainframe.alphafine.CellType;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import java.io.Serializable;
/** /**
* Created by XiaXiang on 2017/3/23. * Created by XiaXiang on 2017/3/23.
*/ */
public class AlphaCellModel implements Serializable{ public abstract class AlphaCellModel implements ModelHandel {
private String name; private String name;
private String content; private String content;
private String description; private String description;
@ -58,4 +59,11 @@ public class AlphaCellModel implements Serializable{
public void setDescription(String description) { public void setDescription(String description) {
this.description = description; this.description = description;
} }
@Override
public JSONObject ModelToJson() throws JSONException {
return null;
}
} }

37
designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/DocumentModel.java

@ -1,6 +1,10 @@
package com.fr.design.mainframe.alphafine.cell.cellModel; package com.fr.design.mainframe.alphafine.cell.cellModel;
import com.fr.design.mainframe.alphafine.AlphaFineConstants;
import com.fr.design.mainframe.alphafine.CellType; import com.fr.design.mainframe.alphafine.CellType;
import com.fr.general.FRLogger;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
/** /**
* Created by XiaXiang on 2017/4/20. * Created by XiaXiang on 2017/4/20.
@ -24,4 +28,37 @@ public class DocumentModel extends AlphaCellModel {
public void setDocumentUrl(String documentUrl) { public void setDocumentUrl(String documentUrl) {
this.documentUrl = documentUrl; this.documentUrl = documentUrl;
} }
@Override
public JSONObject ModelToJson() {
JSONObject object = JSONObject.create();
try {
object.put("name", getName()).put("content", getContent()).put("documentUrl", getDocumentUrl()).put("cellType", getType().getCellType());
} catch (JSONException e) {
FRLogger.getLogger().error(e.getMessage());
}
return object;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof DocumentModel)) return false;
DocumentModel that = (DocumentModel) o;
return documentUrl != null ? documentUrl.equals(that.documentUrl) : that.documentUrl == null;
}
@Override
public int hashCode() {
return documentUrl != null ? documentUrl.hashCode() : 0;
}
public static DocumentModel jsonToModel(JSONObject object) {
String name = object.optString("title");
String content = object.optString("summary");
String documentUrl = AlphaFineConstants.DOCUMENT_DOC_URL + object.optString("did") + ".html";
return new DocumentModel(name, content, documentUrl);
}
} }

36
designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/FileModel.java

@ -2,6 +2,9 @@ package com.fr.design.mainframe.alphafine.cell.cellModel;
import com.fr.design.mainframe.alphafine.AlphaFineHelper; import com.fr.design.mainframe.alphafine.AlphaFineHelper;
import com.fr.design.mainframe.alphafine.CellType; import com.fr.design.mainframe.alphafine.CellType;
import com.fr.general.FRLogger;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
/** /**
* Created by XiaXiang on 2017/4/20. * Created by XiaXiang on 2017/4/20.
@ -26,4 +29,37 @@ public class FileModel extends AlphaCellModel{
public void setFilePath(String filePath) { public void setFilePath(String filePath) {
this.filePath = filePath; this.filePath = filePath;
} }
@Override
public JSONObject ModelToJson() {
JSONObject object = JSONObject.create();
try {
object.put("name", getName()).put("content", getContent()).put("filePath", getFilePath()).put("cellType", getType().getCellType());
} catch (JSONException e) {
FRLogger.getLogger().error(e.getMessage());
}
return object;
}
public static FileModel jsonToModel(JSONObject object) {
String name = object.optString("name");
String content = object.optString("content");
String filePath = object.optString("filePath");
return new FileModel(name, content, filePath);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof FileModel)) return false;
FileModel fileModel = (FileModel) o;
return filePath != null ? filePath.equals(fileModel.filePath) : fileModel.filePath == null;
}
@Override
public int hashCode() {
return filePath != null ? filePath.hashCode() : 0;
}
} }

13
designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/ModelHandel.java

@ -0,0 +1,13 @@
package com.fr.design.mainframe.alphafine.cell.cellModel;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
/**
* Created by XiaXiang on 2017/5/16.
*/
public interface ModelHandel {
JSONObject ModelToJson() throws JSONException;
}

59
designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/PluginModel.java

@ -1,7 +1,14 @@
package com.fr.design.mainframe.alphafine.cell.cellModel; package com.fr.design.mainframe.alphafine.cell.cellModel;
import com.fr.design.mainframe.alphafine.AlphaFineConstants;
import com.fr.design.mainframe.alphafine.CellType; import com.fr.design.mainframe.alphafine.CellType;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogger;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
/** /**
* Created by XiaXiang on 2017/4/20. * Created by XiaXiang on 2017/4/20.
@ -74,4 +81,56 @@ public class PluginModel extends AlphaCellModel {
public void setPrice(int price) { public void setPrice(int price) {
this.price = price; this.price = price;
} }
@Override
public JSONObject ModelToJson() {
JSONObject object = JSONObject.create();
try {
object.put("name", getName()).put("content", getContent()).put("pluginUrl", getPluginUrl()).put("imageUrl", getImageUrl()).put("cellType", getType().getCellType()).put("jartime", getJartime()).put("version", getVersion()).put("price", getPrice());
} catch (JSONException e) {
FRLogger.getLogger().error(e.getMessage());
}
return object;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof PluginModel)) return false;
PluginModel that = (PluginModel) o;
return pluginUrl != null ? pluginUrl.equals(that.pluginUrl) : that.pluginUrl == null;
}
@Override
public int hashCode() {
return pluginUrl != null ? pluginUrl.hashCode() : 0;
}
public static PluginModel jsonToModel(JSONObject object) {
String name = object.optString("name");
String content = object.optString("description");
String pluginUrl = AlphaFineConstants.REUSE_URL + object.optString("id");
String imageUrl = null;
try {
imageUrl = AlphaFineConstants.PLUGIN_IMAGE_URL + URLEncoder.encode(object.optString("pic").toString().substring(AlphaFineConstants.PLUGIN_IMAGE_URL.length()), "utf8");
} catch (UnsupportedEncodingException e) {
FRLogger.getLogger().error(e.getMessage());
}
String version = null;
String jartime = null;
CellType type = CellType.REUSE;
String link = object.optString("link");
if (ComparatorUtils.equals(link, "plugin")) {
version = object.optString("version");
jartime = object.optString("jartime");
type = CellType.PLUGIN;
pluginUrl = AlphaFineConstants.PLUGIN_URL + object.optString("id");
}
int price = object.optInt("price");
return new PluginModel(name, content, pluginUrl, imageUrl, version, jartime, type, price);
}
} }

42
designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java

@ -9,6 +9,7 @@ import com.fr.design.gui.ilable.UILabel;
import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.alphafine.AlphaFineConstants; import com.fr.design.mainframe.alphafine.AlphaFineConstants;
import com.fr.design.mainframe.alphafine.AlphaFineHelper; import com.fr.design.mainframe.alphafine.AlphaFineHelper;
import com.fr.design.mainframe.alphafine.cell.CellModelHelper;
import com.fr.design.mainframe.alphafine.cell.cellRender.ContentCellRender; import com.fr.design.mainframe.alphafine.cell.cellRender.ContentCellRender;
import com.fr.design.mainframe.alphafine.cell.cellModel.*; import com.fr.design.mainframe.alphafine.cell.cellModel.*;
import com.fr.design.mainframe.alphafine.listener.ComponentHandler; import com.fr.design.mainframe.alphafine.listener.ComponentHandler;
@ -19,7 +20,7 @@ import com.fr.design.mainframe.alphafine.previewPane.DocumentPreviewPane;
import com.fr.design.mainframe.alphafine.previewPane.FilePreviewPane; import com.fr.design.mainframe.alphafine.previewPane.FilePreviewPane;
import com.fr.design.mainframe.alphafine.previewPane.PluginPreviewPane; import com.fr.design.mainframe.alphafine.previewPane.PluginPreviewPane;
import com.fr.design.mainframe.alphafine.searchManager.*; import com.fr.design.mainframe.alphafine.searchManager.*;
import com.fr.design.mainframe.alphafine.xmlManager.RecentSearchManager; import com.fr.design.mainframe.alphafine.recentSearch.RecentSearchManager;
import com.fr.file.FileNodeFILE; import com.fr.file.FileNodeFILE;
import com.fr.file.filetree.FileNode; import com.fr.file.filetree.FileNode;
import com.fr.form.main.Form; import com.fr.form.main.Form;
@ -27,9 +28,13 @@ import com.fr.form.main.FormIO;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogger; import com.fr.general.FRLogger;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.general.http.HttpClient;
import com.fr.io.TemplateWorkBookIO; import com.fr.io.TemplateWorkBookIO;
import com.fr.io.exporter.ImageExporter; import com.fr.io.exporter.ImageExporter;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import com.fr.main.impl.WorkBook; import com.fr.main.impl.WorkBook;
import com.fr.stable.CodeUtils;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import com.fr.stable.project.ProjectConstants; import com.fr.stable.project.ProjectConstants;
@ -45,6 +50,9 @@ import java.io.*;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
/** /**
@ -545,18 +553,42 @@ public class AlphaFineDialog extends UIDialog {
*/ */
private void saveHistory(String searchText, AlphaCellModel cellModel) { private void saveHistory(String searchText, AlphaCellModel cellModel) {
RecentSearchManager recentSearchManager = RecentSearchManager.getInstance(); RecentSearchManager recentSearchManager = RecentSearchManager.getInstance();
recentSearchManager.getModelMap().put(cellModel.getName(), cellModel.getType().getCellType()); recentSearchManager.addRecentModel(searchText, cellModel);
recentSearchManager.saveXMLFile(); recentSearchManager.saveXMLFile();
sendToServer(searchText, cellModel);
sendToServer();
} }
/** /**
*todo:还没做上传服务器 *todo:还没做上传服务器
*/ */
private void sendToServer() { private void sendToServer(String searchKey, AlphaCellModel cellModel) {
String username = DesignerEnvManager.getEnvManager().getBBSName();
String uuid = DesignerEnvManager.getEnvManager().getUUID();
String activitykey = DesignerEnvManager.getEnvManager().getActivationKey();
String createTime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(Calendar.getInstance().getTime());
String key = searchKey;
int resultkind = cellModel.getType().getCellType();
String resultValue = CellModelHelper.getResultValueFromModel(cellModel);
JSONObject object = JSONObject.create();
try {
object.put("uuid", uuid).put("activitykey", activitykey).put("username", username).put("createtime", createTime).put("key", key).put("resultkind", resultkind).put("resultValue", resultValue);
} catch (JSONException e) {
FRLogger.getLogger().error(e.getMessage());
}
HashMap<String, String> para = new HashMap<>();
String date = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
para.put("token", CodeUtils.md5Encode(date, "", "MD5"));
para.put("content", object.toString());
HttpClient httpClient = new HttpClient(AlphaFineConstants.testurl, para, true);
httpClient.setTimeout(5000);
httpClient.asGet();
if (!httpClient.isServerAlive()) {
//return false;
}
String res = httpClient.getResponseText();
} }
private void rebuildShowMoreList(int index, MoreModel selectedValue) { private void rebuildShowMoreList(int index, MoreModel selectedValue) {

294
designer/src/com/fr/design/mainframe/alphafine/recentSearch/RecentSearchManager.java

@ -0,0 +1,294 @@
package com.fr.design.mainframe.alphafine.recentSearch;
import com.fr.base.FRContext;
import com.fr.base.Utils;
import com.fr.design.mainframe.alphafine.AlphaFineConstants;
import com.fr.design.mainframe.alphafine.AlphaFineHelper;
import com.fr.design.mainframe.alphafine.cell.CellModelHelper;
import com.fr.design.mainframe.alphafine.cell.cellModel.AlphaCellModel;
import com.fr.file.XMLFileManager;
import com.fr.general.FRLogger;
import com.fr.general.IOUtils;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import com.fr.stable.ProductConstants;
import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.project.ProjectConstants;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLReadable;
import com.fr.stable.xml.XMLTools;
import com.fr.stable.xml.XMLableReader;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by XiaXiang on 2017/5/15.
*/
public class RecentSearchManager extends XMLFileManager {
private static final String XML_TAG = "AlphafineRecent";
private static RecentSearchManager recentSearchManager = null;
private static File recentFile = null;
private List<String> fileList;
private List<String> actionList;
private List<String> documentList;
//private List<recentKVModel> recentKVModelList = new ArrayList<>();
private List<String> pluginList;
private List<AlphaCellModel> recentModelList = new ArrayList<>();
private Map<String, List<AlphaCellModel>> recentKVModelMap = new HashMap<>();
public synchronized static RecentSearchManager getInstance() {
if (recentSearchManager == null) {
recentSearchManager = new RecentSearchManager();
try {
XMLTools.readFileXML(recentSearchManager, recentSearchManager.getRecentEnvFile());
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
return recentSearchManager;
}
@Override
public void readXML(XMLableReader reader) {
if (reader.isAttr()) {
reader.readXMLObject(new XMLReadable() {
public void readXML(XMLableReader reader) {
if (reader.isChildNode()) {
String nodeName = reader.getTagName();
if (nodeName.equals("RecentModel")) {
String key = reader.getAttrAsString("searchKey", StringUtils.EMPTY);
final ArrayList<AlphaCellModel> list = new ArrayList<AlphaCellModel>();
reader.readXMLObject(new XMLReadable() {
@Override
public void readXML(XMLableReader reader) {
if (reader.isChildNode()) {
String nodeName = reader.getTagName();
if (nodeName.equals("modelList")) {
String name = reader.getAttrAsString("cellModel", StringUtils.EMPTY);
try {
list.add(CellModelHelper.jsonToModel(new JSONObject(name)));
} catch (JSONException e) {
FRLogger.getLogger().error(e.getMessage());
}
}
}
}
}
);
recentKVModelMap.put(key, list);
}
}
}
});
}
}
@Override
public void writeXML(XMLPrintWriter writer) {
writer.startTAG(XML_TAG);
if (!recentKVModelMap.isEmpty()) {
for (String key : recentKVModelMap.keySet()) {
writer.startTAG("RecentModel");
writer.attr("searchKey", key);
writer.startTAG("modelList");
for (AlphaCellModel model : recentKVModelMap.get(key)) {
try {
String name = model.ModelToJson().toString();
writer.attr("cellModel", name);
} catch (JSONException e) {
FRLogger.getLogger().error(e.getMessage());
}
}
writer.end();
writer.end();
}
}
writer.end();
}
@Override
public String fileName() {
return "alphafine_recent.xml";
}
public List<String> getFileList() {
return fileList;
}
public void setFileList(List<String> fileList) {
this.fileList = fileList;
}
public List<String> getActionList() {
return actionList;
}
public void setActionList(List<String> actionList) {
this.actionList = actionList;
}
public List<String> getDocumentList() {
return documentList;
}
public void setDocumentList(List<String> documentList) {
this.documentList = documentList;
}
public List<String> getPluginList() {
return pluginList;
}
public void setPluginList(List<String> pluginList) {
this.pluginList = pluginList;
}
private File getRecentFile() {
if (recentFile == null) {
recentFile = new File(ProductConstants.getEnvHome() + File.separator + fileName());
}
return recentFile;
}
private File getRecentEnvFile() {
File envFile = getRecentFile();
if (!envFile.exists()) {
createRecentFile(envFile);
}
return envFile;
}
private void createRecentFile(File envFile) {
try {
FileWriter fileWriter = new FileWriter(envFile);
StringReader stringReader = new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><AlphafineRecent></AlphafineRecent>");
Utils.copyCharTo(stringReader, fileWriter);
stringReader.close();
fileWriter.close();
} catch (IOException e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
/**
* 保存XML到设计器安装目录
*/
public void saveXMLFile() {
File xmlFile = this.getRecentEnvFile();
if (xmlFile == null) {
return;
}
if (!xmlFile.getParentFile().exists()) {//建立目录.
StableUtils.mkdirs(xmlFile.getParentFile());
}
String tempName = xmlFile.getName() + ProjectConstants.TEMP_SUFFIX;
File tempFile = new File(xmlFile.getParentFile(), tempName);
writeTempFile(tempFile);
IOUtils.renameTo(tempFile, xmlFile);
}
private void writeTempFile(File tempFile) {
try {
OutputStream fout = new FileOutputStream(tempFile);
XMLTools.writeOutputStreamXML(this, fout);
fout.flush();
fout.close();
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage());
}
}
public List<AlphaCellModel> getRecentModelList() {
return recentModelList;
}
public void setRecentModelList(List<AlphaCellModel> recentModelList) {
this.recentModelList = recentModelList;
}
public List<AlphaCellModel> getRecentModelList(String searchText) {
for (String key : recentKVModelMap.keySet()) {
if (recentKVModelMap.keySet().contains(searchText)) {
List<AlphaCellModel> list = recentKVModelMap.get(searchText);
return list;
}
}
return null;
}
public void addRecentModel(String searchKey, AlphaCellModel cellModel) {
//final AlphaCellModel alphaCellModel = getCellModel(cellModel);
if (recentKVModelMap.keySet().contains(searchKey)) {
List<AlphaCellModel> cellModels = recentKVModelMap.get(searchKey);
if (cellModels.contains(cellModel)) {
cellModels.remove(cellModel);
cellModels.add(cellModel);
} else {
cellModels.add(cellModel);
}
} else {
List<AlphaCellModel> list = new ArrayList<>();
list.add(cellModel);
recentKVModelMap.put(searchKey, list);
}
// if (alphaCellModel != null) {
// moveOnTop(alphaCellModel);
// } else {
// this.recentModelList.add(cellModel);
// }
// trimToSize();
}
private void moveOnTop(AlphaCellModel alphaCellModel) {
recentModelList.remove(alphaCellModel);
recentModelList.add(alphaCellModel);
}
private synchronized void trimToSize() {
if (recentModelList.size() > AlphaFineConstants.MAX_FILE_SIZE) {
recentModelList.remove(0);
}
}
private synchronized AlphaCellModel getCellModel(AlphaCellModel model) {
for (int i = recentModelList.size() - 1; i >= 0; i--) {
final AlphaCellModel entry = recentModelList.get(i);
String name = entry.getName();
if (name.equals(model.getName())) {
return entry;
}
}
return null;
}
public Map<String, List<AlphaCellModel>> getRecentKVModelMap() {
return recentKVModelMap;
}
public void setRecentKVModelMap(Map<String, List<AlphaCellModel>> recentKVModelMap) {
this.recentKVModelMap = recentKVModelMap;
}
// public List<recentKVModel> getRecentKVModelList() {
// return recentKVModelList;
// }
//
// public void setRecentKVModelList(List<recentKVModel> recentKVModelList) {
// this.recentKVModelList = recentKVModelList;
// }
}

4
designer/src/com/fr/design/mainframe/alphafine/searchManager/LatestSearchManager.java

@ -2,6 +2,7 @@ package com.fr.design.mainframe.alphafine.searchManager;
import com.fr.design.mainframe.alphafine.cell.cellModel.MoreModel; import com.fr.design.mainframe.alphafine.cell.cellModel.MoreModel;
import com.fr.design.mainframe.alphafine.model.SearchResult; import com.fr.design.mainframe.alphafine.model.SearchResult;
import com.fr.design.mainframe.alphafine.recentSearch.RecentSearchManager;
import com.fr.general.Inter; import com.fr.general.Inter;
/** /**
@ -23,6 +24,9 @@ public class LatestSearchManager implements AlphaFineSearchProcessor {
this.modelList = new SearchResult(); this.modelList = new SearchResult();
modelList.add(new MoreModel(Inter.getLocText("FR-Designer_AlphaFine_Latest"), false)); modelList.add(new MoreModel(Inter.getLocText("FR-Designer_AlphaFine_Latest"), false));
//todo: 本地常用逻辑需要重新设计 //todo: 本地常用逻辑需要重新设计
if (RecentSearchManager.getInstance().getRecentModelList(searchText) != null) {
modelList.addAll(RecentSearchManager.getInstance().getRecentModelList(searchText));
}
// if (getLatestModelList() != null && getLatestModelList().size() > 0) { // if (getLatestModelList() != null && getLatestModelList().size() > 0) {
// modelList.addAll(getLatestModelList()); // modelList.addAll(getLatestModelList());
// } // }

2
designer/src/com/fr/design/mainframe/alphafine/searchManager/PluginSearchManager.java

@ -108,4 +108,6 @@ public class PluginSearchManager implements AlphaFineSearchProcessor {
} }
} }

194
designer/src/com/fr/design/mainframe/alphafine/xmlManager/RecentSearchManager.java

@ -1,194 +0,0 @@
package com.fr.design.mainframe.alphafine.xmlManager;
import com.fr.base.FRContext;
import com.fr.base.Utils;
import com.fr.file.XMLFileManager;
import com.fr.general.IOUtils;
import com.fr.stable.ProductConstants;
import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.project.ProjectConstants;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLReadable;
import com.fr.stable.xml.XMLTools;
import com.fr.stable.xml.XMLableReader;
import java.io.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by XiaXiang on 2017/5/15.
*/
public class RecentSearchManager extends XMLFileManager {
private static final String XML_TAG = "AlphafineRecent";
private List<String> fileList;
private List<String> actionList;
private List<String> documentList;
private List<String> pluginList;
private Map<String, Integer> modelMap = new HashMap<>();
private static RecentSearchManager recentSearchManager = null;
public synchronized static RecentSearchManager getInstance() {
if (recentSearchManager == null) {
recentSearchManager = new RecentSearchManager();
}
try {
XMLTools.readFileXML(recentSearchManager, recentSearchManager.getRecentEnvFile());
} catch (Exception e) {
FRContext.getLogger().error(e.getMessage(), e);
}
return recentSearchManager;
}
@Override
public void readXML(XMLableReader reader) {
if (reader.isAttr()) {
reader.readXMLObject(new XMLReadable() {
public void readXML(XMLableReader reader) {
if (reader.isChildNode()) {
String nodeName = reader.getTagName();
if (nodeName.equals("RecentModel")) {
modelMap.put(reader.getAttrAsString("name", StringUtils.EMPTY), reader.getAttrAsInt("celltype", 0));
}
}
}
});
}
}
@Override
public void writeXML(XMLPrintWriter writer) {
writer.startTAG(XML_TAG);
if (!modelMap.isEmpty()) {
for (String name : modelMap.keySet()) {
writer.startTAG("RecentModel");
writer.attr("name", name);
writer.attr("celltype", modelMap.get(name));
writer.end();
}
}
writer.end();
}
@Override
public String fileName() {
return "alphafine_recent.xml";
}
public List<String> getFileList() {
return fileList;
}
public void setFileList(List<String> fileList) {
this.fileList = fileList;
}
public List<String> getActionList() {
return actionList;
}
public void setActionList(List<String> actionList) {
this.actionList = actionList;
}
public List<String> getDocumentList() {
return documentList;
}
public void setDocumentList(List<String> documentList) {
this.documentList = documentList;
}
public List<String> getPluginList() {
return pluginList;
}
public void setPluginList(List<String> pluginList) {
this.pluginList = pluginList;
}
public Map<String, Integer> getModelMap() {
return modelMap;
}
public void setModelMap(Map<String, Integer> modelMap) {
this.modelMap = modelMap;
}
private static File recentFile = null;
private File getRecentFile() {
if (recentFile == null) {
recentFile = new File(ProductConstants.getEnvHome() + File.separator + fileName());
}
return recentFile;
}
private File getRecentEnvFile() {
File envFile = getRecentFile();
if (!envFile.exists()) {
createRecentFile(envFile);
}
return envFile;
}
private void createRecentFile(File envFile) {
try {
FileWriter fileWriter = new FileWriter(envFile);
StringReader stringReader = new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><AlphafineRecent></AlphafineRecent>");
Utils.copyCharTo(stringReader, fileWriter);
stringReader.close();
fileWriter.close();
} catch (IOException e) {
FRContext.getLogger().error(e.getMessage(), e);
}
}
/**
* 保存设计器的配置文件, 该文件不在env的resource目录下
* 而是在Consts.getEnvHome() + File.separator + Consts.APP_NAME
*
*
* @date 2014-9-29-上午11:04:23
*
*/
public void saveXMLFile() {
File xmlFile = this.getRecentEnvFile();
if (xmlFile == null) {
return;
}
if (!xmlFile.getParentFile().exists()) {//建立目录.
StableUtils.mkdirs(xmlFile.getParentFile());
}
String tempName = xmlFile.getName() + ProjectConstants.TEMP_SUFFIX;
File tempFile = new File(xmlFile.getParentFile(), tempName);
writeTempFile(tempFile);
IOUtils.renameTo(tempFile, xmlFile);
}
private void writeTempFile(File tempFile){
try{
OutputStream fout = new FileOutputStream(tempFile);
XMLTools.writeOutputStreamXML(this, fout);
fout.flush();
fout.close();
}catch (Exception e) {
FRContext.getLogger().error(e.getMessage());
}
}
}

12
designer_base/src/com/fr/design/utils/DesignUtils.java

@ -50,12 +50,12 @@ public class DesignUtils {
* @return 启动了返回true * @return 启动了返回true
*/ */
public static boolean isStarted() { public static boolean isStarted() {
try { // try {
new Socket("localhost", port); // new Socket("localhost", port);
return true; // return true;
} catch (Exception exp) { // } catch (Exception exp) {
//
} // }
return false; return false;
} }

Loading…
Cancel
Save