cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r728657 - in /cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler: action/FindAction.java dialog/FindDialog.java dialog/FindDialogView.java
Date Mon, 22 Dec 2008 12:06:46 GMT
Author: aadamchik
Date: Mon Dec 22 04:06:46 2008
New Revision: 728657

URL: http://svn.apache.org/viewvc?rev=728657&view=rev
Log:
CAY-1156 Modeler search improvement

Modified:
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/FindAction.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialog.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialogView.java

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/FindAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/FindAction.java?rev=728657&r1=728656&r2=728657&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/FindAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/FindAction.java
Mon Dec 22 04:06:46 2008
@@ -24,16 +24,32 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import javax.swing.JButton;
 import javax.swing.JTextField;
+import javax.swing.tree.TreePath;
 
+import org.apache.cayenne.access.DataDomain;
 import org.apache.cayenne.map.Attribute;
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.DbRelationship;
 import org.apache.cayenne.map.Entity;
+import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.map.ObjRelationship;
 import org.apache.cayenne.map.Relationship;
 import org.apache.cayenne.modeler.Application;
+import org.apache.cayenne.modeler.CayenneModelerFrame;
+import org.apache.cayenne.modeler.ProjectTreeModel;
 import org.apache.cayenne.modeler.dialog.FindDialog;
+import org.apache.cayenne.modeler.dialog.FindDialogView;
+import org.apache.cayenne.modeler.editor.EditorView;
+import org.apache.cayenne.modeler.event.AttributeDisplayEvent;
+import org.apache.cayenne.modeler.event.EntityDisplayEvent;
+import org.apache.cayenne.modeler.event.RelationshipDisplayEvent;
 import org.apache.cayenne.modeler.util.CayenneAction;
+import org.apache.cayenne.modeler.util.CayenneController;
 import org.apache.cayenne.project.ProjectPath;
 
 public class FindAction extends CayenneAction {
@@ -61,7 +77,7 @@
             Iterator it = getProjectController().getProject().treeNodes();
             while(it.hasNext()) {
                 ProjectPath path = (ProjectPath) it.next();
-
+                
                 Object o = path.getObject();
                 if ((o instanceof ObjEntity || o instanceof DbEntity) && matchFound(((Entity)
o).getName(), pattern))
                     paths.add(path.getPath());
@@ -71,10 +87,19 @@
                     paths.add(path.getPath());
             }
         }
-
-        source.setText("");
-
-        new FindDialog(getApplication().getFrameController(), paths).startupAction();
+     
+        if(paths.size()!=1){
+            new FindDialog(getApplication().getFrameController(), paths).startupAction();
+        } else {
+            
+            Iterator it = paths.iterator();
+            int index = 0;
+            if (it.hasNext()) {
+                Object[] path = (Object[]) it.next();
+                EditorView editor =  ((CayenneModelerFrame) getApplication().getFrameController().getView()).getView();
+                FindDialog.jumpToResult(path, editor);
+            }   
+        }
     }
 
     private boolean matchFound(String entityName, Pattern pattern) {
@@ -82,4 +107,5 @@
 
         return m.find();
     }
+
 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialog.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialog.java?rev=728657&r1=728656&r2=728657&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialog.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialog.java
Mon Dec 22 04:06:46 2008
@@ -18,14 +18,20 @@
  ****************************************************************/
 package org.apache.cayenne.modeler.dialog;
 
+import java.awt.Color;
 import java.awt.Component;
+import java.awt.Font;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.awt.image.ColorModel;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import javax.swing.BorderFactory;
 import javax.swing.JButton;
 import javax.swing.JDialog;
 import javax.swing.tree.TreePath;
@@ -50,12 +56,17 @@
 import org.apache.cayenne.modeler.util.CayenneController;
 
 /**
- * An instance of this class is responsible for displaying search results
- * and navigating to the selected entity's representation.
+ * An instance of this class is responsible for displaying search results and navigating
+ * to the selected entity's representation.
  */
 public class FindDialog extends CayenneController {
+
     private FindDialogView view;
     private List paths;
+    private Integer selectedButton;
+    private Map EntityButtonsIdListAndButtonId;
+    private Font font;
+    private Font fontSelected;
 
     public FindDialog(CayenneController parent, java.util.List paths) {
         super(parent);
@@ -83,11 +94,9 @@
             if (path[path.length - 1] instanceof Relationship) {
                 relatNames.put(new Integer(index++), ((Relationship) path[path.length - 1]).getName());
             }
-
         }
 
         view = new FindDialogView(objEntityNames, dbEntityNames, attrNames, relatNames);
-
         initBindings();
     }
 
