cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r582744 - in /cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler: CayenneModelerFrame.java action/FindAction.java dialog/FindDialog.java dialog/FindDialogView.java util/CayenneAction.java
Date Mon, 08 Oct 2007 08:29:05 GMT
Author: aadamchik
Date: Mon Oct  8 01:29:00 2007
New Revision: 582744

URL: http://svn.apache.org/viewvc?rev=582744&view=rev
Log:
CAY-869 CayenneModeler free-text search
the third patch:

1. the label has been renamed from "Find entity" to "Search" as we are searching for things
other than entities as well, the text field has been made fixed size centered to the right;
2. the hot key (Ctrl+F) is reimplemented platform-independent way;
3. both vertical and horizontal scrollers for results window have been added;
4. the results window is never closed when any result is selected, furthermore it has been
made non-modal so it is possible to edit a result viewed.

Modified:
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CayenneModelerFrame.java
    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
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneAction.java

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CayenneModelerFrame.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CayenneModelerFrame.java?rev=582744&r1=582743&r2=582744&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CayenneModelerFrame.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CayenneModelerFrame.java
Mon Oct  8 01:29:00 2007
@@ -20,19 +20,11 @@
 
 package org.apache.cayenne.modeler;
 
-import java.awt.BorderLayout;
-import java.awt.Component;
-import java.awt.FlowLayout;
-import java.awt.Font;
+import java.awt.*;
 import java.awt.event.KeyEvent;
+import java.awt.event.AWTEventListener;
 
-import javax.swing.Box;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JMenu;
-import javax.swing.JMenuBar;
-import javax.swing.JPanel;
-import javax.swing.JToolBar;
+import javax.swing.*;
 
 import org.apache.cayenne.map.DerivedDbEntity;
 import org.apache.cayenne.modeler.action.AboutAction;
@@ -195,6 +187,7 @@
     /** Initializes main toolbar. */
     protected void initToolbar() {
         JToolBar toolBar = new JToolBar();
+
         toolBar.add(getAction(NewProjectAction.getActionName()).buildButton());
         toolBar.add(getAction(OpenProjectAction.getActionName()).buildButton());
         toolBar.add(getAction(SaveAction.getActionName()).buildButton());
@@ -224,11 +217,23 @@
 
         toolBar.addSeparator();
 
-        Component c = getAction(FindAction.getActionName()).buildTextField();
-        JLabel findLabel = new JLabel("Find entity:");
-        findLabel.setLabelFor(c);
-        toolBar.add(findLabel);
-        toolBar.add(c);
+        JPanel east = new JPanel();
+        final JTextField findField = new JTextField(10);
+        findField.setAction(getAction(FindAction.getActionName()));
+        JLabel findLabel = new JLabel("Search:");
+        findLabel.setLabelFor(findField);
+        east.add(findLabel);
+        east.add(findField);
+        toolBar.add(east, BorderLayout.EAST);
+        Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
+            public void eventDispatched(AWTEvent event) {
+                if (event instanceof KeyEvent) {
+                    if (((KeyEvent) event).getModifiers() == Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()
+                            && ((KeyEvent) event).getKeyCode() == KeyEvent.VK_F)
+                                findField.requestFocus();
+                }
+            }
+        }, AWTEvent.KEY_EVENT_MASK);
 
         getContentPane().add(toolBar, BorderLayout.NORTH);
     }

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=582744&r1=582743&r2=582744&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 Oct  8 01:29:00 2007
@@ -18,20 +18,23 @@
  ****************************************************************/
 package org.apache.cayenne.modeler.action;
 
-import org.apache.cayenne.modeler.util.CayenneAction;
-import org.apache.cayenne.modeler.Application;
-import org.apache.cayenne.modeler.dialog.FindDialog;
-import org.apache.cayenne.project.ProjectPath;
-import org.apache.cayenne.map.*;
-
-import javax.swing.*;
 import java.awt.event.ActionEvent;
-import java.awt.event.KeyEvent;
-import java.awt.*;
-import java.util.Iterator;
 import java.util.ArrayList;
-import java.util.regex.Pattern;
+import java.util.Iterator;
 import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.swing.JTextField;
