1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.gui.table;
21
22 import java.util.LinkedList;
23 import javax.swing.SwingUtilities;
24
25 import org.xnap.event.*;
26 import org.xnap.transfer.Transfer;
27
28 /***
29 *
30 */
31 public class FilteredTransferContainerTreeTableNode
32 extends TransferContainerTreeTableNode
33 {
34
35
36
37
38
39 private LinkedList children = new LinkedList();
40
41
42
43 /***
44 * Constructs a <code>TransferContainerTreeTableNode</code>.
45 *
46 * @param model the table model
47 * @param transfer the container
48 */
49 public FilteredTransferContainerTreeTableNode(TransferTableModel model,
50 Transfer transfer)
51 {
52 super(model, transfer);
53 }
54
55
56
57 /***
58 * Creates a {@link LeafTreeTableNode}, if <code>data</code> is
59 * not already contained in children.
60 *
61 * @return true, if data was added; false, otherwise
62 */
63 public boolean add(Transfer transfer)
64 {
65 if (!children.contains(transfer)) {
66 children.add(transfer);
67 transfer.addStateListener(this);
68 if (transfer.isRunning()) {
69 super.add(new LeafTreeTableNode(transfer));
70 }
71 return true;
72 }
73 return false;
74 }
75
76 public void remove(Transfer transfer)
77 {
78 if (children.contains(transfer)) {
79 transfer.removeStateListener(this);
80 int index = getIndexOfChildByData(transfer);
81 if (index != -1) {
82 removeChildAt(index);
83 }
84 }
85 }
86
87 public void stateChanged(final StateEvent event)
88 {
89 Runnable runner = new Runnable()
90 {
91 public void run()
92 {
93 if (event.getSource() == getData()) {
94 changed();
95 }
96 else {
97 Transfer transfer = (Transfer)event.getSource();
98 int index = getIndexOfChildByData(transfer);
99 if (transfer.isRunning()) {
100 if (index != -1) {
101 changedChildAt(index);
102 }
103 else {
104 FilteredTransferContainerTreeTableNode
105 .super.add
106 (new LeafTreeTableNode(transfer));
107 }
108 }
109 else if (index != -1) {
110 removeChildAt(index);
111 }
112 }
113 }
114 };
115 SwingUtilities.invokeLater(runner);
116 }
117
118 }