@@ -108,121 +117,186 @@
 
     protected void initBindings() {
         view.getOkButton().addActionListener(new ActionListener() {
+
             public void actionPerformed(ActionEvent e) {
                 view.dispose();
             }
         });
 
+        font = view.getOkButton().getFont();
+        fontSelected = new Font(font.getFamily(), font.BOLD, font.getSize() + 2);
+
+        Color color = view.getOkButton().getBackground();        
+        EntityButtonsIdListAndButtonId = new HashMap<Integer, Integer>();
+        Integer idEntityButtons = 0;
         Iterator it = view.getEntityButtons().iterator();
         while (it.hasNext()) {
             JButton b = (JButton) it.next();
             b.addActionListener(new JumpToResultActionListener());
+            b.addKeyListener(new JumpToResultsKeyListener());  
+            EntityButtonsIdListAndButtonId.put(((FindDialogView.EntityButtonModel) b.getModel()).getIndex().intValue(),
idEntityButtons);
+            idEntityButtons++;
+        }
+        
+        if (view.getEntityButtons().size() > 0) {
+            selectedButton = 0;
+            ((JButton) view.getEntityButtons().get(selectedButton)).setFont(fontSelected);
+            
         }
     }
 
-    private class JumpToResultActionListener implements ActionListener {
-        private EditorView editor = ((CayenneModelerFrame) application.getFrameController().getView()).getView();
+    public static void jumpToResult(Object[] path, EditorView editor) {
+        
+        if (path[path.length - 1] instanceof Entity) {
+
+            /** Make selection in a project tree, open correspondent entity tab */
+            editor.getProjectTreeView().getSelectionModel().setSelectionPath(
+                    buildTreePath(path, editor));
+            EntityDisplayEvent event = new EntityDisplayEvent(
+                    editor.getProjectTreeView(),
+                    (Entity) path[path.length - 1],
+                    (DataMap) path[path.length - 2],
+                    (DataDomain) path[path.length - 3]);
+            event.setMainTabFocus(true);
+
+            if (path[path.length - 1] instanceof ObjEntity)
+                editor.getObjDetailView().currentObjEntityChanged(event);
+            if (path[path.length - 1] instanceof DbEntity)
+                editor.getDbDetailView().currentDbEntityChanged(event);
+        }
 
-        public void actionPerformed(ActionEvent e) {
-            JButton source = (JButton) e.getSource();
+        if (path[path.length - 1] instanceof Attribute
+                || path[path.length - 1] instanceof Relationship) {
 
-            Object[] path = (Object[]) paths.get(((FindDialogView.EntityButtonModel) source.getModel()).getIndex().intValue());
+            /** Make selection in a project tree, open correspondent attributes tab */
+            Object[] o = new Object[path.length - 1];
+            for (int i = 0; i < path.length - 1; i++)
+                o[i] = path[i];
+            editor.getProjectTreeView().getSelectionModel().setSelectionPath(
+                    buildTreePath(o, editor));
 
-            if(path[path.length - 1] instanceof Entity) {
+            if (path[path.length - 1] instanceof DbAttribute) {
+                AttributeDisplayEvent event = new AttributeDisplayEvent(
+                        editor.getProjectTreeView(),
+                        (Attribute) path[path.length - 1],
+                        (Entity) path[path.length - 2],
+                        (DataMap) path[path.length - 3],
+                        (DataDomain) path[path.length - 4]);
+                event.setMainTabFocus(true);
+                editor.getDbDetailView().currentDbAttributeChanged(event);
+            }
 
-                /** Make selection in a project tree, open correspondent entity tab */
-                editor.getProjectTreeView().getSelectionModel().setSelectionPath(buildTreePath(path));
-                EntityDisplayEvent event = new EntityDisplayEvent(
+            if (path[path.length - 1] instanceof ObjAttribute) {
+                AttributeDisplayEvent event = new AttributeDisplayEvent(
                         editor.getProjectTreeView(),
-                        (Entity) path[path.length - 1],
-                        (DataMap) path[path.length - 2],
-                        (DataDomain) path[path.length - 3]);
+                        (Attribute) path[path.length - 1],
+                        (Entity) path[path.length - 2],
+                        (DataMap) path[path.length - 3],
+                        (DataDomain) path[path.length - 4]);
                 event.setMainTabFocus(true);
+                editor.getObjDetailView().currentObjAttributeChanged(event);
+            }
 
-                if (path[path.length - 1] instanceof ObjEntity)
-                    editor.getObjDetailView().currentObjEntityChanged(event);
-                if (path[path.length - 1] instanceof DbEntity)
-                    editor.getDbDetailView().currentDbEntityChanged(event);
-            }
-
-            if(path[path.length - 1] instanceof Attribute || path[path.length - 1] instanceof
Relationship) {
-
-                /** Make selection in a project tree, open correspondent attributes tab */
-                Object[] o = new Object[path.length - 1];
-                for(int i = 0; i < path.length - 1; i++)
-                    o[i] = path[i];
-                editor.getProjectTreeView().getSelectionModel().setSelectionPath(buildTreePath(o));
-
-
-                if (path[path.length - 1] instanceof DbAttribute) {
-                    AttributeDisplayEvent event = new AttributeDisplayEvent(
-                            editor.getProjectTreeView(),
-                            (Attribute) path[path.length - 1],
-                            (Entity) path[path.length - 2],
-                            (DataMap) path[path.length - 3],
-                            (DataDomain) path[path.length - 4]);
-                    event.setMainTabFocus(true);
-                    editor.getDbDetailView().currentDbAttributeChanged(event);
-                }
+            if (path[path.length - 1] instanceof DbRelationship) {
+                RelationshipDisplayEvent event = new RelationshipDisplayEvent(
+                        editor.getProjectTreeView(),
+                        (Relationship) path[path.length - 1],
+                        (Entity) path[path.length - 2],
+                        (DataMap) path[path.length - 3],
+                        (DataDomain) path[path.length - 4]);
+                event.setMainTabFocus(true);
+                editor.getDbDetailView().currentDbRelationshipChanged(event);
+            }
+        }
 
-                if (path[path.length - 1] instanceof ObjAttribute) {
-                    AttributeDisplayEvent event = new AttributeDisplayEvent(
-                            editor.getProjectTreeView(),
-                            (Attribute) path[path.length - 1],
-                            (Entity) path[path.length - 2],
-                            (DataMap) path[path.length - 3],
-                            (DataDomain) path[path.length - 4]);
-                    event.setMainTabFocus(true);
-                    editor.getObjDetailView().currentObjAttributeChanged(event);
-                }
+        if (path[path.length - 1] instanceof ObjRelationship) {
+            RelationshipDisplayEvent event = new RelationshipDisplayEvent(
+                    editor.getProjectTreeView(),
+                    (Relationship) path[path.length - 1],
+                    (Entity) path[path.length - 2],
+                    (DataMap) path[path.length - 3],
+                    (DataDomain) path[path.length - 4]);
+            event.setMainTabFocus(true);
+            editor.getObjDetailView().currentObjRelationshipChanged(event);
+        }
+    }
+
+    private class JumpToResultsKeyListener implements KeyListener {
 
-                if (path[path.length - 1] instanceof DbRelationship) {
-                    RelationshipDisplayEvent event = new RelationshipDisplayEvent(
-                            editor.getProjectTreeView(),
-                            (Relationship) path[path.length - 1],
-                            (Entity) path[path.length - 2],
-                            (DataMap) path[path.length - 3],
-                            (DataDomain) path[path.length - 4]
-                    );
-                    event.setMainTabFocus(true);
-                    editor.getDbDetailView().currentDbRelationshipChanged(event);
+        private EditorView editor = ((CayenneModelerFrame) application
+                .getFrameController().getView()).getView();
+        
+        public void keyPressed(KeyEvent e) { 
+            
+            if (e.getKeyCode() == KeyEvent.VK_UP) {
+                if (view.getEntityButtons().size() > 0 && selectedButton - 1 >=
0) {
+                    setSelectedButton(selectedButton-1);
+                  }
+            }
+            if (e.getKeyCode() == KeyEvent.VK_DOWN) {
+                    if (view.getEntityButtons().size() > 0 && selectedButton +
2 <= view.getEntityButtons().size()) {
+                    setSelectedButton(selectedButton+1);
                 }
             }
+            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
+                JButton source = (JButton) view.getEntityButtons().get(selectedButton);
+                
+                setSelectedButton((Integer) EntityButtonsIdListAndButtonId.get(((FindDialogView.EntityButtonModel)
source.getModel()).getIndex().intValue()));
+                Object[] path = (Object[]) paths.get(((FindDialogView.EntityButtonModel)
source.getModel()).getIndex().intValue());
 
-                if (path[path.length - 1] instanceof ObjRelationship) {
-                    RelationshipDisplayEvent event = new RelationshipDisplayEvent(
-                            editor.getProjectTreeView(),
-                            (Relationship) path[path.length - 1],
-                            (Entity) path[path.length - 2],
-                            (DataMap) path[path.length - 3],
-                            (DataDomain) path[path.length - 4]
-                    );
-                    event.setMainTabFocus(true);
-                    editor.getObjDetailView().currentObjRelationshipChanged(event);
-                }
+                jumpToResult(path, editor);
+            }
         }
 
-        /**
-         * Builds a tree path for a given path. Urgent for later selection.
-         * @param path
-         * @return tree path
-         */
-        private TreePath buildTreePath(Object[] path) {
-            Object[] mutableTreeNodes = new Object[path.length];
-            mutableTreeNodes[0] = ((ProjectTreeModel) editor.getProjectTreeView().getModel()).getRootNode();
-
-            Object[] helper;
-            for(int i = 1; i < path.length; i++) {
-                helper = new Object[i];
-                for(int j = 0; j < i;) {
-                    helper[j] = path[++j];
-                }
-                mutableTreeNodes[i] = ((ProjectTreeModel) editor.getProjectTreeView().getModel()).getNodeForObjectPath(helper);
-            }
+        public void keyReleased(KeyEvent e) {
+        }
 
-            return new TreePath(mutableTreeNodes);
+        public void keyTyped(KeyEvent e) {
         }
 
     }
 
+    private class JumpToResultActionListener implements ActionListener {
+
+        private EditorView editor = ((CayenneModelerFrame) application.getFrameController().getView()).getView();
+
+        public void actionPerformed(ActionEvent e) {
+            JButton source = (JButton) e.getSource();
+            setSelectedButton((Integer) EntityButtonsIdListAndButtonId.get(((FindDialogView.EntityButtonModel)
source.getModel()).getIndex().intValue()));
+            Object[] path = (Object[]) paths.get(((FindDialogView.EntityButtonModel) source.getModel()).getIndex().intValue());
+            jumpToResult(path, editor);   
+        }
+    }
+    
+    /**
+     * Builds a tree path for a given path. Urgent for later selection.
+     * 
+     * @param path
+     * @return tree path
+     */
+    private static TreePath buildTreePath(Object[] path, EditorView editor) {
+        Object[] mutableTreeNodes = new Object[path.length];
+        mutableTreeNodes[0] = ((ProjectTreeModel) editor
+                .getProjectTreeView()
+                .getModel()).getRootNode();
+
+        Object[] helper;
+        for (int i = 1; i < path.length; i++) {
+            helper = new Object[i];
+            for (int j = 0; j < i;) {
+                helper[j] = path[++j];
+            }
+            mutableTreeNodes[i] = ((ProjectTreeModel) editor
+                    .getProjectTreeView()
+                    .getModel()).getNodeForObjectPath(helper);
+        }
+        return new TreePath(mutableTreeNodes);
+    }
+    
+    private void setSelectedButton(Integer newSelectedButton) {
+        ((JButton) view.getEntityButtons().get(selectedButton)).setFont(font);
+        selectedButton = newSelectedButton;
+        ((JButton) view.getEntityButtons().get(selectedButton)).setFont(fontSelected);
+    }    
+
 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialogView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialogView.java?rev=728657&r1=728656&r2=728657&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialogView.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialogView.java
Mon Dec 22 04:06:46 2008
@@ -19,9 +19,11 @@
 package org.apache.cayenne.modeler.dialog;
 
 import java.awt.BorderLayout;
+import java.awt.Component;
 import java.awt.Dimension;
 import java.awt.FlowLayout;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 
@@ -46,38 +48,48 @@
  * Swing component displaying results produced by search feature.
  */
 public class FindDialogView extends JDialog {
+
     private JButton okButton;
     private java.util.List entityButtons;
 
-    public FindDialogView(Map objEntityNames, Map dbEntityNames, Map attrNames, Map relatNames)
{
+    public FindDialogView(Map objEntityNames, Map dbEntityNames, Map attrNames,
+            Map relatNames) {
         entityButtons = new ArrayList();
 
         JPanel panel = new JPanel();
         panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
-        if (objEntityNames.isEmpty() && dbEntityNames.isEmpty() && attrNames.isEmpty()
&& relatNames.isEmpty()) {
+
+        if (objEntityNames.isEmpty()
+                && dbEntityNames.isEmpty()
+                && attrNames.isEmpty()
+                && relatNames.isEmpty()) {
             panel.add(new JLabel("Nothing found!"));
         } else {
-            panel.add(createResultPanel(
-                    objEntityNames, CellRenderers.iconForObject(new ObjEntity())));
-            panel.add(createResultPanel(
-                    dbEntityNames, CellRenderers.iconForObject(new DbEntity())));
-            panel.add(createResultPanel(
-                    attrNames, CellRenderers.iconForObject(new ObjAttribute())));
-            panel.add(createResultPanel(
-                    relatNames, CellRenderers.iconForObject(new ObjRelationship())));
+            panel.add(createResultPanel(objEntityNames, CellRenderers
+                    .iconForObject(new ObjEntity())));
+            panel.add(createResultPanel(dbEntityNames, CellRenderers
+                    .iconForObject(new DbEntity())));
+            panel.add(createResultPanel(attrNames, CellRenderers
+                    .iconForObject(new ObjAttribute())));
+            panel.add(createResultPanel(relatNames, CellRenderers
+                    .iconForObject(new ObjRelationship())));
         }
 
-        JPanel okPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
-        okButton = new JButton("OK");
-        okPanel.add(okButton);
-
-        JComponent contentPane = (JComponent) getContentPane();
-        contentPane.setLayout(new BorderLayout());
-        contentPane.add(new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
-        contentPane.add(okPanel, BorderLayout.SOUTH);
+            JPanel okPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
+            okButton = new JButton("OK");
+            okPanel.add(okButton);  
+            
+            JComponent contentPane = (JComponent) getContentPane();
+            
+            contentPane.setLayout(new BorderLayout());
+            contentPane.add(new JScrollPane(
+                    panel,
+                    JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
+                    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
+            contentPane.add(okPanel, BorderLayout.SOUTH);
 
-        contentPane.setPreferredSize(new Dimension(400, 325));
-        setTitle("Search results");
+            contentPane.setPreferredSize(new Dimension(400, 325));            
+            setTitle("Search results"); 
     }
 
     private JPanel createResultPanel(Map names, Icon icon) {
@@ -85,10 +97,10 @@
         panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
 
         Iterator it = names.keySet().iterator();
-        while(it.hasNext()) {
+        while (it.hasNext()) {
             Integer index = (Integer) it.next();
             JButton b = new JButton((String) names.get(index), icon);
-            b.setBorder(new EmptyBorder(2, 10, 2, 10));       // top, left, bottom, right
+            b.setBorder(new EmptyBorder(2, 10, 2, 10)); // top, left, bottom, right
             b.setModel(new EntityButtonModel(index));
             panel.add(b);
 
@@ -107,6 +119,7 @@
     }
 
     public class EntityButtonModel extends DefaultButtonModel {
+
         private Integer index;
 
         EntityButtonModel(Integer index) {



Mime
View raw message