Browse Source

model里加一个count属性,修改本地常用的逻辑,按次数排序

代码质量,
修改部分变量命名
master
XiaXiang 8 years ago
parent
commit
fc104d928f
  1. 1
      designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java
  2. 4
      designer/src/com/fr/design/mainframe/alphafine/cell/CellModelHelper.java
  3. 13
      designer/src/com/fr/design/mainframe/alphafine/cell/model/ActionModel.java
  4. 24
      designer/src/com/fr/design/mainframe/alphafine/cell/model/AlphaCellModel.java
  5. 11
      designer/src/com/fr/design/mainframe/alphafine/cell/model/DocumentModel.java
  6. 9
      designer/src/com/fr/design/mainframe/alphafine/cell/model/FileModel.java
  7. 7
      designer/src/com/fr/design/mainframe/alphafine/cell/model/PluginModel.java
  8. 9
      designer/src/com/fr/design/mainframe/alphafine/search/manager/ActionSearchManager.java
  9. 3
      designer/src/com/fr/design/mainframe/alphafine/search/manager/DocumentSearchManager.java
  10. 9
      designer/src/com/fr/design/mainframe/alphafine/search/manager/FileSearchManager.java
  11. 3
      designer/src/com/fr/design/mainframe/alphafine/search/manager/PluginSearchManager.java
  12. 11
      designer/src/com/fr/design/mainframe/alphafine/search/manager/RecentSearchManager.java

1
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;

4
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:

13
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;
}
}

24
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());
}
}

11
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());

9
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());
}

7
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());

9
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<UpdateActionModel> 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;

3
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

9
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) {

3
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);
}
/**

11
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<AlphaCellModel> 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<AlphaCellModel> list = new ArrayList<>();
list.add(cellModel);

Loading…
Cancel
Save