Author: daceywang
Date: Wed Apr 29 07:21:21 2009
New Revision: 3026

Modified:
   trunk/src/ca/sqlpower/architect/swingui/RelationshipEditPanel.java

Log:
Added a swap button on RelationshipEditPanel so label texts will be swapped easily.

Modified: trunk/src/ca/sqlpower/architect/swingui/RelationshipEditPanel.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/RelationshipEditPanel.java (original) +++ trunk/src/ca/sqlpower/architect/swingui/RelationshipEditPanel.java Wed Apr 29 07:21:21 2009
@@ -48,6 +48,7 @@
 import ca.sqlpower.sqlobject.SQLRelationship.UpdateDeleteRule;
 import ca.sqlpower.swingui.ColorCellRenderer;
 import ca.sqlpower.swingui.DataEntryPanel;
+import ca.sqlpower.swingui.SPSUtils;

 import com.jgoodies.forms.builder.DefaultFormBuilder;
 import com.jgoodies.forms.debug.FormDebugPanel;
@@ -128,11 +129,11 @@
         //so the number of selected relationships is only 1.
         this.color = relationshipLines.get(0).getForegroundColor();

- FormLayout layout = new FormLayout("pref, 4dlu, pref:grow, 4dlu, pref, 4dlu, pref:grow"); //$NON-NLS-1$ + FormLayout layout = new FormLayout("pref, 4dlu, pref:grow, 4dlu, pref, 4dlu, pref:grow, 4dlu, pref"); //$NON-NLS-1$
         layout.setColumnGroups(new int[][] { { 3, 7 } });
DefaultFormBuilder fb = new DefaultFormBuilder(layout, logger.isDebugEnabled() ? new FormDebugPanel() : new JPanel());

- fb.append(Messages.getString("RelationshipEditPanel.name"), relationshipName = new JTextField(), 5); //$NON-NLS-1$ + fb.append(Messages.getString("RelationshipEditPanel.name"), relationshipName = new JTextField(), 7); //$NON-NLS-1$

         fb.nextLine();
fb.append(Messages.getString("RelationshipEditPanel.lineColour"), relationLineColor = new JComboBox(Relationship.SUGGESTED_COLOURS)); //$NON-NLS-1$
@@ -148,10 +149,16 @@
fb.append(Messages.getString("RelationshipEditPanel.pkLabel"), pkLabelTextField = new JTextField()); fb.append(Messages.getString("RelationshipEditPanel.fkLabel"), fkLabelTextField = new JTextField());

+        JButton swapButton = new JButton(swapLabelText);
+ swapButton.setIcon(SPSUtils.createIcon("arrow_refresh", "Swap Labels", ArchitectSwingSessionContext.ICON_SIZE));
+        swapButton.setToolTipText("Swap Label Texts");
+        fb.append(swapButton);
+        fb.nextLine();
+
                identifyingGroup = new ButtonGroup();
- fb.append(Messages.getString("RelationshipEditPanel.type"), identifyingButton = new JRadioButton(Messages.getString("RelationshipEditPanel.identifying")), 5); //$NON-NLS-1$ //$NON-NLS-2$ + fb.append(Messages.getString("RelationshipEditPanel.type"), identifyingButton = new JRadioButton(Messages.getString("RelationshipEditPanel.identifying")), 7); //$NON-NLS-1$ //$NON-NLS-2$
                identifyingGroup.add(identifyingButton);
- fb.append("", nonIdentifyingButton = new JRadioButton(Messages.getString("RelationshipEditPanel.nonIdentifying")), 5); //$NON-NLS-1$ //$NON-NLS-2$ + fb.append("", nonIdentifyingButton = new JRadioButton(Messages.getString("RelationshipEditPanel.nonIdentifying")), 7); //$NON-NLS-1$ //$NON-NLS-2$
                identifyingGroup.add(nonIdentifyingButton);

                fb.nextLine();
@@ -162,21 +169,25 @@
         fb.nextLine();
fb.append(Messages.getString("RelationshipEditPanel.cardinality"), pkTableName = new JLabel("PK Table: Unknown")); //$NON-NLS-1$ //$NON-NLS-2$ fb.append("", fkTableName = new JLabel("FK Table: Unknown")); //$NON-NLS-1$ //$NON-NLS-2$
+        fb.nextLine();

fb.append("", pkTypeZeroToMany = new JRadioButton(Messages.getString("RelationshipEditPanel.zeroOrMore"))); //$NON-NLS-1$ //$NON-NLS-2$
                pkTypeGroup.add(pkTypeZeroToMany);
fb.append("", fkTypeZeroToMany = new JRadioButton(Messages.getString("RelationshipEditPanel.zeroOrMore"))); //$NON-NLS-1$ //$NON-NLS-2$
                fkTypeGroup.add(fkTypeZeroToMany);
+               fb.nextLine();

fb.append("", pkTypeOneToMany = new JRadioButton(Messages.getString("RelationshipEditPanel.oneOrMore"))); //$NON-NLS-1$ //$NON-NLS-2$
                pkTypeGroup.add(pkTypeOneToMany);
fb.append("", fkTypeOneToMany = new JRadioButton(Messages.getString("RelationshipEditPanel.oneOrMore"))); //$NON-NLS-1$ //$NON-NLS-2$
                fkTypeGroup.add(fkTypeOneToMany);
+               fb.nextLine();

fb.append("", pkTypeZeroOne = new JRadioButton(Messages.getString("RelationshipEditPanel.zeroOrOne"))); //$NON-NLS-1$ //$NON-NLS-2$
                pkTypeGroup.add(pkTypeZeroOne);
