Browse Source

bug fix 存储的searchkey需要处理下

master
XiaXiang 8 years ago
parent
commit
2391f48ca0
  1. 4
      designer/src/com/fr/design/mainframe/alphafine/cell/model/AlphaCellModel.java
  2. 29
      designer/src/com/fr/design/mainframe/alphafine/cell/model/MoreModel.java
  3. 7
      designer/src/com/fr/design/mainframe/alphafine/cell/render/ContentCellRender.java
  4. 238
      designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java

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

@ -28,6 +28,10 @@ public abstract class AlphaCellModel implements Comparable {
}
public AlphaCellModel() {
}
public CellType getType() {
return type;
}

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

@ -1,11 +1,13 @@
package com.fr.design.mainframe.alphafine.cell.model;
import com.fr.design.mainframe.alphafine.CellType;
import com.fr.json.JSONException;
import com.fr.json.JSONObject;
/**
* Created by XiaXiang on 2017/4/20.
*/
public class MoreModel {
public class MoreModel extends AlphaCellModel {
private String name;
private boolean needMore;
private String content;
@ -59,6 +61,21 @@ public class MoreModel {
this.content = content;
}
@Override
public JSONObject ModelToJson() throws JSONException {
return null;
}
@Override
public String getStoreInformation() {
return null;
}
@Override
public void doAction() {
}
public CellType getType() {
return type;
}
@ -74,4 +91,14 @@ public class MoreModel {
public void setLoading(boolean loading) {
isLoading = loading;
}
@Override
public boolean hasNoResult() {
return true;
}
@Override
public boolean isNeedToSendToServer() {
return false;
}
}

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

@ -14,8 +14,7 @@ import java.awt.*;
* Created by XiaXiang on 2017/4/20.
*/
public class ContentCellRender implements ListCellRenderer<Object> {
private static final int OFFSET = 30;
private static final int LABEL_OFFSET = 45;
private static final int OFFSET = 45;
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
@ -48,9 +47,11 @@ public class ContentCellRender implements ListCellRenderer<Object> {
panel.add(detailLabel, BorderLayout.CENTER);
int width = (int) (titleLabel.getPreferredSize().getWidth() + detailLabel.getPreferredSize().getWidth());
if ( width > AlphaFineConstants.LEFT_WIDTH - OFFSET) {
int nameWidth = (int) (AlphaFineConstants.LEFT_WIDTH - detailLabel.getPreferredSize().getWidth() - LABEL_OFFSET);
int nameWidth = (int) (AlphaFineConstants.LEFT_WIDTH - detailLabel.getPreferredSize().getWidth() - OFFSET);
titleLabel.setPreferredSize(new Dimension(nameWidth, AlphaFineConstants.CELL_HEIGHT));
}
} else {
titleLabel.setPreferredSize(new Dimension(AlphaFineConstants.LEFT_WIDTH - OFFSET, AlphaFineConstants.CELL_HEIGHT));
}
panel.add(titleLabel, BorderLayout.WEST);

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

@ -74,10 +74,11 @@ public class AlphaFineDialog extends UIDialog {
private Point pressedPoint;
private UIScrollPane leftSearchResultPane;
private JPanel rightSearchResultPane;
private JList searchResultList;
private AlphaFineList searchResultList;
private SearchListModel searchListModel;
private SwingWorker searchWorker;
private SwingWorker showWorker;
private String storeText;
//是否强制打开,因为面板是否关闭绑定了全局鼠标事件,这里需要处理一下
private boolean forceOpen;
@ -113,6 +114,9 @@ public class AlphaFineDialog extends UIDialog {
};
}
/**
* 打开搜索框
*/
private static void doClickAction() {
AlphaFineHelper.showAlphaFineDialog(false);
}
@ -243,7 +247,7 @@ public class AlphaFineDialog extends UIDialog {
private void showSearchResult() {
if (searchResultPane == null) {
initSearchResultComponents();
initListListener();
initTextFieldKeyListener();
}
initSearchWorker();
}
@ -252,27 +256,8 @@ public class AlphaFineDialog extends UIDialog {
* 初始化搜索面板
*/
private void initSearchResultComponents() {
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);
searchResultList = new AlphaFineList();
//searchResultList.setFixedCellHeight(AlphaFineConstants.CELL_HEIGHT);
searchListModel = new SearchListModel(new SearchResult());
searchResultList.setModel(searchListModel);
searchResultPane = new JPanel();
@ -310,9 +295,9 @@ public class AlphaFineDialog extends UIDialog {
@Override
protected void done() {
if (!isCancelled() && searchListModel.getSize() > 1) {
searchResultList.setSelectedIndex(1);
showResult(searchResultList.getSelectedIndex(), searchResultList.getSelectedValue());
if (!isCancelled()) {
searchResultList.setSelectedIndex(0);
showResult(searchResultList.getSelectedValue());
}
}
};
@ -326,23 +311,32 @@ public class AlphaFineDialog extends UIDialog {
* @param searchText
*/
private void rebuildList(String searchText) {
searchResultList.resetSelectedIndex();
searchListModel.removeAllElements();
searchResultList.resetSelectedIndex();
if (searchText.startsWith(ADVANCED_SEARCH_MARK)) {
if (searchText.startsWith(ACTION_MARK_SHORT) || searchText.startsWith(ACTION_MARK)) {
getActionList(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length()));
storeText = searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length());
getActionList(storeText);
} else if (searchText.startsWith(DOCUMENT_MARK_SHORT) || searchText.startsWith(DOCUMENT_MARK)) {
getDocumentList(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length()));
storeText = searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length());
getDocumentList(storeText);
} else if (searchText.startsWith(FILE_MARK_SHORT) || searchText.startsWith(FILE_MARK)) {
getFileList(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length()));
storeText = searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length());
getFileList(storeText);
} else if (searchText.startsWith(CPT_MARK) || searchText.startsWith(FRM_MARK)) {
storeText = searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length());
getFileList(searchText);
} else if (searchText.startsWith(DS_MARK)) {
getFileList(DS_NAME + searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length()));
storeText = searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length());
getFileList(DS_NAME + storeText);
} else if (searchText.startsWith(PLUGIN_MARK_SHORT) || searchText.startsWith(PLUGIN_MARK)) {
getPluginList(searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length()));
storeText = searchText.substring(searchText.indexOf(StringUtils.BLANK) + 1, searchText.length());
getPluginList(storeText);
}
} else {
doNormalSearch(searchText.trim());
storeText = searchText.trim();
doNormalSearch(storeText);
}
}
@ -410,7 +404,7 @@ public class AlphaFineDialog extends UIDialog {
}
private void showResult(int index, final Object selectedValue) {
private void showResult(final AlphaCellModel selectedValue) {
if (selectedValue instanceof FileModel) {
final String fileName = ((FileModel) selectedValue).getFilePath().substring(ProjectConstants.REPORTLETS_NAME.length() + 1);
showDefaultPreviewPane();
@ -562,30 +556,7 @@ public class AlphaFineDialog extends UIDialog {
initMouseListener();
}
/**
* 为面板中各组件添加监听器
*/
private void initListListener() {
initListMouseListener();
initListKeyListener();
}
private void initListKeyListener() {
/**
* 为list添加键盘监听器
*/
searchResultList.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
Object selectedValue = searchResultList.getSelectedValue();
doNavigate();
if (searchResultList.getSelectedValue() instanceof AlphaCellModel) {
saveHistory((AlphaCellModel) selectedValue);
}
}
}
});
private void initTextFieldKeyListener() {
/**
* 为textField添加键盘监听器按上下方向键时把焦点给list,实现键盘操作
*/
@ -599,40 +570,7 @@ public class AlphaFineDialog extends UIDialog {
});
}
private void initListMouseListener() {
/**
* 鼠标监听器
*/
searchResultList.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int selectedIndex = searchResultList.getSelectedIndex();
Object selectedValue = searchResultList.getSelectedValue();
if (e.getClickCount() == 2) {
doNavigate();
if (selectedValue instanceof AlphaCellModel) {
saveHistory((AlphaCellModel) selectedValue);
}
} else if (e.getClickCount() == 1) {
if (selectedValue instanceof MoreModel && ((MoreModel) selectedValue).isNeedMore()) {
HandleMoreOrLessResult(selectedIndex, (MoreModel) selectedValue);
}
}
}
});
/**
*单击时触发右侧面板展示搜索结果
*/
searchResultList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
showResult(searchResultList.getSelectedIndex(), searchResultList.getSelectedValue());
}
}
});
}
/**
* 窗口拖拽
@ -706,10 +644,8 @@ public class AlphaFineDialog extends UIDialog {
private void doNavigate() {
AlphaFineDialog.this.dispose();
final Object value = searchResultList.getSelectedValue();
if (value instanceof AlphaCellModel) {
((AlphaCellModel)(value)).doAction();
}
final AlphaCellModel model = searchResultList.getSelectedValue();
model.doAction();
}
/**
@ -718,11 +654,10 @@ public class AlphaFineDialog extends UIDialog {
* @param cellModel
*/
private void saveHistory(AlphaCellModel cellModel) {
String searchText = searchTextField.getText();
RecentSearchManager recentSearchManager = RecentSearchManager.getRecentSearchManger();
recentSearchManager.addRecentModel(searchText, cellModel);
recentSearchManager.addRecentModel(storeText, cellModel);
recentSearchManager.saveXMLFile();
sendToServer(searchText, cellModel);
sendToServer(storeText, cellModel);
}
@ -781,18 +716,6 @@ 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) {
@ -842,4 +765,101 @@ public class AlphaFineDialog extends UIDialog {
this.forceOpen = forceOpen;
}
public String getStoreText() {
return storeText;
}
public void setStoreText(String storeText) {
this.storeText = storeText;
}
/**
* 自定义JList
*/
private class AlphaFineList extends JList<AlphaCellModel> {
public AlphaFineList() {
initListListener();
}
/**
* 重置选项
*/
public void resetSelectedIndex() {
super.setSelectedIndex(0);
}
/**
* 重写选中的方法
* @param index
*/
@Override
public void setSelectedIndex(int index) {
if (index >= 0 && index <= getModel().getSize()) {
int previousIndex = getSelectedIndex();
super.setSelectedIndex(index);
AlphaCellModel cellModel = getSelectedValue();
if (cellModel != null && cellModel.hasNoResult()) {
if (previousIndex <= getSelectedIndex()) {
setSelectedIndex(index + 1);
} else {
setSelectedIndex(index - 1);
}
}
}
ensureIndexIsVisible(getSelectedIndex());
}
private void initListListener() {
/**
* 为list添加键盘监听器
*/
addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
doNavigate();
saveHistory(getSelectedValue());
}
}
});
/**
* 为list添加鼠标监听器
*/
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int selectedIndex = getSelectedIndex();
AlphaCellModel selectedValue = getSelectedValue();
if (e.getClickCount() == 2) {
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()) {
showResult(getSelectedValue());
}
}
});
}
}
}
Loading…
Cancel
Save