cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r656482 - in /cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler: ./ dialog/ editor/ editor/dbentity/ event/
Date Thu, 15 May 2008 01:02:14 GMT
Author: aadamchik
Date: Wed May 14 18:02:13 2008
New Revision: 656482

URL: http://svn.apache.org/viewvc?rev=656482&view=rev
Log:
CAY-1055 Right-click contextual menu for entities/attributes/relationships that would include
common operations, like "delete".

Added:
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/event/TablePopupHandler.java
Modified:
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectTreeView.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/ConfirmRemoveDialog.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/AbstractCallbackMethodsTab.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityAttributeTab.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityRelationshipTab.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ProcedureParameterTab.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbentity/DbEntityAttributeTab.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbentity/DbEntityRelationshipTab.java

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectTreeView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectTreeView.java?rev=656482&r1=656481&r2=656482&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectTreeView.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectTreeView.java
Wed May 14 18:02:13 2008
@@ -19,6 +19,8 @@
 
 package org.apache.cayenne.modeler;
 
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Comparator;
@@ -26,6 +28,8 @@
 import java.util.Iterator;
 import java.util.List;
 
+import javax.swing.JMenuItem;
+import javax.swing.JPopupMenu;
 import javax.swing.JTree;
 import javax.swing.event.TreeSelectionEvent;
 import javax.swing.event.TreeSelectionListener;
@@ -54,6 +58,15 @@
 import org.apache.cayenne.map.event.ProcedureListener;
 import org.apache.cayenne.map.event.QueryEvent;
 import org.apache.cayenne.map.event.QueryListener;
+import org.apache.cayenne.modeler.action.CreateDataMapAction;
+import org.apache.cayenne.modeler.action.CreateDbEntityAction;
+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.ObjEntitySyncAction;
+import org.apache.cayenne.modeler.action.RemoveAction;
 import org.apache.cayenne.modeler.event.DataMapDisplayEvent;
 import org.apache.cayenne.modeler.event.DataMapDisplayListener;
 import org.apache.cayenne.modeler.event.DataNodeDisplayEvent;
@@ -88,6 +101,11 @@
 
     protected ProjectController mediator;
     protected TreeSelectionListener treeSelectionListener;
+    
+    /**
+     * Popup menu containing basic functions
+     */
+    protected JPopupMenu popup;
 
     public ProjectTreeView(ProjectController mediator) {
         super();
@@ -111,6 +129,8 @@
         };
 
         addTreeSelectionListener(treeSelectionListener);
+        
+        addMouseListener(new PopupHandler());
 
         mediator.addDomainListener(this);
         mediator.addDomainDisplayListener(this);
@@ -812,4 +832,64 @@
     public TreeSelectionListener getTreeSelectionListener() {
         return treeSelectionListener;
     }
