Browse Source

Merge pull request #962 in BA/design from ~XIAOXIA/design:9.0 to 9.0

* commit '9703b53711a25384f180ae4e23c10c0457e24d88': (21 commits)
  是写错了,服务器端代码还没传才写的localhost,先把debug的url删掉,待会传一下服务器端代码,服务器端加了debug使用的url之后这里再判断,现在服务器那边只有正式接口,还没有供测试的接口
  优化键盘选择逻辑
  无
  reformat
  rt
  代码质量 选中状态检查方法放到listmodel里面
  检测到有可用项立即选中
  自动选中第一项优化,之前是全部加载完才选中
  bug fix
  bug fix 代码质量
  代码质量
  rt
  bug fix
  bug fix 代码质量
  rt
  bug fix
  bug fix
  代码质量 bug fix
  bug fix 代码质量
  bug fix 存储的searchkey需要处理下
  ...
master
superman 7 years ago
parent
commit
d6971f650f
  1. 6
      designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java
  2. 2
      designer/src/com/fr/design/mainframe/alphafine/CellType.java
  3. 5
      designer/src/com/fr/design/mainframe/alphafine/cell/model/ActionModel.java
  4. 15
      designer/src/com/fr/design/mainframe/alphafine/cell/model/AlphaCellModel.java
  5. 16
      designer/src/com/fr/design/mainframe/alphafine/cell/model/DocumentModel.java
  6. 12
      designer/src/com/fr/design/mainframe/alphafine/cell/model/FileModel.java
  7. 68
      designer/src/com/fr/design/mainframe/alphafine/cell/model/MoreModel.java
  8. 14
      designer/src/com/fr/design/mainframe/alphafine/cell/model/NoResultModel.java
  9. 16
      designer/src/com/fr/design/mainframe/alphafine/cell/model/PluginModel.java
  10. 21
      designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java
  11. 616
      designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java
  12. 50
      designer/src/com/fr/design/mainframe/alphafine/model/SearchListModel.java
  13. 4
      designer/src/com/fr/design/mainframe/alphafine/model/SearchResult.java
  14. 5
      designer/src/com/fr/design/mainframe/alphafine/search/manager/ActionSearchManager.java
  15. 4
      designer/src/com/fr/design/mainframe/alphafine/search/manager/DocumentSearchManager.java
  16. 5
      designer/src/com/fr/design/mainframe/alphafine/search/manager/FileSearchManager.java
  17. 4
      designer/src/com/fr/design/mainframe/alphafine/search/manager/PluginSearchManager.java
  18. 20
      designer/src/com/fr/design/mainframe/alphafine/search/manager/RecentSearchManager.java
  19. 30
      designer/src/com/fr/design/mainframe/alphafine/search/manager/RecommendSearchManager.java

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

@ -81,9 +81,9 @@ public class AlphaFineConstants {
public static final String PLUGIN_IMAGE_URL = "http://shopres.finereport.com/";
public static final String SERVER_URL = "http://cloud.fanruan.com/api/monitor/record_of_afsearch/single";
public static final String CLOUD_SERVER_URL = "http://cloud.fanruan.com/api/monitor/record_of_afsearch/single";
public static final String SEARCH_API = "http://cloud.fanruan.com/api/intelligence/search/recommend?searchKey=";
//TODO:先用本地服务器测试一下,避免影响云中心正常信息收集
public static final String CLOUD_TEST_URL = "http://localhost:8080/monitor/monitor/record_of_afsearch/single";
}

2
designer/src/com/fr/design/mainframe/alphafine/CellType.java

