1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.plugin.opennap.gui;
21
22 import java.beans.PropertyChangeEvent;
23 import java.beans.PropertyChangeListener;
24
25 import javax.swing.SwingUtilities;
26
27 import org.xnap.event.StateEvent;
28 import org.xnap.event.StateListener;
29 import org.xnap.gui.table.DefaultTreeTableNode;
30 import org.xnap.gui.table.LeafTreeTableNode;
31 import org.xnap.gui.table.TreeTableNode;
32 import org.xnap.plugin.opennap.net.OpenNapNetwork;
33 import org.xnap.plugin.opennap.net.OpenNapServer;
34
35 /***
36 *
37 */
38 public class OpenNapNetworkNode extends DefaultTreeTableNode
39 implements PropertyChangeListener, StateListener
40 {
41
42
43
44
45
46
47
48 /***
49 * Constructs a <code>TransferTreeTableNode</code>.
50 *
51 * @param model the table model
52 * @param name the name of the network
53 */
54 public OpenNapNetworkNode(OpenNapServerTableModel model, OpenNapNetwork network)
55 {
56 super(model, network);
57
58 network.addPropertyChangeListener(this);
59 }
60
61
62
63 public void add(OpenNapServer server)
64 {
65
66 add(new LeafTreeTableNode(server));
67
68 server.addPropertyChangeListener(this);
69 server.addStateListener(this);
70
71 }
72
73 public void remove(OpenNapServer server)
74 {
75 server.removePropertyChangeListener(this);
76 server.removeStateListener(this);
77
78 int index = getIndexOfChildByData(server);
79 removeChildAt(index);
80 }
81
82 public void removeAll()
83 {
84 while (getChildCount() > 0) {
85 remove((OpenNapServer)((TreeTableNode)getChildAt(0)).getData());
86 }
87 }
88
89 public void propertyChange(final PropertyChangeEvent event)
90 {
91 Runnable runner = new Runnable()
92 {
93 public void run()
94 {
95 if (event.getSource() == getData()) {
96 changed();
97 }
98 else {
99 String p = event.getPropertyName();
100
101 int index = getIndexOfChildByData(event.getSource());
102 if (index != -1) {
103 if (p.equals("network")) {
104 OpenNapServer s = (OpenNapServer)event.getSource();
105 remove(s);
106 ((OpenNapServerTableModel)getModel()).move(s);
107 }
108 else {
109 changedChildAt(index);
110 }
111 }
112 }
113 }
114 };
115 SwingUtilities.invokeLater(runner);
116 }
117
118 public void stateChanged(final StateEvent event)
119 {
120 Runnable runner = new Runnable()
121 {
122 public void run()
123 {
124 int index = getIndexOfChildByData(event.getSource());
125 if (index != -1) {
126 changedChildAt(index);
127 }
128 }
129 };
130 SwingUtilities.invokeLater(runner);
131 }
132
133 }