+    
+    /**
+     * Creates JPopupMenu containing main functions
+     */
+    private JPopupMenu createJPopupMenu()
+    {
+        JPopupMenu popup = new JPopupMenu();
+        
+        popup.add(buildMenu(CreateDomainAction.getActionName()));
+        popup.add(buildMenu(CreateNodeAction.getActionName()));
+        popup.add(buildMenu(CreateDataMapAction.getActionName()));
+
+        popup.add(buildMenu(CreateObjEntityAction.getActionName()));
+        popup.add(buildMenu(CreateDbEntityAction.getActionName()));
+        popup.add(buildMenu(CreateProcedureAction.getActionName()));
+        popup.add(buildMenu(CreateQueryAction.getActionName()));
+        popup.addSeparator();
+        popup.add(buildMenu(ObjEntitySyncAction.getActionName()));
+        popup.addSeparator();
+        popup.add(buildMenu(RemoveAction.getActionName()));
+        
+        return popup;
+    }
+    
+    /**
+     * Creates and returns an menu item associated with the key.
+     * @param key action key
+     */
+    private JMenuItem buildMenu(String key) {
+        return mediator.getApplication().getAction(key).buildMenu();
+    }
+
+    /**
+     * Class to handle right-click and show popup for selected tree row 
+     */
+    class PopupHandler extends MouseAdapter
+    {
+        public void mousePressed(MouseEvent e) 
+        {
+            mouseReleased(e);
+        }
+
+        public void mouseReleased(MouseEvent e) 
+        {
+            if(e.isPopupTrigger())
+            {
+                if(popup == null)
+                    popup = createJPopupMenu();
+                
+                /**
+                 * Selecting specified row
+                 */
+                int row = getRowForLocation(e.getX(), e.getY());
+                if(row != -1)
+                    setSelectionRow(row);
+                
+                popup.show(ProjectTreeView.this, e.getX(), e.getY());
+            }
+        }
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/ConfirmRemoveDialog.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/ConfirmRemoveDialog.java?rev=656482&r1=656481&r2=656482&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/ConfirmRemoveDialog.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/ConfirmRemoveDialog.java
Wed May 14 18:02:13 2008
@@ -1,11 +1,13 @@
 package org.apache.cayenne.modeler.dialog;
 
+import javax.swing.JCheckBox;
+import javax.swing.JDialog;
+import javax.swing.JOptionPane;
+
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.dialog.pref.GeneralPreferences;
 import org.apache.cayenne.pref.PreferenceDetail;
 
-import javax.swing.*;
-
 /**
  * Used to confirm deleting items in the model.
  *
@@ -22,7 +24,7 @@
 
         JOptionPane pane = new JOptionPane(message, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
 
-        JDialog dialog = pane.createDialog(Application.getFrame(), "File exists");
+        JDialog dialog = pane.createDialog(Application.getFrame(), "Confirm Remove");
         dialog.setVisible(true);
 
         Object selectedValue = pane.getValue();

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/AbstractCallbackMethodsTab.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/AbstractCallbackMethodsTab.java?rev=656482&r1=656481&r2=656482&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/AbstractCallbackMethodsTab.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/AbstractCallbackMethodsTab.java
Wed May 14 18:02:13 2008
@@ -31,6 +31,7 @@
 import javax.swing.JComponent;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
 import javax.swing.JTable;
 import javax.swing.JToolBar;
 import javax.swing.event.ListSelectionEvent;
@@ -49,6 +50,7 @@
 import org.apache.cayenne.modeler.action.RemoveCallbackMethodAction;
 import org.apache.cayenne.modeler.event.CallbackMethodEvent;
 import org.apache.cayenne.modeler.event.CallbackMethodListener;
+import org.apache.cayenne.modeler.event.TablePopupHandler;
 import org.apache.cayenne.modeler.util.CayenneAction;
 import org.apache.cayenne.modeler.util.CayenneTable;
 import org.apache.cayenne.modeler.util.CayenneWidgetFactory;
@@ -62,9 +64,7 @@
  * methods displaying, creating, removing, esiting, reordering
  * 
  * @author Vasil Tarasevich
- * @version 1.0 Oct 23, 2007
  */
-
 public abstract class AbstractCallbackMethodsTab extends JPanel {
 
     /**
@@ -199,6 +199,15 @@
                 // System.out.println("c");
             }
         });
+
+        /**
+         * Create and install a popup
+         */
+        JPopupMenu popup = new JPopupMenu();
+        popup.add(getRemoveCallbackMethodAction().buildMenu());
+
+        TablePopupHandler.install(table, popup);
+
         auxPanel.add(PanelFactory.createTablePanel(table, null), BorderLayout.CENTER);
 
         add(auxPanel, BorderLayout.CENTER);

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityAttributeTab.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityAttributeTab.java?rev=656482&r1=656481&r2=656482&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityAttributeTab.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityAttributeTab.java
Wed May 14 18:02:13 2008
@@ -27,6 +27,7 @@
 import javax.swing.DefaultCellEditor;
 import javax.swing.JComboBox;
 import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
 import javax.swing.JTable;
 import javax.swing.JToolBar;
 import javax.swing.event.ChangeEvent;
@@ -49,6 +50,7 @@
 import org.apache.cayenne.modeler.event.AttributeDisplayEvent;
 import org.apache.cayenne.modeler.event.EntityDisplayEvent;
 import org.apache.cayenne.modeler.event.ObjEntityDisplayListener;
+import org.apache.cayenne.modeler.event.TablePopupHandler;
 import org.apache.cayenne.modeler.util.CayenneTable;
 import org.apache.cayenne.modeler.util.CayenneWidgetFactory;
 import org.apache.cayenne.modeler.util.ModelerUtil;
@@ -87,6 +89,14 @@
 
         table = new CayenneTable();
         table.setDefaultRenderer(String.class, new CellRenderer());
+        
+        /**
+         * Create and install a popup
+         */
+        JPopupMenu popup = new JPopupMenu();
+        popup.add(app.getAction(RemoveAttributeAction.getActionName()).buildMenu());
+        
+        TablePopupHandler.install(table, popup);
 
         add(PanelFactory.createTablePanel(table, null), BorderLayout.CENTER);
     }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityRelationshipTab.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityRelationshipTab.java?rev=656482&r1=656481&r2=656482&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityRelationshipTab.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityRelationshipTab.java
Wed May 14 18:02:13 2008
@@ -29,10 +29,13 @@
 
 import javax.swing.DefaultCellEditor;
 import javax.swing.DefaultComboBoxModel;
+import javax.swing.Icon;
 import javax.swing.JButton;
 import javax.swing.JComboBox;
 import javax.swing.JLabel;
+import javax.swing.JMenuItem;
 import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
 import javax.swing.JTable;
 import javax.swing.JToolBar;
 import javax.swing.event.ChangeEvent;
@@ -61,6 +64,7 @@
 import org.apache.cayenne.modeler.event.EntityDisplayEvent;
 import org.apache.cayenne.modeler.event.ObjEntityDisplayListener;
 import org.apache.cayenne.modeler.event.RelationshipDisplayEvent;
+import org.apache.cayenne.modeler.event.TablePopupHandler;
 import org.apache.cayenne.modeler.util.CayenneTable;
 import org.apache.cayenne.modeler.util.CayenneWidgetFactory;
 import org.apache.cayenne.modeler.util.CellRenderers;
@@ -93,6 +97,13 @@
 
     CayenneTable table;
     JButton resolve;
+    
+    /**
+     * By now popup menu item is made similiar to toolbar button. 
+     * (i.e. all functionality is here)
+     * This should be probably refactored as Action.
+     */
+    protected JMenuItem resolveMenu;
 
     public ObjEntityRelationshipTab(ProjectController mediator) {
         this.mediator = mediator;
@@ -113,9 +124,11 @@
         toolBar.add(app.getAction(ObjEntitySyncAction.getActionName()).buildButton());
 
         toolBar.addSeparator();
+        
+        Icon ico = ModelerUtil.buildIcon("icon-info.gif");
 
         resolve = new JButton();
-        resolve.setIcon(ModelerUtil.buildIcon("icon-info.gif"));
+        resolve.setIcon(ico);
         resolve.setToolTipText("Edit Relationship");
         toolBar.add(resolve);
 
@@ -130,6 +143,17 @@
         table = new CayenneTable();
         table.setDefaultRenderer(String.class, new StringRenderer());
         table.setDefaultRenderer(ObjEntity.class, new EntityRenderer());
+        
+        /**
+         * Create and install a popup
+         */
+        resolveMenu = new JMenuItem("Database Mapping", ico);
+        
+        JPopupMenu popup = new JPopupMenu();
+        popup.add(resolveMenu);
+        popup.add(app.getAction(RemoveRelationshipAction.getActionName()).buildMenu());
+        
+        TablePopupHandler.install(table, popup);
 
         add(PanelFactory.createTablePanel(table, null), BorderLayout.CENTER);
     }
@@ -139,7 +163,7 @@
         mediator.addObjEntityListener(this);
         mediator.addObjRelationshipListener(this);
 
-        resolve.addActionListener(new ActionListener() {
+        ActionListener resolver = new ActionListener() {
 
             public void actionPerformed(ActionEvent e) {
                 int row = table.getSelectedRow();
@@ -157,7 +181,10 @@
                 table.getSelectionModel().clearSelection();
                 table.select(row);
             }
-        });
+        };
+        
+        resolve.addActionListener(resolver);
+        resolveMenu.addActionListener(resolver);
 
         table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
 
@@ -214,6 +241,8 @@
         }
         else
             resolve.setEnabled(false);
