1 19 20 package org.netbeans.modules.db.explorer.dlg; 21 22 import java.beans.PropertyChangeListener ; 23 import java.beans.PropertyChangeSupport ; 24 import java.util.ArrayList ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import org.netbeans.modules.db.explorer.DatabaseConnection; 28 29 34 public abstract class ConnectionDialogMediator { 35 36 public static final String PROP_VALID = "valid"; 38 private final List connProgressListeners = new ArrayList (); 39 private final PropertyChangeSupport propChangeSupport = new PropertyChangeSupport (this); 40 41 private boolean valid = true; 42 43 public void addConnectionProgressListener(ConnectionProgressListener listener) { 44 synchronized (connProgressListeners) { 45 connProgressListeners.add(listener); 46 } 47 } 48 49 public void addPropertyChangeListener(PropertyChangeListener listener) { 50 propChangeSupport.addPropertyChangeListener(listener); 51 } 52 53 protected abstract boolean retrieveSchemas(SchemaPanel schemaPanel, DatabaseConnection dbcon, String defaultSchema); 54 55 protected void fireConnectionStarted() { 56 for (Iterator i = connProgressListenersCopy(); i.hasNext();) { 57 ((ConnectionProgressListener)i.next()).connectionStarted(); 58 } 59 } 60 61 protected void fireConnectionStep(String step) { 62 for (Iterator i = connProgressListenersCopy(); i.hasNext();) { 63 ((ConnectionProgressListener)i.next()).connectionStep(step); 64 } 65 } 66 67 protected void fireConnectionFinished() { 68 for (Iterator i = connProgressListenersCopy(); i.hasNext();) { 69 ((ConnectionProgressListener)i.next()).connectionFinished(); 70 } 71 } 72 73 protected void fireConnectionFailed() { 74 for (Iterator i = connProgressListenersCopy(); i.hasNext();) { 75 ((ConnectionProgressListener)i.next()).connectionFailed(); 76 } 77 } 78 79 private Iterator connProgressListenersCopy() { 80 List listenersCopy = null; 81 synchronized (connProgressListeners) { 82 listenersCopy = new ArrayList (connProgressListeners); 83 } 84 return listenersCopy.iterator(); 85 } 86 87 public void setValid(boolean valid) { 88 this.valid = valid; 89 propChangeSupport.firePropertyChange(PROP_VALID, null, null); 90 } 91 92 public boolean getValid() { 93 return valid; 94 } 95 } 96 | Popular Tags |