Lines 42-53
Link Here
|
42 |
|
42 |
|
43 |
package org.netbeans.modules.db.explorer.node; |
43 |
package org.netbeans.modules.db.explorer.node; |
44 |
|
44 |
|
|
|
45 |
import java.beans.PropertyChangeEvent; |
46 |
import java.beans.PropertyChangeListener; |
45 |
import java.util.ArrayList; |
47 |
import java.util.ArrayList; |
46 |
import java.util.Collection; |
48 |
import java.util.Collection; |
47 |
import java.util.Comparator; |
49 |
import java.util.Comparator; |
48 |
import java.util.List; |
50 |
import java.util.List; |
49 |
import javax.swing.SwingUtilities; |
51 |
import javax.swing.SwingUtilities; |
50 |
import org.netbeans.api.db.explorer.ConnectionListener; |
52 |
import org.netbeans.api.db.explorer.ConnectionListener; |
|
|
53 |
import org.netbeans.api.db.explorer.node.BaseNode; |
51 |
import org.netbeans.api.db.explorer.node.NodeProvider; |
54 |
import org.netbeans.api.db.explorer.node.NodeProvider; |
52 |
import org.netbeans.api.db.explorer.node.NodeProviderFactory; |
55 |
import org.netbeans.api.db.explorer.node.NodeProviderFactory; |
53 |
import org.netbeans.modules.db.explorer.ConnectionList; |
56 |
import org.netbeans.modules.db.explorer.ConnectionList; |
Lines 61-66
Link Here
|
61 |
* @author Rob Englander |
64 |
* @author Rob Englander |
62 |
*/ |
65 |
*/ |
63 |
public class ConnectionNodeProvider extends NodeProvider { |
66 |
public class ConnectionNodeProvider extends NodeProvider { |
|
|
67 |
private PropertyChangeListener PCL = new PropertyChangeListener() { |
68 |
@Override |
69 |
public void propertyChange(PropertyChangeEvent pce) { |
70 |
if(pce.getPropertyName().equals(BaseNode.PROP_DISPLAY_NAME)) { |
71 |
initialize(); |
72 |
} |
73 |
} |
74 |
}; |
64 |
|
75 |
|
65 |
// lazy initialization holder class idiom for static fields is used |
76 |
// lazy initialization holder class idiom for static fields is used |
66 |
// for retrieving the factory |
77 |
// for retrieving the factory |
Lines 95-105
Link Here
|
95 |
); |
106 |
); |
96 |
} |
107 |
} |
97 |
|
108 |
|
|
|
109 |
@Override |
98 |
protected synchronized void initialize() { |
110 |
protected synchronized void initialize() { |
99 |
List<Node> newList = new ArrayList<Node>(); |
111 |
List<Node> newList = new ArrayList<Node>(); |
100 |
DatabaseConnection newConnection = null; |
112 |
DatabaseConnection newConnection = null; |
101 |
DatabaseConnection[] connections = connectionList.getConnections(); |
113 |
DatabaseConnection[] connections = connectionList.getConnections(); |
102 |
for (DatabaseConnection connection : connections) { |
114 |
for (DatabaseConnection connection : connections) { |
|
|
115 |
// Make sure the PCL is only added once |
116 |
connection.removePropertyChangeListener(PCL); |
117 |
connection.addPropertyChangeListener(PCL); |
103 |
Collection<Node> matches = getNodes(connection); |
118 |
Collection<Node> matches = getNodes(connection); |
104 |
if (matches.size() > 0) { |
119 |
if (matches.size() > 0) { |
105 |
newList.addAll(matches); |
120 |
newList.addAll(matches); |
Lines 110-116
Link Here
|
110 |
newList.add(ConnectionNode.create(lookup, this)); |
125 |
newList.add(ConnectionNode.create(lookup, this)); |
111 |
} |
126 |
} |
112 |
} |
127 |
} |
113 |
|
128 |
|
114 |
setNodes(newList); |
129 |
setNodes(newList); |
115 |
// select added connection in explorer |
130 |
// select added connection in explorer |
116 |
final DatabaseConnection newConnectionFinal = newConnection; |
131 |
final DatabaseConnection newConnectionFinal = newConnection; |
Lines 129-135
Link Here
|
129 |
} |
144 |
} |
130 |
|
145 |
|
131 |
static class ConnectionComparator implements Comparator<Node> { |
146 |
static class ConnectionComparator implements Comparator<Node> { |
132 |
|
147 |
@Override |
133 |
public int compare(Node model1, Node model2) { |
148 |
public int compare(Node model1, Node model2) { |
134 |
return model1.getDisplayName().compareToIgnoreCase(model2.getDisplayName()); |
149 |
return model1.getDisplayName().compareToIgnoreCase(model2.getDisplayName()); |
135 |
} |
150 |
} |