+        
+        resolveMenu.setEnabled(resolve.isEnabled());
 
         RelationshipDisplayEvent ev = new RelationshipDisplayEvent(this, rel, mediator
                 .getCurrentObjEntity(), mediator.getCurrentDataMap(), mediator
@@ -335,6 +364,8 @@
                     }
                     else
                         resolve.setEnabled(false);
+                    
+                    resolveMenu.setEnabled(resolve.isEnabled());
                 }
             }
         });

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ProcedureParameterTab.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ProcedureParameterTab.java?rev=656482&r1=656481&r2=656482&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ProcedureParameterTab.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ProcedureParameterTab.java
Wed May 14 18:02:13 2008
@@ -26,9 +26,12 @@
 import java.util.EventObject;
 
 import javax.swing.DefaultCellEditor;
+import javax.swing.Icon;
 import javax.swing.JButton;
 import javax.swing.JComboBox;
+import javax.swing.JMenuItem;
 import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
 import javax.swing.JToolBar;
 import javax.swing.SwingConstants;
 import javax.swing.event.ChangeEvent;
@@ -51,6 +54,7 @@
 import org.apache.cayenne.modeler.event.ProcedureDisplayEvent;
 import org.apache.cayenne.modeler.event.ProcedureDisplayListener;
 import org.apache.cayenne.modeler.event.ProcedureParameterDisplayEvent;
