Browse Source

代码质量 alphafine 动态扩展库 键盘选择的优化

master
XiaXiang 8 years ago
parent
commit
270ace4e68
  1. 2
      designer/src/com/fr/design/mainframe/alphafine/AlphaFineConstants.java
  2. 5
      designer/src/com/fr/design/mainframe/alphafine/cell/model/ActionModel.java
  3. 9
      designer/src/com/fr/design/mainframe/alphafine/cell/model/AlphaCellModel.java
  4. 16
      designer/src/com/fr/design/mainframe/alphafine/cell/model/DocumentModel.java
  5. 12
      designer/src/com/fr/design/mainframe/alphafine/cell/model/FileModel.java
  6. 10
      designer/src/com/fr/design/mainframe/alphafine/cell/model/NoResultModel.java
  7. 16
      designer/src/com/fr/design/mainframe/alphafine/cell/model/PluginModel.java
  8. 107
      designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java
  9. 8
      designer/src/com/fr/design/mainframe/alphafine/search/manager/RecommendSearchManager.java

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

@ -84,6 +84,6 @@ public class AlphaFineConstants {
public static final String SERVER_URL = "http://cloud.fanruan.com/api/monitor/record_of_afsearch/single"; public static final String SERVER_URL = "http://cloud.fanruan.com/api/monitor/record_of_afsearch/single";
//TODO:先用本地服务器测试一下,避免影响云中心正常信息收集 //TODO:先用本地服务器测试一下,避免影响云中心正常信息收集
public static final String CLOUD_TEST_URL = "http://localhost:8080/monitor/monitor/record_of_afsearch/single"; public static final String CLOUD_TEST_URL = "http://localhost:8080/cloud/monitor/record_of_afsearch/single";
} }

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();
} }

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

