From 5e595038843abbeadbcbe180d37535ae15eee7e7 Mon Sep 17 00:00:00 2001 From: XiaXiang Date: Sat, 23 Sep 2017 00:12:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mainframe/alphafine/AlphaFineHelper.java | 1 - .../alphafine/cell/model/ActionModel.java | 11 +-- .../alphafine/component/AlphaFineDialog.java | 76 ++++++++++--------- .../alphafine/component/AlphaFinePane.java | 3 +- .../search/manager/FileSearchManager.java | 7 +- .../search/manager/RecentSearchManager.java | 29 +++++-- .../toolbar/UpdateActionManager.java | 12 +++ 7 files changed, 87 insertions(+), 52 deletions(-) diff --git a/designer/src/com/fr/design/mainframe/alphafine/AlphaFineHelper.java b/designer/src/com/fr/design/mainframe/alphafine/AlphaFineHelper.java index 178c6d7e31..012f5e8727 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/AlphaFineHelper.java +++ b/designer/src/com/fr/design/mainframe/alphafine/AlphaFineHelper.java @@ -19,7 +19,6 @@ import java.util.List; * Created by XiaXiang on 2017/5/8. */ public class AlphaFineHelper { - public static final NoResultModel NO_RESULT_MODEL = new NoResultModel(Inter.getLocText("FR-Designer_AlphaFine_NoResult")); public static final NoResultModel NO_CONNECTION_MODEL = new NoResultModel(Inter.getLocText("FR-Designer_ConnectionFailed")); private static AlphaFineDialog alphaFineDialog; diff --git a/designer/src/com/fr/design/mainframe/alphafine/cell/model/ActionModel.java b/designer/src/com/fr/design/mainframe/alphafine/cell/model/ActionModel.java index 8e2ccd9a79..cf703d8795 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/cell/model/ActionModel.java +++ b/designer/src/com/fr/design/mainframe/alphafine/cell/model/ActionModel.java @@ -1,5 +1,6 @@ package com.fr.design.mainframe.alphafine.cell.model; +import com.fr.design.actions.UpdateAction; import com.fr.design.mainframe.alphafine.CellType; import com.fr.general.FRLogger; import com.fr.json.JSONException; @@ -11,15 +12,15 @@ import javax.swing.*; * Created by XiaXiang on 2017/4/20. */ public class ActionModel extends AlphaCellModel { - private Action action; + private UpdateAction action; - public ActionModel(String name, String description, Action action, int searchCount) { + public ActionModel(String name, String description, UpdateAction action, int searchCount) { this(name, description, action); setSearchCount(searchCount); } - public ActionModel(String name, String description, Action action) { + public ActionModel(String name, String description, UpdateAction action) { super(name, null, CellType.ACTION); this.action = action; this.setDescription(description); @@ -43,11 +44,11 @@ public class ActionModel extends AlphaCellModel { return action != null ? action.hashCode() : 0; } - public Action getAction() { + public UpdateAction getAction() { return action; } - public void setAction(Action action) { + public void setAction(UpdateAction action) { this.action = action; } diff --git a/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java b/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java index e973c6a422..e712edb478 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java +++ b/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFineDialog.java @@ -367,7 +367,6 @@ public class AlphaFineDialog extends UIDialog { * 停止加载状态 */ private void fireStopLoading() { - searchListModel.resetState(); if (searchResultPane != null) { removeLeftPane(); } @@ -665,25 +664,18 @@ public class AlphaFineDialog extends UIDialog { searchTextField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_DOWN) { - searchResultList.requestFocus(); - searchResultList.setSelectedIndex(searchResultList.getSelectedIndex() + 1); - } - } - - @Override - public void keyReleased(KeyEvent e) { - int keyCode = e.getKeyCode(); - if (keyCode == KeyEvent.VK_ESCAPE) { - if (StringUtils.isBlank(searchTextField.getText()) || ComparatorUtils.equals(searchTextField.getText(), searchTextField.getPlaceHolder())) { - AlphaFineDialog.this.setVisible(false); - } else { - searchTextField.setText(null); - removeSearchResult(); + if (e.getKeyCode() == KeyEvent.VK_ENTER) { + if (searchResultList.getModel().getSize() > 1) { + dealWithSearchResult(searchResultList.getSelectedValue()); } - } else if (e.getKeyCode() == KeyEvent.VK_ENTER) { - dealWithSearchResult(searchResultList.getSelectedValue()); - } + } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { + if (searchResultList.getSelectedIndex() == searchResultList.getModel().getSize() - 1) { + searchResultList.setSelectedIndex(0); + } + searchResultList.setSelectedIndex(searchResultList.getSelectedIndex() + 1); + } else if (e.getKeyCode() == KeyEvent.VK_UP) { + searchResultList.setSelectedIndex(searchResultList.getSelectedIndex() - 1); + } else escAlphaFine(e); } }); @@ -754,7 +746,9 @@ public class AlphaFineDialog extends UIDialog { private void doNavigate() { AlphaFineDialog.this.dispose(); final AlphaCellModel model = searchResultList.getSelectedValue(); - model.doAction(); + if (model != null) { + model.doAction(); + } } /** @@ -888,6 +882,21 @@ public class AlphaFineDialog extends UIDialog { this.splitLabel = splitLabel; } + /** + * 键盘退出AlphaFine + * + * @param e + */ + private void escAlphaFine(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { + if (StringUtils.isBlank(searchTextField.getText()) || ComparatorUtils.equals(searchTextField.getText(), searchTextField.getPlaceHolder())) { + AlphaFineDialog.this.setVisible(false); + } else { + searchTextField.setText(null); + removeSearchResult(); + } + } + } /** * +-------------------------------------+ @@ -907,7 +916,9 @@ public class AlphaFineDialog extends UIDialog { */ @Override public void setSelectedIndex(int index) { - if (index > 0 && checkSelectedIndex(index)) { + if (index == 0 && getModel().getSize() > 1) { + super.setSelectedIndex(1); + } else if (index > 0 && checkSelectedIndex(index)) { int previousIndex = getSelectedIndex(); super.setSelectedIndex(index); AlphaCellModel cellModel = getSelectedValue(); @@ -930,21 +941,6 @@ public class AlphaFineDialog extends UIDialog { } private void initListListener() { - addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_ENTER) { - dealWithSearchResult(getSelectedValue()); - } else if (e.getKeyCode() == KeyEvent.VK_UP) { - if (getSelectedIndex() == 1) { - searchTextField.requestFocus(); - } - } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { - searchTextField.requestFocus(); - } - } - }); - addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { @@ -968,6 +964,14 @@ public class AlphaFineDialog extends UIDialog { } } }); + + addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + escAlphaFine(e); + + } + }); } } diff --git a/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFinePane.java b/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFinePane.java index 8c962a0010..5d24a85c44 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFinePane.java +++ b/designer/src/com/fr/design/mainframe/alphafine/component/AlphaFinePane.java @@ -1,5 +1,6 @@ package com.fr.design.mainframe.alphafine.component; +import com.bulenkov.iconloader.IconLoader; import com.fr.design.DesignerEnvManager; import com.fr.design.actions.help.alphafine.AlphaFineContext; import com.fr.design.actions.help.alphafine.AlphaFineListener; @@ -27,7 +28,7 @@ public class AlphaFinePane extends BasicPane { Toolkit.getDefaultToolkit().addAWTEventListener(AlphaFineDialog.listener(), AWTEvent.KEY_EVENT_MASK); } UIButton refreshButton = new UIButton(); - refreshButton.setIcon(IOUtils.readIcon("/com/fr/design/mainframe/alphafine/images/smallsearch.png")); + refreshButton.setIcon(IconLoader.getIcon("/com/fr/design/mainframe/alphafine/images/smallsearch.png")); refreshButton.setToolTipText(Inter.getLocText("FR-Designer_AlphaFine")); refreshButton.set4ToolbarButton(); refreshButton.setRolloverEnabled(false); diff --git a/designer/src/com/fr/design/mainframe/alphafine/search/manager/FileSearchManager.java b/designer/src/com/fr/design/mainframe/alphafine/search/manager/FileSearchManager.java index 0c1a3b61b2..76cc8a6351 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/search/manager/FileSearchManager.java +++ b/designer/src/com/fr/design/mainframe/alphafine/search/manager/FileSearchManager.java @@ -19,7 +19,12 @@ import com.fr.stable.StableUtils; import com.fr.stable.StringUtils; import com.fr.stable.project.ProjectConstants; -import java.io.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; diff --git a/designer/src/com/fr/design/mainframe/alphafine/search/manager/RecentSearchManager.java b/designer/src/com/fr/design/mainframe/alphafine/search/manager/RecentSearchManager.java index 69959830c5..c191c0c11e 100644 --- a/designer/src/com/fr/design/mainframe/alphafine/search/manager/RecentSearchManager.java +++ b/designer/src/com/fr/design/mainframe/alphafine/search/manager/RecentSearchManager.java @@ -10,6 +10,7 @@ import com.fr.design.mainframe.alphafine.cell.model.ActionModel; import com.fr.design.mainframe.alphafine.cell.model.AlphaCellModel; import com.fr.design.mainframe.alphafine.cell.model.MoreModel; import com.fr.design.mainframe.alphafine.model.SearchResult; +import com.fr.design.mainframe.toolbar.UpdateActionManager; import com.fr.file.XMLFileManager; import com.fr.general.ComparatorUtils; import com.fr.general.FRLogger; @@ -26,8 +27,17 @@ import com.fr.stable.xml.XMLReadable; import com.fr.stable.xml.XMLTools; import com.fr.stable.xml.XMLableReader; -import java.io.*; -import java.util.*; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.io.StringReader; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; /** * Created by XiaXiang on 2017/5/15. @@ -220,21 +230,24 @@ public class RecentSearchManager extends XMLFileManager implements AlphaFineSear recentModelList = recentKVModelMap.get(searchText); SearchResult resultModelList = recentModelList; Iterator modelIterator = resultModelList.iterator(); + SearchResult searchResult = new SearchResult(); while (modelIterator.hasNext()) { AlphaCellModel model = modelIterator.next(); - if (model.getType() == CellType.ACTION && !((ActionModel) model).getAction().isEnabled()) { - modelIterator.remove(); + if (model.getType() == CellType.ACTION && !UpdateActionManager.getUpdateActionManager().isEnable(((ActionModel) model).getAction())) { + continue; + } else { + searchResult.add(model); } } - Collections.sort(resultModelList); - int size = resultModelList.size(); + Collections.sort(searchResult); + int size = searchResult.size(); if (size > MAX_SIZE) { SearchResult result = new SearchResult(); - result.addAll(resultModelList.subList(0, MAX_SIZE)); + result.addAll(searchResult.subList(0, MAX_SIZE)); return result; } - return resultModelList; + return searchResult; } } return recentModelList; diff --git a/designer_base/src/com/fr/design/mainframe/toolbar/UpdateActionManager.java b/designer_base/src/com/fr/design/mainframe/toolbar/UpdateActionManager.java index 47ae6101fa..845eb3660e 100644 --- a/designer_base/src/com/fr/design/mainframe/toolbar/UpdateActionManager.java +++ b/designer_base/src/com/fr/design/mainframe/toolbar/UpdateActionManager.java @@ -1,5 +1,8 @@ package com.fr.design.mainframe.toolbar; +import com.fr.design.actions.UpdateAction; +import com.fr.general.ComparatorUtils; + import java.util.List; /** @@ -23,4 +26,13 @@ public class UpdateActionManager { public void setUpdateActions(List updateActions) { this.updateActions = updateActions; } + + public boolean isEnable(UpdateAction updateAction) { + for (UpdateActionModel action : updateActions) { + if (ComparatorUtils.equals(updateAction.getName(), action.getActionName()) && action.getAction().isEnabled()) { + return true; + } + } + return false; + } }