|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
package com.fr.design.mainframe.alphafine.search.manager; |
|
|
|
|
package com.fr.design.mainframe.alphafine.search.manager.impl; |
|
|
|
|
|
|
|
|
|
import com.fr.base.Env; |
|
|
|
|
import com.fr.base.FRContext; |
|
|
|
@ -6,10 +6,10 @@ import com.fr.design.DesignerEnvManager;
|
|
|
|
|
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.model.AlphaCellModel; |
|
|
|
|
import com.fr.design.mainframe.alphafine.cell.model.FileModel; |
|
|
|
|
import com.fr.design.mainframe.alphafine.cell.model.MoreModel; |
|
|
|
|
import com.fr.design.mainframe.alphafine.model.SearchResult; |
|
|
|
|
import com.fr.design.mainframe.alphafine.search.manager.fun.AlphaFineSearchProvider; |
|
|
|
|
import com.fr.file.filetree.FileNode; |
|
|
|
|
import com.fr.general.ComparatorUtils; |
|
|
|
|
import com.fr.general.FRLogger; |
|
|
|
@ -31,7 +31,7 @@ import java.util.List;
|
|
|
|
|
/** |
|
|
|
|
* Created by XiaXiang on 2017/3/27. |
|
|
|
|
*/ |
|
|
|
|
public class FileSearchManager implements AlphaFineSearchProcessor { |
|
|
|
|
public class FileSearchManager implements AlphaFineSearchProvider { |
|
|
|
|
private static final int MARK_LENGTH = 6; |
|
|
|
|
private static final String DS_NAME = "dsname=\""; |
|
|
|
|
private static final String FRM_PREFIX = "k:frm "; |
|
|
|
@ -39,13 +39,14 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
|
|
|
|
|
private static FileSearchManager fileSearchManager = null; |
|
|
|
|
private SearchResult filterModelList; |
|
|
|
|
private SearchResult lessModelList; |
|
|
|
|
private SearchResult moreModelList; |
|
|
|
|
private List<FileNode> fileNodes = null; |
|
|
|
|
//停止搜索
|
|
|
|
|
private boolean stopSearch = false; |
|
|
|
|
//隐藏的搜索功能,可根据特殊的字符标记判断搜索分类
|
|
|
|
|
private boolean isContainCpt = true; |
|
|
|
|
private boolean isContainFrm = true; |
|
|
|
|
|
|
|
|
|
public synchronized static FileSearchManager getFileSearchManager() { |
|
|
|
|
public synchronized static FileSearchManager getInstance() { |
|
|
|
|
init(); |
|
|
|
|
return fileSearchManager; |
|
|
|
|
} |
|
|
|
@ -72,52 +73,66 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
|
|
|
|
|
public synchronized SearchResult getLessSearchResult(String searchText) { |
|
|
|
|
this.filterModelList = new SearchResult(); |
|
|
|
|
this.lessModelList = new SearchResult(); |
|
|
|
|
this.moreModelList = new SearchResult(); |
|
|
|
|
if (searchText.startsWith(FRM_PREFIX)) { |
|
|
|
|
isContainCpt = false; |
|
|
|
|
searchText = searchText.substring(MARK_LENGTH, searchText.length()); |
|
|
|
|
} else if (searchText.startsWith(CPT_PREFIX)) { |
|
|
|
|
isContainFrm = false; |
|
|
|
|
searchText = searchText.substring(MARK_LENGTH, searchText.length()); |
|
|
|
|
} |
|
|
|
|
searchText = dealWithSearchText(searchText); |
|
|
|
|
if (StringUtils.isBlank(searchText) || ComparatorUtils.equals(searchText, DS_NAME)) { |
|
|
|
|
lessModelList.add(new MoreModel(Inter.getLocText("FR-Designer_Templates"))); |
|
|
|
|
return lessModelList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Env env = FRContext.getCurrentEnv(); |
|
|
|
|
fileNodes = new ArrayList<>(); |
|
|
|
|
fileNodes = listTpl(env, ProjectConstants.REPORTLETS_NAME, true); |
|
|
|
|
AlphaFineHelper.checkCancel(); |
|
|
|
|
isContainCpt = true; |
|
|
|
|
isContainFrm = true; |
|
|
|
|
doSearch(searchText, true, env); |
|
|
|
|
if (stopSearch) { |
|
|
|
|
lessModelList.add(0, new MoreModel(Inter.getLocText("FR-Designer_Templates"), Inter.getLocText("FR-Designer_AlphaFine_ShowAll"), true, CellType.FILE)); |
|
|
|
|
lessModelList.addAll(filterModelList.subList(0, AlphaFineConstants.SHOW_SIZE)); |
|
|
|
|
stopSearch = false; |
|
|
|
|
return this.lessModelList; |
|
|
|
|
} |
|
|
|
|
if (filterModelList.isEmpty()) { |
|
|
|
|
return new SearchResult(); |
|
|
|
|
} |
|
|
|
|
lessModelList.add(0, new MoreModel(Inter.getLocText("FR-Designer_Templates"), Inter.getLocText("FR-Designer_AlphaFine_ShowAll"), false, CellType.FILE)); |
|
|
|
|
lessModelList.addAll(filterModelList); |
|
|
|
|
return lessModelList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public SearchResult getMoreSearchResult(String searchText) { |
|
|
|
|
this.filterModelList = new SearchResult(); |
|
|
|
|
this.lessModelList = new SearchResult(); |
|
|
|
|
searchText = dealWithSearchText(searchText); |
|
|
|
|
Env env = FRContext.getCurrentEnv(); |
|
|
|
|
AlphaFineHelper.checkCancel(); |
|
|
|
|
isContainCpt = true; |
|
|
|
|
isContainFrm = true; |
|
|
|
|
doSearch(searchText, false, env); |
|
|
|
|
lessModelList.addAll(filterModelList.subList(AlphaFineConstants.SHOW_SIZE, filterModelList.size())); |
|
|
|
|
return lessModelList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void doSearch(String searchText, boolean needMore, Env env) { |
|
|
|
|
for (FileNode node : fileNodes) { |
|
|
|
|
boolean isAlreadyContain = false; |
|
|
|
|
String fileEnvPath = node.getEnvPath(); |
|
|
|
|
String filePath = StableUtils.pathJoin(env.getPath(), fileEnvPath); |
|
|
|
|
isAlreadyContain = searchFile(searchText, node, isAlreadyContain); |
|
|
|
|
searchFileContent(searchText, node, isAlreadyContain, filePath); |
|
|
|
|
isAlreadyContain = searchFile(searchText, node, isAlreadyContain, needMore); |
|
|
|
|
searchFileContent(searchText, node, isAlreadyContain, filePath, needMore); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
SearchResult result = new SearchResult(); |
|
|
|
|
for (AlphaCellModel object : filterModelList) { |
|
|
|
|
if (!AlphaFineHelper.getFilterResult().contains(object)) { |
|
|
|
|
result.add(object); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private String dealWithSearchText(String searchText) { |
|
|
|
|
if (searchText.startsWith(FRM_PREFIX)) { |
|
|
|
|
isContainCpt = false; |
|
|
|
|
searchText = searchText.substring(MARK_LENGTH, searchText.length()); |
|
|
|
|
} else if (searchText.startsWith(CPT_PREFIX)) { |
|
|
|
|
isContainFrm = false; |
|
|
|
|
searchText = searchText.substring(MARK_LENGTH, searchText.length()); |
|
|
|
|
} |
|
|
|
|
if (result.isEmpty()) { |
|
|
|
|
return lessModelList; |
|
|
|
|
} else if (result.size() < AlphaFineConstants.SHOW_SIZE + 1) { |
|
|
|
|
lessModelList.add(0, new MoreModel(Inter.getLocText("FR-Designer_Templates"))); |
|
|
|
|
lessModelList.addAll(result); |
|
|
|
|
} else { |
|
|
|
|
lessModelList.add(0, new MoreModel(Inter.getLocText("FR-Designer_Templates"), Inter.getLocText("FR-Designer_AlphaFine_ShowAll"), true, CellType.FILE)); |
|
|
|
|
lessModelList.addAll(result.subList(0, AlphaFineConstants.SHOW_SIZE)); |
|
|
|
|
moreModelList.addAll(result.subList(AlphaFineConstants.SHOW_SIZE, result.size())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return this.lessModelList; |
|
|
|
|
return searchText; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -128,7 +143,7 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
|
|
|
|
|
* @param isAlreadyContain |
|
|
|
|
* @param filePath |
|
|
|
|
*/ |
|
|
|
|
private void searchFileContent(String searchText, FileNode node, boolean isAlreadyContain, String filePath) { |
|
|
|
|
private void searchFileContent(String searchText, FileNode node, boolean isAlreadyContain, String filePath, boolean needMore) { |
|
|
|
|
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainFileContent()) { |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
@ -146,7 +161,12 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
|
|
|
|
|
} |
|
|
|
|
if (isFoundInContent && !isAlreadyContain) { |
|
|
|
|
FileModel model = new FileModel(node.getName(), node.getEnvPath()); |
|
|
|
|
this.filterModelList.add(model); |
|
|
|
|
if (!AlphaFineHelper.getFilterResult().contains(model)) { |
|
|
|
|
filterModelList.add(model); |
|
|
|
|
} |
|
|
|
|
if (this.filterModelList.size() > AlphaFineConstants.SHOW_SIZE && needMore) { |
|
|
|
|
stopSearch = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
isr.close(); |
|
|
|
|
reader.close(); |
|
|
|
@ -166,22 +186,22 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
|
|
|
|
|
* @param isAlreadyContain |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private boolean searchFile(String searchText, FileNode node, boolean isAlreadyContain) { |
|
|
|
|
private boolean searchFile(String searchText, FileNode node, boolean isAlreadyContain, boolean needMore) { |
|
|
|
|
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainTemplate()) { |
|
|
|
|
if (node.getName().toLowerCase().contains(searchText)) { |
|
|
|
|
FileModel model = new FileModel(node.getName(), node.getEnvPath()); |
|
|
|
|
this.filterModelList.add(model); |
|
|
|
|
if (!AlphaFineHelper.getFilterResult().contains(model)) { |
|
|
|
|
filterModelList.add(model); |
|
|
|
|
} |
|
|
|
|
if (filterModelList.size() > AlphaFineConstants.SHOW_SIZE && needMore) { |
|
|
|
|
stopSearch = true; |
|
|
|
|
} |
|
|
|
|
isAlreadyContain = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return isAlreadyContain; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public SearchResult getMoreSearchResult() { |
|
|
|
|
return moreModelList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取工作目录下所有符合要求的模板 |
|
|
|
|
* |