|
|
|
@ -10,9 +10,11 @@ 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.file.filetree.FileNode; |
|
|
|
|
import com.fr.general.ComparatorUtils; |
|
|
|
|
import com.fr.general.FRLogger; |
|
|
|
|
import com.fr.general.Inter; |
|
|
|
|
import com.fr.stable.StableUtils; |
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
import com.fr.stable.project.ProjectConstants; |
|
|
|
|
|
|
|
|
|
import java.io.*; |
|
|
|
@ -23,14 +25,17 @@ import java.util.List;
|
|
|
|
|
* Created by XiaXiang on 2017/3/27. |
|
|
|
|
*/ |
|
|
|
|
public class FileSearchManager implements AlphaFineSearchProcessor { |
|
|
|
|
private static final int MARK_LENGTH = 6; |
|
|
|
|
private static final String DS_NAME = "dsname=\""; |
|
|
|
|
private static final MoreModel TITLE_MODEL = new MoreModel(Inter.getLocText("FR-Designer_Templates"), CellType.FILE); |
|
|
|
|
private static FileSearchManager fileSearchManager = null; |
|
|
|
|
private SearchResult filterModelList; |
|
|
|
|
private SearchResult lessModelList; |
|
|
|
|
private SearchResult moreModelList; |
|
|
|
|
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); |
|
|
|
|
//隐藏的搜索功能,可根据特殊的字符标记判断搜索分类
|
|
|
|
|
private boolean isContainCpt = true; |
|
|
|
|
private boolean isContainFrm = true; |
|
|
|
|
|
|
|
|
|
public synchronized static FileSearchManager getFileSearchManager() { |
|
|
|
|
init(); |
|
|
|
@ -43,47 +48,72 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 根据文件路径获取文件模型 |
|
|
|
|
* |
|
|
|
|
* @param filePath |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public static FileModel getModelFromCloud(String filePath) { |
|
|
|
|
String name = AlphaFineHelper.findFileName(filePath); |
|
|
|
|
return new FileModel(name, filePath); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public synchronized SearchResult getLessSearchResult(String searchText) { |
|
|
|
|
this.filterModelList = new SearchResult(); |
|
|
|
|
this.lessModelList = new SearchResult(); |
|
|
|
|
this.moreModelList = new SearchResult(); |
|
|
|
|
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainTemplate()) { |
|
|
|
|
Env env = FRContext.getCurrentEnv(); |
|
|
|
|
fileNodes = new ArrayList<>(); |
|
|
|
|
fileNodes = listTpl(env, ProjectConstants.REPORTLETS_NAME, true); |
|
|
|
|
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); |
|
|
|
|
if (searchText.startsWith("k:frm ")) { |
|
|
|
|
isContainCpt = false; |
|
|
|
|
searchText = searchText.substring(MARK_LENGTH, searchText.length()); |
|
|
|
|
} else if (searchText.startsWith("k:cpt ")) { |
|
|
|
|
isContainFrm = false; |
|
|
|
|
searchText = searchText.substring(MARK_LENGTH, searchText.length()); |
|
|
|
|
} |
|
|
|
|
if (StringUtils.isBlank(searchText) || ComparatorUtils.equals(searchText, DS_NAME)) { |
|
|
|
|
lessModelList.add(TITLE_MODEL); |
|
|
|
|
return lessModelList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
SearchResult result = new SearchResult(); |
|
|
|
|
for (Object object : filterModelList) { |
|
|
|
|
if (!AlphaFineHelper.getFilterResult().contains(object)) { |
|
|
|
|
result.add(object); |
|
|
|
|
} |
|
|
|
|
Env env = FRContext.getCurrentEnv(); |
|
|
|
|
fileNodes = new ArrayList<>(); |
|
|
|
|
fileNodes = listTpl(env, ProjectConstants.REPORTLETS_NAME, true); |
|
|
|
|
isContainCpt = true; |
|
|
|
|
isContainFrm = true; |
|
|
|
|
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); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
SearchResult result = new SearchResult(); |
|
|
|
|
for (Object object : filterModelList) { |
|
|
|
|
if (!AlphaFineHelper.getFilterResult().contains(object)) { |
|
|
|
|
result.add(object); |
|
|
|
|
} |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
if (result.size() < AlphaFineConstants.SHOW_SIZE + 1) { |
|
|
|
|
lessModelList.add(0, TITLE_MODEL); |
|
|
|
|
if (result.size() == 0) { |
|
|
|
|
lessModelList.add(AlphaFineHelper.NO_RESULT_MODEL); |
|
|
|
|
} else { |
|
|
|
|
lessModelList.add(0, MORE_MODEL); |
|
|
|
|
lessModelList.addAll(result.subList(0, AlphaFineConstants.SHOW_SIZE)); |
|
|
|
|
moreModelList.addAll(result.subList(AlphaFineConstants.SHOW_SIZE, result.size())); |
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 搜索文件内容 |
|
|
|
|
* |
|
|
|
|
* @param searchText |
|
|
|
|
* @param node |
|
|
|
|
* @param isAlreadyContain |
|
|
|
@ -118,6 +148,7 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 搜索模板 |
|
|
|
|
* |
|
|
|
|
* @param searchText |
|
|
|
|
* @param node |
|
|
|
|
* @param isAlreadyContain |
|
|
|
@ -125,7 +156,7 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
|
|
|
|
|
*/ |
|
|
|
|
private boolean searchFile(String searchText, FileNode node, boolean isAlreadyContain) { |
|
|
|
|
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainTemplate()) { |
|
|
|
|
if (node.getName().toLowerCase().contains(searchText.toLowerCase())) { |
|
|
|
|
if (node.getName().toLowerCase().contains(searchText)) { |
|
|
|
|
FileModel model = new FileModel(node.getName(), node.getEnvPath()); |
|
|
|
|
this.filterModelList.add(model); |
|
|
|
|
isAlreadyContain = true; |
|
|
|
@ -141,6 +172,7 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取工作目录下所有符合要求的模板 |
|
|
|
|
* |
|
|
|
|
* @param env |
|
|
|
|
* @param rootFilePath |
|
|
|
|
* @param recurse |
|
|
|
@ -151,13 +183,14 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
|
|
|
|
|
try { |
|
|
|
|
listAll(env, rootFilePath, fileNodeList, recurse); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
FRContext.getLogger().error(e.getMessage(), e); |
|
|
|
|
FRContext.getLogger().error("file search error: " + e.getMessage(), e); |
|
|
|
|
} |
|
|
|
|
return fileNodeList; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取当前工作目录下所有模板 |
|
|
|
|
* |
|
|
|
|
* @param env |
|
|
|
|
* @param rootFilePath |
|
|
|
|
* @param nodeList |
|
|
|
@ -174,20 +207,37 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
|
|
|
|
|
} else { |
|
|
|
|
nodeList.add(fns[i]); |
|
|
|
|
} |
|
|
|
|
} else if (fileNode.isFileType("cpt") || fileNode.isFileType("frm")) { |
|
|
|
|
} else if (isContainCpt && fileNode.isFileType("cpt")) { |
|
|
|
|
nodeList.add(fileNode); |
|
|
|
|
} else if (isContainFrm && fileNode.isFileType("frm")) { |
|
|
|
|
nodeList.add(fileNode); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 根据文件路径获取文件模型 |
|
|
|
|
* @param filePath |
|
|
|
|
* 是否包含cpt |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public static FileModel getModelFromCloud(String filePath) { |
|
|
|
|
String name = AlphaFineHelper.findFileName(filePath); |
|
|
|
|
return new FileModel(name, filePath); |
|
|
|
|
public boolean isContainCpt() { |
|
|
|
|
return isContainCpt; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setContainCpt(boolean containCpt) { |
|
|
|
|
isContainCpt = containCpt; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 是否包含frm |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public boolean isContainFrm() { |
|
|
|
|
return isContainFrm; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setContainFrm(boolean containFrm) { |
|
|
|
|
isContainFrm = containFrm; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|