@ -64,6 +64,10 @@ public abstract class AlphaCellModel implements Comparable {
public boolean hasNoResult() { public boolean hasNoResult() {
return false; return false;
} }
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) {

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

@ -22,8 +22,18 @@ public class NoResultModel extends AlphaCellModel {
return null; return null;
} }
@Override
public void doAction() {
}
@Override @Override
public boolean hasNoResult() { public boolean hasNoResult() {
return true; return true;
} }
@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) {

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

@ -6,7 +6,6 @@ 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;
@ -21,8 +20,6 @@ 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 +44,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;
@ -257,7 +252,27 @@ public class AlphaFineDialog extends UIDialog {
* 初始化搜索面板 * 初始化搜索面板
*/ */
private void initSearchResultComponents() { private void initSearchResultComponents() {
searchResultList = new JList(); searchResultList = new JList() {
@Override
public void setSelectedIndex(int index) {
if (index > 0 && index < getModel().getSize()) {
int previousIndex = getSelectedIndex();
super.setSelectedIndex(index);
Object object = getSelectedValue();
if (object instanceof MoreModel || ((AlphaCellModel) object).hasNoResult()) {
if (previousIndex <= getSelectedIndex()) {
setSelectedIndex(index + 1);
} else {
setSelectedIndex(index - 1);
}
}
}
ensureIndexIsVisible(getSelectedIndex());
}
};
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();
@ -564,7 +579,7 @@ public class AlphaFineDialog extends UIDialog {
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) { if (e.getKeyCode() == KeyEvent.VK_ENTER) {
Object selectedValue = searchResultList.getSelectedValue(); Object selectedValue = searchResultList.getSelectedValue();
doNavigate(searchResultList.getSelectedIndex()); doNavigate();
if (searchResultList.getSelectedValue() instanceof AlphaCellModel) { if (searchResultList.getSelectedValue() instanceof AlphaCellModel) {
saveHistory((AlphaCellModel) selectedValue); saveHistory((AlphaCellModel) selectedValue);
} }
@ -594,7 +609,7 @@ public class AlphaFineDialog extends UIDialog {
int selectedIndex = searchResultList.getSelectedIndex(); int selectedIndex = searchResultList.getSelectedIndex();
Object selectedValue = searchResultList.getSelectedValue(); Object selectedValue = searchResultList.getSelectedValue();
if (e.getClickCount() == 2) { if (e.getClickCount() == 2) {
doNavigate(selectedIndex); doNavigate();
if (selectedValue instanceof AlphaCellModel) { if (selectedValue instanceof AlphaCellModel) {
saveHistory((AlphaCellModel) selectedValue); saveHistory((AlphaCellModel) selectedValue);
} }
@ -689,34 +704,12 @@ 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 Object value = searchResultList.getSelectedValue();
if (value instanceof ActionModel) { if (value instanceof AlphaCellModel) {
((ActionModel) value).getAction().actionPerformed(null); ((AlphaCellModel)(value)).doAction();
} 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());
}
} }
} }
/** /**
@ -740,30 +733,34 @@ public class AlphaFineDialog extends UIDialog {
* @param cellModel * @param cellModel
*/ */
private void sendToServer(String searchKey, AlphaCellModel cellModel) { private void sendToServer(String searchKey, AlphaCellModel cellModel) {
String username = DesignerEnvManager.getEnvManager().getBBSName(); if (cellModel.isNeedToSendToServer()) {
String uuid = DesignerEnvManager.getEnvManager().getUUID(); String username = DesignerEnvManager.getEnvManager().getBBSName();
String activitykey = DesignerEnvManager.getEnvManager().getActivationKey(); String uuid = DesignerEnvManager.getEnvManager().getUUID();
String createTime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(Calendar.getInstance().getTime()); String activityKey = DesignerEnvManager.getEnvManager().getActivationKey();
String key = searchKey; String createTime = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(Calendar.getInstance().getTime());
int resultkind = cellModel.getType().getTypeValue(); String key = searchKey;
String resultValue = CellModelHelper.getResultValueFromModel(cellModel); int resultKind = cellModel.getType().getTypeValue();
JSONObject object = JSONObject.create(); String resultValue = CellModelHelper.getResultValueFromModel(cellModel);
try { JSONObject object = JSONObject.create();
object.put("uuid", uuid).put("activitykey", activitykey).put("username", username).put("createtime", createTime).put("key", key).put("resultkind", resultkind).put("resultValue", resultValue); try {
} catch (JSONException e) { object.put("uuid", uuid).put("activityKey", activityKey).put("username", username).put("createTime", createTime).put("key", key).put("resultKind", resultKind).put("resultValue", resultValue);
FRLogger.getLogger().error(e.getMessage()); } 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()); final HashMap<String, String> para = new HashMap<>();
para.put("token", CodeUtils.md5Encode(date, "", "MD5")); String date = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
para.put("content", object.toString()); para.put("token", CodeUtils.md5Encode(date, "", "MD5"));
HttpClient httpClient = new HttpClient(AlphaFineConstants.CLOUD_TEST_URL, para, true); para.put("content", object.toString());
httpClient.setTimeout(5000); HttpClient httpClient = new HttpClient(AlphaFineConstants.CLOUD_TEST_URL, para, true);
httpClient.asGet(); httpClient.setTimeout(5000);
if (!httpClient.isServerAlive()) { httpClient.asGet();
FRLogger.getLogger().error("Failed to sent data to server!"); if (!httpClient.isServerAlive()) {
FRLogger.getLogger().error("Failed to sent data to server!");
}
} }
} }
/** /**

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

@ -25,7 +25,7 @@ import java.util.List;
*/ */
public class RecommendSearchManager implements AlphaFineSearchProcessor { public class RecommendSearchManager implements AlphaFineSearchProcessor {
//todo:for test //todo:for test
private static final String SEARCHAPI = "http://localhost:8080/monitor/alphafine/search/recommend?searchKey="; private static final String SEARCHAPI = "http://localhost:8080/cloud/intelligence/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 List<AlphaCellModel> recommendModelList = new ArrayList<>();
@ -59,7 +59,7 @@ 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);
} }
} }
@ -86,6 +86,10 @@ public class RecommendSearchManager implements AlphaFineSearchProcessor {
return modelList; return modelList;
} }
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));

Loading…
Cancel
Save