@ -4,7 +4,7 @@ package com.fr.design.mainframe.alphafine;
* Created by XiaXiang on 2017/4/27.
*/
public enum CellType {
RECOMMEND(0), ACTION(1), DOCUMENT(2), FILE(3), PLUGIN(4), REUSE(5), NO_RESULT(6);
RECOMMEND(0), ACTION(1), DOCUMENT(2), FILE(3), PLUGIN(4), REUSE(5), NO_RESULT(6), MORE(7);
private int typeValue;

5
designer/src/com/fr/design/mainframe/alphafine/cell/model/ActionModel.java

@ -69,6 +69,11 @@ public class ActionModel extends AlphaCellModel {
return getClassName();
}
@Override
public void doAction() {
getAction().actionPerformed(null);
}
public String getClassName() {
return getAction().getClass().getName();
}

15
designer/src/com/fr/design/mainframe/alphafine/cell/model/AlphaCellModel.java

@ -27,7 +27,7 @@ public abstract class AlphaCellModel implements Comparable {
this.content = content;
}
public CellType getType() {
return type;
}
@ -61,8 +61,12 @@ public abstract class AlphaCellModel implements Comparable {
this.description = description;
}
public boolean hasNoResult() {
return false;
public boolean hasAction() {
return true;
}
public boolean isNeedToSendToServer() {
return true;
}
/**
* model转json
@ -79,6 +83,11 @@ public abstract class AlphaCellModel implements Comparable {
*/
abstract public String getStoreInformation();
/**
* 双击时所需执行的操作
*/
abstract public void doAction();
public int getSearchCount() {
return searchCount;
}

16
designer/src/com/fr/design/mainframe/alphafine/cell/model/DocumentModel.java

@ -6,6 +6,11 @@ import com.fr.general.FRLogger;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
/**
* Created by XiaXiang on 2017/4/20.
*/
@ -52,6 +57,17 @@ public class DocumentModel extends AlphaCellModel {
return getInformationUrl();
}
@Override
public void doAction() {
try {
Desktop.getDesktop().browse(new URI(getDocumentUrl()));
} catch (IOException e) {
FRLogger.getLogger().error(e.getMessage());
} catch (URISyntaxException e) {
FRLogger.getLogger().error(e.getMessage());
}
}
@Override
public boolean equals(Object o) {
if (this == o) {

12
designer/src/com/fr/design/mainframe/alphafine/cell/model/FileModel.java

@ -1,7 +1,10 @@
package com.fr.design.mainframe.alphafine.cell.model;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.alphafine.AlphaFineHelper;
import com.fr.design.mainframe.alphafine.CellType;
import com.fr.file.FileNodeFILE;
import com.fr.file.filetree.FileNode;
import com.fr.general.FRLogger;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
@ -49,6 +52,15 @@ public class FileModel extends AlphaCellModel {
return getFilePath();
}
@Override
public void doAction() {
DesignerContext.getDesignerFrame().openTemplate(new FileNodeFILE(new FileNode(getFilePath(), false)));
}
@Override
public boolean isNeedToSendToServer() {
return false;
}
@Override
public boolean equals(Object o) {

68
designer/src/com/fr/design/mainframe/alphafine/cell/model/MoreModel.java

@ -1,48 +1,33 @@
package com.fr.design.mainframe.alphafine.cell.model;
import com.fr.design.mainframe.alphafine.CellType;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
/**
* Created by XiaXiang on 2017/4/20.
*/
public class MoreModel {
private String name;
public class MoreModel extends AlphaCellModel {
private boolean needMore;
private String content;
private CellType type;
private boolean isLoading;
private CellType contentType;
public MoreModel(String name, String content, boolean needMore, CellType type) {
this.name = name;
super(name, content, CellType.MORE);
this.needMore = needMore;
this.content = content;
this.type = type;
}
public MoreModel(String name, CellType type) {
this.name = name;
this.needMore = false;
this.type = type;
this.contentType = type;
}
public MoreModel(String name) {
this.name = name;
this.isLoading = true;
super(name, null, CellType.MORE);
this.needMore = false;
}
public MoreModel(String name, boolean isLoading) {
this.name = name;
super(name, null, CellType.MORE);
this.isLoading = isLoading;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isNeedMore() {
return needMore;
}
@ -51,20 +36,19 @@ public class MoreModel {
this.needMore = needMore;
}
public String getContent() {
return content;
@Override
public JSONObject ModelToJson() throws JSONException {
return null;
}
public void setContent(String content) {
this.content = content;
@Override
public String getStoreInformation() {
return null;
}
public CellType getType() {
return type;
}
@Override
public void doAction() {
public void setType(CellType type) {
this.type = type;
}
public boolean isLoading() {
@ -74,4 +58,22 @@ public class MoreModel {
public void setLoading(boolean loading) {
isLoading = loading;
}
@Override
public boolean hasAction() {
return false;
}
@Override
public boolean isNeedToSendToServer() {
return false;
}
public CellType getContentType() {
return contentType;
}
public void setContentType(CellType contentType) {
this.contentType = contentType;
}
}

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

@ -23,7 +23,17 @@ public class NoResultModel extends AlphaCellModel {
}
@Override
public boolean hasNoResult() {
return true;
public void doAction() {
}
@Override
public boolean hasAction() {
return false;
}
@Override
public boolean isNeedToSendToServer() {
return false;
}
}

16
designer/src/com/fr/design/mainframe/alphafine/cell/model/PluginModel.java

@ -6,6 +6,11 @@ import com.fr.general.FRLogger;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
/**
* Created by XiaXiang on 2017/4/20.
*/
@ -112,6 +117,17 @@ public class PluginModel extends AlphaCellModel {
return getInformationUrl();
}
@Override
public void doAction() {
try {
Desktop.getDesktop().browse(new URI(getPluginUrl()));
} catch (IOException e) {
FRLogger.getLogger().error(e.getMessage());
} catch (URISyntaxException e) {
FRLogger.getLogger().error(e.getMessage());
}
}
@Override
public boolean equals(Object o) {

21
designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java

@ -14,8 +14,7 @@ import java.awt.*;
* Created by XiaXiang on 2017/4/20.
*/
public class ContentCellRender implements ListCellRenderer<Object> {
private static final int OFFSET = 30;
private static final int LABEL_OFFSET = 45;
private static final int OFFSET = 45;
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
@ -27,18 +26,18 @@ public class ContentCellRender implements ListCellRenderer<Object> {
AlphaCellModel model = (AlphaCellModel) value;
JPanel panel = new JPanel(new BorderLayout());
panel.setBackground(null);
if (isSelected && !model.hasNoResult()) {
panel.setBackground(AlphaFineConstants.BLUE);
}
panel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
titleLabel.setText(" " + model.getName());
String iconUrl = "/com/fr/design/mainframe/alphafine/images/alphafine" + model.getType().getTypeValue() + ".png";
if (model.hasNoResult()) {
titleLabel.setIcon(null);
titleLabel.setForeground(AlphaFineConstants.MEDIUM_GRAY);
} else {
if (model.hasAction()) {
if (isSelected) {
panel.setBackground(AlphaFineConstants.BLUE);
}
titleLabel.setIcon(new ImageIcon(IOUtils.readImage(iconUrl)));
titleLabel.setForeground(AlphaFineConstants.BLACK);
} else {
titleLabel.setIcon(null);
titleLabel.setForeground(AlphaFineConstants.MEDIUM_GRAY);
}
titleLabel.setFont(AlphaFineConstants.MEDIUM_FONT);
String description = model.getDescription();
@ -48,9 +47,11 @@ public class ContentCellRender implements ListCellRenderer<Object> {
panel.add(detailLabel, BorderLayout.CENTER);
int width = (int) (titleLabel.getPreferredSize().getWidth() + detailLabel.getPreferredSize().getWidth());
if ( width > AlphaFineConstants.LEFT_WIDTH - OFFSET) {
int nameWidth = (int) (AlphaFineConstants.LEFT_WIDTH - detailLabel.getPreferredSize().getWidth() - LABEL_OFFSET);
int nameWidth = (int) (AlphaFineConstants.LEFT_WIDTH - detailLabel.getPreferredSize().getWidth() - OFFSET);
titleLabel.setPreferredSize(new Dimension(nameWidth, AlphaFineConstants.CELL_HEIGHT));
}
} else {
titleLabel.setPreferredSize(new Dimension(AlphaFineConstants.LEFT_WIDTH - OFFSET, AlphaFineConstants.CELL_HEIGHT));
}
panel.add(titleLabel, BorderLayout.WEST);

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

@ -6,23 +6,22 @@ import com.fr.design.dialog.UIDialog;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.alphafine.AlphaFineConstants;
import com.fr.design.mainframe.alphafine.AlphaFineHelper;
import com.fr.design.mainframe.alphafine.cell.CellModelHelper;
import com.fr.design.mainframe.alphafine.cell.model.*;
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.cell.model.PluginModel;
import com.fr.design.mainframe.alphafine.cell.render.ContentCellRender;
import com.fr.design.mainframe.alphafine.listener.ComponentHandler;
import com.fr.design.mainframe.alphafine.listener.DocumentAdapter;
import com.fr.design.mainframe.alphafine.model.SearchListModel;
import com.fr.design.mainframe.alphafine.model.SearchResult;
import com.fr.design.mainframe.alphafine.preview.ActionPreviewPane;
import com.fr.design.mainframe.alphafine.preview.DocumentPreviewPane;
import com.fr.design.mainframe.alphafine.preview.FilePreviewPane;
import com.fr.design.mainframe.alphafine.preview.PluginPreviewPane;
import com.fr.design.mainframe.alphafine.search.manager.*;
import com.fr.file.FileNodeFILE;
import com.fr.file.filetree.FileNode;
import com.fr.form.main.Form;
import com.fr.form.main.FormIO;
import com.fr.general.ComparatorUtils;
@ -47,8 +46,6 @@ import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Calendar;
@ -79,10 +76,11 @@ public class AlphaFineDialog extends UIDialog {
private Point pressedPoint;
private UIScrollPane leftSearchResultPane;
private JPanel rightSearchResultPane;
private JList searchResultList;
private AlphaFineList searchResultList;
private SearchListModel searchListModel;
private SwingWorker searchWorker;
private SwingWorker showWorker;
private String storeText;
//是否强制打开,因为面板是否关闭绑定了全局鼠标事件,这里需要处理一下
private boolean forceOpen;
@ -118,6 +116,9 @@ public class AlphaFineDialog extends UIDialog {
};
}
/**
* 打开搜索框
*/
private static void doClickAction() {
AlphaFineHelper.showAlphaFineDialog(false);
}
@ -248,7 +249,7 @@ public class AlphaFineDialog extends UIDialog {
private void showSearchResult() {
if (searchResultPane == null) {
initSearchResultComponents();
initListListener();
initTextFieldKeyListener();
}
initSearchWorker();
}
@ -257,7 +258,8 @@ public class AlphaFineDialog extends UIDialog {
* 初始化搜索面板
*/
private void initSearchResultComponents() {
searchResultList = new JList();
searchResultList = new AlphaFineList();
searchResultList.setFixedCellHeight(AlphaFineConstants.CELL_HEIGHT);
searchListModel = new SearchListModel(new SearchResult());
searchResultList.setModel(searchListModel);
searchResultPane = new JPanel();
@ -292,14 +294,6 @@ public class AlphaFineDialog extends UIDialog {
rebuildList(searchTextField.getText().toLowerCase());
return null;
}
@Override
protected void done() {
if (!isCancelled() && searchListModel.getSize() > 1) {
searchResultList.setSelectedIndex(1);
showResult(searchResultList.getSelectedIndex(), searchResultList.getSelectedValue());
}
}
};
this.searchWorker.execute();
}
@ -311,27 +305,45 @@ public class AlphaFineDialog extends UIDialog {
* @param searchText
*/
private void rebuildList(String searchText) {
searchListModel.removeAllElements();
resetContainer();
if (searchText.startsWith(ADVANCED_SEARCH_MARK)) {
if (searchText.startsWith(ACTION_MARK_SHORT) || searchText.startsWith(ACTION_MARK)) {
getActionList(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length()));
storeText = searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length());
getActionList(storeText);
} else if (searchText.startsWith(DOCUMENT_MARK_SHORT) || searchText.startsWith(DOCUMENT_MARK)) {
getDocumentList(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length()));
storeText = searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length());
getDocumentList(storeText);
} else if (searchText.startsWith(FILE_MARK_SHORT) || searchText.startsWith(FILE_MARK)) {
getFileList(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length()));
storeText = searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length());
getFileList(storeText);
} else if (searchText.startsWith(CPT_MARK) || searchText.startsWith(FRM_MARK)) {
storeText = searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length());
getFileList(searchText);
} else if (searchText.startsWith(DS_MARK)) {
getFileList(DS_NAME + searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length()));
storeText = searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length());
getFileList(DS_NAME + storeText);
} else if (searchText.startsWith(PLUGIN_MARK_SHORT) || searchText.startsWith(PLUGIN_MARK)) {
getPluginList(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length()));
storeText = searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length());
getPluginList(storeText);
}
} else {
doNormalSearch(searchText.trim());
storeText = searchText.trim();
doNormalSearch(storeText);
}
}
/**
* 重置面板
*/
private void resetContainer() {
searchListModel.removeAllElements();
searchListModel.resetSelectedState();
rightSearchResultPane.removeAll();
rightSearchResultPane.validate();
rightSearchResultPane.repaint();
}
/**
* 普通搜索
*
@ -348,7 +360,7 @@ public class AlphaFineDialog extends UIDialog {
private void getDocumentList(final String searchText) {
SearchResult documentModelList = DocumentSearchManager.getDocumentSearchManager().getLessSearchResult(searchText);
for (Object object : documentModelList) {
for (AlphaCellModel object : documentModelList) {
AlphaFineHelper.checkCancel();
searchListModel.addElement(object);
}
@ -356,7 +368,7 @@ public class AlphaFineDialog extends UIDialog {
private void getFileList(final String searchText) {
SearchResult fileModelList = FileSearchManager.getFileSearchManager().getLessSearchResult(searchText);
for (Object object : fileModelList) {
for (AlphaCellModel object : fileModelList) {
AlphaFineHelper.checkCancel();
searchListModel.addElement(object);
}
@ -364,7 +376,7 @@ public class AlphaFineDialog extends UIDialog {
private void getActionList(final String searchText) {
SearchResult actionModelList = ActionSearchManager.getActionSearchManager().getLessSearchResult(searchText);
for (Object object : actionModelList) {
for (AlphaCellModel object : actionModelList) {
AlphaFineHelper.checkCancel();
searchListModel.addElement(object);
}
@ -372,7 +384,7 @@ public class AlphaFineDialog extends UIDialog {
private void getPluginList(final String searchText) {
SearchResult pluginModelList = PluginSearchManager.getPluginSearchManager().getLessSearchResult(searchText);
for (Object object : pluginModelList) {
for (AlphaCellModel object : pluginModelList) {
AlphaFineHelper.checkCancel();
searchListModel.addElement(object);
}
@ -380,7 +392,7 @@ public class AlphaFineDialog extends UIDialog {
private void getRecommendList(final String searchText) {
SearchResult recommendModelList = RecommendSearchManager.getRecommendSearchManager().getLessSearchResult(searchText);
for (Object object : recommendModelList) {
for (AlphaCellModel object : recommendModelList) {
AlphaFineHelper.checkCancel();
searchListModel.addElement(object);
}
@ -388,123 +400,144 @@ public class AlphaFineDialog extends UIDialog {
private void getRecentList(final String searchText) {
SearchResult recentModelList = RecentSearchManager.getRecentSearchManger().getLessSearchResult(searchText);
for (Object object : recentModelList) {
for (AlphaCellModel object : recentModelList) {
AlphaFineHelper.checkCancel();
searchListModel.addElement(object);
}
}
private void showResult(int index, final Object selectedValue) {
if (selectedValue instanceof FileModel) {
final String fileName = ((FileModel) selectedValue).getFilePath().substring(ProjectConstants.REPORTLETS_NAME.length() + 1);
showDefaultPreviewPane();
if (fileName.endsWith(ProjectConstants.FRM_SUFFIX)) {
checkWorker();
this.showWorker = new SwingWorker<BufferedImage, Void>() {
@Override
protected BufferedImage doInBackground() throws Exception {
Form form = FormIO.readForm(FRContext.getCurrentEnv(), fileName);
return FormIO.exportFormAsImage(form);
}
@Override
protected void done() {
if (!isCancelled()) {
rightSearchResultPane.removeAll();
/**
* 右侧面板展示搜索结果的内容
*
* @param selectedValue
*/
private void showResult(final AlphaCellModel selectedValue) {
switch (selectedValue.getType()) {
case FILE:
final String fileName = ((FileModel) selectedValue).getFilePath().substring(ProjectConstants.REPORTLETS_NAME.length() + 1);
showDefaultPreviewPane();
if (fileName.endsWith(ProjectConstants.FRM_SUFFIX)) {
checkWorker();
this.showWorker = new SwingWorker<BufferedImage, Void>() {
@Override
protected BufferedImage doInBackground() {
Form form = null;
try {
rightSearchResultPane.add(new FilePreviewPane(get()));
} catch (InterruptedException e) {
form = FormIO.readForm(FRContext.getCurrentEnv(), fileName);
} catch (Exception e) {
FRLogger.getLogger().error(e.getMessage());
} catch (ExecutionException e) {
}
return FormIO.exportFormAsImage(form);
}
@Override
protected void done() {
if (!isCancelled()) {
rightSearchResultPane.removeAll();
try {
rightSearchResultPane.add(new FilePreviewPane(get()));
} catch (InterruptedException e) {
FRLogger.getLogger().error(e.getMessage());
} catch (ExecutionException e) {
FRLogger.getLogger().error(e.getMessage());
}
validate();
repaint();
}
}
};
this.showWorker.execute();
} else if (fileName.endsWith(ProjectConstants.CPT_SUFFIX)) {
checkWorker();
this.showWorker = new SwingWorker<BufferedImage, Void>() {
@Override
protected BufferedImage doInBackground() {
WorkBook workBook = null;
try {
workBook = (WorkBook) TemplateWorkBookIO.readTemplateWorkBook(FRContext.getCurrentEnv(), fileName);
} catch (Exception e) {
FRLogger.getLogger().error(e.getMessage());
}
validate();
repaint();
BufferedImage bufferedImage = new ImageExporter().exportToImage(workBook);
return bufferedImage;
}
}
};
this.showWorker.execute();
} else if (fileName.endsWith(ProjectConstants.CPT_SUFFIX)) {
@Override
protected void done() {
if (!isCancelled()) {
rightSearchResultPane.removeAll();
try {
rightSearchResultPane.add(new FilePreviewPane(get()));
validate();
repaint();
} catch (InterruptedException e) {
FRLogger.getLogger().error(e.getMessage());
} catch (ExecutionException e) {
FRLogger.getLogger().error(e.getMessage());
}
}
}
};
this.showWorker.execute();
}
break;
case ACTION:
rightSearchResultPane.removeAll();
rightSearchResultPane.add(new ActionPreviewPane());
validate();
repaint();
break;
case DOCUMENT:
rightSearchResultPane.removeAll();
rightSearchResultPane.add(new DocumentPreviewPane((selectedValue).getName(), (selectedValue).getContent()));
validate();
repaint();
break;
case PLUGIN:
case REUSE:
showDefaultPreviewPane();
checkWorker();
this.showWorker = new SwingWorker<BufferedImage, Void>() {
this.showWorker = new SwingWorker<Image, Void>() {
@Override
protected BufferedImage doInBackground() throws Exception {
WorkBook workBook = (WorkBook) TemplateWorkBookIO.readTemplateWorkBook(FRContext.getCurrentEnv(), fileName);
BufferedImage bufferedImage = new ImageExporter().exportToImage(workBook);
protected Image doInBackground() {
BufferedImage bufferedImage = null;
try {
bufferedImage = ImageIO.read(new URL(((PluginModel) selectedValue).getImageUrl()));
} catch (IOException e) {
try {
bufferedImage = ImageIO.read(getClass().getResource("/com/fr/design/mainframe/alphafine/images/default_product.png"));
} catch (IOException e1) {
FRLogger.getLogger().error(e.getMessage());
}
}
return bufferedImage;
}
@Override
protected void done() {
if (!isCancelled()) {
rightSearchResultPane.removeAll();
try {
rightSearchResultPane.add(new FilePreviewPane(get()));
try {
if (!isCancelled()) {
rightSearchResultPane.removeAll();
rightSearchResultPane.add(new PluginPreviewPane((selectedValue).getName(), get(), ((PluginModel) selectedValue).getVersion(), ((PluginModel) selectedValue).getJartime(), ((PluginModel) selectedValue).getType(), ((PluginModel) selectedValue).getPrice()));
validate();
repaint();
} catch (InterruptedException e) {
FRLogger.getLogger().error(e.getMessage());
} catch (ExecutionException e) {
FRLogger.getLogger().error(e.getMessage());
}
} catch (InterruptedException e) {
FRLogger.getLogger().error(e.getMessage());
} catch (ExecutionException e) {
FRLogger.getLogger().error(e.getMessage());
}
}
};
this.showWorker.execute();
break;
default:
return;
}
} else if (selectedValue instanceof DocumentModel) {
rightSearchResultPane.removeAll();
rightSearchResultPane.add(new DocumentPreviewPane(((DocumentModel) selectedValue).getName(), ((DocumentModel) selectedValue).getContent()));
validate();
repaint();
} else if (selectedValue instanceof PluginModel) {
showDefaultPreviewPane();
checkWorker();
this.showWorker = new SwingWorker<Image, Void>() {
@Override
protected Image doInBackground() {
BufferedImage bufferedImage = null;
try {
bufferedImage = ImageIO.read(new URL(((PluginModel) selectedValue).getImageUrl()));
} catch (IOException e) {
try {
bufferedImage = ImageIO.read(getClass().getResource("/com/fr/design/mainframe/alphafine/images/default_product.png"));
} catch (IOException e1) {
FRLogger.getLogger().error(e.getMessage());
}
}
return bufferedImage;
}
@Override
protected void done() {
try {
if (!isCancelled()) {
rightSearchResultPane.removeAll();
rightSearchResultPane.add(new PluginPreviewPane(((PluginModel) selectedValue).getName(), get(), ((PluginModel) selectedValue).getVersion(), ((PluginModel) selectedValue).getJartime(), ((PluginModel) selectedValue).getType(), ((PluginModel) selectedValue).getPrice()));
validate();
repaint();
}
} catch (InterruptedException e) {
FRLogger.getLogger().error(e.getMessage());
} catch (ExecutionException e) {
FRLogger.getLogger().error(e.getMessage());
}
}
};
this.showWorker.execute();
} else if (selectedValue instanceof ActionModel) {
rightSearchResultPane.removeAll();
rightSearchResultPane.add(new ActionPreviewPane());
validate();
repaint();
}
}
@ -547,73 +580,16 @@ public class AlphaFineDialog extends UIDialog {
initMouseListener();
}
/**
* 为面板中各组件添加监听器
*/
private void initListListener() {
initListMouseListener();
initListKeyListener();
}
private void initListKeyListener() {
/**
* 为list添加键盘监听器
*/
searchResultList.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
Object selectedValue = searchResultList.getSelectedValue();
doNavigate(searchResultList.getSelectedIndex());
if (searchResultList.getSelectedValue() instanceof AlphaCellModel) {
saveHistory((AlphaCellModel) selectedValue);
}
}
}
});
private void initTextFieldKeyListener() {
/**
* 为textField添加键盘监听器按上下方向键时把焦点给list,实现键盘操作
*/
searchTextField.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_UP) {
if (e.getKeyCode() == KeyEvent.VK_DOWN && searchTextField.hasFocus()) {
searchResultList.requestFocus();
}
}
});
}
private void initListMouseListener() {
/**
* 鼠标监听器
*/
searchResultList.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int selectedIndex = searchResultList.getSelectedIndex();
Object selectedValue = searchResultList.getSelectedValue();
if (e.getClickCount() == 2) {
doNavigate(selectedIndex);
if (selectedValue instanceof AlphaCellModel) {
saveHistory((AlphaCellModel) selectedValue);
}
} else if (e.getClickCount() == 1) {
if (selectedValue instanceof MoreModel && ((MoreModel) selectedValue).isNeedMore()) {
HandleMoreOrLessResult(selectedIndex, (MoreModel) selectedValue);
}
}
}
});
/**
*单击时触发右侧面板展示搜索结果
*/
searchResultList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
showResult(searchResultList.getSelectedIndex(), searchResultList.getSelectedValue());
searchResultList.setSelectedIndex(searchResultList.getSelectedIndex() + 1);
}
}
});
@ -689,34 +665,10 @@ public class AlphaFineDialog extends UIDialog {
}
private void doNavigate(int index) {
private void doNavigate() {
AlphaFineDialog.this.dispose();
final Object value = searchResultList.getSelectedValue();
if (value instanceof ActionModel) {
((ActionModel) value).getAction().actionPerformed(null);
} else if (value instanceof FileModel) {
DesignerContext.getDesignerFrame().openTemplate(new FileNodeFILE(new FileNode(((FileModel) value).getFilePath(), false)));
} else if (value instanceof PluginModel) {
String url = ((PluginModel) value).getPluginUrl();
try {
Desktop.getDesktop().browse(new URI(url));
} catch (IOException e) {
FRLogger.getLogger().error(e.getMessage());
} catch (URISyntaxException e) {
FRLogger.getLogger().error(e.getMessage());
}
} else if (value instanceof DocumentModel) {
String url = ((DocumentModel) value).getDocumentUrl();
try {
Desktop.getDesktop().browse(new URI(url));
} catch (IOException e) {
FRLogger.getLogger().error(e.getMessage());
} catch (URISyntaxException e) {
FRLogger.getLogger().error(e.getMessage());
}
}
final AlphaCellModel model = searchResultList.getSelectedValue();
model.doAction();
}
/**
@ -725,11 +677,10 @@ public class AlphaFineDialog extends UIDialog {
* @param cellModel
*/
private void saveHistory(AlphaCellModel cellModel) {
String searchText = searchTextField.getText();
RecentSearchManager recentSearchManager = RecentSearchManager.getRecentSearchManger();
recentSearchManager.addRecentModel(searchText, cellModel);
recentSearchManager.addRecentModel(storeText, cellModel);
recentSearchManager.saveXMLFile();
sendToServer(searchText, cellModel);
sendToServer(storeText, cellModel);
}
@ -740,30 +691,33 @@ public class AlphaFineDialog extends UIDialog {
* @param cellModel
*/
private void sendToServer(String searchKey, AlphaCellModel cellModel) {
String username = DesignerEnvManager.getEnvManager().getBBSName();
String uuid = DesignerEnvManager.getEnvManager().getUUID();
String activitykey = DesignerEnvManager.getEnvManager().getActivationKey();
String createTime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(Calendar.getInstance().getTime());
String key = searchKey;
int resultkind = cellModel.getType().getTypeValue();
String resultValue = CellModelHelper.getResultValueFromModel(cellModel);
JSONObject object = JSONObject.create();
try {
object.put("uuid", uuid).put("activitykey", activitykey).put("username", username).put("createtime", createTime).put("key", key).put("resultkind", resultkind).put("resultValue", resultValue);
} catch (JSONException e) {
FRLogger.getLogger().error(e.getMessage());
}
HashMap<String, String> para = new HashMap<>();
String date = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
para.put("token", CodeUtils.md5Encode(date, "", "MD5"));
para.put("content", object.toString());
HttpClient httpClient = new HttpClient(AlphaFineConstants.CLOUD_TEST_URL, para, true);
httpClient.setTimeout(5000);
httpClient.asGet();
if (!httpClient.isServerAlive()) {
FRLogger.getLogger().error("Failed to sent data to server!");
if (cellModel.isNeedToSendToServer()) {
String username = DesignerEnvManager.getEnvManager().getBBSName();
String uuid = DesignerEnvManager.getEnvManager().getUUID();
String activityKey = DesignerEnvManager.getEnvManager().getActivationKey();
String createTime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(Calendar.getInstance().getTime());
String key = searchKey;
int resultKind = cellModel.getType().getTypeValue();
String resultValue = CellModelHelper.getResultValueFromModel(cellModel);
JSONObject object = JSONObject.create();
try {
object.put("uuid", uuid).put("activityKey", activityKey).put("username", username).put("createTime", createTime).put("key", key).put("resultKind", resultKind).put("resultValue", resultValue);
} catch (JSONException e) {
FRLogger.getLogger().error(e.getMessage());
}
final HashMap<String, String> para = new HashMap<>();
String date = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
para.put("token", CodeUtils.md5Encode(date, "", "MD5"));
para.put("content", object.toString());
HttpClient httpClient = new HttpClient(AlphaFineConstants.CLOUD_SERVER_URL, para, true);
httpClient.setTimeout(5000);
httpClient.asGet();
if (!httpClient.isServerAlive()) {
FRLogger.getLogger().error("Failed to sent data to server!");
}
}
}
/**
@ -784,23 +738,11 @@ public class AlphaFineDialog extends UIDialog {
}
}
this.searchResultList.validate();
this.searchResultList.repaint();
validate();
repaint();
}
private void rebuildList() {
this.searchResultList.validate();
this.searchResultList.repaint();
validate();
repaint();
}
private SearchResult getMoreResult(MoreModel selectedValue) {
SearchResult moreResult;
switch (selectedValue.getType()) {
switch (selectedValue.getContentType()) {
case PLUGIN:
moreResult = PluginSearchManager.getPluginSearchManager().getMoreSearchResult();
break;
@ -845,4 +787,190 @@ public class AlphaFineDialog extends UIDialog {
this.forceOpen = forceOpen;
}
public String getStoreText() {
return storeText;
}
public void setStoreText(String storeText) {
this.storeText = storeText;
}
/**
* +-------------------------------------+
* | 自定义JList |
* +-------------------------------------+
*/
private class AlphaFineList extends JList<AlphaCellModel> {
public AlphaFineList() {
initListListener();
}
/**
* 重写选中的方法
*
* @param index
*/
@Override
public void setSelectedIndex(int index) {
if (index > 0 && checkSelectedIndex(index)) {
int previousIndex = getSelectedIndex();
super.setSelectedIndex(index);
AlphaCellModel cellModel = getSelectedValue();
if (cellModel != null && !cellModel.hasAction()) {
if (previousIndex <= getSelectedIndex()) {
setSelectedIndex(index + 1);
} else {
setSelectedIndex(index - 1);
}
}
}
ensureIndexIsVisible(getSelectedIndex());
}
private boolean checkSelectedIndex(int index) {
int size = getModel().getSize();
return size > 0 && index < size;
}
private void initListListener() {
/**
* 为list添加键盘监听器
*/
addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
doNavigate();
saveHistory(getSelectedValue());
} else if (e.getKeyCode() == KeyEvent.VK_UP) {
if (getSelectedIndex() == 1) {
searchTextField.requestFocus();
}
}
}
});
/**
* 为list添加鼠标监听器
*/
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int selectedIndex = getSelectedIndex();
AlphaCellModel selectedValue = getSelectedValue();
if (e.getClickCount() == 2 && selectedValue.hasAction()) {
doNavigate();
saveHistory(selectedValue);
} else if (e.getClickCount() == 1) {
if (selectedValue instanceof MoreModel && ((MoreModel) selectedValue).isNeedMore()) {
HandleMoreOrLessResult(selectedIndex, (MoreModel) selectedValue);
}
}
}
});
/**
*单击时触发右侧面板展示搜索结果
*/
addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting() && getSelectedValue() != null) {
showResult(getSelectedValue());
}
}
});
}
}
/**
* +-------------------------------------+
* | 自定义ListModel |
* +-------------------------------------+
*/
private class SearchListModel extends DefaultListModel<AlphaCellModel> {
SearchResult myDelegate;
/**
* 第一有效的项是否被选中
*/
private boolean isValidSelected;
public SearchListModel(SearchResult searchResult) {
this.myDelegate = searchResult;
}
@Override
public void addElement(AlphaCellModel element) {
int index = myDelegate.size();
myDelegate.add(element);
fireContentsChanged(this, index, index);
fireSelectedStateChanged(element, index);
}
/**
* 触发选中第一有效的项
*
* @param element
* @param index
*/
private void fireSelectedStateChanged(AlphaCellModel element, int index) {
if (element.hasAction() && !isValidSelected()) {
searchResultList.setSelectedIndex(index);
setValidSelected(true);
}
}
@Override
public AlphaCellModel getElementAt(int index) {
return myDelegate.get(index);
}
@Override
public void add(int index, AlphaCellModel element) {
myDelegate.add(index, element);
fireIntervalAdded(this, index, index);
}
@Override
public AlphaCellModel remove(int index) {
AlphaCellModel object = myDelegate.get(index);
myDelegate.remove(object);
fireIntervalRemoved(this, index, index);
return object;
}
@Override
public int getSize() {
return this.myDelegate.size();
}
@Override
public void removeAllElements() {
this.myDelegate.clear();
}
/**
* 重置选中状态
*/
public void resetSelectedState() {
setValidSelected(false);
}
private boolean isValidSelected() {
return isValidSelected;
}
private void setValidSelected(boolean selected) {
isValidSelected = selected;
}
}
}

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

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

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

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