+import org.apache.cayenne.modeler.event.TablePopupHandler;
 import org.apache.cayenne.modeler.util.CayenneTable;
 import org.apache.cayenne.modeler.util.CayenneWidgetFactory;
 import org.apache.cayenne.modeler.util.ModelerUtil;
@@ -74,6 +78,15 @@
     protected JButton removeParameterButton;
     protected JButton moveUp;
     protected JButton moveDown;
+    
+    /**
+     * By now popup menu items are made similiar to toolbar button. 
+     * (i.e. all functionality is here)
+     * This should be probably refactored as Action.
+     */
+    protected JMenuItem removeParameterMenu;
+    protected JMenuItem moveUpMenu;
+    protected JMenuItem moveDownMenu;
 
     public ProcedureParameterTab(ProjectController eventController) {
         this.eventController = eventController;
@@ -91,6 +104,9 @@
         
         moveDown.addActionListener(this);
         moveUp.addActionListener(this);
+        
+        moveDownMenu.addActionListener(this);
+        moveUpMenu.addActionListener(this);
     }
 
     protected void init() {
@@ -103,14 +119,17 @@
         removeParameterButton = app.getAction(RemoveProcedureParameterAction.getActionName()).buildButton();
         toolBar.add(removeParameterButton);
         toolBar.addSeparator();
+        
+        Icon up = ModelerUtil.buildIcon("icon-move_up.gif");
+        Icon down = ModelerUtil.buildIcon("icon-move_down.gif");
 
         moveUp = new JButton();
-        moveUp.setIcon(ModelerUtil.buildIcon("icon-move_up.gif"));
+        moveUp.setIcon(up);
         moveUp.setToolTipText("Move Parameter Up");
         toolBar.add(moveUp);
         
         moveDown = new JButton();
-        moveDown.setIcon(ModelerUtil.buildIcon("icon-move_down.gif"));
+        moveDown.setIcon(down);
         moveDown.setToolTipText("Move Parameter Down");
         toolBar.add(moveDown);
         
@@ -118,6 +137,25 @@
 
         // Create table with two columns and no rows.
         table = new CayenneTable();
+        
+        /**
+         * Create and install a popup
+         */
+        JPopupMenu popup = new JPopupMenu();
+        
+        removeParameterMenu = app.getAction(RemoveProcedureParameterAction.getActionName()).buildMenu();

+        
+        popup.add(removeParameterMenu);
+        popup.addSeparator();
+        
+        moveUpMenu = new JMenuItem("Move Parameter Up", up);
+        moveDownMenu = new JMenuItem("Move Parameter Down", down);
+        
+        popup.add(moveUpMenu);
+        popup.add(moveDownMenu);
+        
+        TablePopupHandler.install(table, popup);
+        
         add(PanelFactory.createTablePanel(table, null), BorderLayout.CENTER);
     }
     
@@ -151,6 +189,8 @@
         removeParameterButton.setEnabled(enableRemoveButton);
         moveUp.setEnabled(enableUp);
         moveDown.setEnabled(enableDown);
