cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r582229 - in /cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler: ./ action/ dialog/ editor/ util/
Date Fri, 05 Oct 2007 12:33:22 GMT
Author: aadamchik
Date: Fri Oct  5 05:33:18 2007
New Revision: 582229

URL: http://svn.apache.org/viewvc?rev=582229&view=rev
Log:
CAY-869 CayenneModeler free-text search
the second patch - now searches for relationships attributes and DB entities. still some display
issues to solve

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/editor/EditorView.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=582229&r1=582228&r2=582229&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
Fri Oct  5 05:33:18 2007
@@ -20,7 +20,10 @@
 
 package org.apache.cayenne.modeler;
 
-import java.awt.*;
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.FlowLayout;
+import java.awt.Font;
 import java.awt.event.KeyEvent;
 
 import javax.swing.Box;
@@ -31,9 +34,36 @@
 import javax.swing.JPanel;
 import javax.swing.JToolBar;
 
-import org.apache.commons.lang.SystemUtils;
 import org.apache.cayenne.map.DerivedDbEntity;
-import org.apache.cayenne.modeler.action.*;
+import org.apache.cayenne.modeler.action.AboutAction;
+import org.apache.cayenne.modeler.action.ConfigurePreferencesAction;
+import org.apache.cayenne.modeler.action.CreateDataMapAction;
+import org.apache.cayenne.modeler.action.CreateDbEntityAction;
+import org.apache.cayenne.modeler.action.CreateDerivedDbEntityAction;
+import org.apache.cayenne.modeler.action.CreateDomainAction;
+import org.apache.cayenne.modeler.action.CreateNodeAction;
+import org.apache.cayenne.modeler.action.CreateObjEntityAction;
+import org.apache.cayenne.modeler.action.CreateProcedureAction;
+import org.apache.cayenne.modeler.action.CreateQueryAction;
+import org.apache.cayenne.modeler.action.DerivedEntitySyncAction;
+import org.apache.cayenne.modeler.action.ExitAction;
+import org.apache.cayenne.modeler.action.FindAction;
+import org.apache.cayenne.modeler.action.GenerateCodeAction;
+import org.apache.cayenne.modeler.action.GenerateDBAction;
+import org.apache.cayenne.modeler.action.ImportDBAction;
+import org.apache.cayenne.modeler.action.ImportDataMapAction;
+import org.apache.cayenne.modeler.action.ImportEOModelAction;
+import org.apache.cayenne.modeler.action.NavigateBackwardAction;
+import org.apache.cayenne.modeler.action.NavigateForwardAction;
+import org.apache.cayenne.modeler.action.NewProjectAction;
+import org.apache.cayenne.modeler.action.ObjEntitySyncAction;
+import org.apache.cayenne.modeler.action.OpenProjectAction;
+import org.apache.cayenne.modeler.action.ProjectAction;
+import org.apache.cayenne.modeler.action.RemoveAction;
+import org.apache.cayenne.modeler.action.RevertAction;
+import org.apache.cayenne.modeler.action.SaveAction;
+import org.apache.cayenne.modeler.action.SaveAsAction;
+import org.apache.cayenne.modeler.action.ValidateAction;
 import org.apache.cayenne.modeler.editor.EditorView;
 import org.apache.cayenne.modeler.event.DataMapDisplayEvent;
 import org.apache.cayenne.modeler.event.DataMapDisplayListener;
@@ -48,6 +78,7 @@
 import org.apache.cayenne.modeler.event.QueryDisplayListener;
 import org.apache.cayenne.modeler.util.CayenneAction;
 import org.apache.cayenne.modeler.util.RecentFileMenu;
