kerry 7 years ago
parent
commit
b3cf2f6af2
  1. 6
      designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java
  2. 7
      designer/src/com/fr/design/mainframe/alphafine/AlphaFineHelper.java
  3. 2
      designer/src/com/fr/design/mainframe/alphafine/CellType.java
  4. 5
      designer/src/com/fr/design/mainframe/alphafine/cell/model/ActionModel.java
  5. 13
      designer/src/com/fr/design/mainframe/alphafine/cell/model/AlphaCellModel.java
  6. 16
      designer/src/com/fr/design/mainframe/alphafine/cell/model/DocumentModel.java
  7. 12
      designer/src/com/fr/design/mainframe/alphafine/cell/model/FileModel.java
  8. 68
      designer/src/com/fr/design/mainframe/alphafine/cell/model/MoreModel.java
  9. 14
      designer/src/com/fr/design/mainframe/alphafine/cell/model/NoResultModel.java
  10. 16
      designer/src/com/fr/design/mainframe/alphafine/cell/model/PluginModel.java
  11. 21
      designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java
  12. 453
      designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java
  13. 28
      designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineTextField.java
  14. BIN
      designer/src/com/fr/design/mainframe/alphafine/images/remind.png
  15. 50
      designer/src/com/fr/design/mainframe/alphafine/model/SearchListModel.java
  16. 4
      designer/src/com/fr/design/mainframe/alphafine/model/SearchResult.java
  17. 5
      designer/src/com/fr/design/mainframe/alphafine/search/manager/ActionSearchManager.java
  18. 4
      designer/src/com/fr/design/mainframe/alphafine/search/manager/DocumentSearchManager.java
  19. 5
      designer/src/com/fr/design/mainframe/alphafine/search/manager/FileSearchManager.java
  20. 4
      designer/src/com/fr/design/mainframe/alphafine/search/manager/PluginSearchManager.java
  21. 22
      designer/src/com/fr/design/mainframe/alphafine/search/manager/RecentSearchManager.java
  22. 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 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";
} }

7
designer/src/com/fr/design/mainframe/alphafine/AlphaFineHelper.java

@ -6,6 +6,7 @@ import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel; import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel;
import com.fr.design.mainframe.alphafine.cell.model.NoResultModel; import com.fr.design.mainframe.alphafine.cell.model.NoResultModel;
import com.fr.design.mainframe.alphafine.component.AlphaFineDialog; import com.fr.design.mainframe.alphafine.component.AlphaFineDialog;
import com.fr.design.mainframe.alphafine.model.SearchResult;
import com.fr.design.mainframe.alphafine.search.manager.RecentSearchManager; import com.fr.design.mainframe.alphafine.search.manager.RecentSearchManager;
import com.fr.design.mainframe.alphafine.search.manager.RecommendSearchManager; import com.fr.design.mainframe.alphafine.search.manager.RecommendSearchManager;
import com.fr.general.Inter; import com.fr.general.Inter;
@ -81,8 +82,10 @@ public class AlphaFineHelper {
public static List<AlphaCellModel> getFilterResult() { public static List<AlphaCellModel> getFilterResult() {
List<AlphaCellModel> recentList = RecentSearchManager.getRecentSearchManger().getRecentModelList(); List<AlphaCellModel> recentList = RecentSearchManager.getRecentSearchManger().getRecentModelList();
List<AlphaCellModel> recommendList = RecommendSearchManager.getRecommendSearchManager().getRecommendModelList(); List<AlphaCellModel> recommendList = RecommendSearchManager.getRecommendSearchManager().getRecommendModelList();
recentList.addAll(recommendList); SearchResult filterResult = new SearchResult();
return recentList; filterResult.addAll(recentList);
filterResult.addAll(recommendList);
return filterResult;
} }

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. * Created by XiaXiang on 2017/4/27.
*/ */
public enum CellType { 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; 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(); return getClassName();
} }
@Override
public void doAction() {
getAction().actionPerformed(null);
}
public String getClassName() { public String getClassName() {
return getAction().getClass().getName(); return getAction().getClass().getName();
} }

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

