KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > db > explorer > dlg > ConnectionDialogMediator


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.db.explorer.dlg;
21
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.beans.PropertyChangeSupport JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import org.netbeans.modules.db.explorer.DatabaseConnection;
28
29 /**
30  * Base class for the connection dialogs.
31  *
32  * @author Andrei Badea
33  */

34 public abstract class ConnectionDialogMediator {
35     
36     public static final String JavaDoc PROP_VALID = "valid"; // NOI18N
37

38     private final List JavaDoc/*<ConnectionProgressListener>*/ connProgressListeners = new ArrayList JavaDoc/*<ConnectionProgressListener>*/();
39     private final PropertyChangeSupport JavaDoc propChangeSupport = new PropertyChangeSupport JavaDoc(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 JavaDoc listener) {
50         propChangeSupport.addPropertyChangeListener(listener);
51     }
52     
53     protected abstract boolean retrieveSchemas(SchemaPanel schemaPanel, DatabaseConnection dbcon, String JavaDoc defaultSchema);
54     
55     protected void fireConnectionStarted() {
56         for (Iterator JavaDoc i = connProgressListenersCopy(); i.hasNext();) {
57             ((ConnectionProgressListener)i.next()).connectionStarted();
58         }
59     }
60     
61     protected void fireConnectionStep(String JavaDoc step) {
62         for (Iterator JavaDoc i = connProgressListenersCopy(); i.hasNext();) {
63             ((ConnectionProgressListener)i.next()).connectionStep(step);
64         }
65     }
66     
67     protected void fireConnectionFinished() {
68         for (Iterator JavaDoc i = connProgressListenersCopy(); i.hasNext();) {
69             ((ConnectionProgressListener)i.next()).connectionFinished();
70         }
71     }
72
73     protected void fireConnectionFailed() {
74         for (Iterator JavaDoc i = connProgressListenersCopy(); i.hasNext();) {
75             ((ConnectionProgressListener)i.next()).connectionFailed();
76         }
77     }
78     
79     private Iterator JavaDoc/*<ConnectionProgressListener>*/ connProgressListenersCopy() {
80         List JavaDoc listenersCopy = null;
81         synchronized (connProgressListeners) {
82             listenersCopy = new ArrayList JavaDoc(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