[hg] main-silver: #61417: Cannot cancel Connect action

  • From: Libor Fischmeistr < >
  • To:
  • Subject: [hg] main-silver: #61417: Cannot cancel Connect action
  • Date: Wed, 11 Dec 2013 22:54:21 +0000

changeset 88e0d4e707f7 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/88e0d4e707f7
description:
        #61417: Cannot cancel Connect action

diffstat:

 db/src/org/netbeans/modules/db/explorer/action/ConnectAction.java |   4 +-
 db/src/org/netbeans/modules/db/explorer/dlg/Bundle.properties     |   2 +
 db/src/org/netbeans/modules/db/explorer/dlg/ConnectionDialog.java |  37 
+++++++--
 3 files changed, 33 insertions(+), 10 deletions(-)

diffs (94 lines):

diff --git 
a/db/src/org/netbeans/modules/db/explorer/action/ConnectAction.java 
b/db/src/org/netbeans/modules/db/explorer/action/ConnectAction.java
--- a/db/src/org/netbeans/modules/db/explorer/action/ConnectAction.java
+++ b/db/src/org/netbeans/modules/db/explorer/action/ConnectAction.java
@@ -286,8 +286,8 @@
                     progressComponent.setPreferredSize(new Dimension(350, 
20));
                     ConnectProgressDialog panel = new 
ConnectProgressDialog(progressComponent, null);
                     
panel.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage 
(ConnectAction.class, "ACS_ConnectingDialogTextA11yDesc"));
-                    descriptor = new DialogDescriptor(panel, 
NbBundle.getMessage (ConnectAction.class, "ConnectingDialogTitle"), true, new 
Object[] { DialogDescriptor.CANCEL_OPTION },
-                            DialogDescriptor.CANCEL_OPTION, 
DialogDescriptor.DEFAULT_ALIGN, null, null);
+                    descriptor = new DialogDescriptor(panel, 
NbBundle.getMessage (ConnectAction.class, "ConnectingDialogTitle"), true, new 
Object[] {},
+                            null, DialogDescriptor.DEFAULT_ALIGN, null, 
null);
                     final Dialog dialog = 
DialogDisplayer.getDefault().createDialog(descriptor);
                     
                     final PropertyChangeListener connectionListener = new 
PropertyChangeListener() {
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
@@ -392,3 +392,5 @@
 MSG_ConnectionNamePanelComment=Override the default name for the connection. 
The name should be descriptive about the connection you are creating.
 NewConnectionPanel.bConnectionProperties=Connection &Properties
 NewConnectionPanel.dlgConnectionProperties=Connection Properties
+
+ConnectionDlg.CancelOption=Cancel
diff --git 
a/db/src/org/netbeans/modules/db/explorer/dlg/ConnectionDialog.java 
b/db/src/org/netbeans/modules/db/explorer/dlg/ConnectionDialog.java
--- a/db/src/org/netbeans/modules/db/explorer/dlg/ConnectionDialog.java
+++ b/db/src/org/netbeans/modules/db/explorer/dlg/ConnectionDialog.java
@@ -46,14 +46,13 @@
 
 import java.awt.Dialog;
 import java.awt.Window;
+import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
-import javax.swing.JComponent;
-
+import javax.swing.JButton;
 import javax.swing.JPanel;
 
-
 import org.openide.DialogDescriptor;
 import org.openide.DialogDisplayer;
 import org.openide.util.HelpCtx;
@@ -66,8 +65,10 @@
     
     final DialogDescriptor descriptor;
     final Dialog dialog;
+    final JButton cancelButton;
     
     public ConnectionDialog(ConnectionDialogMediator mediator, 
FocusablePanel basePane, String dlgTitle, HelpCtx helpCtx, ActionListener 
actionListener) {
+        this.cancelButton = new 
JButton(NbBundle.getMessage(ConnectionDialog.class, 
"ConnectionDlg.CancelOption"));
         this.mediator = mediator;
         ConnectionProgressListener progressListener = new 
ConnectionProgressListener() {
             @Override
@@ -105,14 +106,34 @@
         
basePane.getAccessibleContext().setAccessibleName(NbBundle.getMessage 
(ConnectionDialog.class, "ACS_ConnectDialogA11yName"));
         
basePane.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage 
(ConnectionDialog.class, "ACS_ConnectDialogA11yDesc"));
 
-        descriptor = new DialogDescriptor(basePane, dlgTitle, true, 
DialogDescriptor.OK_CANCEL_OPTION,
+        descriptor = new DialogDescriptor(basePane, dlgTitle, true, new 
Object[] {DialogDescriptor.OK_OPTION, cancelButton},
                      DialogDescriptor.OK_OPTION, 
DialogDescriptor.DEFAULT_ALIGN, helpCtx, actionListener);
-        // inbuilt close of the dialog is only after CANCEL button click
-        // after OK button is dialog closed by hand
-        Object [] closingOptions = {DialogDescriptor.CANCEL_OPTION};
-        descriptor.setClosingOptions(closingOptions);
+        
+        // Valid in this case means: connection is not establishing
+        // when the connection is created the process can't be canceled 
anymore
+        descriptor.addPropertyChangeListener(new PropertyChangeListener() {
+            @Override
+            public void propertyChange(PropertyChangeEvent e) {
+                if("valid".equals(e.getPropertyName())) {
+                    cancelButton.setEnabled((Boolean) e.getNewValue());
+                }
+            }
+        });
+
+        // disable automatic closing
+        descriptor.setClosingOptions(new Object[0]);
         updateValid();
+        
         dialog = DialogDisplayer.getDefault().createDialog(descriptor);
+        
+        // Explicitly close dialog on cancelbutton
+        cancelButton.addActionListener(new ActionListener() {
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                dialog.setVisible(false);
+            }
+        });
+        
         // needed for issue 82787, allows the panel to request the focus
         // to the password text field
         basePane.initializeFocus();

[hg] main-silver: #61417: Cannot cancel Connect action

Libor Fischmeistr 12/11/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