From ee6890d7bc04653811cbac57ea2701456c3d5b83 Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Fri, 9 Jun 2017 17:17:40 +0800 Subject: [PATCH] =?UTF-8?q?alphafine=20bug=20fix=20=E5=8E=BB=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mainframe/alphafine/AlphaFineHelper.java | 17 ++++- .../alphafine/component/AlphaFinePane.java | 2 +- .../search/manager/ActionSearchManager.java | 33 +++++----- .../search/manager/DocumentSearchManager.java | 42 +++++-------- .../search/manager/FileSearchManager.java | 33 +++++----- .../search/manager/PluginSearchManager.java | 54 +++++++--------- .../search/manager/RecentSearchManager.java | 62 +------------------ .../manager/RecommendSearchManager.java | 20 ++++-- 8 files changed, 107 insertions(+), 156 deletions(-) diff --git a/designer/src/com/fr/design/mainframe/alphafine/AlphaFineHelper.java b/designer/src/com/fr/design/mainframe/alphafine/AlphaFineHelper.java index 53b60c6b2c..1cfe25c4da 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/AlphaFineHelper.java +++ b/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 getFilterResult() { + List recentList = RecentSearchManager.getRecentSearchManger().getRecentModelList(); + List recommendList = RecommendSearchManager.getRecommendSearchManager().getRecommendModelList(); + recentList.addAll(recommendList); + return recentList; + } + diff --git a/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFinePane.java b/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFinePane.java index 3d4173bc5c..e5ea8e2588 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFinePane.java +++ b/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() { 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 a38c52b434..8d21c239de 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 @@ -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; } 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 7d5d4a6dfa..2c4e5546f9 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 @@ -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; } 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 b3d8ee9415..99e76ada1f 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 @@ -29,6 +29,9 @@ public class FileSearchManager implements AlphaFineSearchProcessor { private List 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; } 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 44266cad27..53fc0bb17d 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 @@ -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 { } } - - - - } 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 8f818fd9d6..2d88acbe43 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 @@ -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 fileList = new ArrayList<>(); - private List actionList = new ArrayList<>(); - private List documentList = new ArrayList<>(); - private List pluginList = new ArrayList<>(); private List recentModelList = new ArrayList<>(); private Map> recentKVModelMap = new HashMap<>(); @@ -99,7 +96,7 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear private void addModelToList(List 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 getFileList() { - return fileList; - } - - public List getActionList() { - return actionList; - } - - public List getDocumentList() { - return documentList; - } - - public List 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; } diff --git a/designer/src/com/fr/design/mainframe/alphafine/search/manager/RecommendSearchManager.java b/designer/src/com/fr/design/mainframe/alphafine/search/manager/RecommendSearchManager.java index b632418680..051c8e66ee 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/search/manager/RecommendSearchManager.java +++ b/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 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 getRecommendModelList() { + return recommendModelList; + } + + public void setRecommendModelList(List recommendModelList) { + this.recommendModelList = recommendModelList; + } }