+
+import org.apache.cayenne.map.Attribute;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.Entity;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.map.Relationship;
+import org.apache.cayenne.modeler.Application;
+import org.apache.cayenne.modeler.dialog.FindDialog;
+import org.apache.cayenne.modeler.util.CayenneAction;
+import org.apache.cayenne.project.ProjectPath;
 
 public class FindAction extends CayenneAction {
     private java.util.List paths;
@@ -51,23 +54,22 @@
     public void performAction(ActionEvent e) {
         JTextField source = (JTextField) e.getSource();
 
-        Pattern pattern = null;
-        if (!source.getText().trim().equals(""))
-            pattern = Pattern.compile(source.getText().trim(), Pattern.CASE_INSENSITIVE);
-
         paths = new ArrayList();
+        if (!source.getText().trim().equals("")) {
+            Pattern pattern = Pattern.compile(source.getText().trim(), Pattern.CASE_INSENSITIVE);
 
-        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());
-            else if (o instanceof Attribute && matchFound(((Attribute) o).getName(),
pattern))
-                paths.add(path.getPath());
-            else if (o instanceof Relationship && matchFound(((Relationship) o).getName(),
pattern))
-                paths.add(path.getPath());
+            Iterator it = getProjectController().getProject().treeNodes();
+            while(it.hasNext()) {
+                ProjectPath path = (ProjectPath) it.next();
+
+                Object o = path.getObject();
+                if (o instanceof Entity && matchFound(((Entity) o).getName(), pattern))
+                    paths.add(path.getPath());
+                else if (o instanceof Attribute && matchFound(((Attribute) o).getName(),
pattern))
+                    paths.add(path.getPath());
+                else if (o instanceof Relationship && matchFound(((Relationship)
o).getName(), pattern))
+                    paths.add(path.getPath());
+            }
         }
 
         source.setText("");

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=582744&r1=582743&r2=582744&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 Oct  8 01:29:00 2007
@@ -37,7 +37,7 @@
 
 /**
  * An instance of this class is responsible for displaying search results
- * and navigating to the selected entity's representation. 
+ * and navigating to the selected entity's representation.
  */
 public class FindDialog extends CayenneController {
     private FindDialogView view;
@@ -84,7 +84,7 @@
         makeCloseableOnEscape();
 
         view.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
-        view.setModal(true);
+        view.setModal(false);
         view.setVisible(true);
     }
 
@@ -114,7 +114,6 @@
             Object[] path = (Object[]) paths.get(((FindDialogView.EntityButtonModel) ((JButton)
e.getSource()).getModel()).getIndex().intValue());
 
 
-//            DbEntityTabbedView dbEntityTabbedView = editor.getDbDetailView();
             if(path[path.length - 1] instanceof ObjEntity || path[path.length - 1] instanceof
DbEntity)
                 /**
                  * Make selection in a project tree, open correspondent entity tab.
@@ -175,8 +174,6 @@
                     );
                     ((CayenneModelerController) parent).getProjectController().fireObjRelationshipDisplayEvent(event);
                 }
-
-            view.dispose();
         }
 
         /**

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=582744&r1=582743&r2=582744&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 Oct  8 01:29:00 2007
@@ -19,6 +19,7 @@
 package org.apache.cayenne.modeler.dialog;
 
 import java.awt.BorderLayout;
+import java.awt.Dimension;
 import java.awt.FlowLayout;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -28,9 +29,11 @@
 import javax.swing.DefaultButtonModel;
 import javax.swing.Icon;
 import javax.swing.JButton;
+import javax.swing.JComponent;
 import javax.swing.JDialog;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
+import javax.swing.JScrollPane;
 import javax.swing.border.EmptyBorder;
 
 import org.apache.cayenne.map.DbEntity;
@@ -42,7 +45,6 @@
 /**
  * Swing component displaying results produced by search feature.
  */
-// TODO: render the output, add scroll pane
 public class FindDialogView extends JDialog {
     private JButton okButton;
     private java.util.List entityButtons;
@@ -69,10 +71,12 @@
         okButton = new JButton("OK");
         okPanel.add(okButton);
 
-        getContentPane().setLayout(new BorderLayout());
-        getContentPane().add(panel, BorderLayout.CENTER);
-        getContentPane().add(okPanel, BorderLayout.SOUTH);
+        JComponent container = (JComponent) getContentPane();
+        container.setLayout(new BorderLayout());
+        container.add(new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
+        container.add(okPanel, BorderLayout.SOUTH);
 
+        container.setPreferredSize(new Dimension(400, 325));
         setTitle("Found entities");
     }
 

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneAction.java?rev=582744&r1=582743&r2=582744&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneAction.java
Mon Oct  8 01:29:00 2007
@@ -180,16 +180,6 @@
     }
 
     /**
-     * Factory method that creates a text field hooked up to this action
-     */
-    public JTextField buildTextField() {
-        CayenneTextField ctf = new CayenneTextField(this);
-        Toolkit.getDefaultToolkit().addAWTEventListener(ctf, AWTEvent.KEY_EVENT_MASK);
-
-        return ctf;
-    }
-
-    /**
      * Returns true if this action is always enabled.
      * 
      * @return boolean
@@ -219,25 +209,6 @@
             super.setEnabled(b);
         }
     }
-
-    /**
-     * A text field that gains focus when some predefined combonation if keys is pressed.
-     */
-    final class CayenneTextField extends JTextField implements AWTEventListener {
-
-        public CayenneTextField(Action a) {
-            super();
-            setAction(a);
-        }
-
-        public void eventDispatched(AWTEvent event) {
-            if (event instanceof KeyEvent) {
-                if (((KeyEvent) event).isControlDown() && ((KeyEvent) event).getKeyCode()
== KeyEvent.VK_F)
-                    this.requestFocus();
-            }
-        }
-    }
-
 
     /**
      * On changes in action text, will update toolbar tip instead.



Mime
View raw message