+        
+        syncButtons();
 
         ProcedureParameterDisplayEvent ppde =
             new ProcedureParameterDisplayEvent(
@@ -262,10 +302,10 @@
         
         int index = -1;
 
-        if (e.getSource() == moveUp) {
+        if (e.getSource() == moveUp || e.getSource() == moveUpMenu) {
             index = model.moveRowUp(parameter);
         }
-        else if (e.getSource() == moveDown) {
+        else if (e.getSource() == moveDown || e.getSource() == moveDownMenu) {
             index = model.moveRowDown(parameter);
         }
 
@@ -277,5 +317,15 @@
             eventController.fireProcedureEvent(
                 new ProcedureEvent(this, parameter.getProcedure(), MapEvent.CHANGE));
         }
-    }    
+    }
+    
+    /**
+     * Synchronizes state of toolbar and popup menu buttons
+     */
+    private void syncButtons()
+    {
+        removeParameterMenu.setEnabled(removeParameterButton.isEnabled());
+        moveUpMenu.setEnabled(moveUp.isEnabled());
+        moveDownMenu.setEnabled(moveDown.isEnabled());   
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbentity/DbEntityAttributeTab.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbentity/DbEntityAttributeTab.java?rev=656482&r1=656481&r2=656482&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbentity/DbEntityAttributeTab.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbentity/DbEntityAttributeTab.java
Wed May 14 18:02:13 2008
@@ -25,6 +25,7 @@
 import javax.swing.DefaultCellEditor;
 import javax.swing.JComboBox;
 import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
 import javax.swing.JToolBar;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ListSelectionEvent;
@@ -46,6 +47,7 @@
 import org.apache.cayenne.modeler.event.AttributeDisplayEvent;
 import org.apache.cayenne.modeler.event.DbEntityDisplayListener;
 import org.apache.cayenne.modeler.event.EntityDisplayEvent;
+import org.apache.cayenne.modeler.event.TablePopupHandler;
 import org.apache.cayenne.modeler.util.CayenneTable;
 import org.apache.cayenne.modeler.util.CayenneWidgetFactory;
 import org.apache.cayenne.modeler.util.PanelFactory;
@@ -88,9 +90,18 @@
         toolBar.add(app.getAction(RemoveAttributeAction.getActionName()).buildButton());
 
         add(toolBar, BorderLayout.NORTH);
-
+        
         // Create table with two columns and no rows.
         table = new CayenneTable();
+        
+        /**
+         * Create and install a popup
+         */
+        JPopupMenu popup = new JPopupMenu();
+        popup.add(app.getAction(RemoveAttributeAction.getActionName()).buildMenu());
+        
+        TablePopupHandler.install(table, popup);
+        
         add(PanelFactory.createTablePanel(table, null), BorderLayout.CENTER);
     }
 

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbentity/DbEntityRelationshipTab.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbentity/DbEntityRelationshipTab.java?rev=656482&r1=656481&r2=656482&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbentity/DbEntityRelationshipTab.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/dbentity/DbEntityRelationshipTab.java
Wed May 14 18:02:13 2008
@@ -28,9 +28,12 @@
 import javax.swing.ComboBoxModel;
 import javax.swing.DefaultCellEditor;
 import javax.swing.DefaultComboBoxModel;
+import javax.swing.Icon;
 import javax.swing.JButton;
 import javax.swing.JComboBox;
+import javax.swing.JMenuItem;
 import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
 import javax.swing.JTable;
 import javax.swing.JToolBar;
 import javax.swing.event.ChangeEvent;
@@ -60,6 +63,7 @@
 import org.apache.cayenne.modeler.event.DbEntityDisplayListener;
 import org.apache.cayenne.modeler.event.EntityDisplayEvent;
 import org.apache.cayenne.modeler.event.RelationshipDisplayEvent;
+import org.apache.cayenne.modeler.event.TablePopupHandler;
 import org.apache.cayenne.modeler.util.CayenneTable;
 import org.apache.cayenne.modeler.util.CayenneWidgetFactory;
 import org.apache.cayenne.modeler.util.CellRenderers;
@@ -81,6 +85,13 @@
     protected ProjectController mediator;
     protected CayenneTable table;
     protected JButton resolve;
