Browse Source

代码质量

master
XiaXiang 8 years ago
parent
commit
8b264630c2
  1. 12
      designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java
  2. 14
      designer/src/com/fr/design/mainframe/alphafine/model/SearchListModel.java
  3. 4
      designer/src/com/fr/design/mainframe/alphafine/model/SearchResult.java
  4. 3
      designer/src/com/fr/design/mainframe/alphafine/search/manager/ActionSearchManager.java
  5. 3
      designer/src/com/fr/design/mainframe/alphafine/search/manager/FileSearchManager.java
  6. 20
      designer/src/com/fr/design/mainframe/alphafine/search/manager/RecentSearchManager.java
  7. 7
      designer/src/com/fr/design/mainframe/alphafine/search/manager/RecommendSearchManager.java

12
designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java

@ -366,7 +366,7 @@ public class AlphaFineDialog extends UIDialog {
private void getDocumentList(final String searchText) { private void getDocumentList(final String searchText) {
SearchResult documentModelList = DocumentSearchManager.getDocumentSearchManager().getLessSearchResult(searchText); SearchResult documentModelList = DocumentSearchManager.getDocumentSearchManager().getLessSearchResult(searchText);
for (Object object : documentModelList) { for (AlphaCellModel object : documentModelList) {
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
searchListModel.addElement(object); searchListModel.addElement(object);
} }
@ -374,7 +374,7 @@ public class AlphaFineDialog extends UIDialog {
private void getFileList(final String searchText) { private void getFileList(final String searchText) {
SearchResult fileModelList = FileSearchManager.getFileSearchManager().getLessSearchResult(searchText); SearchResult fileModelList = FileSearchManager.getFileSearchManager().getLessSearchResult(searchText);
for (Object object : fileModelList) { for (AlphaCellModel object : fileModelList) {
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
searchListModel.addElement(object); searchListModel.addElement(object);
} }
@ -382,7 +382,7 @@ public class AlphaFineDialog extends UIDialog {
private void getActionList(final String searchText) { private void getActionList(final String searchText) {
SearchResult actionModelList = ActionSearchManager.getActionSearchManager().getLessSearchResult(searchText); SearchResult actionModelList = ActionSearchManager.getActionSearchManager().getLessSearchResult(searchText);
for (Object object : actionModelList) { for (AlphaCellModel object : actionModelList) {
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
searchListModel.addElement(object); searchListModel.addElement(object);
} }
@ -390,7 +390,7 @@ public class AlphaFineDialog extends UIDialog {
private void getPluginList(final String searchText) { private void getPluginList(final String searchText) {
SearchResult pluginModelList = PluginSearchManager.getPluginSearchManager().getLessSearchResult(searchText); SearchResult pluginModelList = PluginSearchManager.getPluginSearchManager().getLessSearchResult(searchText);
for (Object object : pluginModelList) { for (AlphaCellModel object : pluginModelList) {
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
searchListModel.addElement(object); searchListModel.addElement(object);
} }
@ -398,7 +398,7 @@ public class AlphaFineDialog extends UIDialog {
private void getRecommendList(final String searchText) { private void getRecommendList(final String searchText) {
SearchResult recommendModelList = RecommendSearchManager.getRecommendSearchManager().getLessSearchResult(searchText); SearchResult recommendModelList = RecommendSearchManager.getRecommendSearchManager().getLessSearchResult(searchText);
for (Object object : recommendModelList) { for (AlphaCellModel object : recommendModelList) {
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
searchListModel.addElement(object); searchListModel.addElement(object);
} }
@ -406,7 +406,7 @@ public class AlphaFineDialog extends UIDialog {
private void getRecentList(final String searchText) { private void getRecentList(final String searchText) {
SearchResult recentModelList = RecentSearchManager.getRecentSearchManger().getLessSearchResult(searchText); SearchResult recentModelList = RecentSearchManager.getRecentSearchManger().getLessSearchResult(searchText);
for (Object object : recentModelList) { for (AlphaCellModel object : recentModelList) {
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
searchListModel.addElement(object); searchListModel.addElement(object);
} }

14
designer/src/com/fr/design/mainframe/alphafine/model/SearchListModel.java

@ -1,11 +1,13 @@
package com.fr.design.mainframe.alphafine.model; package com.fr.design.mainframe.alphafine.model;
import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel;
import javax.swing.*; import javax.swing.*;
/** /**
* Created by XiaXiang on 2017/4/20. * Created by XiaXiang on 2017/4/20.
*/ */
public class SearchListModel extends DefaultListModel { public class SearchListModel extends DefaultListModel<AlphaCellModel> {
SearchResult myDelegate; SearchResult myDelegate;
public SearchListModel(SearchResult searchResult) { public SearchListModel(SearchResult searchResult) {
@ -13,26 +15,26 @@ public class SearchListModel extends DefaultListModel {
} }
@Override @Override
public void addElement(Object element) { public void addElement(AlphaCellModel element) {
int index = myDelegate.size(); int index = myDelegate.size();
myDelegate.add(element); myDelegate.add(element);
fireContentsChanged(this, index, index); fireContentsChanged(this, index, index);
} }
@Override @Override
public Object getElementAt(int index) { public AlphaCellModel getElementAt(int index) {
return myDelegate.get(index); return myDelegate.get(index);
} }
@Override @Override
public void add(int index, Object element) { public void add(int index, AlphaCellModel element) {
myDelegate.add(index, element); myDelegate.add(index, element);
fireIntervalAdded(this, index, index); fireIntervalAdded(this, index, index);
} }
@Override @Override
public Object remove(int index) { public AlphaCellModel remove(int index) {
Object object = myDelegate.get(index); AlphaCellModel object = myDelegate.get(index);
myDelegate.remove(object); myDelegate.remove(object);
fireIntervalRemoved(this, index, index); fireIntervalRemoved(this, index, index);
return object; return object;

4
designer/src/com/fr/design/mainframe/alphafine/model/SearchResult.java

@ -1,11 +1,13 @@
package com.fr.design.mainframe.alphafine.model; package com.fr.design.mainframe.alphafine.model;
import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
* Created by XiaXiang on 2017/4/20. * Created by XiaXiang on 2017/4/20.
*/ */
public class SearchResult extends ArrayList<Object> { public class SearchResult extends ArrayList<AlphaCellModel> {
private boolean needMore; private boolean needMore;

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

@ -5,6 +5,7 @@ import com.fr.design.mainframe.alphafine.AlphaFineConstants;
import com.fr.design.mainframe.alphafine.AlphaFineHelper; import com.fr.design.mainframe.alphafine.AlphaFineHelper;
import com.fr.design.mainframe.alphafine.CellType; import com.fr.design.mainframe.alphafine.CellType;
import com.fr.design.mainframe.alphafine.cell.model.ActionModel; import com.fr.design.mainframe.alphafine.cell.model.ActionModel;
import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel;
import com.fr.design.mainframe.alphafine.cell.model.MoreModel; import com.fr.design.mainframe.alphafine.cell.model.MoreModel;
import com.fr.design.mainframe.alphafine.model.SearchResult; import com.fr.design.mainframe.alphafine.model.SearchResult;
import com.fr.design.mainframe.toolbar.UpdateActionManager; import com.fr.design.mainframe.toolbar.UpdateActionManager;
@ -70,7 +71,7 @@ public class ActionSearchManager implements AlphaFineSearchProcessor {
} }
} }
SearchResult result = new SearchResult(); SearchResult result = new SearchResult();
for (Object object : filterModelList) { for (AlphaCellModel object : filterModelList) {
if (!AlphaFineHelper.getFilterResult().contains(object)) { if (!AlphaFineHelper.getFilterResult().contains(object)) {
result.add(object); result.add(object);
} }

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

@ -6,6 +6,7 @@ import com.fr.design.DesignerEnvManager;
import com.fr.design.mainframe.alphafine.AlphaFineConstants; import com.fr.design.mainframe.alphafine.AlphaFineConstants;
import com.fr.design.mainframe.alphafine.AlphaFineHelper; import com.fr.design.mainframe.alphafine.AlphaFineHelper;
import com.fr.design.mainframe.alphafine.CellType; import com.fr.design.mainframe.alphafine.CellType;
import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel;
import com.fr.design.mainframe.alphafine.cell.model.FileModel; import com.fr.design.mainframe.alphafine.cell.model.FileModel;
import com.fr.design.mainframe.alphafine.cell.model.MoreModel; import com.fr.design.mainframe.alphafine.cell.model.MoreModel;
import com.fr.design.mainframe.alphafine.model.SearchResult; import com.fr.design.mainframe.alphafine.model.SearchResult;
@ -94,7 +95,7 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
} }
SearchResult result = new SearchResult(); SearchResult result = new SearchResult();
for (Object object : filterModelList) { for (AlphaCellModel object : filterModelList) {
if (!AlphaFineHelper.getFilterResult().contains(object)) { if (!AlphaFineHelper.getFilterResult().contains(object)) {
result.add(object); result.add(object);
} }

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

@ -39,8 +39,8 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear
private static RecentSearchManager recentSearchManager = null; private static RecentSearchManager recentSearchManager = null;
private static File recentFile = null; private static File recentFile = null;
private SearchResult modelList; private SearchResult modelList;
private List<AlphaCellModel> recentModelList = new ArrayList<>(); private SearchResult recentModelList;
private Map<String, List<AlphaCellModel>> recentKVModelMap = new HashMap<>(); private Map<String, SearchResult> recentKVModelMap = new HashMap<>();
public synchronized static RecentSearchManager getRecentSearchManger() { public synchronized static RecentSearchManager getRecentSearchManger() {
if (recentSearchManager == null) { if (recentSearchManager == null) {
@ -64,7 +64,7 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear
String nodeName = reader.getTagName(); String nodeName = reader.getTagName();
if (nodeName.equals("RecentModelList")) { if (nodeName.equals("RecentModelList")) {
String key = reader.getAttrAsString("searchKey", StringUtils.EMPTY); String key = reader.getAttrAsString("searchKey", StringUtils.EMPTY);
final ArrayList<AlphaCellModel> list = new ArrayList<>(); final SearchResult list = new SearchResult();
reader.readXMLObject(new XMLReadable() { reader.readXMLObject(new XMLReadable() {
@Override @Override
public void readXML(XMLableReader reader) { public void readXML(XMLableReader reader) {
@ -206,23 +206,19 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear
return recentModelList; return recentModelList;
} }
public void setRecentModelList(List<AlphaCellModel> recentModelList) {
this.recentModelList = recentModelList;
}
/** /**
* 根据搜索字段获取对应的model列表 * 根据搜索字段获取对应的model列表
* *
* @param searchText * @param searchText
* @return * @return
*/ */
public synchronized List<AlphaCellModel> getRecentModelList(String searchText) { private synchronized SearchResult getRecentModelList(String searchText) {
recentModelList = new ArrayList<>(); recentModelList = new SearchResult();
for (String key : recentKVModelMap.keySet()) { for (String key : recentKVModelMap.keySet()) {
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
if (ComparatorUtils.equals(key, searchText)) { if (ComparatorUtils.equals(key, searchText)) {
recentModelList = recentKVModelMap.get(searchText); recentModelList = recentKVModelMap.get(searchText);
List<AlphaCellModel> resultModelList = new ArrayList<>(recentModelList); SearchResult resultModelList = recentModelList;
Iterator<AlphaCellModel> modelIterator = resultModelList.iterator(); Iterator<AlphaCellModel> modelIterator = resultModelList.iterator();
while (modelIterator.hasNext()) { while (modelIterator.hasNext()) {
AlphaCellModel model = modelIterator.next(); AlphaCellModel model = modelIterator.next();
@ -234,7 +230,7 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear
Collections.sort(resultModelList); Collections.sort(resultModelList);
int size = resultModelList.size(); int size = resultModelList.size();
if (size > MAX_SIZE) { if (size > MAX_SIZE) {
return resultModelList.subList(0, MAX_SIZE); return (SearchResult) resultModelList.subList(0, MAX_SIZE);
} }
return resultModelList; return resultModelList;
} }
@ -259,7 +255,7 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear
} }
//trimToSize(cellModels); //trimToSize(cellModels);
} else { } else {
List<AlphaCellModel> list = new ArrayList<>(); SearchResult list = new SearchResult();
list.add(cellModel); list.add(cellModel);
recentKVModelMap.put(searchKey, list); recentKVModelMap.put(searchKey, list);
} }

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

@ -27,7 +27,7 @@ import java.util.List;
public class RecommendSearchManager implements AlphaFineSearchProcessor { public class RecommendSearchManager implements AlphaFineSearchProcessor {
private static RecommendSearchManager recommendSearchManager = null; private static RecommendSearchManager recommendSearchManager = null;
private SearchResult modelList; private SearchResult modelList;
private List<AlphaCellModel> recommendModelList = new ArrayList<>(); private SearchResult recommendModelList;
public synchronized static RecommendSearchManager getRecommendSearchManager() { public synchronized static RecommendSearchManager getRecommendSearchManager() {
if (recommendSearchManager == null) { if (recommendSearchManager == null) {
@ -39,7 +39,7 @@ public class RecommendSearchManager implements AlphaFineSearchProcessor {
@Override @Override
public synchronized SearchResult getLessSearchResult(String searchText) { public synchronized SearchResult getLessSearchResult(String searchText) {
this.modelList = new SearchResult(); this.modelList = new SearchResult();
this.recommendModelList = new ArrayList<>(); this.recommendModelList = new SearchResult();
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainRecommend()) { if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainRecommend()) {
String result; String result;
HttpClient httpClient = new HttpClient(AlphaFineConstants.SEARCHAPI + CodeUtils.cjkEncode(searchText)); HttpClient httpClient = new HttpClient(AlphaFineConstants.SEARCHAPI + CodeUtils.cjkEncode(searchText));
@ -105,7 +105,4 @@ public class RecommendSearchManager implements AlphaFineSearchProcessor {
return recommendModelList; return recommendModelList;
} }
public void setRecommendModelList(List<AlphaCellModel> recommendModelList) {
this.recommendModelList = recommendModelList;
}
} }

Loading…
Cancel
Save