fb.append("", fkTypeZeroOne = new JRadioButton(Messages.getString("RelationshipEditPanel.zeroOrOne"))); //$NON-NLS-1$ //$NON-NLS-2$
                fkTypeGroup.add(fkTypeZeroOne);
+               fb.nextLine();

fb.append("", pkTypeOne = new JRadioButton(Messages.getString("RelationshipEditPanel.exactlyOne"))); //$NON-NLS-1$ //$NON-NLS-2$
                pkTypeGroup.add(pkTypeOne);
@@ -184,12 +195,13 @@
                fb.nextLine();
         fb.appendUnrelatedComponentsGapRow();
         fb.nextLine();
+
         deferrabilityGroup = new ButtonGroup();
- fb.append(Messages.getString("RelationshipEditPanel.deferrability"), notDeferrable = new JRadioButton(Messages.getString("RelationshipEditPanel.notDeferrable")), 5); //$NON-NLS-1$ //$NON-NLS-2$ + fb.append(Messages.getString("RelationshipEditPanel.deferrability"), notDeferrable = new JRadioButton(Messages.getString("RelationshipEditPanel.notDeferrable")), 7); //$NON-NLS-1$ //$NON-NLS-2$
         deferrabilityGroup.add(notDeferrable);
- fb.append("", initiallyDeferred = new JRadioButton(Messages.getString("RelationshipEditPanel.initiallyDeferred")), 5); //$NON-NLS-1$ //$NON-NLS-2$ + fb.append("", initiallyDeferred = new JRadioButton(Messages.getString("RelationshipEditPanel.initiallyDeferred")), 7); //$NON-NLS-1$ //$NON-NLS-2$
         deferrabilityGroup.add(initiallyDeferred);
- fb.append("", initiallyImmediate = new JRadioButton(Messages.getString("RelationshipEditPanel.initiallyImmediate")), 5); //$NON-NLS-1$ //$NON-NLS-2$ + fb.append("", initiallyImmediate = new JRadioButton(Messages.getString("RelationshipEditPanel.initiallyImmediate")), 7); //$NON-NLS-1$ //$NON-NLS-2$
         deferrabilityGroup.add(initiallyImmediate);

         fb.nextLine();
@@ -202,26 +214,31 @@
         updateRuleGroup.add(updateCascade);
fb.append(Messages.getString("RelationshipEditPanel.deleteRule"), deleteCascade = new JRadioButton(Messages.getString("RelationshipEditPanel.cascade"))); //$NON-NLS-1$ //$NON-NLS-2$
         deleteRuleGroup.add(deleteCascade);
+        fb.nextLine();

fb.append("", updateRestrict = new JRadioButton(Messages.getString("RelationshipEditPanel.restrict"))); //$NON-NLS-1$ //$NON-NLS-2$
         updateRuleGroup.add(updateRestrict);
fb.append("", deleteRestrict = new JRadioButton(Messages.getString("RelationshipEditPanel.restrict"))); //$NON-NLS-1$ //$NON-NLS-2$
         deleteRuleGroup.add(deleteRestrict);
+        fb.nextLine();

fb.append("", updateNoAction = new JRadioButton(Messages.getString("RelationshipEditPanel.noAction"))); //$NON-NLS-1$ //$NON-NLS-2$
         updateRuleGroup.add(updateNoAction);
fb.append("", deleteNoAction = new JRadioButton(Messages.getString("RelationshipEditPanel.noAction"))); //$NON-NLS-1$ //$NON-NLS-2$
         deleteRuleGroup.add(deleteNoAction);
+        fb.nextLine();

fb.append("", updateSetNull = new JRadioButton(Messages.getString("RelationshipEditPanel.setNull"))); //$NON-NLS-1$ //$NON-NLS-2$
         updateRuleGroup.add(updateSetNull);
fb.append("", deleteSetNull = new JRadioButton(Messages.getString("RelationshipEditPanel.setNull"))); //$NON-NLS-1$ //$NON-NLS-2$
         deleteRuleGroup.add(deleteSetNull);
+        fb.nextLine();

fb.append("", updateSetDefault = new JRadioButton(Messages.getString("RelationshipEditPanel.setDefault"))); //$NON-NLS-1$ //$NON-NLS-2$
         updateRuleGroup.add(updateSetDefault);
fb.append("", deleteSetDefault = new JRadioButton(Messages.getString("RelationshipEditPanel.setDefault"))); //$NON-NLS-1$ //$NON-NLS-2$
         deleteRuleGroup.add(deleteSetDefault);
+        fb.nextLine();

         //TODO  Doesn't work!
         relationshipName.selectAll();
@@ -438,7 +455,7 @@
         this.editDialog = editDialog;
     }

-    Action customColour = new AbstractAction("Custom Colour...") {
+    Action customColour = new AbstractAction("Customize") {
         public void actionPerformed(ActionEvent arg0) {
Color colour = session.getCustomColour(relationshipLines.get(0).getForegroundColor());
             if (colour != null) {
@@ -449,7 +466,16 @@
             }
         }
     };
-
+
+    Action swapLabelText = new AbstractAction() {
+        public void actionPerformed(ActionEvent e) {
+            String parentText = pkLabelTextField.getText();
+            String childText = fkLabelTextField.getText();
+            pkLabelTextField.setText(childText);
+            fkLabelTextField.setText(parentText);
+        }
+    };
+
        private boolean containsColor(Vector<Color> colorSet, Color color) {
            boolean contains = false;
            for (Color eachColor : colorSet) {

Reply via email to