1 19 20 package org.netbeans.modules.db.explorer.dlg; 21 22 import java.awt.Dialog ; 23 import java.awt.event.ActionListener ; 24 import java.beans.PropertyChangeEvent ; 25 import java.beans.PropertyChangeListener ; 26 import java.util.ResourceBundle ; 27 28 import javax.swing.JPanel ; 29 import javax.swing.JTabbedPane ; 30 31 import javax.swing.event.ChangeListener ; 32 33 import org.openide.DialogDescriptor; 34 import org.openide.DialogDisplayer; 35 import org.openide.util.NbBundle; 36 37 public class ConnectionDialog { 38 39 private transient ConnectionDialogMediator mediator; 40 private transient JTabbedPane tabs; 41 private transient Exception storedExp; 42 43 ResourceBundle bundle = NbBundle.getBundle("org.netbeans.modules.db.resources.Bundle"); 45 final DialogDescriptor descriptor; 46 final Dialog dialog; 47 48 public ConnectionDialog(ConnectionDialogMediator mediator, FocusablePanel basePane, JPanel extendPane, String dlgTitle, ActionListener actionListener, ChangeListener tabListener) { 49 if(basePane.equals(extendPane)) { 50 throw new IllegalArgumentException ("The basePane and extendPane must not equal!"); } 52 53 this.mediator = mediator; 54 ConnectionProgressListener progressListener = new ConnectionProgressListener() { 55 public void connectionStarted() { 56 descriptor.setValid(false); 57 } 58 59 public void connectionStep(String step) { 60 } 61 62 public void connectionFinished() { 63 descriptor.setValid(true); 64 } 65 66 public void connectionFailed() { 67 descriptor.setValid(true); 68 } 69 }; 70 mediator.addConnectionProgressListener(progressListener); 71 72 PropertyChangeListener propChangeListener = new PropertyChangeListener () { 73 public void propertyChange(PropertyChangeEvent evt) { 74 String propertyName = evt.getPropertyName(); 75 if (propertyName == null || propertyName.equals(ConnectionDialogMediator.PROP_VALID)) { 76 updateValid(); 77 } 78 } 79 }; 80 mediator.addPropertyChangeListener(propChangeListener); 81 82 tabs = new JTabbedPane (JTabbedPane.TOP); 83 84 tabs.addChangeListener(tabListener); 85 86 tabs.addTab( bundle.getString("BasePanelTitle"), null, basePane, 89 bundle.getString("BasePanelHint") ); 91 tabs.addTab( bundle.getString("ExtendPanelTitle"), null, 94 extendPane, 95 bundle.getString("ExtendPanelHint") ); 97 tabs.getAccessibleContext().setAccessibleName(bundle.getString("ACS_ConnectDialogA11yName")); 98 tabs.getAccessibleContext().setAccessibleDescription(bundle.getString("ACS_ConnectDialogA11yDesc")); 99 100 descriptor = new DialogDescriptor(tabs, dlgTitle, true, actionListener); Object [] closingOptions = {DialogDescriptor.CANCEL_OPTION}; 104 descriptor.setClosingOptions(closingOptions); 105 updateValid(); 106 dialog = DialogDisplayer.getDefault().createDialog(descriptor); 107 basePane.initializeFocus(); 110 dialog.setVisible(false); 111 } 112 113 public void close() { 114 dialog.setVisible(false); 116 dialog.dispose(); 117 } 118 119 public void setVisible(boolean mode) { 120 dialog.setVisible(mode); 121 } 122 123 public void setSelectedComponent(JPanel panel) { 124 tabs.setSelectedComponent(panel); 125 } 126 127 public void setException(Exception e) { 128 storedExp = e; 129 } 130 131 public boolean isException() { 132 return (storedExp != null); 133 } 134 135 private void updateValid() { 136 boolean valid = ConnectionDialog.this.mediator.getValid(); 137 descriptor.setValid(valid); 138 tabs.setEnabledAt(1, valid); 139 } 140 141 149 public static abstract class FocusablePanel extends JPanel { 150 151 public abstract void initializeFocus(); 152 } 153 } 154 | Popular Tags |