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. 71
      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";
//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();
}
@Override
public void doAction() {
getAction().actionPerformed(null);
}
public String getClassName() {
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() {
return false;
}
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) {

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

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

71
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.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;
@ -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.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 +44,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;
@ -257,7 +252,27 @@ public class AlphaFineDialog extends UIDialog {
* 初始化搜索面板
*/
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());
searchResultList.setModel(searchListModel);
searchResultPane = new JPanel();
@ -564,7 +579,7 @@ public class AlphaFineDialog extends UIDialog {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
Object selectedValue = searchResultList.getSelectedValue();
doNavigate(searchResultList.getSelectedIndex());
doNavigate();
if (searchResultList.getSelectedValue() instanceof AlphaCellModel) {
saveHistory((AlphaCellModel) selectedValue);
}
@ -594,7 +609,7 @@ public class AlphaFineDialog extends UIDialog {
int selectedIndex = searchResultList.getSelectedIndex();
Object selectedValue = searchResultList.getSelectedValue();
if (e.getClickCount() == 2) {
doNavigate(selectedIndex);
doNavigate();
if (selectedValue instanceof AlphaCellModel) {
saveHistory((AlphaCellModel) selectedValue);
}
@ -689,34 +704,12 @@ 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());
}
if (value instanceof AlphaCellModel) {
((AlphaCellModel)(value)).doAction();
}
}
/**
@ -740,20 +733,21 @@ public class AlphaFineDialog extends UIDialog {
* @param cellModel
*/
private void sendToServer(String searchKey, AlphaCellModel cellModel) {
if (cellModel.isNeedToSendToServer()) {
String username = DesignerEnvManager.getEnvManager().getBBSName();
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 key = searchKey;
int resultkind = cellModel.getType().getTypeValue();
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);
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<>();
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());
@ -763,6 +757,9 @@ public class AlphaFineDialog extends UIDialog {
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 {
//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 SearchResult modelList;
private List<AlphaCellModel> recommendModelList = new ArrayList<>();
@ -59,7 +59,7 @@ 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);
}
}
@ -86,6 +86,10 @@ public class RecommendSearchManager implements AlphaFineSearchProcessor {
return modelList;
}
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));

Loading…
Cancel
Save