@ -61,8 +61,12 @@ public abstract class AlphaCellModel implements Comparable {
this.description = description; this.description = description;
} }
public boolean hasNoResult() { public boolean hasAction() {
return false; return true;
}
public boolean isNeedToSendToServer() {
return true;
} }
/** /**
* model转json * model转json
@ -79,6 +83,11 @@ public abstract class AlphaCellModel implements Comparable {
*/ */
abstract public String getStoreInformation(); abstract public String getStoreInformation();
/**
* 双击时所需执行的操作
*/
abstract public void doAction();
public int getSearchCount() { public int getSearchCount() {
return searchCount; 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.JSONException;
import com.fr.json.JSONObject; 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. * Created by XiaXiang on 2017/4/20.
*/ */
@ -52,6 +57,17 @@ public class DocumentModel extends AlphaCellModel {
return getInformationUrl(); 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 @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == 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; 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.AlphaFineHelper;
import com.fr.design.mainframe.alphafine.CellType; 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.general.FRLogger;
import com.fr.json.JSONException; import com.fr.json.JSONException;
import com.fr.json.JSONObject; import com.fr.json.JSONObject;
@ -49,6 +52,15 @@ public class FileModel extends AlphaCellModel {
return getFilePath(); return getFilePath();
} }
@Override
public void doAction() {
DesignerContext.getDesignerFrame().openTemplate(new FileNodeFILE(new FileNode(getFilePath(), false)));
}
@Override
public boolean isNeedToSendToServer() {
return false;
}
@Override @Override
public boolean equals(Object o) { 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; package com.fr.design.mainframe.alphafine.cell.model;
import com.fr.design.mainframe.alphafine.CellType; import com.fr.design.mainframe.alphafine.CellType;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
/** /**
* Created by XiaXiang on 2017/4/20. * Created by XiaXiang on 2017/4/20.
*/ */
public class MoreModel { public class MoreModel extends AlphaCellModel {
private String name;
private boolean needMore; private boolean needMore;
private String content;
private CellType type;
private boolean isLoading; private boolean isLoading;
private CellType contentType;
public MoreModel(String name, String content, boolean needMore, CellType type) { public MoreModel(String name, String content, boolean needMore, CellType type) {
this.name = name; super(name, content, CellType.MORE);
this.needMore = needMore; this.needMore = needMore;
this.content = content; this.contentType = type;
this.type = type;
}
public MoreModel(String name, CellType type) {
this.name = name;
this.needMore = false;
this.type = type;
} }
public MoreModel(String name) { public MoreModel(String name) {
this.name = name; super(name, null, CellType.MORE);
this.isLoading = true; this.needMore = false;
} }
public MoreModel(String name, boolean isLoading) { public MoreModel(String name, boolean isLoading) {
this.name = name; super(name, null, CellType.MORE);
this.isLoading = isLoading; this.isLoading = isLoading;
} }
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isNeedMore() { public boolean isNeedMore() {
return needMore; return needMore;
} }
@ -51,20 +36,19 @@ public class MoreModel {
this.needMore = needMore; this.needMore = needMore;
} }
public String getContent() { @Override
return content; public JSONObject ModelToJson() throws JSONException {
return null;
} }
public void setContent(String content) { @Override
this.content = content; public String getStoreInformation() {
return null;
} }
public CellType getType() { @Override
return type; public void doAction() {
}
public void setType(CellType type) {
this.type = type;
} }
public boolean isLoading() { public boolean isLoading() {
@ -74,4 +58,22 @@ public class MoreModel {
public void setLoading(boolean loading) { public void setLoading(boolean loading) {
isLoading = 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 @Override
public boolean hasNoResult() { public void doAction() {
return true;
}
@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.JSONException;
import com.fr.json.JSONObject; 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. * Created by XiaXiang on 2017/4/20.
*/ */
@ -112,6 +117,17 @@ public class PluginModel extends AlphaCellModel {
return getInformationUrl(); 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 @Override
public boolean equals(Object o) { 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. * Created by XiaXiang on 2017/4/20.
*/ */
public class ContentCellRender implements ListCellRenderer<Object> { public class ContentCellRender implements ListCellRenderer<Object> {
private static final int OFFSET = 30; private static final int OFFSET = 45;
private static final int LABEL_OFFSET = 45;
@Override @Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 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; AlphaCellModel model = (AlphaCellModel) value;
JPanel panel = new JPanel(new BorderLayout()); JPanel panel = new JPanel(new BorderLayout());
panel.setBackground(null); panel.setBackground(null);
if (isSelected && !model.hasNoResult()) {
panel.setBackground(AlphaFineConstants.BLUE);
}
panel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0)); panel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
titleLabel.setText(" " + model.getName()); titleLabel.setText(" " + model.getName());
String iconUrl = "/com/fr/design/mainframe/alphafine/images/alphafine" + model.getType().getTypeValue() + ".png"; String iconUrl = "/com/fr/design/mainframe/alphafine/images/alphafine" + model.getType().getTypeValue() + ".png";
if (model.hasNoResult()) { if (model.hasAction()) {
titleLabel.setIcon(null); if (isSelected) {
titleLabel.setForeground(AlphaFineConstants.MEDIUM_GRAY); panel.setBackground(AlphaFineConstants.BLUE);
} else { }
titleLabel.setIcon(new ImageIcon(IOUtils.readImage(iconUrl))); titleLabel.setIcon(new ImageIcon(IOUtils.readImage(iconUrl)));
titleLabel.setForeground(AlphaFineConstants.BLACK); titleLabel.setForeground(AlphaFineConstants.BLACK);
} else {
titleLabel.setIcon(null);
titleLabel.setForeground(AlphaFineConstants.MEDIUM_GRAY);
} }
titleLabel.setFont(AlphaFineConstants.MEDIUM_FONT); titleLabel.setFont(AlphaFineConstants.MEDIUM_FONT);
String description = model.getDescription(); String description = model.getDescription();
@ -48,9 +47,11 @@ public class ContentCellRender implements ListCellRenderer<Object> {
panel.add(detailLabel, BorderLayout.CENTER); panel.add(detailLabel, BorderLayout.CENTER);
int width = (int) (titleLabel.getPreferredSize().getWidth() + detailLabel.getPreferredSize().getWidth()); int width = (int) (titleLabel.getPreferredSize().getWidth() + detailLabel.getPreferredSize().getWidth());
if ( width > AlphaFineConstants.LEFT_WIDTH - OFFSET) { 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)); 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); panel.add(titleLabel, BorderLayout.WEST);

453
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.ibutton.UIButton;
import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel; 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.AlphaFineConstants;
import com.fr.design.mainframe.alphafine.AlphaFineHelper; import com.fr.design.mainframe.alphafine.AlphaFineHelper;
import com.fr.design.mainframe.alphafine.cell.CellModelHelper; 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.cell.render.ContentCellRender;
import com.fr.design.mainframe.alphafine.listener.ComponentHandler; import com.fr.design.mainframe.alphafine.listener.ComponentHandler;
import com.fr.design.mainframe.alphafine.listener.DocumentAdapter; 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.model.SearchResult;
import com.fr.design.mainframe.alphafine.preview.ActionPreviewPane; import com.fr.design.mainframe.alphafine.preview.ActionPreviewPane;
import com.fr.design.mainframe.alphafine.preview.DocumentPreviewPane; import com.fr.design.mainframe.alphafine.preview.DocumentPreviewPane;
import com.fr.design.mainframe.alphafine.preview.FilePreviewPane; import com.fr.design.mainframe.alphafine.preview.FilePreviewPane;
import com.fr.design.mainframe.alphafine.preview.PluginPreviewPane; import com.fr.design.mainframe.alphafine.preview.PluginPreviewPane;
import com.fr.design.mainframe.alphafine.search.manager.*; 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.Form;
import com.fr.form.main.FormIO; import com.fr.form.main.FormIO;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
@ -47,8 +46,6 @@ import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
@ -79,10 +76,11 @@ public class AlphaFineDialog extends UIDialog {
private Point pressedPoint; private Point pressedPoint;
private UIScrollPane leftSearchResultPane; private UIScrollPane leftSearchResultPane;
private JPanel rightSearchResultPane; private JPanel rightSearchResultPane;
private JList searchResultList; private AlphaFineList searchResultList;
private SearchListModel searchListModel; private SearchListModel searchListModel;
private SwingWorker searchWorker; private SwingWorker searchWorker;
private SwingWorker showWorker; private SwingWorker showWorker;
private String storeText;
//是否强制打开,因为面板是否关闭绑定了全局鼠标事件,这里需要处理一下 //是否强制打开,因为面板是否关闭绑定了全局鼠标事件,这里需要处理一下
private boolean forceOpen; private boolean forceOpen;
@ -118,6 +116,9 @@ public class AlphaFineDialog extends UIDialog {
}; };
} }
/**
* 打开搜索框
*/
private static void doClickAction() { private static void doClickAction() {
AlphaFineHelper.showAlphaFineDialog(false); AlphaFineHelper.showAlphaFineDialog(false);
} }
@ -126,11 +127,7 @@ public class AlphaFineDialog extends UIDialog {
* 初始化全部组件 * 初始化全部组件
*/ */
private void initComponents() { private void initComponents() {
searchTextField = new AlphaFineTextField("AlphaFine"); initSearchTextField();
searchTextField.setFont(AlphaFineConstants.GREATER_FONT);
searchTextField.setBackground(Color.white);
searchTextField.setBorderPainted(false);
searchTextField.initKeyListener(this);
JPanel topPane = new JPanel(new BorderLayout()); JPanel topPane = new JPanel(new BorderLayout());
UILabel iconLabel = new UILabel(new ImageIcon(getClass().getResource("/com/fr/design/mainframe/alphafine/images/bigsearch.png"))); UILabel iconLabel = new UILabel(new ImageIcon(getClass().getResource("/com/fr/design/mainframe/alphafine/images/bigsearch.png")));
iconLabel.setPreferredSize(AlphaFineConstants.ICON_LABEL_SIZE); iconLabel.setPreferredSize(AlphaFineConstants.ICON_LABEL_SIZE);
@ -170,6 +167,17 @@ public class AlphaFineDialog extends UIDialog {
}); });
} }
/**
* 初始化输入框
*/
private void initSearchTextField() {
searchTextField = new AlphaFineTextField("AlphaFine");
initTextFieldKeyListener();
searchTextField.setFont(AlphaFineConstants.GREATER_FONT);
searchTextField.setBackground(Color.white);
searchTextField.setBorderPainted(false);
}
/** /**
* *
*/ */
@ -248,7 +256,6 @@ public class AlphaFineDialog extends UIDialog {
private void showSearchResult() { private void showSearchResult() {
if (searchResultPane == null) { if (searchResultPane == null) {
initSearchResultComponents(); initSearchResultComponents();
initListListener();
} }
initSearchWorker(); initSearchWorker();
} }
@ -257,7 +264,8 @@ public class AlphaFineDialog extends UIDialog {
* 初始化搜索面板 * 初始化搜索面板
*/ */
private void initSearchResultComponents() { private void initSearchResultComponents() {
searchResultList = new JList(); searchResultList = new AlphaFineList();
searchResultList.setFixedCellHeight(AlphaFineConstants.CELL_HEIGHT);
searchListModel = new SearchListModel(new SearchResult()); searchListModel = new SearchListModel(new SearchResult());
searchResultList.setModel(searchListModel); searchResultList.setModel(searchListModel);
searchResultPane = new JPanel(); searchResultPane = new JPanel();
@ -292,14 +300,6 @@ public class AlphaFineDialog extends UIDialog {
rebuildList(searchTextField.getText().toLowerCase()); rebuildList(searchTextField.getText().toLowerCase());
return null; return null;
} }
@Override
protected void done() {
if (!isCancelled() && searchListModel.getSize() > 1) {
searchResultList.setSelectedIndex(1);
showResult(searchResultList.getSelectedIndex(), searchResultList.getSelectedValue());
}
}
}; };
this.searchWorker.execute(); this.searchWorker.execute();
} }
@ -311,27 +311,45 @@ public class AlphaFineDialog extends UIDialog {
* @param searchText * @param searchText
*/ */
private void rebuildList(String searchText) { private void rebuildList(String searchText) {
searchListModel.removeAllElements(); resetContainer();
if (searchText.startsWith(ADVANCED_SEARCH_MARK)) { if (searchText.startsWith(ADVANCED_SEARCH_MARK)) {
if (searchText.startsWith(ACTION_MARK_SHORT) || searchText.startsWith(ACTION_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)) { } 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)) { } 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)) { } else if (searchText.startsWith(CPT_MARK) || searchText.startsWith(FRM_MARK)) {
storeText = searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length());
getFileList(searchText); getFileList(searchText);
} else if (searchText.startsWith(DS_MARK)) { } 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)) { } 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 { } else {
doNormalSearch(searchText.trim()); storeText = searchText.trim();
doNormalSearch(storeText);
} }
} }
/**
* 重置面板
*/
private void resetContainer() {
searchListModel.removeAllElements();
searchListModel.resetSelectedState();
rightSearchResultPane.removeAll();
rightSearchResultPane.validate();
rightSearchResultPane.repaint();
}
/** /**
* 普通搜索 * 普通搜索
* *
@ -348,7 +366,7 @@ public class AlphaFineDialog extends UIDialog {
private void getDocumentList(final String searchText) { private void getDocumentList(final String searchText) {
SearchResult documentModelList = DocumentSearchManager.getDocumentSearchManager().getLessSearchResult(searchText); SearchResult documentModelList = DocumentSearchManager.getDocumentSearchManager().getLessSearchResult(searchText);
for (Object object : documentModelList) { for (AlphaCellModel object : documentModelList) {
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
searchListModel.addElement(object); searchListModel.addElement(object);
} }
@ -356,7 +374,7 @@ public class AlphaFineDialog extends UIDialog {
private void getFileList(final String searchText) { private void getFileList(final String searchText) {
SearchResult fileModelList = FileSearchManager.getFileSearchManager().getLessSearchResult(searchText); SearchResult fileModelList = FileSearchManager.getFileSearchManager().getLessSearchResult(searchText);
for (Object object : fileModelList) { for (AlphaCellModel object : fileModelList) {
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
searchListModel.addElement(object); searchListModel.addElement(object);
} }
@ -364,7 +382,7 @@ public class AlphaFineDialog extends UIDialog {
private void getActionList(final String searchText) { private void getActionList(final String searchText) {
SearchResult actionModelList = ActionSearchManager.getActionSearchManager().getLessSearchResult(searchText); SearchResult actionModelList = ActionSearchManager.getActionSearchManager().getLessSearchResult(searchText);
for (Object object : actionModelList) { for (AlphaCellModel object : actionModelList) {
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
searchListModel.addElement(object); searchListModel.addElement(object);
} }
@ -372,7 +390,7 @@ public class AlphaFineDialog extends UIDialog {
private void getPluginList(final String searchText) { private void getPluginList(final String searchText) {
SearchResult pluginModelList = PluginSearchManager.getPluginSearchManager().getLessSearchResult(searchText); SearchResult pluginModelList = PluginSearchManager.getPluginSearchManager().getLessSearchResult(searchText);
for (Object object : pluginModelList) { for (AlphaCellModel object : pluginModelList) {
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
searchListModel.addElement(object); searchListModel.addElement(object);
} }
@ -380,7 +398,7 @@ public class AlphaFineDialog extends UIDialog {
private void getRecommendList(final String searchText) { private void getRecommendList(final String searchText) {
SearchResult recommendModelList = RecommendSearchManager.getRecommendSearchManager().getLessSearchResult(searchText); SearchResult recommendModelList = RecommendSearchManager.getRecommendSearchManager().getLessSearchResult(searchText);
for (Object object : recommendModelList) { for (AlphaCellModel object : recommendModelList) {
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
searchListModel.addElement(object); searchListModel.addElement(object);
} }
@ -388,23 +406,34 @@ public class AlphaFineDialog extends UIDialog {
private void getRecentList(final String searchText) { private void getRecentList(final String searchText) {
SearchResult recentModelList = RecentSearchManager.getRecentSearchManger().getLessSearchResult(searchText); SearchResult recentModelList = RecentSearchManager.getRecentSearchManger().getLessSearchResult(searchText);
for (Object object : recentModelList) { for (AlphaCellModel object : recentModelList) {
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
searchListModel.addElement(object); searchListModel.addElement(object);
} }
} }
private void showResult(int index, final Object selectedValue) { /**
if (selectedValue instanceof FileModel) { * 右侧面板展示搜索结果的内容
*
* @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); final String fileName = ((FileModel) selectedValue).getFilePath().substring(ProjectConstants.REPORTLETS_NAME.length() + 1);
showDefaultPreviewPane(); showDefaultPreviewPane();
if (fileName.endsWith(ProjectConstants.FRM_SUFFIX)) { if (fileName.endsWith(ProjectConstants.FRM_SUFFIX)) {
checkWorker(); checkWorker();
this.showWorker = new SwingWorker<BufferedImage, Void>() { this.showWorker = new SwingWorker<BufferedImage, Void>() {
@Override @Override
protected BufferedImage doInBackground() throws Exception { protected BufferedImage doInBackground() {
Form form = FormIO.readForm(FRContext.getCurrentEnv(), fileName); Form form = null;
try {
form = FormIO.readForm(FRContext.getCurrentEnv(), fileName);
} catch (Exception e) {
FRLogger.getLogger().error(e.getMessage());
}
return FormIO.exportFormAsImage(form); return FormIO.exportFormAsImage(form);
} }
@ -430,8 +459,13 @@ public class AlphaFineDialog extends UIDialog {
checkWorker(); checkWorker();
this.showWorker = new SwingWorker<BufferedImage, Void>() { this.showWorker = new SwingWorker<BufferedImage, Void>() {
@Override @Override
protected BufferedImage doInBackground() throws Exception { protected BufferedImage doInBackground() {
WorkBook workBook = (WorkBook) TemplateWorkBookIO.readTemplateWorkBook(FRContext.getCurrentEnv(), fileName); WorkBook workBook = null;
try {
workBook = (WorkBook) TemplateWorkBookIO.readTemplateWorkBook(FRContext.getCurrentEnv(), fileName);
} catch (Exception e) {
FRLogger.getLogger().error(e.getMessage());
}
BufferedImage bufferedImage = new ImageExporter().exportToImage(workBook); BufferedImage bufferedImage = new ImageExporter().exportToImage(workBook);
return bufferedImage; return bufferedImage;
} }
@ -454,15 +488,22 @@ public class AlphaFineDialog extends UIDialog {
} }
}; };
this.showWorker.execute(); this.showWorker.execute();
} }
} else if (selectedValue instanceof DocumentModel) { break;
case ACTION:
rightSearchResultPane.removeAll(); rightSearchResultPane.removeAll();
rightSearchResultPane.add(new DocumentPreviewPane(((DocumentModel) selectedValue).getName(), ((DocumentModel) selectedValue).getContent())); rightSearchResultPane.add(new ActionPreviewPane());
validate(); validate();
repaint(); repaint();
} else if (selectedValue instanceof PluginModel) { break;
case DOCUMENT:
rightSearchResultPane.removeAll();
rightSearchResultPane.add(new DocumentPreviewPane((selectedValue).getName(), (selectedValue).getContent()));
validate();
repaint();
break;
case PLUGIN:
case REUSE:
showDefaultPreviewPane(); showDefaultPreviewPane();
checkWorker(); checkWorker();
this.showWorker = new SwingWorker<Image, Void>() { this.showWorker = new SwingWorker<Image, Void>() {
@ -486,7 +527,7 @@ public class AlphaFineDialog extends UIDialog {
try { try {
if (!isCancelled()) { if (!isCancelled()) {
rightSearchResultPane.removeAll(); rightSearchResultPane.removeAll();
rightSearchResultPane.add(new PluginPreviewPane(((PluginModel) selectedValue).getName(), get(), ((PluginModel) selectedValue).getVersion(), ((PluginModel) selectedValue).getJartime(), ((PluginModel) selectedValue).getType(), ((PluginModel) selectedValue).getPrice())); rightSearchResultPane.add(new PluginPreviewPane((selectedValue).getName(), get(), ((PluginModel) selectedValue).getVersion(), ((PluginModel) selectedValue).getJartime(), ((PluginModel) selectedValue).getType(), ((PluginModel) selectedValue).getPrice()));
validate(); validate();
repaint(); repaint();
} }
@ -499,12 +540,10 @@ public class AlphaFineDialog extends UIDialog {
} }
}; };
this.showWorker.execute(); this.showWorker.execute();
break;
default:
return;
} else if (selectedValue instanceof ActionModel) {
rightSearchResultPane.removeAll();
rightSearchResultPane.add(new ActionPreviewPane());
validate();
repaint();
} }
} }
@ -548,75 +587,35 @@ public class AlphaFineDialog extends UIDialog {
} }
/** /**
* 为面板中各组件添加监听器 * 为textfield添加键盘监听器
*/
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);
}
}
}
});
/**
* 为textField添加键盘监听器按上下方向键时把焦点给list,实现键盘操作
*/ */
private void initTextFieldKeyListener() {
searchTextField.addKeyListener(new KeyAdapter() { searchTextField.addKeyListener(new KeyAdapter() {
@Override @Override
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_UP) { if (e.getKeyCode() == KeyEvent.VK_DOWN) {
searchResultList.requestFocus(); searchResultList.requestFocus();
searchResultList.setSelectedIndex(searchResultList.getSelectedIndex() + 1);
} else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
doNavigate();
saveHistory(searchResultList.getSelectedValue());
} }
} }
});
}
private void initListMouseListener() {
/**
* 鼠标监听器
*/
searchResultList.addMouseListener(new MouseAdapter() {
@Override @Override
public void mouseClicked(MouseEvent e) { public void keyReleased(KeyEvent e) {
int selectedIndex = searchResultList.getSelectedIndex(); int keyCode = e.getKeyCode();
Object selectedValue = searchResultList.getSelectedValue(); if (keyCode == KeyEvent.VK_ESCAPE) {
if (e.getClickCount() == 2) { if (StringUtils.isBlank(searchTextField.getText()) || ComparatorUtils.equals(searchTextField.getText(), searchTextField.getPlaceHolder())) {
doNavigate(selectedIndex); AlphaFineDialog.this.setVisible(false);
if (selectedValue instanceof AlphaCellModel) { } else {
saveHistory((AlphaCellModel) selectedValue); searchTextField.setText(null);
}
} 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());
}
}
});
} }
/** /**
@ -689,34 +688,10 @@ public class AlphaFineDialog extends UIDialog {
} }
private void doNavigate(int index) { private void doNavigate() {
AlphaFineDialog.this.dispose(); AlphaFineDialog.this.dispose();
final Object value = searchResultList.getSelectedValue(); final AlphaCellModel model = searchResultList.getSelectedValue();
if (value instanceof ActionModel) { model.doAction();
((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());
}
}
} }
/** /**
@ -725,11 +700,10 @@ public class AlphaFineDialog extends UIDialog {
* @param cellModel * @param cellModel
*/ */
private void saveHistory(AlphaCellModel cellModel) { private void saveHistory(AlphaCellModel cellModel) {
String searchText = searchTextField.getText();
RecentSearchManager recentSearchManager = RecentSearchManager.getRecentSearchManger(); RecentSearchManager recentSearchManager = RecentSearchManager.getRecentSearchManger();
recentSearchManager.addRecentModel(searchText, cellModel); recentSearchManager.addRecentModel(storeText, cellModel);
recentSearchManager.saveXMLFile(); recentSearchManager.saveXMLFile();
sendToServer(searchText, cellModel); sendToServer(storeText, cellModel);
} }
@ -740,29 +714,32 @@ public class AlphaFineDialog extends UIDialog {
* @param cellModel * @param cellModel
*/ */
private void sendToServer(String searchKey, AlphaCellModel cellModel) { private void sendToServer(String searchKey, AlphaCellModel cellModel) {
if (cellModel.isNeedToSendToServer()) {
String username = DesignerEnvManager.getEnvManager().getBBSName(); String username = DesignerEnvManager.getEnvManager().getBBSName();
String uuid = DesignerEnvManager.getEnvManager().getUUID(); String uuid = DesignerEnvManager.getEnvManager().getUUID();
String activitykey = DesignerEnvManager.getEnvManager().getActivationKey(); String activityKey = DesignerEnvManager.getEnvManager().getActivationKey();
String createTime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(Calendar.getInstance().getTime()); String createTime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(Calendar.getInstance().getTime());
String key = searchKey; String key = searchKey;
int resultkind = cellModel.getType().getTypeValue(); int resultKind = cellModel.getType().getTypeValue();
String resultValue = CellModelHelper.getResultValueFromModel(cellModel); String resultValue = CellModelHelper.getResultValueFromModel(cellModel);
JSONObject object = JSONObject.create(); JSONObject object = JSONObject.create();
try { try {
object.put("uuid", uuid).put("activitykey", activitykey).put("username", username).put("createtime", createTime).put("key", key).put("resultkind", resultkind).put("resultValue", resultValue); 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) { } catch (JSONException e) {
FRLogger.getLogger().error(e.getMessage()); FRLogger.getLogger().error(e.getMessage());
} }
HashMap<String, String> para = new HashMap<>(); final HashMap<String, String> para = new HashMap<>();
String date = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime()); String date = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
para.put("token", CodeUtils.md5Encode(date, "", "MD5")); para.put("token", CodeUtils.md5Encode(date, "", "MD5"));
para.put("content", object.toString()); para.put("content", object.toString());
HttpClient httpClient = new HttpClient(AlphaFineConstants.CLOUD_TEST_URL, para, true); HttpClient httpClient = new HttpClient(AlphaFineConstants.CLOUD_SERVER_URL, para, true);
httpClient.setTimeout(5000);
httpClient.asGet(); httpClient.asGet();
if (!httpClient.isServerAlive()) { if (!httpClient.isServerAlive()) {
FRLogger.getLogger().error("Failed to sent data to server!"); FRLogger.getLogger().error("Failed to sent data to server!");
} }
httpClient.setTimeout(5000);
}
} }
@ -784,23 +761,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) { private SearchResult getMoreResult(MoreModel selectedValue) {
SearchResult moreResult; SearchResult moreResult;
switch (selectedValue.getType()) { switch (selectedValue.getContentType()) {
case PLUGIN: case PLUGIN:
moreResult = PluginSearchManager.getPluginSearchManager().getMoreSearchResult(); moreResult = PluginSearchManager.getPluginSearchManager().getMoreSearchResult();
break; break;
@ -845,4 +810,178 @@ public class AlphaFineDialog extends UIDialog {
this.forceOpen = forceOpen; 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);
}
}
}
showResult(getSelectedValue());
ensureIndexIsVisible(getSelectedIndex());
}
private boolean checkSelectedIndex(int index) {
int size = getModel().getSize();
return size > 0 && index < size;
}
private void initListListener() {
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();
}
}
}
});
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;
}
}
} }

