Author: jfuerth
Date: Wed Sep  3 07:59:32 2008
New Revision: 2679

Modified:
   trunk/src/ca/sqlpower/architect/swingui/ColumnEditPanel.java
   trunk/src/ca/sqlpower/architect/swingui/action/EditColumnAction.java
   trunk/src/ca/sqlpower/architect/swingui/action/InsertColumnAction.java

Log:
Cleaned up the logic in EditColumnAction and also renamed the makeDialog() methods to showDialog() to better reflect their actual purpose.

This fixes the bug where the column edit dialog appears entirely grey on OS X (it was because the OK and Cancel actions were disabling the dialog, and it was being reused by all subsequent edit actions)

Modified: trunk/src/ca/sqlpower/architect/swingui/ColumnEditPanel.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/ColumnEditPanel.java        
(original)
+++ trunk/src/ca/sqlpower/architect/swingui/ColumnEditPanel.java Wed Sep 3 07:59:32 2008
@@ -236,11 +236,13 @@
* Updates all the UI components to reflect the given column's properties. * Also saves a reference to the given column so the changes made in the UI
      * can be written back into the column.
+     * <p>
+ * Normally, this should not be used. Instead, create a new ColumnEditPanel.
      *
      * @param col
      *            The column to edit
      */
-    public void editColumn(SQLColumn col) throws ArchitectException {
+    void editColumn(SQLColumn col) throws ArchitectException {
logger.debug("Edit Column '" + col + "' is being called"); //$NON-NLS-1$ //$NON-NLS-2$
         if (col == null) {
throw new NullPointerException("Edit null column is not allowed"); //$NON-NLS-1$

Modified: trunk/src/ca/sqlpower/architect/swingui/action/EditColumnAction.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/action/EditColumnAction.java (original) +++ trunk/src/ca/sqlpower/architect/swingui/action/EditColumnAction.java Wed Sep 3 07:59:32 2008
@@ -27,20 +27,17 @@
 import javax.swing.JDialog;
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
-import javax.swing.tree.TreePath;

 import org.apache.log4j.Logger;

 import ca.sqlpower.architect.ArchitectException;
 import ca.sqlpower.architect.SQLColumn;
-import ca.sqlpower.architect.SQLObject;
 import ca.sqlpower.architect.SQLTable;
 import ca.sqlpower.architect.swingui.ASUtils;
-import ca.sqlpower.architect.swingui.ArchitectSwingConstants;
 import ca.sqlpower.architect.swingui.ArchitectSwingSession;
 import ca.sqlpower.architect.swingui.ColumnEditPanel;
 import ca.sqlpower.architect.swingui.ContainerPane;
-import ca.sqlpower.architect.swingui.DBTree;
+import ca.sqlpower.architect.swingui.PlayPenComponent;
 import ca.sqlpower.architect.swingui.Selectable;
 import ca.sqlpower.architect.swingui.TablePane;
 import ca.sqlpower.architect.swingui.event.SelectionEvent;
@@ -50,114 +47,54 @@
public class EditColumnAction extends AbstractArchitectAction implements SelectionListener { private static final Logger logger = Logger.getLogger(EditColumnAction.class);

-       /**
-        * The DBTree instance that is associated with this Action.
-        */
-       protected final DBTree dbt;
-
-
-       protected JDialog editDialog;                   
-       protected ColumnEditPanel columnEditPanel;
-       protected ArchitectSwingSession session;
+       private final ArchitectSwingSession session;

        public EditColumnAction(ArchitectSwingSession session) {
super(session, Messages.getString("EditColumnAction.name"), Messages.getString("EditColumnAction.description"), "edit_column"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
         this.session = session;
- putValue(ACTION_COMMAND_KEY, ArchitectSwingConstants.ACTION_COMMAND_SRC_PLAYPEN);
                setEnabled(false);

         playpen.addSelectionListener(this);
         setupAction(playpen.getSelectedItems());
-
-        dbt = frame.getDbTree();
        }

        public void actionPerformed(ActionEvent evt) {
- if (evt.getActionCommand().equals(ArchitectSwingConstants.ACTION_COMMAND_SRC_PLAYPEN)) {
-                       List selection = playpen.getSelectedItems();
- logger.debug("selections length is: " + selection.size()); //$NON-NLS-1$
-                       if (selection.size() < 1) {
-                               setEnabled(false);
- JOptionPane.showMessageDialog(playpen, Messages.getString("EditColumnAction.noColumnSelected")); //$NON-NLS-1$
-                       } else if (selection.size() > 1) {
- JOptionPane.showMessageDialog(playpen, Messages.getString("EditColumnAction.multipleItemsSelected")); //$NON-NLS-1$
-                       } else if (selection.get(0) instanceof TablePane) {
-                               setEnabled(true);
-                               TablePane tp = (TablePane) selection.get(0);
-                               try {
-                                       List<SQLColumn> selectedCols = 
tp.getSelectedItems();
-                                       if (selectedCols.size() != 1) {
- JOptionPane.showMessageDialog(playpen, Messages.getString("EditColumnAction.pleaseSelectOnlyOneColumn")); //$NON-NLS-1$
-                                               logger.error("Please select one and 
only one column"); //$NON-NLS-1$
-                                               cleanup();
-                                               return;
-                                       }
-                                       int idx = tp.getSelectedItemIndex();
-                                       if (idx < 0) { // header must have been 
selected
-                                               logger.error("CantHaplaypenen: idx < 
0"); //$NON-NLS-1$
- JOptionPane.showMessageDialog(playpen, Messages.getString("EditColumnAction.pleaseSelectColumn")); //$NON-NLS-1$
-                                       } else {                                
-                                               makeDialog(tp.getModel(),idx);
-                                       }
-                               } catch (ArchitectException e) {
- JOptionPane.showMessageDialog(playpen, Messages.getString("EditColumnAction.errorFindingSelectedColumn")); //$NON-NLS-1$
-                                       logger.error("Error finding the selected 
column", e); //$NON-NLS-1$
-                                       cleanup();
-                               }
-                       } else {
- JOptionPane.showMessageDialog(playpen, Messages.getString("EditColumnAction.pleaseSelectColumn")); //$NON-NLS-1$
-                               cleanup();
-                       }
- } else if (evt.getActionCommand().equals(ArchitectSwingConstants.ACTION_COMMAND_SRC_DBTREE)) {
-                       TreePath [] selections = dbt.getSelectionPaths();
- logger.debug("selections length is: " + selections.length); //$NON-NLS-1$
-                       // both tables and columns are selected on the tree
-                       if (selections.length != 2) {
- JOptionPane.showMessageDialog(dbt, Messages.getString("EditColumnAction.pleaseSelectColumn")); //$NON-NLS-1$
-                       } else {
-                               SQLObject so = (SQLObject) 
selections[0].getLastPathComponent();
-                               if (so instanceof SQLTable) {
-                                   // if this is the table, the other must be 
the column...
-                                   so = (SQLObject) 
selections[1].getLastPathComponent();
-                               }
-                               if (so instanceof SQLColumn) {
-                                       SQLColumn sc = (SQLColumn) so;
-                                       SQLTable st = sc.getParentTable();
-                                       try {
-                                               int idx = st.getColumnIndex(sc);
-                                               if (idx < 0) {
- JOptionPane.showMessageDialog(dbt, Messages.getString("EditColumnAction.errorFindingSelectedColumn")); //$NON-NLS-1$
-                                               } else {
-                                                       makeDialog(st,idx);
-                                               }                               
                        
-                                       } catch (ArchitectException ex) {
- JOptionPane.showMessageDialog(dbt, Messages.getString("EditColumnAction.errorFindingSelectedColumn")); //$NON-NLS-1$
-                                               logger.error("Error finding the 
selected column", ex); //$NON-NLS-1$
-                                               cleanup();
-                                       }                                       
                                        
-                               } else {
- JOptionPane.showMessageDialog(dbt, Messages.getString("EditColumnAction.pleaseSelectColumn")); //$NON-NLS-1$
-                               }
-                       }
-               } else {
-                       // unknown action command source, do nothing
-               }       
+           List<PlayPenComponent> selection = playpen.getSelectedItems();
+ logger.debug("selections length is: " + selection.size()); //$NON-NLS-1$
+           if (selection.size() < 1) {
+ JOptionPane.showMessageDialog(playpen, Messages.getString("EditColumnAction.noColumnSelected")); //$NON-NLS-1$
+           } else if (selection.size() > 1) {
+ JOptionPane.showMessageDialog(playpen, Messages.getString("EditColumnAction.multipleItemsSelected")); //$NON-NLS-1$
+           } else if (selection.get(0) instanceof TablePane) {
+               TablePane tp = (TablePane) selection.get(0);
+               try {
+                   List<SQLColumn> selectedCols = tp.getSelectedItems();
+                   if (selectedCols.size() != 1) {
+ JOptionPane.showMessageDialog(playpen, Messages.getString("EditColumnAction.pleaseSelectOnlyOneColumn")); //$NON-NLS-1$
+                       return;
+                   }
+                   int idx = tp.getSelectedItemIndex();
+                   if (idx < 0) { // header must have been selected
+ throw new IllegalStateException("There was one selected column but the selected item index was negative");
+                   } else {                            
+                       showDialog(tp.getModel(),idx);
+                   }
+               } catch (ArchitectException e) {
+ JOptionPane.showMessageDialog(playpen, Messages.getString("EditColumnAction.errorFindingSelectedColumn")); //$NON-NLS-1$
+               }
+           } else {
+               // One thing was selected, but it wasn't a tablepane
+ JOptionPane.showMessageDialog(playpen, Messages.getString("EditColumnAction.pleaseSelectColumn")); //$NON-NLS-1$
+           }
        }
        
- protected void makeDialog(final SQLTable st, final int colIdx) throws ArchitectException {
-        makeDialog(st, colIdx, false, null);
+ protected void showDialog(final SQLTable st, final int colIdx) throws ArchitectException {
+        showDialog(st, colIdx, false, null);
     }

        
- protected void makeDialog(final SQLTable st, final int colIdx, final boolean addToTable, + protected void showDialog(final SQLTable st, final int colIdx, final boolean addToTable,
                final TablePane tp) throws ArchitectException {
-               if (editDialog != null) {
-                       columnEditPanel.editColumn(st.getColumn(colIdx));       
                
- editDialog.setTitle(Messages.getString("EditColumnAction.dialogTitle", st.getName())); //$NON-NLS-1$
-                       editDialog.setVisible(true);                            
-                       //editDialog.requestFocus();
-                       
-               } else {
                                
                    logger.debug("Creating new column editor panel"); 
//$NON-NLS-1$
                
@@ -175,11 +112,11 @@
// sequence name until it has a parent. By then, it will be too late. column.setAutoIncrementSequenceName(st.getName() + "_" + column.getName() + "_seq"); //$NON-NLS-1$ //$NON-NLS-2$
                        }
-                       columnEditPanel = new ColumnEditPanel(column, session);
                        
+ final ColumnEditPanel columnEditPanel = new ColumnEditPanel(column, session);
                        panel.add(columnEditPanel, BorderLayout.CENTER);
                        
-                       editDialog = 
DataEntryPanelBuilder.createDataEntryPanelDialog(
+                       JDialog editDialog = 
DataEntryPanelBuilder.createDataEntryPanelDialog(
                                        columnEditPanel,
                                        frame,
Messages.getString("EditColumnAction.columnPropertiesDialogTitle", st.getName()), //$NON-NLS-1$
@@ -213,27 +150,15 @@
                        editDialog.pack();
                        editDialog.setLocationRelativeTo(frame);
                        editDialog.setVisible(true);
-               }               
-       }
-
-       /**
-        * Permanently closes the edit dialog.
-        */
-       protected void cleanup() {
-               if (editDialog != null) {
-                       editDialog.setVisible(false);
-                       editDialog.dispose();
-                       editDialog = null;
-               }
        }

-       private void setupAction(List selectedItems) {
+       private void setupAction(List<PlayPenComponent> selectedItems) {
                if (selectedItems.size() == 0) {
                        setEnabled(false);
                        logger.debug("Disabling EditColumnAction"); 
//$NON-NLS-1$
putValue(SHORT_DESCRIPTION, Messages.getString("EditColumnAction.shortDescription")); //$NON-NLS-1$
                } else {
-                       Selectable item = (Selectable) selectedItems.get(0);
+                       Selectable item = selectedItems.get(0);
String name = Messages.getString("EditColumnAction.selected"); //$NON-NLS-1$
                        logger.debug("Selected Table"); //$NON-NLS-1$
                        if (item instanceof TablePane) {                        
        

Modified: trunk/src/ca/sqlpower/architect/swingui/action/InsertColumnAction.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/action/InsertColumnAction.java (original) +++ trunk/src/ca/sqlpower/architect/swingui/action/InsertColumnAction.java Wed Sep 3 07:59:32 2008
@@ -68,7 +68,7 @@
         }
         st.addColumn(idx, new SQLColumn());
         EditColumnAction editColumnAction = new EditColumnAction(session);
-        editColumnAction.makeDialog(st, idx);
+        editColumnAction.showDialog(st, idx);

     }

@@ -80,7 +80,7 @@
         EditColumnAction editColumnAction = new EditColumnAction(session);

         //The actual column is added to the table when the user presses OK
-        editColumnAction.makeDialog(tp.getModel(), idx,true, tp);
+        editColumnAction.showDialog(tp.getModel(), idx,true, tp);
     }

     @Override

Reply via email to