[hg] main-silver: #154634: Add "Move Up" and "Move Down" buttons...

  • From: Jaroslav Havlin < >
  • To:
  • Subject: [hg] main-silver: #154634: Add "Move Up" and "Move Down" buttons...
  • Date: Fri, 15 Feb 2013 06:39:32 -0800

changeset 806bbc5dd3a2 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/806bbc5dd3a2
description:
        #154634: Add "Move Up" and "Move Down" buttons to "Create Table" 
dialog for moving columns

diffstat:

 db/src/org/netbeans/modules/db/explorer/dlg/Bundle.properties      |   4 +
 db/src/org/netbeans/modules/db/explorer/dlg/CreateTableDialog.java |  49 
+++++++++-
 2 files changed, 51 insertions(+), 2 deletions(-)

diffs (111 lines):

diff --git a/db/src/org/netbeans/modules/db/explorer/dlg/Bundle.properties 
b/db/src/org/netbeans/modules/db/explorer/dlg/Bundle.properties
--- a/db/src/org/netbeans/modules/db/explorer/dlg/Bundle.properties
+++ b/db/src/org/netbeans/modules/db/explorer/dlg/Bundle.properties
@@ -142,6 +142,8 @@
 CreateTableAddButtonTitle=A&dd column
 CreateTableEditButtonTitle=&Edit
 CreateTableRemoveButtonTitle=&Remove
+CreateTableUpButtonTitle=Move &Up
+CreateTableDownButtonTitle=Move Do&wn
 CreateTableDialogTitle=Create Table
 CreateTableMissingTableName=Provide valid table name.
 CreateTableNoColumns=Add columns to the list.
@@ -153,6 +155,8 @@
 ACS_CreateTableAddButtonTitleA11yDesc=Add column to the table.
 ACS_CreateTableEditButtonTitleA11yDesc=Edit selected column in the table.
 ACS_CreateTableRemoveButtonTitleA11yDesc=Remove column from the table.
+ACS_CreateTableUpButtonTitleA11yDesc=Move column up.
+ACS_CreateTableDownButtonTitleA11yDesc=Move column down.
 ACS_CreateTableDialogA11yDesc=Create table dialog.
 
 # Used in CreateTableDialog
diff --git 
a/db/src/org/netbeans/modules/db/explorer/dlg/CreateTableDialog.java 
b/db/src/org/netbeans/modules/db/explorer/dlg/CreateTableDialog.java
--- a/db/src/org/netbeans/modules/db/explorer/dlg/CreateTableDialog.java
+++ b/db/src/org/netbeans/modules/db/explorer/dlg/CreateTableDialog.java
@@ -67,6 +67,7 @@
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
+import javax.swing.JSeparator;
 import javax.swing.JTable;
 import javax.swing.JTextField;
 import javax.swing.border.BevelBorder;
@@ -96,7 +97,7 @@
     Dialog dialog = null;
     JTextField dbnamefield, dbownerfield;
     JTable table;
-    JButton addbtn, delbtn, editBtn;
+    JButton addbtn, delbtn, editBtn, upBtn, downBtn;
     Specification spec;
     private DialogDescriptor descriptor = null;
     private NotificationLineSupport statusLine;
@@ -237,7 +238,7 @@
             constr.gridy = 1;
             constr.insets = new java.awt.Insets (2, 8, 2, 2);
             JPanel btnpane = new JPanel();
-            GridLayout btnlay = new GridLayout(3,1,0,5);
+            GridLayout btnlay = new GridLayout(5,1,0,5);
             btnpane.setLayout(btnlay);
             layout.setConstraints(btnpane, constr);
             pane.add(btnpane);
@@ -299,6 +300,46 @@
                 }
             });
 
+            // Button to move row up
+            upBtn = new JButton();
+            Mnemonics.setLocalizedText(upBtn, 
NbBundle.getMessage(CreateTableDialog.class, "CreateTableUpButtonTitle")); // 
NOI18N
+            
upBtn.setToolTipText(NbBundle.getMessage(CreateTableDialog.class, 
"ACS_CreateTableUpButtonTitleA11yDesc")); // NOI18N
+            btnpane.add(upBtn);
+            upBtn.addActionListener(new ActionListener() {
+                @Override
+                public void actionPerformed(ActionEvent event) {
+                    int idx = table.getSelectedRow();
+                    if (idx > 0) {
+                        DataModel dm = (DataModel) table.getModel();
+                        ColumnItem ci = dm.getRow(idx);
+                        dm.removeRow(idx);
+                        dm.insertRow(idx - 1, ci);
+                        table.getSelectionModel().setSelectionInterval(
+                                idx - 1, idx - 1);
+                    }
+                }
+            });
+
+            // Button to move row down
+            downBtn = new JButton();
+            Mnemonics.setLocalizedText(downBtn, 
NbBundle.getMessage(CreateTableDialog.class, "CreateTableDownButtonTitle")); 
// NOI18N
+            
downBtn.setToolTipText(NbBundle.getMessage(CreateTableDialog.class, 
"ACS_CreateTableDownButtonTitleA11yDesc")); // NOI18N
+            btnpane.add(downBtn);
+            downBtn.addActionListener(new ActionListener() {
+                @Override
+                public void actionPerformed(ActionEvent event) {
+                    int idx = table.getSelectedRow();
+                    if (idx < table.getRowCount() - 1) {
+                        DataModel dm = (DataModel) table.getModel();
+                        ColumnItem ci = dm.getRow(idx);
+                        dm.removeRow(idx);
+                        dm.insertRow(idx + 1, ci);
+                        table.getSelectionModel().setSelectionInterval(
+                                idx + 1, idx + 1);
+                    }
+                }
+            });
+
             ActionListener listener = new ActionListener() {
                 @Override
                 public void actionPerformed(ActionEvent event) {
@@ -380,9 +421,13 @@
     private void validate() {
         assert statusLine != null : "Notification status line not 
available";  //NOI18N
 
+        int selectedIndex = table.getSelectedRow();
         boolean oneRowSelected = table.getSelectedRowCount() == 1;
         editBtn.setEnabled(oneRowSelected);
         delbtn.setEnabled(oneRowSelected);
+        upBtn.setEnabled(oneRowSelected && selectedIndex > 0);
+        downBtn.setEnabled(oneRowSelected
+                && selectedIndex < table.getRowCount() - 1);
 
         String tname = getTableName();
         if (tname == null || tname.length() < 1) {

[hg] main-silver: #154634: Add "Move Up" and "Move Down" buttons...

Jaroslav Havlin 02/15/2013

Project Features

About this Project

DB was started in November 2009, is owned by Antonin Nebuzelsky, and has 113 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close