28
designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineTextField.java

@ -1,15 +1,9 @@
package com.fr.design.mainframe.alphafine.component; package com.fr.design.mainframe.alphafine.component;
import com.fr.design.gui.itextfield.UITextField; import com.fr.design.gui.itextfield.UITextField;
import com.fr.general.ComparatorUtils;
import com.fr.report.web.button.Image; import com.fr.report.web.button.Image;
import com.fr.stable.StringUtils;
import java.awt.*; import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import static java.awt.event.KeyEvent.VK_ESCAPE;
/** /**
* Created by XiaXiang on 2017/3/21. * Created by XiaXiang on 2017/3/21.
@ -63,25 +57,7 @@ public class AlphaFineTextField extends UITextField {
this.image = image; this.image = image;
} }
/** public String getPlaceHolder() {
* 添加键盘监听器 return placeHolder;
*
* @param component
*/
public void initKeyListener(final Component component) {
addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
int keyCode = e.getKeyCode();
if (keyCode == VK_ESCAPE) {
if (StringUtils.isBlank(getText()) || ComparatorUtils.equals(getText(), placeHolder)) {
component.setVisible(false);
} else {
setText(null);
}
}
}
});
} }
} }

BIN
designer/src/com/fr/design/mainframe/alphafine/images/remind.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 185 KiB

