Browse Source

alphafine bug fix 去重

master
XiaXiang 8 years ago
parent
commit
ee6890d7bc
  1. 17
      designer/src/com/fr/design/mainframe/alphafine/AlphaFineHelper.java
  2. 2
      designer/src/com/fr/design/mainframe/alphafine/component/AlphaFinePane.java
  3. 33
      designer/src/com/fr/design/mainframe/alphafine/search/manager/ActionSearchManager.java
  4. 42
      designer/src/com/fr/design/mainframe/alphafine/search/manager/DocumentSearchManager.java
  5. 33
      designer/src/com/fr/design/mainframe/alphafine/search/manager/FileSearchManager.java
  6. 54
      designer/src/com/fr/design/mainframe/alphafine/search/manager/PluginSearchManager.java
  7. 62
      designer/src/com/fr/design/mainframe/alphafine/search/manager/RecentSearchManager.java
  8. 20
      designer/src/com/fr/design/mainframe/alphafine/search/manager/RecommendSearchManager.java

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

@ -3,18 +3,24 @@ package com.fr.design.mainframe.alphafine;
import com.fr.design.DesignerEnvManager;
import com.fr.design.actions.help.alphafine.AlphaFineConfigManager;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel;
import com.fr.design.mainframe.alphafine.cell.model.NoResultModel;
import com.fr.design.mainframe.alphafine.component.AlphaFineDialog;
import com.fr.design.mainframe.alphafine.search.manager.RecentSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.RecommendSearchManager;
import com.fr.general.Inter;
import com.fr.general.ProcessCanceledException;
import com.fr.stable.StringUtils;
import java.util.ArrayList;
import java.util.List;
/**
* Created by XiaXiang on 2017/5/8.
*/
public class AlphaFineHelper {
public static final NoResultModel noResultModel = new NoResultModel(Inter.getLocText("FR-Designere_AlphaFine_NoResult"));
public static final NoResultModel noConnectionModel = new NoResultModel(Inter.getLocText("FR-Designer_ConnectionFailed"));
public static final NoResultModel NO_RESULT_MODEL = new NoResultModel(Inter.getLocText("FR-Designer_AlphaFine_NoResult"));
public static final NoResultModel NO_CONNECTION_MODEL = new NoResultModel(Inter.getLocText("FR-Designer_ConnectionFailed"));
/**
* 弹出alphafine搜索面板
@ -70,6 +76,13 @@ public class AlphaFineHelper {
}
}
public static List<AlphaCellModel> getFilterResult() {
List<AlphaCellModel> recentList = RecentSearchManager.getRecentSearchManger().getRecentModelList();
List<AlphaCellModel> recommendList = RecommendSearchManager.getRecommendSearchManager().getRecommendModelList();
recentList.addAll(recommendList);
return recentList;
}

2
designer/src/com/fr/design/mainframe/alphafine/component/AlphaFinePane.java

@ -33,7 +33,7 @@ public class AlphaFinePane extends BasicPane {
}
UIButton refreshButton = new UIButton();
refreshButton.setIcon(IOUtils.readIcon("/com/fr/design/mainframe/alphafine/images/smallsearch.png"));
refreshButton.setToolTipText(Inter.getLocText("AlphaFine"));
refreshButton.setToolTipText(Inter.getLocText("FR-Designer_AlphaFine"));
refreshButton.set4ToolbarButton();
this.add(refreshButton);
refreshButton.addActionListener(new ActionListener() {

33
designer/src/com/fr/design/mainframe/alphafine/search/manager/ActionSearchManager.java

@ -12,6 +12,7 @@ import com.fr.design.mainframe.toolbar.UpdateActionModel;
import com.fr.general.ComparatorUtils;
import com.fr.general.Inter;
import com.fr.stable.StringUtils;
import com.fr.third.com.lowagie.text.pdf.PRAcroForm;
import java.util.List;
@ -24,6 +25,9 @@ public class ActionSearchManager implements AlphaFineSearchProcessor {
private SearchResult lessModelList;
private SearchResult moreModelList;
private static final MoreModel TITLE_MODEL = new MoreModel(Inter.getLocText("FR-Designer_Set"), CellType.ACTION);
private static final MoreModel MORE_MODEL = new MoreModel(Inter.getLocText("FR-Designer_Set"), Inter.getLocText("FR-Designer_AlphaFine_ShowAll"), true, CellType.ACTION);
public synchronized static ActionSearchManager getActionSearchManager() {
if (actionSearchManager == null) {
actionSearchManager = new ActionSearchManager();
@ -45,25 +49,24 @@ public class ActionSearchManager implements AlphaFineSearchProcessor {
}
}
}
final int length = Math.min(AlphaFineConstants.SHOW_SIZE, filterModelList.size());
for (int i = 0; i < length; i++) {
lessModelList.add(filterModelList.get(i));
}
for (int i = length; i < filterModelList.size(); i++) {
moreModelList.add(filterModelList.get(i));
SearchResult result = new SearchResult();
for (Object object : filterModelList) {
if (!AlphaFineHelper.getFilterResult().contains(object))
result.add(object);
}
if (filterModelList.size() > AlphaFineConstants.SHOW_SIZE) {
lessModelList.add(0, new MoreModel(Inter.getLocText("FR-Designer_Set"), Inter.getLocText("FR-Designer_AlphaFine_ShowAll"), true, CellType.ACTION));
} else {
lessModelList.add(0, new MoreModel(Inter.getLocText("FR-Designer_Set"), CellType.ACTION));
if (lessModelList.size() == 1) {
lessModelList.add(AlphaFineHelper.noResultModel);
if (result.size() < AlphaFineConstants.SHOW_SIZE + 1) {
lessModelList.add(0, TITLE_MODEL);
if (result.size() == 0) {
lessModelList.add(AlphaFineHelper.NO_RESULT_MODEL);
} else {
lessModelList.addAll(result);
}
} else {
lessModelList.add(0, MORE_MODEL);
lessModelList.addAll(result.subList(0, AlphaFineConstants.SHOW_SIZE));
moreModelList.addAll(result.subList(AlphaFineConstants.SHOW_SIZE, result.size()));
}
}
return lessModelList;
}

42
designer/src/com/fr/design/mainframe/alphafine/search/manager/DocumentSearchManager.java

@ -22,6 +22,7 @@ public class DocumentSearchManager implements AlphaFineSearchProcessor {
private SearchResult lessModelList;
private SearchResult moreModelList;
private static final MoreModel TITLE_MODEL = new MoreModel(Inter.getLocText("FR-Designer_COMMUNITY_HELP"), CellType.DOCUMENT);
private static final MoreModel MORE_MODEL = new MoreModel(Inter.getLocText("FR-Designer_COMMUNITY_HELP"), Inter.getLocText("FR-Designer_AlphaFine_ShowAll"),true, CellType.DOCUMENT);
public synchronized static DocumentSearchManager getDocumentSearchManager() {
if (documentSearchManager == null) {
@ -50,50 +51,41 @@ public class DocumentSearchManager implements AlphaFineSearchProcessor {
JSONObject jsonObject = new JSONObject(result);
JSONArray jsonArray = jsonObject.optJSONArray("docdata");
if (jsonArray != null) {
final int length = Math.min(AlphaFineConstants.SHOW_SIZE, jsonArray.length());
for (int i = 0; i < length; i++) {
SearchResult searchResult = new SearchResult();
for (int i = 0; i < jsonArray.length(); i++) {
AlphaFineHelper.checkCancel();
DocumentModel cellModel = getModelFromCloud(jsonArray.optJSONObject(i));
this.lessModelList.add(cellModel);
}
for (int i = length; i < jsonArray.length(); i++) {
AlphaFineHelper.checkCancel();
DocumentModel cellModel = getModelFromCloud(jsonArray.optJSONObject(i));
this.moreModelList.add(cellModel);
if (!AlphaFineHelper.getFilterResult().contains(cellModel)) {
searchResult.add(cellModel);
}
}
if (jsonArray.length() > AlphaFineConstants.SHOW_SIZE) {
lessModelList.add(0, new MoreModel(Inter.getLocText("FR-Designer_COMMUNITY_HELP"), Inter.getLocText("FR-Designer_AlphaFine_ShowAll"),true, CellType.DOCUMENT));
} else {
if (searchResult.size() < AlphaFineConstants.SHOW_SIZE + 1) {
lessModelList.add(0, TITLE_MODEL);
if (lessModelList.size() == 1) {
lessModelList.add(AlphaFineHelper.noResultModel);
if (searchResult.size() == 0) {
lessModelList.add(AlphaFineHelper.NO_RESULT_MODEL);
} else {
lessModelList.addAll(searchResult);
}
} else {
lessModelList.add(0, MORE_MODEL);
lessModelList.addAll(searchResult.subList(0, AlphaFineConstants.SHOW_SIZE));
moreModelList.addAll(searchResult.subList(AlphaFineConstants.SHOW_SIZE, searchResult.size()));
}
}
} catch (JSONException e) {
FRLogger.getLogger().error(e.getMessage());
return getNoResultList();
FRLogger.getLogger().error("document search error: " + e.getMessage());
}
}
return lessModelList;
}
private SearchResult getNoResultList() {
SearchResult result = new SearchResult();
result.add(0, TITLE_MODEL);
result.add(AlphaFineHelper.noResultModel);
return result;
}
private SearchResult getNoConnectList() {
SearchResult result = new SearchResult();
result.add(0, TITLE_MODEL);
result.add(AlphaFineHelper.noConnectionModel);
result.add(AlphaFineHelper.NO_CONNECTION_MODEL);
return result;
}

33
designer/src/com/fr/design/mainframe/alphafine/search/manager/FileSearchManager.java

@ -29,6 +29,9 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
private List<FileNode> fileNodes = null;
private static FileSearchManager fileSearchManager = null;
private static final MoreModel TITLE_MODEL = new MoreModel(Inter.getLocText("FR-Designer_Templates"), CellType.FILE);
private static final MoreModel MORE_MODEL = new MoreModel(Inter.getLocText("FR-Designer_Templates"), Inter.getLocText("FR-Designer_AlphaFine_ShowAll"),true, CellType.FILE);
public synchronized static FileSearchManager getFileSearchManager() {
init();
return fileSearchManager;
@ -56,26 +59,24 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
searchFileContent(searchText, node, isAlreadyContain, filePath);
}
final int length = Math.min(AlphaFineConstants.SHOW_SIZE, filterModelList.size());
for (int i = 0; i < length; i++) {
lessModelList.add(filterModelList.get(i));
}
for (int i = length; i< filterModelList.size(); i++) {
moreModelList.add(filterModelList.get(i));
SearchResult result = new SearchResult();
for (Object object : filterModelList) {
if (!AlphaFineHelper.getFilterResult().contains(object))
result.add(object);
}
if (filterModelList.size() > AlphaFineConstants.SHOW_SIZE) {
lessModelList.add(0,new MoreModel(Inter.getLocText("FR-Designer_Templates"), Inter.getLocText("FR-Designer_AlphaFine_ShowAll"),true, CellType.FILE));
} else {
lessModelList.add(0,new MoreModel(Inter.getLocText("FR-Designer_Templates"), CellType.FILE));
if (lessModelList.size() == 1) {
lessModelList.add(AlphaFineHelper.noResultModel);
if (result.size() < AlphaFineConstants.SHOW_SIZE + 1) {
lessModelList.add(0, TITLE_MODEL);
if (result.size() == 0) {
lessModelList.add(AlphaFineHelper.NO_RESULT_MODEL);
} else {
lessModelList.addAll(result);
}
} else {
lessModelList.add(0, MORE_MODEL);
lessModelList.addAll(result.subList(0, AlphaFineConstants.SHOW_SIZE));
moreModelList.addAll(result.subList(AlphaFineConstants.SHOW_SIZE, result.size()));
}
}
return this.lessModelList;
}

54
designer/src/com/fr/design/mainframe/alphafine/search/manager/PluginSearchManager.java

@ -12,6 +12,7 @@ import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.general.http.HttpClient;
import com.fr.json.JSONArray;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import java.io.UnsupportedEncodingException;
@ -24,7 +25,7 @@ public class PluginSearchManager implements AlphaFineSearchProcessor {
private static PluginSearchManager pluginSearchManager = null;
private static final MoreModel TITLE_MODEL = new MoreModel(Inter.getLocText("FR-Designer-Plugin_Addon"), CellType.PLUGIN);
private static final MoreModel MORE_MODEL = new MoreModel(Inter.getLocText("FR-Designer-Plugin_Addon"), Inter.getLocText("FR-Designer_AlphaFine_ShowAll"),true, CellType.PLUGIN);
private SearchResult lessModelList;
private SearchResult moreModelList;
@ -58,33 +59,32 @@ public class PluginSearchManager implements AlphaFineSearchProcessor {
JSONObject jsonObject = new JSONObject(result);
JSONArray jsonArray = jsonObject.optJSONArray("result");
if (jsonArray != null) {
int length = Math.min(AlphaFineConstants.SHOW_SIZE, jsonArray.length());
for (int i = 0; i < length; i++) {
AlphaFineHelper.checkCancel();
PluginModel cellModel = getPluginModel(jsonArray.optJSONObject(i), false);
this.lessModelList.add(cellModel);
}
for (int i = length; i < jsonArray.length(); i++) {
AlphaFineHelper.checkCancel();
SearchResult searchResult = new SearchResult();
for (int i = 0; i < jsonArray.length(); i++) {
PluginModel cellModel = getPluginModel(jsonArray.optJSONObject(i), false);
this.moreModelList.add(cellModel);
if (!AlphaFineHelper.getFilterResult().contains(cellModel)) {
searchResult.add(cellModel);
}
}
if (jsonArray.length() > AlphaFineConstants.SHOW_SIZE) {
lessModelList.add(0, new MoreModel(Inter.getLocText("FR-Designer-Plugin_Addon"), Inter.getLocText("FR-Designer_AlphaFine_ShowAll"),true, CellType.PLUGIN));
} else {
if (searchResult.size() < AlphaFineConstants.SHOW_SIZE + 1) {
lessModelList.add(0, TITLE_MODEL);
if (lessModelList.size() == 1) {
lessModelList.add(AlphaFineHelper.noResultModel);
if (searchResult.size() == 0) {
lessModelList.add(AlphaFineHelper.NO_RESULT_MODEL);
} else {
lessModelList.addAll(searchResult);
}
} else {
lessModelList.add(0, MORE_MODEL);
lessModelList.addAll(searchResult.subList(0, AlphaFineConstants.SHOW_SIZE));
moreModelList.addAll(searchResult.subList(AlphaFineConstants.SHOW_SIZE, searchResult.size()));
}
} else {
return getNoResultList();
}
} catch (Exception e) {
FRLogger.getLogger().error(e.getMessage());
return getNoResultList();
} catch (JSONException e) {
FRLogger.getLogger().error("plugin search json error :" + e.getMessage());
} catch (UnsupportedEncodingException e) {
FRLogger.getLogger().error("plugin search encode error :" + e.getMessage());
}
}
return this.lessModelList;
@ -92,18 +92,10 @@ public class PluginSearchManager implements AlphaFineSearchProcessor {
}
private SearchResult getNoResultList() {
SearchResult result = new SearchResult();
result.add(0, TITLE_MODEL);
result.add(AlphaFineHelper.noResultModel);
return result;
}
private SearchResult getNoConnectList() {
SearchResult result = new SearchResult();
result.add(0, TITLE_MODEL);
result.add(AlphaFineHelper.noConnectionModel);
result.add(AlphaFineHelper.NO_CONNECTION_MODEL);
return result;
}
@ -151,8 +143,4 @@ public class PluginSearchManager implements AlphaFineSearchProcessor {
}
}
}

62
designer/src/com/fr/design/mainframe/alphafine/search/manager/RecentSearchManager.java

@ -5,6 +5,7 @@ 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.CellType;
import com.fr.design.mainframe.alphafine.cell.CellModelHelper;
import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel;
import com.fr.design.mainframe.alphafine.cell.model.MoreModel;
import com.fr.design.mainframe.alphafine.model.SearchResult;
@ -40,10 +41,6 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear
private static RecentSearchManager recentSearchManager = null;
private static File recentFile = null;
private SearchResult modelList;
private List<AlphaCellModel> fileList = new ArrayList<>();
private List<AlphaCellModel> actionList = new ArrayList<>();
private List<AlphaCellModel> documentList = new ArrayList<>();
private List<AlphaCellModel> pluginList = new ArrayList<>();
private List<AlphaCellModel> recentModelList = new ArrayList<>();
private Map<String, List<AlphaCellModel>> recentKVModelMap = new HashMap<>();
@ -99,7 +96,7 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear
private void addModelToList(List<AlphaCellModel> list, String name) {
try {
AlphaCellModel model = getModelFromJson(new JSONObject(name));
AlphaCellModel model = CellModelHelper.getModelFromJson(new JSONObject(name));
if (model != null) {
list.add(model);
}
@ -108,60 +105,6 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear
}
}
/**
* 转成cellModel
* @param object
* @return
*/
private AlphaCellModel getModelFromJson(JSONObject object) {
int typeValue = object.optInt("cellType");
AlphaCellModel cellModel = null;
switch (CellType.parse(typeValue)) {
case ACTION:
cellModel = ActionSearchManager.getModelFromCloud(object.optString("result"));
if (cellModel != null) {
actionList.add(cellModel);
}
break;
case DOCUMENT:
cellModel = DocumentSearchManager.getModelFromCloud(object.optJSONObject("result"));
if (cellModel != null) {
documentList.add(cellModel);
}
break;
case FILE:
cellModel = FileSearchManager.getModelFromCloud(object.optString("result"));
if (cellModel != null) {
fileList.add(cellModel);
}
break;
case PLUGIN:
case REUSE:
cellModel = PluginSearchManager.getModelFromCloud(object.optJSONObject("result"));
if (cellModel != null) {
pluginList.add(cellModel);
}
break;
}
return cellModel;
}
public List<AlphaCellModel> getFileList() {
return fileList;
}
public List<AlphaCellModel> getActionList() {
return actionList;
}
public List<AlphaCellModel> getDocumentList() {
return documentList;
}
public List<AlphaCellModel> getPluginList() {
return pluginList;
}
@Override
public void writeXML(XMLPrintWriter writer) {
@ -210,7 +153,6 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear
if (!envFile.exists()) {
createRecentFile(envFile);
}
return envFile;
}

20
designer/src/com/fr/design/mainframe/alphafine/search/manager/RecommendSearchManager.java

@ -14,12 +14,16 @@ import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import com.fr.stable.CodeUtils;
import java.util.ArrayList;
import java.util.List;
/**
* Created by XiaXiang on 2017/3/31.
*/
public class RecommendSearchManager implements AlphaFineSearchProcessor {
private static RecommendSearchManager recommendSearchManager = null;
private SearchResult modelList;
private List<AlphaCellModel> recommendModelList = new ArrayList<>();
//todo:for test
private static final String SEARCHAPI = "http://localhost:8080/monitor/alphafine/search/recommend?searchKey=";
@ -51,17 +55,18 @@ public class RecommendSearchManager implements AlphaFineSearchProcessor {
AlphaFineHelper.checkCancel();
AlphaCellModel alphaCellModel = CellModelHelper.getModelFromJson((JSONObject) jsonArray.get(i));
if (alphaCellModel != null && !RecentSearchManager.getRecentSearchManger().getRecentModelList().contains(alphaCellModel)) {
this.modelList.add(alphaCellModel);
this.recommendModelList.add(alphaCellModel);
}
}
}
}
} catch (JSONException e) {
FRLogger.getLogger().error("data transform error! :" + e.getMessage());
FRLogger.getLogger().error("recommend search error! :" + e.getMessage());
}
if (modelList.size() > 0) {
modelList.add(0, new MoreModel(Inter.getLocText("FR-Designer_AlphaFine_Recommend"), false));
modelList.add(new MoreModel(Inter.getLocText("FR-Designer_AlphaFine_Recommend"), false));
modelList.addAll(recommendModelList);
}
}
@ -71,7 +76,7 @@ public class RecommendSearchManager implements AlphaFineSearchProcessor {
private SearchResult getNoConnectList() {
SearchResult result = new SearchResult();
result.add(0, new MoreModel(Inter.getLocText("FR-Designer_AlphaFine_Recommend"), false));
result.add(AlphaFineHelper.noConnectionModel);
result.add(AlphaFineHelper.NO_CONNECTION_MODEL);
return result;
}
@ -80,4 +85,11 @@ public class RecommendSearchManager implements AlphaFineSearchProcessor {
return new SearchResult();
}
public List<AlphaCellModel> getRecommendModelList() {
return recommendModelList;
}
public void setRecommendModelList(List<AlphaCellModel> recommendModelList) {
this.recommendModelList = recommendModelList;
}
}

Loading…
Cancel
Save