From 2cea885f4be2c0fc64fdd9fdd8800d57b2dfe24c Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Thu, 18 May 2017 13:39:16 +0800 Subject: [PATCH] rt --- .../mainframe/alphafine/AlphaFineHelper.java | 3 + .../alphafine/cell/CellModelHelper.java | 42 +++ .../alphafine/cell/cellModel/ActionModel.java | 46 +++ .../cell/cellModel/AlphaCellModel.java | 12 +- .../cell/cellModel/DocumentModel.java | 37 +++ .../alphafine/cell/cellModel/FileModel.java | 36 +++ .../alphafine/cell/cellModel/ModelHandel.java | 13 + .../alphafine/cell/cellModel/PluginModel.java | 59 ++++ .../alphafine/component/AlphaFineDialog.java | 42 ++- .../recentSearch/RecentSearchManager.java | 294 ++++++++++++++++++ .../searchManager/LatestSearchManager.java | 4 + .../searchManager/PluginSearchManager.java | 2 + .../xmlManager/RecentSearchManager.java | 194 ------------ .../src/com/fr/design/utils/DesignUtils.java | 12 +- 14 files changed, 589 insertions(+), 207 deletions(-) create mode 100644 designer/src/com/fr/design/mainframe/alphafine/cell/CellModelHelper.java create mode 100644 designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/ModelHandel.java create mode 100644 designer/src/com/fr/design/mainframe/alphafine/recentSearch/RecentSearchManager.java delete mode 100644 designer/src/com/fr/design/mainframe/alphafine/xmlManager/RecentSearchManager.java diff --git a/designer/src/com/fr/design/mainframe/alphafine/AlphaFineHelper.java b/designer/src/com/fr/design/mainframe/alphafine/AlphaFineHelper.java index 572de96a7..b25c6af30 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/AlphaFineHelper.java +++ b/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.design.mainframe.DesignerContext; +import com.fr.design.mainframe.alphafine.cell.cellModel.*; import com.fr.design.mainframe.alphafine.component.AlphaFineDialog; import com.fr.stable.StableUtils; @@ -31,4 +32,6 @@ public class AlphaFineHelper { } + + } diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/CellModelHelper.java b/designer/src/com/fr/design/mainframe/alphafine/cell/CellModelHelper.java new file mode 100644 index 000000000..11ae7f8a9 --- /dev/null +++ b/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; + } +} diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/ActionModel.java b/designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/ActionModel.java index 8cbfae7e8..c3c7f7153 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/ActionModel.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/ActionModel.java @@ -1,6 +1,9 @@ package com.fr.design.mainframe.alphafine.cell.cellModel; 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 java.io.Serializable; @@ -15,6 +18,21 @@ public class ActionModel extends AlphaCellModel implements Serializable { 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) { super(name, null, CellType.ACTION); this.action = action; @@ -27,4 +45,32 @@ public class ActionModel extends AlphaCellModel implements Serializable { public void setAction(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); + } } diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/AlphaCellModel.java b/designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/AlphaCellModel.java index 61867e3d2..c8a42d78e 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/AlphaCellModel.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/AlphaCellModel.java @@ -1,13 +1,14 @@ package com.fr.design.mainframe.alphafine.cell.cellModel; 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. */ -public class AlphaCellModel implements Serializable{ +public abstract class AlphaCellModel implements ModelHandel { private String name; private String content; private String description; @@ -58,4 +59,11 @@ public class AlphaCellModel implements Serializable{ public void setDescription(String description) { this.description = description; } + + @Override + public JSONObject ModelToJson() throws JSONException { + return null; + } + + } diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/DocumentModel.java b/designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/DocumentModel.java index 887763118..5be4ccbf3 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/DocumentModel.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/DocumentModel.java @@ -1,6 +1,10 @@ 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.general.FRLogger; +import com.fr.json.JSONException; +import com.fr.json.JSONObject; /** * Created by XiaXiang on 2017/4/20. @@ -24,4 +28,37 @@ public class DocumentModel extends AlphaCellModel { public void setDocumentUrl(String 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); + } } diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/FileModel.java b/designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/FileModel.java index 81e229552..5ca5e0870 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/FileModel.java +++ b/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.CellType; +import com.fr.general.FRLogger; +import com.fr.json.JSONException; +import com.fr.json.JSONObject; /** * Created by XiaXiang on 2017/4/20. @@ -26,4 +29,37 @@ public class FileModel extends AlphaCellModel{ public void setFilePath(String 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; + } } diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/ModelHandel.java b/designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/ModelHandel.java new file mode 100644 index 000000000..99609cda2 --- /dev/null +++ b/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; + +} diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/PluginModel.java b/designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/PluginModel.java index 9be4e4dfd..ddbfa34e8 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/PluginModel.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/cellModel/PluginModel.java @@ -1,7 +1,14 @@ 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.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. @@ -74,4 +81,56 @@ public class PluginModel extends AlphaCellModel { public void setPrice(int 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); + } } diff --git a/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java b/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java index 8a8ac6b5a..675466cd1 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java +++ b/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.alphafine.AlphaFineConstants; 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.cellModel.*; 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.PluginPreviewPane; 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.filetree.FileNode; 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.FRLogger; import com.fr.general.Inter; +import com.fr.general.http.HttpClient; import com.fr.io.TemplateWorkBookIO; 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.stable.CodeUtils; import com.fr.stable.StringUtils; import com.fr.stable.project.ProjectConstants; @@ -45,6 +50,9 @@ import java.io.*; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.HashMap; import java.util.concurrent.ExecutionException; /** @@ -545,18 +553,42 @@ public class AlphaFineDialog extends UIDialog { */ private void saveHistory(String searchText, AlphaCellModel cellModel) { RecentSearchManager recentSearchManager = RecentSearchManager.getInstance(); - recentSearchManager.getModelMap().put(cellModel.getName(), cellModel.getType().getCellType()); + recentSearchManager.addRecentModel(searchText, cellModel); recentSearchManager.saveXMLFile(); - - sendToServer(); + sendToServer(searchText, cellModel); } /** *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 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) { diff --git a/designer/src/com/fr/design/mainframe/alphafine/recentSearch/RecentSearchManager.java b/designer/src/com/fr/design/mainframe/alphafine/recentSearch/RecentSearchManager.java new file mode 100644 index 000000000..ce0302d97 --- /dev/null +++ b/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 fileList; + private List actionList; + private List documentList; + + //private List recentKVModelList = new ArrayList<>(); + private List pluginList; + private List recentModelList = new ArrayList<>(); + private Map> 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 list = new ArrayList(); + 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 getFileList() { + return fileList; + } + + public void setFileList(List fileList) { + this.fileList = fileList; + } + + public List getActionList() { + return actionList; + } + + public void setActionList(List actionList) { + this.actionList = actionList; + } + + public List getDocumentList() { + return documentList; + } + + public void setDocumentList(List documentList) { + this.documentList = documentList; + } + + public List getPluginList() { + return pluginList; + } + + public void setPluginList(List 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(""); + 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 getRecentModelList() { + return recentModelList; + } + + public void setRecentModelList(List recentModelList) { + this.recentModelList = recentModelList; + } + + public List getRecentModelList(String searchText) { + for (String key : recentKVModelMap.keySet()) { + if (recentKVModelMap.keySet().contains(searchText)) { + List 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 cellModels = recentKVModelMap.get(searchKey); + if (cellModels.contains(cellModel)) { + cellModels.remove(cellModel); + cellModels.add(cellModel); + } else { + cellModels.add(cellModel); + } + } else { + List 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> getRecentKVModelMap() { + return recentKVModelMap; + } + + public void setRecentKVModelMap(Map> recentKVModelMap) { + this.recentKVModelMap = recentKVModelMap; + } + +// public List getRecentKVModelList() { +// return recentKVModelList; +// } +// +// public void setRecentKVModelList(List recentKVModelList) { +// this.recentKVModelList = recentKVModelList; +// } +} diff --git a/designer/src/com/fr/design/mainframe/alphafine/searchManager/LatestSearchManager.java b/designer/src/com/fr/design/mainframe/alphafine/searchManager/LatestSearchManager.java index 8fb391946..9d35de211 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/searchManager/LatestSearchManager.java +++ b/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.model.SearchResult; +import com.fr.design.mainframe.alphafine.recentSearch.RecentSearchManager; import com.fr.general.Inter; /** @@ -23,6 +24,9 @@ public class LatestSearchManager implements AlphaFineSearchProcessor { this.modelList = new SearchResult(); modelList.add(new MoreModel(Inter.getLocText("FR-Designer_AlphaFine_Latest"), false)); //todo: 本地常用逻辑需要重新设计 + if (RecentSearchManager.getInstance().getRecentModelList(searchText) != null) { + modelList.addAll(RecentSearchManager.getInstance().getRecentModelList(searchText)); + } // if (getLatestModelList() != null && getLatestModelList().size() > 0) { // modelList.addAll(getLatestModelList()); // } diff --git a/designer/src/com/fr/design/mainframe/alphafine/searchManager/PluginSearchManager.java b/designer/src/com/fr/design/mainframe/alphafine/searchManager/PluginSearchManager.java index 5e5410a79..71f9a7697 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/searchManager/PluginSearchManager.java +++ b/designer/src/com/fr/design/mainframe/alphafine/searchManager/PluginSearchManager.java @@ -108,4 +108,6 @@ public class PluginSearchManager implements AlphaFineSearchProcessor { } + + } diff --git a/designer/src/com/fr/design/mainframe/alphafine/xmlManager/RecentSearchManager.java b/designer/src/com/fr/design/mainframe/alphafine/xmlManager/RecentSearchManager.java deleted file mode 100644 index 8a7bf5793..000000000 --- a/designer/src/com/fr/design/mainframe/alphafine/xmlManager/RecentSearchManager.java +++ /dev/null @@ -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 fileList; - - private List actionList; - - private List documentList; - - private List pluginList; - - private Map 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 getFileList() { - return fileList; - } - - public void setFileList(List fileList) { - this.fileList = fileList; - } - - public List getActionList() { - return actionList; - } - - public void setActionList(List actionList) { - this.actionList = actionList; - } - - public List getDocumentList() { - return documentList; - } - - public void setDocumentList(List documentList) { - this.documentList = documentList; - } - - public List getPluginList() { - return pluginList; - } - - public void setPluginList(List pluginList) { - this.pluginList = pluginList; - } - - public Map getModelMap() { - return modelMap; - } - - public void setModelMap(Map 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(""); - 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()); - } - } -} diff --git a/designer_base/src/com/fr/design/utils/DesignUtils.java b/designer_base/src/com/fr/design/utils/DesignUtils.java index 8ed8aa617..9e4c92463 100644 --- a/designer_base/src/com/fr/design/utils/DesignUtils.java +++ b/designer_base/src/com/fr/design/utils/DesignUtils.java @@ -50,12 +50,12 @@ public class DesignUtils { * @return 启动了返回true */ public static boolean isStarted() { - try { - new Socket("localhost", port); - return true; - } catch (Exception exp) { - - } +// try { +// new Socket("localhost", port); +// return true; +// } catch (Exception exp) { +// +// } return false; }