From 4a0bb32a04227e1bff56876e1b0af3638a3b8fa2 Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Thu, 26 Jul 2018 15:27:07 +0800 Subject: [PATCH 1/4] =?UTF-8?q?REPORT-9407=20=E3=80=9010.0=E4=B8=80?= =?UTF-8?q?=E8=BD=AE=E5=9B=9E=E5=BD=92=E3=80=91=E8=BF=9C=E7=A8=8B=E8=AE=BE?= =?UTF-8?q?=E8=AE=A1=E6=97=B6alphafine=E6=90=9C=E7=B4=A2=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manager/impl/FileSearchManager.java | 187 ++++-------------- 1 file changed, 34 insertions(+), 153 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java index ea32a4427a..b3aa48d188 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java @@ -1,6 +1,7 @@ package com.fr.design.mainframe.alphafine.search.manager.impl; import com.fr.base.FRContext; +import com.fr.base.extension.FileExtension; import com.fr.design.DesignerEnvManager; import com.fr.design.mainframe.alphafine.AlphaFineConstants; import com.fr.design.mainframe.alphafine.AlphaFineHelper; @@ -11,21 +12,11 @@ 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.Inter; import com.fr.json.JSONObject; -import com.fr.log.FineLoggerFactory; -import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; import com.fr.stable.project.ProjectConstants; -import com.fr.workspace.WorkContext; -import java.io.BufferedReader; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.List; /** * Created by XiaXiang on 2017/3/27. @@ -40,7 +31,7 @@ public class FileSearchManager implements AlphaFineSearchProvider { private SearchResult lessModelList; private SearchResult moreModelList; private String searchText; - private List fileNodes = null; + private FileNode[] fileNodes = null; //停止搜索 private boolean stopSearch = false; //隐藏的搜索功能,可根据特殊的字符标记判断搜索分类 @@ -58,9 +49,6 @@ public class FileSearchManager implements AlphaFineSearchProvider { return instance; } - public synchronized static void init() { - - } /** * 根据文件路径获取文件模型 @@ -81,55 +69,55 @@ public class FileSearchManager implements AlphaFineSearchProvider { this.moreModelList = new SearchResult(); this.searchText = dealWithSearchText(searchText); if (StringUtils.isBlank(this.searchText) || ComparatorUtils.equals(this.searchText, DS_NAME)) { - lessModelList.add(new MoreModel(com.fr.design.i18n.Toolkit.i18nText("FR-Designer_Templates"))); + lessModelList.add(new MoreModel(Inter.getLocText("FR-Designer_Templates"))); return lessModelList; } - fileNodes = new ArrayList<>(); - fileNodes = listTpl(ProjectConstants.REPORTLETS_NAME, true); AlphaFineHelper.checkCancel(); + fileNodes = FRContext.getFileNodes().list(ProjectConstants.REPORTLETS_NAME, new FileExtension[]{FileExtension.CPT, FileExtension.FRM}, true); isContainCpt = true; isContainFrm = true; - doSearch(this.searchText, true); - if (stopSearch) { - lessModelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("FR-Designer_Templates"), com.fr.design.i18n.Toolkit.i18nText("FR-Designer_AlphaFine_ShowAll"), true, CellType.FILE)); - lessModelList.addAll(filterModelList.subList(0, AlphaFineConstants.SHOW_SIZE)); - stopSearch = false; - return this.lessModelList; - } + doSearch(this.searchText); if (filterModelList.isEmpty()) { return new SearchResult(); + } else if (filterModelList.size() < AlphaFineConstants.SHOW_SIZE + 1) { + lessModelList.add(0, new MoreModel(Inter.getLocText("FR-Designer_Templates"))); + lessModelList.addAll(filterModelList); + } else { + 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)); + moreModelList.addAll(filterModelList.subList(AlphaFineConstants.SHOW_SIZE, filterModelList.size())); + } - lessModelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("FR-Designer_Templates"), com.fr.design.i18n.Toolkit.i18nText("FR-Designer_AlphaFine_ShowAll"), false, CellType.FILE)); - lessModelList.addAll(filterModelList); return lessModelList; } @Override public SearchResult getMoreSearchResult(String searchText) { - if (moreModelList != null && !moreModelList.isEmpty()) { - return moreModelList; - } - this.filterModelList = new SearchResult(); - this.moreModelList = new SearchResult(); - AlphaFineHelper.checkCancel(); - isContainCpt = true; - isContainFrm = true; - doSearch(this.searchText, false); - moreModelList.addAll(filterModelList.subList(AlphaFineConstants.SHOW_SIZE, filterModelList.size())); return moreModelList; } - private void doSearch(String searchText, boolean needMore) { - for (FileNode node : fileNodes) { - boolean isAlreadyContain = false; - isAlreadyContain = searchFile(searchText, node, isAlreadyContain, needMore); - if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainFileContent() && node.getLock() == null) { - searchFileContent(searchText, node, isAlreadyContain, needMore); + private void doSearch(String searchText) { + if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainTemplate()) { + for (FileNode node : fileNodes) { + if (node.getName().toLowerCase().contains(searchText)) { + FileModel model = new FileModel(node.getName(), node.getEnvPath()); + if (!AlphaFineHelper.getFilterResult().contains(model)) { + AlphaFineHelper.checkCancel(); + filterModelList.add(model); + } + } + } - if (filterModelList.size() > AlphaFineConstants.SHOW_SIZE && stopSearch) { - return; + } + if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainFileContent()) { + FileNode[] fileNodes = FRContext.getFileNodes().filterFiles(searchText, ProjectConstants.REPORTLETS_NAME, new FileExtension[]{FileExtension.CPT, FileExtension.FRM}, true); + for (FileNode node : fileNodes) { + FileModel model = new FileModel(node.getName(), node.getEnvPath()); + if (!AlphaFineHelper.getFilterResult().contains(model) && !filterModelList.contains(model)) { + AlphaFineHelper.checkCancel(); + filterModelList.add(model); + } } - } } @@ -144,113 +132,6 @@ public class FileSearchManager implements AlphaFineSearchProvider { return searchText; } - /** - * 搜索文件内容 - * - * @param searchText - * @param node - * @param isAlreadyContain - */ - private void searchFileContent(String searchText, FileNode node, boolean isAlreadyContain, boolean needMore) { - try { - InputStream inputStream = new ByteArrayInputStream(WorkContext.getWorkResource().readFully(StableUtils.pathJoin(ProjectConstants.REPORTLETS_NAME, node.getEnvPath().substring(ProjectConstants.REPORTLETS_NAME.length() + 1)))); - InputStreamReader isr = new InputStreamReader(inputStream, "UTF-8"); - BufferedReader reader = new BufferedReader(isr); - String line; - int columnNumber; - boolean isFoundInContent = false; - while ((line = reader.readLine()) != null) { - columnNumber = line.toLowerCase().indexOf(searchText); - if (columnNumber != -1) { - isFoundInContent = true; - break; - } - } - if (isFoundInContent && !isAlreadyContain) { - FileModel model = new FileModel(node.getName(), node.getEnvPath()); - if (!AlphaFineHelper.getFilterResult().contains(model)) { - AlphaFineHelper.checkCancel(); - filterModelList.add(model); - } - if (this.filterModelList.size() > AlphaFineConstants.SHOW_SIZE && needMore) { - stopSearch = true; - } - } - isr.close(); - reader.close(); - } catch (Exception e) { - FineLoggerFactory.getLogger().error("file read error: " + e.getMessage()); - } - } - - /** - * 搜索模板 - * - * @param searchText - * @param node - * @param isAlreadyContain - * @return - */ - 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()); - if (!AlphaFineHelper.getFilterResult().contains(model)) { - AlphaFineHelper.checkCancel(); - filterModelList.add(model); - } - if (filterModelList.size() > AlphaFineConstants.SHOW_SIZE && needMore) { - stopSearch = true; - } - isAlreadyContain = true; - } - } - return isAlreadyContain; - } - - /** - * 获取工作目录下所有符合要求的模板 - * - * @param rootFilePath - * @param recurse - * @return - */ - private List listTpl(String rootFilePath, boolean recurse) { - List fileNodeList = new ArrayList(); - try { - listAll(rootFilePath, fileNodeList, recurse); - } catch (Exception e) { - FRContext.getLogger().error("file search error: " + e.getMessage(), e); - } - return fileNodeList; - } - - /** - * 获取当前工作目录下所有模板 - * - * @param rootFilePath - * @param nodeList - * @param recurse - * @throws Exception - */ - private void listAll(String rootFilePath, List nodeList, boolean recurse) throws Exception { - - FileNode[] fns = FRContext.getFileNodes().list(rootFilePath); - for (int i = 0; i < fns.length; i++) { - FileNode fileNode = fns[i]; - if (fileNode.isDirectory()) { - if (recurse) { - listAll(rootFilePath + File.separator + fns[i].getName(), nodeList, true); - } else { - nodeList.add(fns[i]); - } - } else if (isContainCpt && fileNode.isFileType("cpt")) { - nodeList.add(fileNode); - } else if (isContainFrm && fileNode.isFileType("frm")) { - nodeList.add(fileNode); - } - } - } /** * 是否包含cpt From b5a17d313e4cc0d49784db7aef8d9e9b3ce68a8f Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Thu, 26 Jul 2018 19:10:18 +0800 Subject: [PATCH 2/4] rt --- .../alphafine/search/manager/impl/FileSearchManager.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java index b3aa48d188..0c2ac63aee 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java @@ -14,6 +14,7 @@ import com.fr.file.filetree.FileNode; import com.fr.general.ComparatorUtils; import com.fr.general.Inter; import com.fr.json.JSONObject; +import com.fr.locale.InterProviderFactory; import com.fr.stable.StringUtils; import com.fr.stable.project.ProjectConstants; @@ -33,7 +34,6 @@ public class FileSearchManager implements AlphaFineSearchProvider { private String searchText; private FileNode[] fileNodes = null; //停止搜索 - private boolean stopSearch = false; //隐藏的搜索功能,可根据特殊的字符标记判断搜索分类 private boolean isContainCpt = true; private boolean isContainFrm = true; @@ -80,10 +80,10 @@ public class FileSearchManager implements AlphaFineSearchProvider { if (filterModelList.isEmpty()) { return new SearchResult(); } else if (filterModelList.size() < AlphaFineConstants.SHOW_SIZE + 1) { - lessModelList.add(0, new MoreModel(Inter.getLocText("FR-Designer_Templates"))); + lessModelList.add(0, new MoreModel(InterProviderFactory.getProvider().getLocText("FR-Designer_Templates"))); lessModelList.addAll(filterModelList); } else { - lessModelList.add(0, new MoreModel(Inter.getLocText("FR-Designer_Templates"), Inter.getLocText("FR-Designer_AlphaFine_ShowAll"), true, CellType.FILE)); + lessModelList.add(0, new MoreModel(InterProviderFactory.getProvider().getLocText("FR-Designer_Templates"), Inter.getLocText("FR-Designer_AlphaFine_ShowAll"), true, CellType.FILE)); lessModelList.addAll(filterModelList.subList(0, AlphaFineConstants.SHOW_SIZE)); moreModelList.addAll(filterModelList.subList(AlphaFineConstants.SHOW_SIZE, filterModelList.size())); From 3871b1d1031a7f140541da268dbd8b2030fae765 Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Thu, 26 Jul 2018 19:27:23 +0800 Subject: [PATCH 3/4] rt --- .../alphafine/search/manager/impl/FileSearchManager.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java index 0c2ac63aee..c2b5aa5470 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java @@ -33,6 +33,7 @@ public class FileSearchManager implements AlphaFineSearchProvider { private SearchResult moreModelList; private String searchText; private FileNode[] fileNodes = null; + //停止搜索 //隐藏的搜索功能,可根据特殊的字符标记判断搜索分类 private boolean isContainCpt = true; @@ -69,7 +70,7 @@ public class FileSearchManager implements AlphaFineSearchProvider { this.moreModelList = new SearchResult(); this.searchText = dealWithSearchText(searchText); if (StringUtils.isBlank(this.searchText) || ComparatorUtils.equals(this.searchText, DS_NAME)) { - lessModelList.add(new MoreModel(Inter.getLocText("FR-Designer_Templates"))); + lessModelList.add(new MoreModel(InterProviderFactory.getProvider().getLocText("FR-Designer_Templates"))); return lessModelList; } AlphaFineHelper.checkCancel(); From 55a6f0a622c113446f00574dd17f91530189a027 Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Thu, 26 Jul 2018 19:57:18 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=9B=BD=E9=99=85=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../search/manager/impl/FileSearchManager.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java index c2b5aa5470..5262046a8d 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/search/manager/impl/FileSearchManager.java @@ -12,9 +12,7 @@ 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.Inter; import com.fr.json.JSONObject; -import com.fr.locale.InterProviderFactory; import com.fr.stable.StringUtils; import com.fr.stable.project.ProjectConstants; @@ -33,7 +31,7 @@ public class FileSearchManager implements AlphaFineSearchProvider { private SearchResult moreModelList; private String searchText; private FileNode[] fileNodes = null; - + //停止搜索 //隐藏的搜索功能,可根据特殊的字符标记判断搜索分类 private boolean isContainCpt = true; @@ -70,7 +68,7 @@ public class FileSearchManager implements AlphaFineSearchProvider { this.moreModelList = new SearchResult(); this.searchText = dealWithSearchText(searchText); if (StringUtils.isBlank(this.searchText) || ComparatorUtils.equals(this.searchText, DS_NAME)) { - lessModelList.add(new MoreModel(InterProviderFactory.getProvider().getLocText("FR-Designer_Templates"))); + lessModelList.add(new MoreModel(com.fr.design.i18n.Toolkit.i18nText("FR-Designer_Templates"))); return lessModelList; } AlphaFineHelper.checkCancel(); @@ -81,10 +79,10 @@ public class FileSearchManager implements AlphaFineSearchProvider { if (filterModelList.isEmpty()) { return new SearchResult(); } else if (filterModelList.size() < AlphaFineConstants.SHOW_SIZE + 1) { - lessModelList.add(0, new MoreModel(InterProviderFactory.getProvider().getLocText("FR-Designer_Templates"))); + lessModelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("FR-Designer_Templates"))); lessModelList.addAll(filterModelList); } else { - lessModelList.add(0, new MoreModel(InterProviderFactory.getProvider().getLocText("FR-Designer_Templates"), Inter.getLocText("FR-Designer_AlphaFine_ShowAll"), true, CellType.FILE)); + lessModelList.add(0, new MoreModel(com.fr.design.i18n.Toolkit.i18nText("FR-Designer_Templates"), com.fr.design.i18n.Toolkit.i18nText("FR-Designer_AlphaFine_ShowAll"), true, CellType.FILE)); lessModelList.addAll(filterModelList.subList(0, AlphaFineConstants.SHOW_SIZE)); moreModelList.addAll(filterModelList.subList(AlphaFineConstants.SHOW_SIZE, filterModelList.size()));