+import org.apache.commons.lang.SystemUtils;
 
 /**
  * Main frame of CayenneModeler. Responsibilities include coordination of
@@ -191,23 +222,15 @@
         toolBar.add(getAction(NavigateBackwardAction.getActionName()).buildButton());
         toolBar.add(getAction(NavigateForwardAction.getActionName()).buildButton());
 
+        toolBar.addSeparator();
 
-        Component c = getAction(FindAction.getActionName()).buildTextField(10);
-
+        Component c = getAction(FindAction.getActionName()).buildTextField();
         JLabel findLabel = new JLabel("Find entity:");
-        findLabel.setDisplayedMnemonic('e');
         findLabel.setLabelFor(c);
+        toolBar.add(findLabel);
+        toolBar.add(c);
 
-        JToolBar findToolBar = new JToolBar();
-        findToolBar.add(findLabel);
-        findToolBar.add(c);
-
-
-        JPanel panel = new JPanel(new BorderLayout());
-        panel.add(toolBar, BorderLayout.WEST);
-        panel.add(findToolBar, BorderLayout.EAST);
-
-        getContentPane().add(panel, BorderLayout.NORTH);
+        getContentPane().add(toolBar, BorderLayout.NORTH);
     }
 
     public void currentDataNodeChanged(DataNodeDisplayEvent e) {

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=582229&r1=582228&r2=582229&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
Fri Oct  5 05:33:18 2007
@@ -1,75 +1,83 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-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.ObjEntity;
-
-import javax.swing.*;
-import java.awt.event.ActionEvent;
-import java.util.Iterator;
-import java.util.ArrayList;
-import java.util.regex.Pattern;
-import java.util.regex.Matcher;
-
-public class FindAction extends CayenneAction {
-    private java.util.List paths;
-
-    public static String getActionName() {
-        return "Find";
-    }
-
-    public FindAction(Application application) {
-        super(getActionName(), application);
-    }
-
-    /**
-     * All entities that contain a pattern substring (case-indifferent) in the name are produced.
-     * @param e
-     */
-    public void performAction(ActionEvent e) {
-        String pattern = ((JTextField) e.getSource()).getText();
-
-        paths = new ArrayList();
-
-        Iterator it = getProjectController().getProject().treeNodes();
-        while(it.hasNext()) {
-            ProjectPath path = (ProjectPath) it.next();
-
-            Object o = path.getObject();
-            if(o instanceof ObjEntity && matchFound(((ObjEntity) o).getName(), pattern))
{
-                 paths.add(path.getPath());
-            }
-        }
-
-        new FindDialog(getApplication().getFrameController(), paths).startupAction();
-    }
-
-    private boolean matchFound(String entityName, String pattern) {
-        if(pattern.trim().equals(""))
-            return false;
-        Pattern p = Pattern.compile(pattern.trim(), Pattern.CASE_INSENSITIVE);
-        Matcher m = p.matcher(entityName);
-
-        return m.find();
-    }
-}
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+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.regex.Matcher;
+
+public class FindAction extends CayenneAction {
+    private java.util.List paths;
+
+    public static String getActionName() {
+        return "Find";
+    }
+
+    public FindAction(Application application) {
+        super(getActionName(), application);
+    }
+
+    /**
+     * All entities that contain a pattern substring (case-indifferent) in the name are produced.
+     * @param e
+     */
+    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();
+
+        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());
+        }
+
+        source.setText("");
+
+        new FindDialog(getApplication().getFrameController(), paths).startupAction();
+    }
+
+    private boolean matchFound(String entityName, Pattern pattern) {
+        Matcher m = pattern.matcher(entityName);
+
+        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=582229&r1=582228&r2=582229&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
Fri Oct  5 05:33:18 2007
@@ -1,130 +1,205 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-package org.apache.cayenne.modeler.dialog;
-
-import java.awt.Component;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.util.ArrayList;
-import java.util.Iterator;
-
-import javax.swing.JButton;
-import javax.swing.JDialog;
-import javax.swing.event.TreeSelectionEvent;
-import javax.swing.event.TreeSelectionListener;
-import javax.swing.tree.TreePath;
-
-import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.modeler.CayenneModelerFrame;
-import org.apache.cayenne.modeler.ProjectTreeModel;
-import org.apache.cayenne.modeler.ProjectTreeView;
-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. 
- */
-public class FindDialog extends CayenneController {
-    private FindDialogView view;
-    private java.util.List paths;
-    private java.util.List names;
-
-    public FindDialog(CayenneController parent, java.util.List paths) {
-        super(parent);
-
-        this.paths = paths;
-
-        names = new ArrayList();
-        Iterator it = paths.iterator();
-        while (it.hasNext()) {
-            Object[] path = (Object[]) it.next();
-            ObjEntity entity = (ObjEntity) path[path.length - 1];
-            names.add(entity.getName());
-        }
-
-        view = new FindDialogView(names);
-
-        initBindings();
-    }
-
-    public void startupAction() {
-        view.pack();
-
-        centerView();
-        makeCloseableOnEscape();
-
-        view.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
-        view.setModal(true);
-        view.setVisible(true);
-    }
-
-    public Component getView() {
-        return view;
-    }
-
-    protected void initBindings() {
-        view.getOkButton().addActionListener(new ActionListener() {
-
-            public void actionPerformed(ActionEvent e) {
-                view.dispose();
-            }
-        });
-
-        Iterator it = view.getEntityButtons().iterator();
-        while (it.hasNext()) {
-            JButton b = (JButton) it.next();
-            b.addActionListener(new JumpToResultActionListener());
-        }
-    }
-
-    private class JumpToResultActionListener implements ActionListener {
-        public void actionPerformed(ActionEvent e) {
-            Object[] path = (Object[]) paths.get(names.indexOf(((JButton)e.getSource()).getActionCommand()));
-
-            ProjectTreeView treeView = ((CayenneModelerFrame) application.getFrameController().getView())
-                    .getView().getProjectTreeView();
-            ProjectTreeModel treeModel = (ProjectTreeModel) treeView.getModel();
-
-
-            Object[] mutableTreeNodes = new Object[path.length];
-            mutableTreeNodes[0] = treeModel.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] = treeModel.getNodeForObjectPath(helper);
-            }
-
-            TreePath tp = new TreePath(mutableTreeNodes);
-
-            // TODO: selection in a project tree view itself: there is no selection currently,
so event doesn't track the previous selection
-            TreeSelectionListener listener = treeView.getTreeSelectionListener();
-            listener.valueChanged(new TreeSelectionEvent(treeView,
-                    new TreePath[] {tp},
-                    new boolean[] {true},
-                    null, tp)
-            );
-
-            view.dispose();
-        }
-    }
-}
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.modeler.dialog;
+
+import java.awt.Component;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.*;
+
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.tree.TreePath;
+
+import org.apache.cayenne.map.*;
+import org.apache.cayenne.modeler.*;
+import org.apache.cayenne.modeler.editor.EditorView;
+import org.apache.cayenne.modeler.event.AttributeDisplayEvent;
+import org.apache.cayenne.modeler.event.RelationshipDisplayEvent;
+import org.apache.cayenne.modeler.util.CayenneController;
+import org.apache.cayenne.access.DataDomain;
+
+/**
+ * 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;
+
+    public FindDialog(CayenneController parent, java.util.List paths) {
+        super(parent);
+
+        this.paths = paths;
+
+        Map objEntityNames = new HashMap(), dbEntityNames = new HashMap(), attrNames = new
HashMap(), relatNames = new HashMap();
+        Iterator it = paths.iterator();
+        int index = 0;
+        while (it.hasNext()) {
+            Object[] path = (Object[]) it.next();
+
+            if (path[path.length - 1] instanceof ObjEntity) {
+                objEntityNames.put(new Integer(index++), ((ObjEntity) path[path.length -
1]).getName());
+            }
+
+            if (path[path.length - 1] instanceof DbEntity) {
+                dbEntityNames.put(new Integer(index++), ((DbEntity) path[path.length - 1]).getName());
+            }
+
+            if (path[path.length - 1] instanceof Attribute) {
+                attrNames.put(new Integer(index++), ((Attribute) path[path.length - 1]).getName());
+            }
+
+            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();
+    }
+
+    public void startupAction() {
+        view.pack();
+
+        centerView();
+        makeCloseableOnEscape();
+
+        view.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
+        view.setModal(true);
+        view.setVisible(true);
+    }
+
+    public Component getView() {
+        return view;
+    }
+
+    protected void initBindings() {
+        view.getOkButton().addActionListener(new ActionListener() {
+
+            public void actionPerformed(ActionEvent e) {
+                view.dispose();
+            }
+        });
+
+        Iterator it = view.getEntityButtons().iterator();
+        while (it.hasNext()) {
+            JButton b = (JButton) it.next();
+            b.addActionListener(new JumpToResultActionListener());
+        }
+    }
+
+    private class JumpToResultActionListener implements ActionListener {
+        private EditorView editor = ((CayenneModelerFrame) application.getFrameController().getView()).getView();
+
+        public void actionPerformed(ActionEvent e) {
+            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.
+                 */
+                editor.getProjectTreeView().getSelectionModel().addSelectionPath(buildTreePath(path));
+
+
+            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().addSelectionPath(buildTreePath(o));
+
+
+                if (path[path.length - 1] instanceof DbAttribute) {
+                    AttributeDisplayEvent event = new AttributeDisplayEvent(
+                            editor.getDbDetailView(),
+                            (Attribute) path[path.length - 1],
+                            (Entity) path[path.length - 2],
+                            (DataMap) path[path.length - 3],
+                            (DataDomain) path[path.length - 4]);
+
+                    ((CayenneModelerController) parent).getProjectController().fireDbAttributeDisplayEvent(event);
+                }
+
+                if (path[path.length - 1] instanceof ObjAttribute) {
+                    AttributeDisplayEvent event = new AttributeDisplayEvent(
+                            editor.getObjDetailView(),
+                            (Attribute) path[path.length - 1],
+                            (Entity) path[path.length - 2],
+                            (DataMap) path[path.length - 3],
+                            (DataDomain) path[path.length - 4]);
+                    ((CayenneModelerController) parent).getProjectController().fireObjAttributeDisplayEvent(event);
+                }
+
+                if (path[path.length - 1] instanceof DbRelationship) {
+                    RelationshipDisplayEvent event = new RelationshipDisplayEvent(
+                            editor.getDbDetailView(),
+                            (Relationship) path[path.length - 1],
+                            (Entity) path[path.length - 2],
+                            (DataMap) path[path.length - 3],
+                            (DataDomain) path[path.length - 4]
+                    );
+                    ((CayenneModelerController) parent).getProjectController().fireDbRelationshipDisplayEvent(event);
+                }
+            }
+
+                if (path[path.length - 1] instanceof ObjRelationship) {
+                    RelationshipDisplayEvent event = new RelationshipDisplayEvent(
+                            editor.getObjDetailView(),
+                            (Relationship) path[path.length - 1],
+                            (Entity) path[path.length - 2],
+                            (DataMap) path[path.length - 3],
+                            (DataDomain) path[path.length - 4]
+                    );
+                    ((CayenneModelerController) parent).getProjectController().fireObjRelationshipDisplayEvent(event);
+                }
+
+            view.dispose();
+        }
+
+        /**
+         * 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);
+            }
+
+            return new TreePath(mutableTreeNodes);
+        }
+
+    }
+
+}

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=582229&r1=582228&r2=582229&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
Fri Oct  5 05:33:18 2007
@@ -1,76 +1,117 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-package org.apache.cayenne.modeler.dialog;
-
-import java.awt.BorderLayout;
-import java.awt.FlowLayout;
-import java.util.ArrayList;
-import java.util.Iterator;
-
-import javax.swing.BoxLayout;
-import javax.swing.JButton;
-import javax.swing.JDialog;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.border.EmptyBorder;
-
-/**
- * Swing component displaying results produced by search feature.
- */
-public class FindDialogView extends JDialog {
-    private JButton okButton;
-    private java.util.List entityButtons;
-
-    public FindDialogView(java.util.List names) {
-        entityButtons = new ArrayList();
-
-        JPanel panel = new JPanel();
-        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
-        Iterator it = names.iterator();
-        
-        while(it.hasNext()) {
-            String name = (String) it.next();
-            JButton b = new JButton(name);
-            b.setBorder(new EmptyBorder(2, 10, 2, 10));       // top, left, bottom, right
-            panel.add(b);
-
-            entityButtons.add(b);
-        }
-        if(entityButtons.isEmpty())
-            panel.add(new JLabel("No matched entities found!"));
-
-        JPanel okPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
-        okButton = new JButton("OK");
-        okPanel.add(okButton);
-
-        getContentPane().setLayout(new BorderLayout());
-        getContentPane().add(panel, BorderLayout.CENTER);
-        getContentPane().add(okPanel, BorderLayout.SOUTH);
-
-        setTitle("Found entities");
-    }
-
-    public JButton getOkButton() {
-        return okButton;
-    }
-
-    public java.util.List getEntityButtons() {
-        return entityButtons;
-    }
-}
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.modeler.dialog;
+
+import java.awt.BorderLayout;
+import java.awt.FlowLayout;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.swing.BoxLayout;
+import javax.swing.DefaultButtonModel;
+import javax.swing.Icon;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.border.EmptyBorder;
+
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.ObjAttribute;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.map.ObjRelationship;
+import org.apache.cayenne.modeler.util.CellRenderers;
+
+/**
+ * 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;
+
+    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()) {
+            panel.add(new JLabel("No matched entities 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())));
+        }
+
+        JPanel okPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
+        okButton = new JButton("OK");
+        okPanel.add(okButton);
+
+        getContentPane().setLayout(new BorderLayout());
+        getContentPane().add(panel, BorderLayout.CENTER);
+        getContentPane().add(okPanel, BorderLayout.SOUTH);
+
+        setTitle("Found entities");
+    }
+
+    private JPanel createResultPanel(Map names, Icon icon) {
+        JPanel panel = new JPanel();
+        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
+
+        Iterator it = names.keySet().iterator();
+        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.setModel(new EntityButtonModel(index));
+            panel.add(b);
+
+            entityButtons.add(b);
+        }
+
+        return panel;
+    }
+
+    public JButton getOkButton() {
+        return okButton;
+    }
+
+    public java.util.List getEntityButtons() {
+        return entityButtons;
+    }
+
+    public class EntityButtonModel extends DefaultButtonModel {
+        private Integer index;
+
+        EntityButtonModel(Integer index) {
+            super();
+            this.index = index;
+        }
+
+        public Integer getIndex() {
+            return index;
+        }
+    }
+}

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EditorView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EditorView.java?rev=582229&r1=582228&r2=582229&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EditorView.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EditorView.java
Fri Oct  5 05:33:18 2007
@@ -78,11 +78,21 @@
 
     protected CardLayout detailLayout;
 
-    ProjectTreeView treePanel;
+    private ProjectTreeView treePanel;
     public ProjectTreeView getProjectTreeView() {
         return treePanel;
     }
 
+    private DbEntityTabbedView dbDetailView;
+    public DbEntityTabbedView getDbDetailView() {
+        return dbDetailView;
+    }
+
+    private ObjEntityTabbedView objDetailView;
+    public ObjEntityTabbedView getObjDetailView() {
+        return objDetailView;
+    }
+
     public EditorView(ProjectController eventController) {
         this.eventController = eventController;
         initView();
@@ -130,10 +140,10 @@
         Component procedureQueryView = new ProcedureQueryView(eventController);
         detailPanel.add(new JScrollPane(procedureQueryView), PROCEDURE_QUERY_VIEW);
 
-        Component objDetailView = new ObjEntityTabbedView(eventController);
+        objDetailView = new ObjEntityTabbedView(eventController);
         detailPanel.add(objDetailView, OBJ_VIEW);
 
-        Component dbDetailView = new DbEntityTabbedView(eventController);
+        dbDetailView = new DbEntityTabbedView(eventController);
         detailPanel.add(dbDetailView, DB_VIEW);
 
         splitPane.setLeftComponent(new JScrollPane(treePanel));

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=582229&r1=582228&r2=582229&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
Fri Oct  5 05:33:18 2007
@@ -21,6 +21,9 @@
 package org.apache.cayenne.modeler.util;
 
 import java.awt.event.ActionEvent;
+import java.awt.event.AWTEventListener;
+import java.awt.event.KeyEvent;
+import java.awt.*;
 
 import javax.swing.*;
 
@@ -179,11 +182,11 @@
     /**
      * Factory method that creates a text field hooked up to this action
      */
-    public JTextField buildTextField(int size) {
-        JTextField field = new JTextField(size);
-        field.setAction(this);
+    public JTextField buildTextField() {
+        CayenneTextField ctf = new CayenneTextField(this);
+        Toolkit.getDefaultToolkit().addAWTEventListener(ctf, AWTEvent.KEY_EVENT_MASK);
 
-        return field;
+        return ctf;
     }
 
     /**
@@ -216,6 +219,25 @@
             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