+    
+    /**
+     * By now popup menu item is made similiar to toolbar button. 
+     * (i.e. all functionality is here)
+     * This should be probably refactored as Action.
+     */
+    protected JMenuItem resolveMenu;
 
     public DbEntityRelationshipTab(ProjectController mediator) {
 
@@ -90,12 +101,16 @@
         this.mediator.addDbRelationshipListener(this);
 
         init();
-        resolve.addActionListener(new ActionListener() {
+        
+        ActionListener resolver = new ActionListener() {
 
             public void actionPerformed(ActionEvent e) {
                 resolveRelationship();
             }
-        });
+        };
+        
+        resolve.addActionListener(resolver);
+        resolveMenu.addActionListener(resolver);
     }
 
     protected void init() {
@@ -113,7 +128,10 @@
         toolBar.addSeparator();
 
         resolve = new JButton();
-        resolve.setIcon(ModelerUtil.buildIcon("icon-info.gif"));
+        
+        Icon ico = ModelerUtil.buildIcon("icon-info.gif");
+        
+        resolve.setIcon(ico);
         resolve.setToolTipText("Database Mapping");
         toolBar.add(resolve);
 
@@ -127,6 +145,17 @@
 
         table = new CayenneTable();
         table.setDefaultRenderer(DbEntity.class, new EntityRenderer());
+        
+        /**
+         * Create and install a popup
+         */
+        resolveMenu = new JMenuItem("Database Mapping", ico);
+        
+        JPopupMenu popup = new JPopupMenu();
+        popup.add(resolveMenu);
+        popup.add(app.getAction(RemoveRelationshipAction.getActionName()).buildMenu());
+        
+        TablePopupHandler.install(table, popup);
 
         add(PanelFactory.createTablePanel(table, null), BorderLayout.CENTER);
     }
@@ -141,6 +170,7 @@
             DbRelationshipTableModel model = (DbRelationshipTableModel) table.getModel();
             rel = model.getRelationship(table.getSelectedRow());
             resolve.setEnabled(rel.getTargetEntity() != null);
+            resolveMenu.setEnabled(resolve.isEnabled());
         }
     }
 
@@ -185,6 +215,8 @@
         }
         else
             resolve.setEnabled(false);
+        
+        resolveMenu.setEnabled(resolve.isEnabled());
 
         RelationshipDisplayEvent ev = new RelationshipDisplayEvent(this, rel, mediator
                 .getCurrentDbEntity(), mediator.getCurrentDataMap(), mediator

Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/event/TablePopupHandler.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/event/TablePopupHandler.java?rev=656482&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/event/TablePopupHandler.java
(added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/event/TablePopupHandler.java
Wed May 14 18:02:13 2008
@@ -0,0 +1,77 @@
+/*****************************************************************
+ *   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.event;
+
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+import javax.swing.JPopupMenu;
+import javax.swing.JTable;
+
+/**
+ * A class to handle mouse right-click on table and show popup
+ * after selecting specified table row
+ */
+public class TablePopupHandler extends MouseAdapter 
+{
+    private JTable table;
+    
+    private JPopupMenu popup;
+    
+    /**
+     * Creates new mouse handler for table, which shows specified
+     * popupmenu on right-click 
+     */
+    public TablePopupHandler(JTable table, JPopupMenu popup)
+    {
+        this.table = table;
+        this.popup = popup;
+    }
+    
+    /**
+     * Creates and installs mouse listener for a table 
+     */
+    public static void install(JTable table, JPopupMenu popup)
+    {
+        table.addMouseListener(new TablePopupHandler(table, popup));
+    }
+    
+    /**
+     * Invoked when a mouse button has been pressed on a component.
+     */
+    public void mousePressed(MouseEvent e) 
+    {
+        mouseReleased(e);
+    }
+
+    /**
+     * Invoked when a mouse button has been released on a component.
+     */
+    public void mouseReleased(MouseEvent e) 
+    {
+        if(e.isPopupTrigger())
+        {
+            int row = table.rowAtPoint(e.getPoint());
+            if(row != -1)
+                table.setRowSelectionInterval(row, row);
+            
+            popup.show(table, e.getX(), e.getY());
+        }
+    }
+}



Mime
View raw message