5
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.CellType;
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.model.SearchResult;
import com.fr.design.mainframe.toolbar.UpdateActionManager;
@ -20,7 +21,7 @@ import java.util.List;
* Created by XiaXiang on 2017/3/27.
*/
public class ActionSearchManager implements AlphaFineSearchProcessor {
private static final MoreModel TITLE_MODEL = new MoreModel(Inter.getLocText("FR-Designer_Set"), CellType.ACTION);
private static final MoreModel TITLE_MODEL = new MoreModel(Inter.getLocText("FR-Designer_Set"));
private static ActionSearchManager actionSearchManager = null;
private SearchResult filterModelList;
private SearchResult lessModelList;
@ -70,7 +71,7 @@ public class ActionSearchManager implements AlphaFineSearchProcessor {
}
}
SearchResult result = new SearchResult();
for (Object object : filterModelList) {
for (AlphaCellModel object : filterModelList) {
if (!AlphaFineHelper.getFilterResult().contains(object)) {
result.add(object);
}

4
designer/src/com/fr/design/mainframe/alphafine/search/manager/DocumentSearchManager.java

@ -19,7 +19,7 @@ import com.fr.stable.StringUtils;
* Created by XiaXiang on 2017/3/27.
*/
public class DocumentSearchManager implements AlphaFineSearchProcessor {
private static final MoreModel TITLE_MODEL = new MoreModel(Inter.getLocText("FR-Designer_COMMUNITY_HELP"), CellType.DOCUMENT);
private static final MoreModel TITLE_MODEL = new MoreModel(Inter.getLocText("FR-Designer_COMMUNITY_HELP"));
private static DocumentSearchManager documentSearchManager = null;
private SearchResult lessModelList;
private SearchResult moreModelList;
@ -58,11 +58,11 @@ public class DocumentSearchManager implements AlphaFineSearchProcessor {
String result;
String url = AlphaFineConstants.DOCUMENT_SEARCH_URL + searchText + "-1";
HttpClient httpClient = new HttpClient(url);
httpClient.setTimeout(5000);
httpClient.asGet();
if (!httpClient.isServerAlive()) {
return getNoConnectList();
}
httpClient.setTimeout(5000);
result = httpClient.getResponseText();
AlphaFineHelper.checkCancel();
try {

5
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.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;
@ -30,7 +31,7 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
private static final String DS_NAME = "dsname=\"";
private static final String FRM_PREFIX = "k:frm ";
private static final String CPT_PREFIX = "k:cpt ";
private static final MoreModel TITLE_MODEL = new MoreModel(Inter.getLocText("FR-Designer_Templates"), CellType.FILE);
private static final MoreModel TITLE_MODEL = new MoreModel(Inter.getLocText("FR-Designer_Templates"));
private static FileSearchManager fileSearchManager = null;
private SearchResult filterModelList;
private SearchResult lessModelList;
@ -94,7 +95,7 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
}
SearchResult result = new SearchResult();
for (Object object : filterModelList) {
for (AlphaCellModel object : filterModelList) {
if (!AlphaFineHelper.getFilterResult().contains(object)) {
result.add(object);
}

4
designer/src/com/fr/design/mainframe/alphafine/search/manager/PluginSearchManager.java

@ -23,7 +23,7 @@ import java.net.URLEncoder;
* Created by XiaXiang on 2017/3/27.
*/
public class PluginSearchManager implements AlphaFineSearchProcessor {
private static final MoreModel TITLE_MODEL = new MoreModel(Inter.getLocText("FR-Designer-Plugin_Addon"), CellType.PLUGIN);
private static final MoreModel TITLE_MODEL = new MoreModel(Inter.getLocText("FR-Designer-Plugin_Addon"));
private static PluginSearchManager pluginSearchManager = null;
private SearchResult lessModelList;
private SearchResult moreModelList;
@ -93,11 +93,11 @@ public class PluginSearchManager implements AlphaFineSearchProcessor {
String encodedKey = URLEncoder.encode(searchText, "UTF-8");
String url = AlphaFineConstants.PLUGIN_SEARCH_URL + "?keyword=" + encodedKey;
HttpClient httpClient = new HttpClient(url);
httpClient.setTimeout(5000);
httpClient.asGet();
if (!httpClient.isServerAlive()) {
return getNoConnectList();
}
httpClient.setTimeout(5000);
result = httpClient.getResponseText();
AlphaFineHelper.checkCancel();
JSONObject jsonObject = new JSONObject(result);

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

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

@ -1,6 +1,7 @@
package com.fr.design.mainframe.alphafine.search.manager;
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.CellModelHelper;
@ -16,7 +17,6 @@ import com.fr.json.JSONException;
import com.fr.json.JSONObject;
import com.fr.stable.CodeUtils;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@ -24,11 +24,9 @@ import java.util.List;
* Created by XiaXiang on 2017/3/31.
*/
public class RecommendSearchManager implements AlphaFineSearchProcessor {
//todo:for test
private static final String SEARCHAPI = "http://localhost:8080/monitor/alphafine/search/recommend?searchKey=";
private static RecommendSearchManager recommendSearchManager = null;
private SearchResult modelList;
private List<AlphaCellModel> recommendModelList = new ArrayList<>();
private SearchResult recommendModelList;
public synchronized static RecommendSearchManager getRecommendSearchManager() {
if (recommendSearchManager == null) {
@ -40,15 +38,15 @@ public class RecommendSearchManager implements AlphaFineSearchProcessor {
@Override
public synchronized SearchResult getLessSearchResult(String searchText) {
this.modelList = new SearchResult();
this.recommendModelList = new ArrayList<>();
this.recommendModelList = new SearchResult();
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainRecommend()) {
String result;
HttpClient httpClient = new HttpClient(SEARCHAPI + CodeUtils.cjkEncode(searchText));
HttpClient httpClient = new HttpClient(AlphaFineConstants.SEARCH_API + CodeUtils.cjkEncode(searchText));
httpClient.asGet();
httpClient.setTimeout(5000);
if (!httpClient.isServerAlive()) {
return getNoConnectList();
}
httpClient.setTimeout(5000);
result = httpClient.getResponseText();
AlphaFineHelper.checkCancel();
try {
@ -59,13 +57,12 @@ public class RecommendSearchManager implements AlphaFineSearchProcessor {
for (int i = 0; i < jsonArray.length(); i++) {
AlphaFineHelper.checkCancel();
AlphaCellModel alphaCellModel = CellModelHelper.getModelFromJson((JSONObject) jsonArray.get(i));
if (alphaCellModel != null && !RecentSearchManager.getRecentSearchManger().getRecentModelList().contains(alphaCellModel)) {
if (alphaCellModel != null && !alreadyContain(alphaCellModel)) {
this.recommendModelList.add(alphaCellModel);
}
}
}
}
} catch (JSONException e) {
FRLogger.getLogger().error("recommend search error! :" + e.getMessage());
}
@ -75,17 +72,25 @@ public class RecommendSearchManager implements AlphaFineSearchProcessor {
if (model.getType() == CellType.ACTION && !((ActionModel) model).getAction().isEnabled()) {
modelIterator.remove();
}
}
if (recommendModelList.size() > 0) {
modelList.add(new MoreModel(Inter.getLocText("FR-Designer_AlphaFine_Recommend"), false));
modelList.addAll(recommendModelList);
}
}
return modelList;
}
/**
* 是否已包含该model
*
* @param cellModel
* @return
*/
private boolean alreadyContain(AlphaCellModel cellModel) {
return RecentSearchManager.getRecentSearchManger().getRecentModelList().contains(cellModel) || this.recommendModelList.contains(cellModel);
}
private SearchResult getNoConnectList() {
SearchResult result = new SearchResult();
result.add(0, new MoreModel(Inter.getLocText("FR-Designer_AlphaFine_Recommend"), false));
@ -102,7 +107,4 @@ public class RecommendSearchManager implements AlphaFineSearchProcessor {
return recommendModelList;
}
public void setRecommendModelList(List<AlphaCellModel> recommendModelList) {
this.recommendModelList = recommendModelList;
}
}

Loading…
Cancel
Save