After

Width:  |  Height:  |  Size: 161 KiB

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; package com.fr.design.mainframe.alphafine.model;
import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
* Created by XiaXiang on 2017/4/20. * Created by XiaXiang on 2017/4/20.
*/ */
public class SearchResult extends ArrayList<Object> { public class SearchResult extends ArrayList<AlphaCellModel> {
private boolean needMore; 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.AlphaFineHelper;
import com.fr.design.mainframe.alphafine.CellType; import com.fr.design.mainframe.alphafine.CellType;
import com.fr.design.mainframe.alphafine.cell.model.ActionModel; 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.cell.model.MoreModel;
import com.fr.design.mainframe.alphafine.model.SearchResult; import com.fr.design.mainframe.alphafine.model.SearchResult;
import com.fr.design.mainframe.toolbar.UpdateActionManager; import com.fr.design.mainframe.toolbar.UpdateActionManager;
@ -20,7 +21,7 @@ import java.util.List;
* Created by XiaXiang on 2017/3/27. * Created by XiaXiang on 2017/3/27.
*/ */
public class ActionSearchManager implements AlphaFineSearchProcessor { 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 static ActionSearchManager actionSearchManager = null;
private SearchResult filterModelList; private SearchResult filterModelList;
private SearchResult lessModelList; private SearchResult lessModelList;
@ -70,7 +71,7 @@ public class ActionSearchManager implements AlphaFineSearchProcessor {
} }
} }
SearchResult result = new SearchResult(); SearchResult result = new SearchResult();
for (Object object : filterModelList) { for (AlphaCellModel object : filterModelList) {
if (!AlphaFineHelper.getFilterResult().contains(object)) { if (!AlphaFineHelper.getFilterResult().contains(object)) {
result.add(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. * Created by XiaXiang on 2017/3/27.
*/ */
public class DocumentSearchManager implements AlphaFineSearchProcessor { 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 static DocumentSearchManager documentSearchManager = null;
private SearchResult lessModelList; private SearchResult lessModelList;
private SearchResult moreModelList; private SearchResult moreModelList;
@ -58,11 +58,11 @@ public class DocumentSearchManager implements AlphaFineSearchProcessor {
String result; String result;
String url = AlphaFineConstants.DOCUMENT_SEARCH_URL + searchText + "-1"; String url = AlphaFineConstants.DOCUMENT_SEARCH_URL + searchText + "-1";
HttpClient httpClient = new HttpClient(url); HttpClient httpClient = new HttpClient(url);
httpClient.setTimeout(5000);
httpClient.asGet(); httpClient.asGet();
if (!httpClient.isServerAlive()) { if (!httpClient.isServerAlive()) {
return getNoConnectList(); return getNoConnectList();
} }
httpClient.setTimeout(5000);
result = httpClient.getResponseText(); result = httpClient.getResponseText();
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
try { 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.AlphaFineConstants;
import com.fr.design.mainframe.alphafine.AlphaFineHelper; import com.fr.design.mainframe.alphafine.AlphaFineHelper;
import com.fr.design.mainframe.alphafine.CellType; 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.FileModel;
import com.fr.design.mainframe.alphafine.cell.model.MoreModel; import com.fr.design.mainframe.alphafine.cell.model.MoreModel;
import com.fr.design.mainframe.alphafine.model.SearchResult; 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 DS_NAME = "dsname=\"";
private static final String FRM_PREFIX = "k:frm "; private static final String FRM_PREFIX = "k:frm ";
private static final String CPT_PREFIX = "k:cpt "; 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 static FileSearchManager fileSearchManager = null;
private SearchResult filterModelList; private SearchResult filterModelList;
private SearchResult lessModelList; private SearchResult lessModelList;
@ -94,7 +95,7 @@ public class FileSearchManager implements AlphaFineSearchProcessor {
} }
SearchResult result = new SearchResult(); SearchResult result = new SearchResult();
for (Object object : filterModelList) { for (AlphaCellModel object : filterModelList) {
if (!AlphaFineHelper.getFilterResult().contains(object)) { if (!AlphaFineHelper.getFilterResult().contains(object)) {
result.add(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. * Created by XiaXiang on 2017/3/27.
*/ */
public class PluginSearchManager implements AlphaFineSearchProcessor { 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 static PluginSearchManager pluginSearchManager = null;
private SearchResult lessModelList; private SearchResult lessModelList;
private SearchResult moreModelList; private SearchResult moreModelList;
@ -93,11 +93,11 @@ public class PluginSearchManager implements AlphaFineSearchProcessor {
String encodedKey = URLEncoder.encode(searchText, "UTF-8"); String encodedKey = URLEncoder.encode(searchText, "UTF-8");
String url = AlphaFineConstants.PLUGIN_SEARCH_URL + "?keyword=" + encodedKey; String url = AlphaFineConstants.PLUGIN_SEARCH_URL + "?keyword=" + encodedKey;
HttpClient httpClient = new HttpClient(url); HttpClient httpClient = new HttpClient(url);
httpClient.setTimeout(5000);
httpClient.asGet(); httpClient.asGet();
if (!httpClient.isServerAlive()) { if (!httpClient.isServerAlive()) {
return getNoConnectList(); return getNoConnectList();
} }
httpClient.setTimeout(5000);
result = httpClient.getResponseText(); result = httpClient.getResponseText();
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
JSONObject jsonObject = new JSONObject(result); JSONObject jsonObject = new JSONObject(result);

22
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 RecentSearchManager recentSearchManager = null;
private static File recentFile = null; private static File recentFile = null;
private SearchResult modelList; private SearchResult modelList;
private List<AlphaCellModel> recentModelList = new ArrayList<>(); private SearchResult recentModelList;
private Map<String, List<AlphaCellModel>> recentKVModelMap = new HashMap<>(); private Map<String, SearchResult> recentKVModelMap = new HashMap<>();
public synchronized static RecentSearchManager getRecentSearchManger() { public synchronized static RecentSearchManager getRecentSearchManger() {
if (recentSearchManager == null) { if (recentSearchManager == null) {
@ -64,7 +64,7 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear
String nodeName = reader.getTagName(); String nodeName = reader.getTagName();
if (nodeName.equals("RecentModelList")) { if (nodeName.equals("RecentModelList")) {
String key = reader.getAttrAsString("searchKey", StringUtils.EMPTY); String key = reader.getAttrAsString("searchKey", StringUtils.EMPTY);
final ArrayList<AlphaCellModel> list = new ArrayList<>(); final SearchResult list = new SearchResult();
reader.readXMLObject(new XMLReadable() { reader.readXMLObject(new XMLReadable() {
@Override @Override
public void readXML(XMLableReader reader) { public void readXML(XMLableReader reader) {
@ -206,23 +206,19 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear
return recentModelList; return recentModelList;
} }
public void setRecentModelList(List<AlphaCellModel> recentModelList) {
this.recentModelList = recentModelList;
}
/** /**
* 根据搜索字段获取对应的model列表 * 根据搜索字段获取对应的model列表
* *
* @param searchText * @param searchText
* @return * @return
*/ */
public synchronized List<AlphaCellModel> getRecentModelList(String searchText) { private synchronized SearchResult getRecentModelList(String searchText) {
recentModelList = new ArrayList<>(); recentModelList = new SearchResult();
for (String key : recentKVModelMap.keySet()) { for (String key : recentKVModelMap.keySet()) {
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
if (ComparatorUtils.equals(key, searchText)) { if (ComparatorUtils.equals(key, searchText)) {
recentModelList = recentKVModelMap.get(searchText); recentModelList = recentKVModelMap.get(searchText);
List<AlphaCellModel> resultModelList = new ArrayList<>(recentModelList); SearchResult resultModelList = recentModelList;
Iterator<AlphaCellModel> modelIterator = resultModelList.iterator(); Iterator<AlphaCellModel> modelIterator = resultModelList.iterator();
while (modelIterator.hasNext()) { while (modelIterator.hasNext()) {
AlphaCellModel model = modelIterator.next(); AlphaCellModel model = modelIterator.next();
@ -234,7 +230,9 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear
Collections.sort(resultModelList); Collections.sort(resultModelList);
int size = resultModelList.size(); int size = resultModelList.size();
if (size > MAX_SIZE) { if (size > MAX_SIZE) {
return resultModelList.subList(0, MAX_SIZE); SearchResult result = new SearchResult();
result.addAll(resultModelList.subList(0, MAX_SIZE));
return result;
} }
return resultModelList; return resultModelList;
} }
@ -259,7 +257,7 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear
} }
//trimToSize(cellModels); //trimToSize(cellModels);
} else { } else {
List<AlphaCellModel> list = new ArrayList<>(); SearchResult list = new SearchResult();
list.add(cellModel); list.add(cellModel);
recentKVModelMap.put(searchKey, list); 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; package com.fr.design.mainframe.alphafine.search.manager;
import com.fr.design.DesignerEnvManager; 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.AlphaFineHelper;
import com.fr.design.mainframe.alphafine.CellType; import com.fr.design.mainframe.alphafine.CellType;
import com.fr.design.mainframe.alphafine.cell.CellModelHelper; 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.json.JSONObject;
import com.fr.stable.CodeUtils; import com.fr.stable.CodeUtils;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -24,11 +24,9 @@ import java.util.List;
* Created by XiaXiang on 2017/3/31. * Created by XiaXiang on 2017/3/31.
*/ */
public class RecommendSearchManager implements AlphaFineSearchProcessor { 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 static RecommendSearchManager recommendSearchManager = null;
private SearchResult modelList; private SearchResult modelList;
private List<AlphaCellModel> recommendModelList = new ArrayList<>(); private SearchResult recommendModelList;
public synchronized static RecommendSearchManager getRecommendSearchManager() { public synchronized static RecommendSearchManager getRecommendSearchManager() {
if (recommendSearchManager == null) { if (recommendSearchManager == null) {
@ -40,15 +38,15 @@ public class RecommendSearchManager implements AlphaFineSearchProcessor {
@Override @Override
public synchronized SearchResult getLessSearchResult(String searchText) { public synchronized SearchResult getLessSearchResult(String searchText) {
this.modelList = new SearchResult(); this.modelList = new SearchResult();
this.recommendModelList = new ArrayList<>(); this.recommendModelList = new SearchResult();
if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainRecommend()) { if (DesignerEnvManager.getEnvManager().getAlphaFineConfigManager().isContainRecommend()) {
String result; String result;
HttpClient httpClient = new HttpClient(SEARCHAPI + CodeUtils.cjkEncode(searchText)); HttpClient httpClient = new HttpClient(AlphaFineConstants.SEARCH_API + CodeUtils.cjkEncode(searchText));
httpClient.asGet(); httpClient.asGet();
httpClient.setTimeout(5000);
if (!httpClient.isServerAlive()) { if (!httpClient.isServerAlive()) {
return getNoConnectList(); return getNoConnectList();
} }
httpClient.setTimeout(5000);
result = httpClient.getResponseText(); result = httpClient.getResponseText();
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
try { try {
@ -59,13 +57,12 @@ public class RecommendSearchManager implements AlphaFineSearchProcessor {
for (int i = 0; i < jsonArray.length(); i++) { for (int i = 0; i < jsonArray.length(); i++) {
AlphaFineHelper.checkCancel(); AlphaFineHelper.checkCancel();
AlphaCellModel alphaCellModel = CellModelHelper.getModelFromJson((JSONObject) jsonArray.get(i)); 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); this.recommendModelList.add(alphaCellModel);
} }
} }
} }
} }
} catch (JSONException e) { } catch (JSONException e) {
FRLogger.getLogger().error("recommend search error! :" + e.getMessage()); 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()) { if (model.getType() == CellType.ACTION && !((ActionModel) model).getAction().isEnabled()) {
modelIterator.remove(); modelIterator.remove();
} }
} }
if (recommendModelList.size() > 0) { if (recommendModelList.size() > 0) {
modelList.add(new MoreModel(Inter.getLocText("FR-Designer_AlphaFine_Recommend"), false)); modelList.add(new MoreModel(Inter.getLocText("FR-Designer_AlphaFine_Recommend"), false));
modelList.addAll(recommendModelList); modelList.addAll(recommendModelList);
} }
} }
return modelList; return modelList;
} }
/**
* 是否已包含该model
*
* @param cellModel
* @return
*/
private boolean alreadyContain(AlphaCellModel cellModel) {
return RecentSearchManager.getRecentSearchManger().getRecentModelList().contains(cellModel) || this.recommendModelList.contains(cellModel);
}
private SearchResult getNoConnectList() { private SearchResult getNoConnectList() {
SearchResult result = new SearchResult(); SearchResult result = new SearchResult();
result.add(0, new MoreModel(Inter.getLocText("FR-Designer_AlphaFine_Recommend"), false)); result.add(0, new MoreModel(Inter.getLocText("FR-Designer_AlphaFine_Recommend"), false));
@ -102,7 +107,4 @@ public class RecommendSearchManager implements AlphaFineSearchProcessor {
return recommendModelList; return recommendModelList;
} }
public void setRecommendModelList(List<AlphaCellModel> recommendModelList) {
this.recommendModelList = recommendModelList;
}
} }

Loading…
Cancel
Save