diff --git a/designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java b/designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java index c1f200d24c..a05e520f4f 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java +++ b/designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java @@ -8,7 +8,6 @@ import java.awt.*; * Created by XiaXiang on 2017/5/10. */ public class AlphaFineConstants { - public static final String SAVE_FILE_NAME = "alpha.coco"; public static final int SHOW_SIZE = 5; diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/CellModelHelper.java b/designer/src/com/fr/design/mainframe/alphafine/cell/CellModelHelper.java index 52a8fafd4b..ae86cab4d4 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/CellModelHelper.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/CellModelHelper.java @@ -19,13 +19,13 @@ public class CellModelHelper { AlphaCellModel cellModel = null; switch (CellType.parse(typeValue)) { case ACTION: - cellModel = ActionSearchManager.getModelFromCloud(object.optString(RESULT)); + cellModel = ActionSearchManager.getModelFromCloud(object.optJSONObject(RESULT)); break; case DOCUMENT: cellModel = DocumentSearchManager.getModelFromCloud(object.optJSONObject(RESULT)); break; case FILE: - cellModel = FileSearchManager.getModelFromCloud(object.optString(RESULT)); + cellModel = FileSearchManager.getModelFromCloud(object.optJSONObject(RESULT)); break; case PLUGIN: case REUSE: diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/model/ActionModel.java b/designer/src/com/fr/design/mainframe/alphafine/cell/model/ActionModel.java index 2850e01568..5fe38c7ba2 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/model/ActionModel.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/model/ActionModel.java @@ -13,10 +13,10 @@ import javax.swing.*; public class ActionModel extends AlphaCellModel { private Action action; - private String className; - public ActionModel(String name, String content, CellType type) { - super(name, content, type); + public ActionModel(String name, String description, Action action, int searchCount) { + this(name, description, action); + setSearchCount(searchCount); } public ActionModel(String name, String description, Action action) { @@ -55,7 +55,9 @@ public class ActionModel extends AlphaCellModel { public JSONObject ModelToJson() { JSONObject object = JSONObject.create(); try { - object.put("result", getAction().getClass().getName()).put("cellType", getType().getTypeValue()); + JSONObject modelObject = JSONObject.create(); + modelObject.put("className", getAction().getClass().getName()).put("searchCount", getSearchCount()); + object.put("result", modelObject).put("cellType", getType().getTypeValue()); } catch (JSONException e) { FRLogger.getLogger().error(e.getMessage()); } @@ -71,7 +73,4 @@ public class ActionModel extends AlphaCellModel { return getAction().getClass().getName(); } - public void setClassName(String className) { - this.className = className; - } } diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/model/AlphaCellModel.java b/designer/src/com/fr/design/mainframe/alphafine/cell/model/AlphaCellModel.java index d37d2708d9..c9226ff003 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/model/AlphaCellModel.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/model/AlphaCellModel.java @@ -8,11 +8,12 @@ import com.fr.json.JSONObject; /** * Created by XiaXiang on 2017/3/23. */ -public abstract class AlphaCellModel { +public abstract class AlphaCellModel implements Comparable { private String name; private String content; private String description; private CellType type; + private int searchCount; public AlphaCellModel(String name, String content, CellType type) { this.name = name; @@ -78,4 +79,25 @@ public abstract class AlphaCellModel { */ abstract public String getStoreInformation(); + public int getSearchCount() { + return searchCount; + } + + public void setSearchCount(int searchCount) { + this.searchCount = searchCount; + } + + public void addSearchCount() { + searchCount++; + } + + @Override + public int compareTo(Object o) { + AlphaCellModel cellModel = (AlphaCellModel)o; + int difference = cellModel.getSearchCount() - this.getSearchCount(); + if (difference != 0) { + return difference; + } + return this.getName().compareTo(cellModel.getName()); + } } diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/model/DocumentModel.java b/designer/src/com/fr/design/mainframe/alphafine/cell/model/DocumentModel.java index b9237c671f..642629675c 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/model/DocumentModel.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/model/DocumentModel.java @@ -14,10 +14,6 @@ public class DocumentModel extends AlphaCellModel { private String informationUrl; private int documentId; - public DocumentModel(String name, String content, CellType type) { - super(name, content, type); - } - public DocumentModel(String name, String content, int documentId) { super(name, content, CellType.DOCUMENT); this.documentId = documentId; @@ -25,6 +21,11 @@ public class DocumentModel extends AlphaCellModel { this.documentUrl = AlphaFineConstants.DOCUMENT_DOC_URL + documentId + ".html"; } + public DocumentModel(String name, String content, int documentId, int searchCount) { + this(name, content, documentId); + setSearchCount(searchCount); + } + public String getDocumentUrl() { return documentUrl; } @@ -38,7 +39,7 @@ public class DocumentModel extends AlphaCellModel { JSONObject object = JSONObject.create(); try { JSONObject modelObject = JSONObject.create(); - modelObject.put("title", getName()).put("summary", getContent()).put("did", getDocumentId()); + modelObject.put("title", getName()).put("summary", getContent()).put("did", getDocumentId()).put("searchCount", getSearchCount()); object.put("result", modelObject).put("cellType", getType().getTypeValue()); } catch (JSONException e) { FRLogger.getLogger().error("DocumentModel: " + e.getMessage()); diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/model/FileModel.java b/designer/src/com/fr/design/mainframe/alphafine/cell/model/FileModel.java index 3d5289cca3..4ab0bb2f4c 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/model/FileModel.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/model/FileModel.java @@ -12,8 +12,9 @@ import com.fr.json.JSONObject; public class FileModel extends AlphaCellModel { private String filePath; - public FileModel(String name, String content, CellType type) { - super(name, content, type); + public FileModel(String name, String filePath, int searchCount) { + this(name, filePath); + setSearchCount(searchCount); } public FileModel(String name, String filePath) { @@ -34,7 +35,9 @@ public class FileModel extends AlphaCellModel { public JSONObject ModelToJson() { JSONObject object = JSONObject.create(); try { - object.put("result", getFilePath()).put("cellType", getType().getTypeValue()); + JSONObject modelObject = JSONObject.create(); + modelObject.put("filePath", getFilePath()).put("searchCount", getSearchCount()); + object.put("result", modelObject).put("cellType", getType().getTypeValue()); } catch (JSONException e) { FRLogger.getLogger().error(e.getMessage()); } diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/model/PluginModel.java b/designer/src/com/fr/design/mainframe/alphafine/cell/model/PluginModel.java index dce1dd2816..27b5520966 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/model/PluginModel.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/model/PluginModel.java @@ -21,8 +21,9 @@ public class PluginModel extends AlphaCellModel { private int pluginId; private int price; - public PluginModel(String name, String content, CellType type) { - super(name, content, type); + public PluginModel(String name, String content, String imageUrl, String version, String jartime, String link, CellType type, int price, int pluginId, int serchCount) { + this(name, content, imageUrl, version, jartime, link, type, price, pluginId); + setSearchCount(serchCount); } public PluginModel(String name, String content, String imageUrl, String version, String jartime, String link, CellType type, int price, int pluginId) { @@ -97,7 +98,7 @@ public class PluginModel extends AlphaCellModel { JSONObject object = JSONObject.create(); try { JSONObject modelObject = JSONObject.create(); - modelObject.put("name", getName()).put("description", getContent()).put("pic", getImageUrl()).put("version", getVersion()).put("jartime", getJartime()).put("type", getType().getTypeValue()).put("price", getPrice()).put("id", getPluginId()).put("link", getLink()); + modelObject.put("name", getName()).put("description", getContent()).put("pic", getImageUrl()).put("version", getVersion()).put("jartime", getJartime()).put("type", getType().getTypeValue()).put("price", getPrice()).put("id", getPluginId()).put("link", getLink()).put("searchCount", getSearchCount()); object.put("result", modelObject).put("cellType", getType().getTypeValue()); } catch (JSONException e) { FRLogger.getLogger().error(e.getMessage()); diff --git a/designer/src/com/fr/design/mainframe/alphafine/search/manager/ActionSearchManager.java b/designer/src/com/fr/design/mainframe/alphafine/search/manager/ActionSearchManager.java index 03a63e063a..6b048c4a4f 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/search/manager/ActionSearchManager.java +++ b/designer/src/com/fr/design/mainframe/alphafine/search/manager/ActionSearchManager.java @@ -11,6 +11,7 @@ import com.fr.design.mainframe.toolbar.UpdateActionManager; import com.fr.design.mainframe.toolbar.UpdateActionModel; import com.fr.general.ComparatorUtils; import com.fr.general.Inter; +import com.fr.json.JSONObject; import com.fr.stable.StringUtils; import java.util.List; @@ -35,14 +36,16 @@ public class ActionSearchManager implements AlphaFineSearchProcessor { /** * 根据类名获取对象 * - * @param actionName + * @param object * @return */ - public static ActionModel getModelFromCloud(String actionName) { + public static ActionModel getModelFromCloud(JSONObject object) { + String actionName = object.optString("className"); + int searchCount = object.optInt("searchCount"); List updateActions = UpdateActionManager.getUpdateActionManager().getUpdateActions(); for (UpdateActionModel updateActionModel : updateActions) { if (ComparatorUtils.equals(actionName, updateActionModel.getClassName())) { - return new ActionModel(updateActionModel.getActionName(), updateActionModel.getParentName(), updateActionModel.getAction()); + return new ActionModel(updateActionModel.getActionName(), updateActionModel.getParentName(), updateActionModel.getAction(), searchCount); } } return null; diff --git a/designer/src/com/fr/design/mainframe/alphafine/search/manager/DocumentSearchManager.java b/designer/src/com/fr/design/mainframe/alphafine/search/manager/DocumentSearchManager.java index b56b975aa8..c9418792fd 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/search/manager/DocumentSearchManager.java +++ b/designer/src/com/fr/design/mainframe/alphafine/search/manager/DocumentSearchManager.java @@ -42,7 +42,8 @@ public class DocumentSearchManager implements AlphaFineSearchProcessor { String name = object.optString("title"); String content = object.optString("summary"); int documentId = object.optInt("did"); - return new DocumentModel(name, content, documentId); + int searchCount = object.optInt("searchCount"); + return new DocumentModel(name, content, documentId, searchCount); } @Override diff --git a/designer/src/com/fr/design/mainframe/alphafine/search/manager/FileSearchManager.java b/designer/src/com/fr/design/mainframe/alphafine/search/manager/FileSearchManager.java index dd8f6312ba..c198ee9175 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/search/manager/FileSearchManager.java +++ b/designer/src/com/fr/design/mainframe/alphafine/search/manager/FileSearchManager.java @@ -13,6 +13,7 @@ import com.fr.file.filetree.FileNode; import com.fr.general.ComparatorUtils; import com.fr.general.FRLogger; import com.fr.general.Inter; +import com.fr.json.JSONObject; import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; import com.fr.stable.project.ProjectConstants; @@ -53,12 +54,14 @@ public class FileSearchManager implements AlphaFineSearchProcessor { /** * 根据文件路径获取文件模型 * - * @param filePath + * @param object * @return */ - public static FileModel getModelFromCloud(String filePath) { + public static FileModel getModelFromCloud(JSONObject object) { + String filePath = object.optString("filePath"); + int searchCount = object.optInt("searchCount"); String name = AlphaFineHelper.findFileName(filePath); - return new FileModel(name, filePath); + return new FileModel(name, filePath, searchCount); } public synchronized SearchResult getLessSearchResult(String searchText) { diff --git a/designer/src/com/fr/design/mainframe/alphafine/search/manager/PluginSearchManager.java b/designer/src/com/fr/design/mainframe/alphafine/search/manager/PluginSearchManager.java index 569ae79367..3e457fd1af 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/search/manager/PluginSearchManager.java +++ b/designer/src/com/fr/design/mainframe/alphafine/search/manager/PluginSearchManager.java @@ -41,6 +41,7 @@ public class PluginSearchManager implements AlphaFineSearchProcessor { String name = object.optString("name"); String content = object.optString("description"); int pluginId = object.optInt("id"); + int searchCount = object.optInt("searchCount"); String imageUrl = null; try { imageUrl = isFromCloud ? AlphaFineConstants.PLUGIN_IMAGE_URL + URLEncoder.encode(object.optString("pic").toString().substring(AlphaFineConstants.PLUGIN_IMAGE_URL.length()), "utf8") : object.optString("pic"); @@ -59,7 +60,7 @@ public class PluginSearchManager implements AlphaFineSearchProcessor { type = CellType.REUSE; } int price = object.optInt("price"); - return new PluginModel(name, content, imageUrl, version, jartime, link, type, price, pluginId); + return new PluginModel(name, content, imageUrl, version, jartime, link, type, price, pluginId, searchCount); } /** diff --git a/designer/src/com/fr/design/mainframe/alphafine/search/manager/RecentSearchManager.java b/designer/src/com/fr/design/mainframe/alphafine/search/manager/RecentSearchManager.java index e27a01038b..4e70277f1b 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/search/manager/RecentSearchManager.java +++ b/designer/src/com/fr/design/mainframe/alphafine/search/manager/RecentSearchManager.java @@ -231,9 +231,10 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear } } + Collections.sort(resultModelList); int size = resultModelList.size(); if (size > MAX_SIZE) { - return resultModelList.subList(size - MAX_SIZE, size); + return resultModelList.subList(0, MAX_SIZE); } return resultModelList; } @@ -250,13 +251,13 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear public void addRecentModel(String searchKey, AlphaCellModel cellModel) { if (recentKVModelMap.keySet().contains(searchKey)) { List cellModels = recentKVModelMap.get(searchKey); - if (cellModels.contains(cellModel)) { - cellModels.remove(cellModel); - cellModels.add(cellModel); + int index = cellModels.indexOf(cellModel); + if (index >= 0) { + cellModels.get(index).addSearchCount(); } else { cellModels.add(cellModel); } - trimToSize(cellModels); + //trimToSize(cellModels); } else { List list = new ArrayList<>(); list.add(cellModel);