xiaoxia 7 years ago
parent
commit
3955ce43a4
  1. 4
      designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java
  2. 118
      designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java
  3. 5
      designer/src/com/fr/design/mainframe/alphafine/searchManager/ActionSearchManager.java
  4. 6
      designer/src/com/fr/design/mainframe/alphafine/searchManager/DocumentSearchManager.java
  5. 81
      designer/src/com/fr/design/mainframe/alphafine/searchManager/FileSearchManager.java

4
designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java

@ -68,7 +68,9 @@ public class AlphaFineConstants {
public static final String REUSE_IMAGE_URL = "http://shop.finereport.com/reuse/";
public static final String DOCUMENT_SEARCH_URL = "http://help.finereport.com/doc-view-";
public static final String DOCUMENT_DOC_URL = "http://help.finereport.com/doc-view-";
public static final String DOCUMENT_SEARCH_URL = "http://help.finereport.com/?api-search-title-";
}

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

@ -170,58 +170,34 @@ public class AlphaFineDialog extends UIDialog {
private void showSearchResult(String searchText) {
if (searchResultPane == null) {
searchResultList = new JList();
searchResultPane = new JPanel();
searchResultPane.setPreferredSize(AlphaFineConstants.CONTENT_SIZE);
searchResultPane.setLayout(new BorderLayout());
searchResultList.setCellRenderer(new ContentCellRender());
searchResultList.setFixedCellHeight(AlphaFineConstants.CELL_HEIGHT);
searchResultList.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int selectedIndex = searchResultList.getSelectedIndex();
Object selectedValue = searchResultList.getSelectedValue();
if (e.getClickCount() == 2) {
final int i = searchResultList.locationToIndex(e.getPoint());
searchResultList.setSelectedIndex(i);
doNavigate(selectedIndex);
if (selectedValue instanceof AlphaCellModel) {
SearchResult originalResultList = LatestSearchManager.getLatestSearchManager().getLatestModelList();
originalResultList.add(searchResultList.getSelectedValue());
LatestSearchManager.getLatestSearchManager().setLatestModelList(originalResultList);
//保存最近搜索
saveHistory(originalResultList);
}
} else if (e.getClickCount() == 1) {
if (selectedValue instanceof MoreModel && ((MoreModel) selectedValue).isNeedMore()) {
HandleMoreOrLessResult(selectedIndex, (MoreModel) selectedValue);
}
}
}
});
initSearchResultComponents();
initListListener();
}
initSearchWorker(searchText);
}
// TODO: 2017/5/8 xiaxiang: e.getClickCount() == 1 时,偶发性的不能触发,所以先放到valueChanged
searchResultList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
showResult(searchResultList.getSelectedIndex(), searchResultList.getSelectedValue());
private void initSearchResultComponents() {
searchResultList = new JList();
searchResultPane = new JPanel();
searchResultPane.setPreferredSize(AlphaFineConstants.CONTENT_SIZE);
searchResultPane.setLayout(new BorderLayout());
searchResultList.setCellRenderer(new ContentCellRender());
searchResultList.setFixedCellHeight(AlphaFineConstants.CELL_HEIGHT);
leftSearchResultPane = new UIScrollPane(searchResultList);
leftSearchResultPane.setBackground(Color.white);
leftSearchResultPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
leftSearchResultPane.setPreferredSize(new Dimension(AlphaFineConstants.LEFT_WIDTH, AlphaFineConstants.CONTENT_HEIGHT));
rightSearchResultPane = new JPanel();
rightSearchResultPane.setBackground(Color.white);
searchResultPane.add(leftSearchResultPane, BorderLayout.WEST);
rightSearchResultPane.setPreferredSize(new Dimension(AlphaFineConstants.RIGHT_WIDTH, AlphaFineConstants.CONTENT_HEIGHT));
searchResultPane.add(rightSearchResultPane, BorderLayout.EAST);
add(searchResultPane, BorderLayout.SOUTH);
setSize(AlphaFineConstants.FULL_SIZE);
}
}
}
});
leftSearchResultPane = new UIScrollPane(searchResultList);
leftSearchResultPane.setBackground(Color.white);
leftSearchResultPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
leftSearchResultPane.setPreferredSize(new Dimension(AlphaFineConstants.LEFT_WIDTH, AlphaFineConstants.CONTENT_HEIGHT));
rightSearchResultPane = new JPanel();
rightSearchResultPane.setBackground(Color.white);
searchResultPane.add(leftSearchResultPane, BorderLayout.WEST);
rightSearchResultPane.setPreferredSize(new Dimension(AlphaFineConstants.RIGHT_WIDTH, AlphaFineConstants.CONTENT_HEIGHT));
searchResultPane.add(rightSearchResultPane, BorderLayout.EAST);
add(searchResultPane, BorderLayout.SOUTH);
setSize(AlphaFineConstants.FULL_SIZE);
}
private void initSearchWorker(final String searchText) {
searchResultList.setModel(new SearchListModel(AlphaSearchManager.getSearchManager().showDefaultSearchResult()));
if (this.searchWorker != null && !this.searchWorker.isDone()) {
this.searchWorker.cancel(true);
@ -257,6 +233,43 @@ public class AlphaFineDialog extends UIDialog {
this.searchWorker.execute();
}
private void initListListener() {
searchResultList.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int selectedIndex = searchResultList.getSelectedIndex();
Object selectedValue = searchResultList.getSelectedValue();
if (e.getClickCount() == 2) {
final int i = searchResultList.locationToIndex(e.getPoint());
searchResultList.setSelectedIndex(i);
doNavigate(selectedIndex);
if (selectedValue instanceof AlphaCellModel) {
SearchResult originalResultList = LatestSearchManager.getLatestSearchManager().getLatestModelList();
originalResultList.add(searchResultList.getSelectedValue());
LatestSearchManager.getLatestSearchManager().setLatestModelList(originalResultList);
//保存最近搜索
saveHistory(originalResultList);
}
} else if (e.getClickCount() == 1) {
if (selectedValue instanceof MoreModel && ((MoreModel) selectedValue).isNeedMore()) {
HandleMoreOrLessResult(selectedIndex, (MoreModel) selectedValue);
}
}
}
});
// TODO: 2017/5/8 xiaxiang: e.getClickCount() == 1 时,偶发性的不能触发,所以先放到valueChanged
searchResultList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
showResult(searchResultList.getSelectedIndex(), searchResultList.getSelectedValue());
}
}
});
}
private void showResult(int index, Object selectedValue) {
if (selectedValue instanceof FileModel) {
String fileName = ((FileModel) selectedValue).getFilePath().substring(ProjectConstants.REPORTLETS_NAME.length() + 1);
@ -538,17 +551,18 @@ public class AlphaFineDialog extends UIDialog {
*todo:还没做上传服务器
*/
private void sendToServer() {
}
private void rebuildList(int index, MoreModel selectedValue) {
SearchResult moreResult = getMoreResult(selectedValue);
if((selectedValue).getContent().equals(Inter.getLocText("FR-Designer_AlphaFine_ShowLess"))) {
for (int i = 0; i < moreResult.size(); i++) {
this.searchListModel.insertElementAt(moreResult.get(i), index + 4 + i);
this.searchListModel.insertElementAt(moreResult.get(i), index + AlphaFineConstants.SHOW_SIZE -1 + i);
}
} else {
for (int i = 0; i < moreResult.size(); i++) {
this.searchListModel.removeElementAt(index + 4);
this.searchListModel.removeElementAt(index + AlphaFineConstants.SHOW_SIZE - 1);
}
}

5
designer/src/com/fr/design/mainframe/alphafine/searchManager/ActionSearchManager.java

@ -2,6 +2,7 @@ package com.fr.design.mainframe.alphafine.searchManager;
import com.fr.design.DesignerEnvManager;
import com.fr.design.actions.UpdateAction;
import com.fr.design.mainframe.alphafine.AlphaFineConstants;
import com.fr.design.mainframe.alphafine.CellType;
import com.fr.design.mainframe.alphafine.cell.cellModel.MoreModel;
import com.fr.design.mainframe.alphafine.cell.cellModel.ActionModel;
@ -39,7 +40,7 @@ public class ActionSearchManager implements AlphaFineSearchProcessor {
filterModelList.add(new ActionModel(updateAction.getName() ,updateAction));
}
}
final int length = Math.min(5, filterModelList.size());
final int length = Math.min(AlphaFineConstants.SHOW_SIZE, filterModelList.size());
for (int i = 0; i < length; i++) {
lessModelList.add(filterModelList.get(i));
}
@ -47,7 +48,7 @@ public class ActionSearchManager implements AlphaFineSearchProcessor {
moreModelList.add(filterModelList.get(i));
}
if (filterModelList.size() > 0) {
if (filterModelList.size() > 5) {
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));

6
designer/src/com/fr/design/mainframe/alphafine/searchManager/DocumentSearchManager.java

@ -37,7 +37,7 @@ public class DocumentSearchManager implements AlphaFineSearchProcessor {
this.moreModelList = new SearchResult();
if (DesignerEnvManager.getEnvManager().getAlphafineConfigManager().isContainDocument()) {
String result;
String url = "http://help.finereport.com/?api-search-title-" + searchText + "-1";
String url = AlphaFineConstants.DOCUMENT_SEARCH_URL + searchText + "-1";
HttpClient httpClient = new HttpClient(url);
httpClient.setTimeout(5000);
httpClient.asGet();
@ -49,7 +49,7 @@ public class DocumentSearchManager implements AlphaFineSearchProcessor {
jsonArray = (JSONArray) jsonObject.get("docdata");
}
if (jsonArray.length() > 0) {
if (jsonArray.length() > 5) {
if (jsonArray.length() > AlphaFineConstants.SHOW_SIZE) {
lessModelList.add(new MoreModel(Inter.getLocText("FR-Designer_COMMUNITY_HELP"), Inter.getLocText("FR-Designer_AlphaFine_ShowAll"),true, CellType.DOCUMENT));
} else {
lessModelList.add(new MoreModel(Inter.getLocText("FR-Designer_COMMUNITY_HELP"), CellType.DOCUMENT));
@ -79,7 +79,7 @@ public class DocumentSearchManager implements AlphaFineSearchProcessor {
JSONObject object = jsonArray.getJSONObject(i);
String name = (String) object.get("title");
String content = ((String) object.get("summary"));
String documentUrl = AlphaFineConstants.DOCUMENT_SEARCH_URL + object.get("did") + ".html";
String documentUrl = AlphaFineConstants.DOCUMENT_DOC_URL + object.get("did") + ".html";
return new DocumentModel(name, content, documentUrl);
}

81
designer/src/com/fr/design/mainframe/alphafine/searchManager/FileSearchManager.java

@ -47,41 +47,11 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
fileNodes = new ArrayList<>();
fileNodes = listTpl(env, ProjectConstants.REPORTLETS_NAME, true);
for (FileNode node : fileNodes) {
boolean hasName = false;
boolean isAlreadyContain = false;
String fileEnvPath = node.getEnvPath();
String filePath = StableUtils.pathJoin(env.getPath(), fileEnvPath);
if (DesignerEnvManager.getEnvManager().getAlphafineConfigManager().isContainTemplate()) {
if (node.getName().toLowerCase().contains(searchText.toLowerCase())) {
FileModel model = new FileModel(node.getName(), node.getEnvPath().substring(node.getName().length(), node.getEnvPath().length()),node.getEnvPath());
this.filterModelList.add(model);
hasName = true;
}
}
if (DesignerEnvManager.getEnvManager().getAlphafineConfigManager().isContainFileContent()) {
//文件的内容搜索
try {
BufferedReader reader = new BufferedReader(new FileReader(filePath));
String line;
int columnNumber;
boolean test = false;
while ((line = reader.readLine()) != null) {
columnNumber = line.toLowerCase().indexOf(searchText);
if (columnNumber != -1) {
test = true;
}
}
if (test && !hasName) {
FileModel model = new FileModel(node.getName(), node.getEnvPath().substring(node.getName().length(), node.getEnvPath().length()),node.getEnvPath());
this.filterModelList.add(model);
}
reader.close();
} catch (FileNotFoundException e) {
FRLogger.getLogger().error(e.getMessage());
} catch (IOException e) {
FRLogger.getLogger().error(e.getMessage());
}
}
isAlreadyContain = searchFile(searchText, node, isAlreadyContain);
searchFileContent(searchText, node, isAlreadyContain, filePath);
}
@ -99,9 +69,52 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
lessModelList.add(0,new MoreModel(Inter.getLocText("FR-Designer_Templates"), CellType.FILE));
}
}
return this.lessModelList;
}
/**
* 搜索文件内容
* @param searchText
* @param node
* @param isAlreadyContain
* @param filePath
*/
private void searchFileContent(String searchText, FileNode node, boolean isAlreadyContain, String filePath) {
if (DesignerEnvManager.getEnvManager().getAlphafineConfigManager().isContainFileContent()) {
return this.lessModelList;
try {
BufferedReader reader = new BufferedReader(new FileReader(filePath));
String line;
int columnNumber;
boolean test = false;
while ((line = reader.readLine()) != null) {
columnNumber = line.toLowerCase().indexOf(searchText);
if (columnNumber != -1) {
test = true;
}
}
if (test && !isAlreadyContain) {
FileModel model = new FileModel(node.getName(), node.getEnvPath().substring(node.getName().length(), node.getEnvPath().length()),node.getEnvPath());
this.filterModelList.add(model);
}
reader.close();
} catch (FileNotFoundException e) {
FRLogger.getLogger().error(e.getMessage());
} catch (IOException e) {
FRLogger.getLogger().error(e.getMessage());
}
}
}
private boolean searchFile(String searchText, FileNode node, boolean isAlreadyContain) {
if (DesignerEnvManager.getEnvManager().getAlphafineConfigManager().isContainTemplate()) {
if (node.getName().toLowerCase().contains(searchText.toLowerCase())) {
FileModel model = new FileModel(node.getName(), node.getEnvPath().substring(node.getName().length(), node.getEnvPath().length()),node.getEnvPath());
this.filterModelList.add(model);
isAlreadyContain = true;
}
}
return isAlreadyContain;
}
@Override

Loading…
Cancel
Save