1 19 package org.netbeans.modules.tasklist.core; 20 21 import java.util.*; 22 23 import org.openide.nodes.Node; 24 import org.openide.nodes.Children; 25 import org.openide.util.WeakListeners; 26 27 28 35 public class TaskChildren extends Children.Keys { 36 37 private final Task parent; 38 private Monitor monitor; 39 40 public TaskChildren(Task parent) { 41 this.parent = parent; 42 } 43 44 private void refreshKeys() { 45 Collection keys; 46 if (parent.hasSubtasks() == false) { 47 keys = Collections.EMPTY_SET; 48 } else { 49 50 keys = parent.getSubtasks(); 67 } 68 69 Task[] tasks = (Task[])keys.toArray(new Task[keys.size()]); 70 setKeys(tasks); 71 } 72 73 77 protected void addNotify() { 78 super.addNotify(); 79 assert monitor == null : "Dangling addNotify()"; monitor = new Monitor(); 81 82 TaskListener l = (TaskListener) WeakListeners.create(TaskListener.class, monitor, parent); 86 parent.addTaskListener(l); 87 refreshKeys(); 88 } 89 90 91 protected void removeNotify() { 92 assert monitor != null : "Dangling removeNotify()"; monitor = null; 95 setKeys(Collections.EMPTY_SET); 96 super.removeNotify(); 97 } 98 99 104 protected Node[] createNodes(Object key) { 105 109 114 Task task = (Task)key; 115 return new Node[] { createNode(task) }; 116 } 117 118 public Object clone() { 119 return new TaskChildren(this.parent); 120 } 121 122 123 124 127 protected TaskNode createNode(Task task) { 128 return new TaskNode(task); 129 } 130 131 132 134 private class Monitor implements TaskListener { 135 public Monitor () {} 136 137 public void selectedTask(Task t) { 138 } 140 141 public void warpedTask(Task t) { 142 } 144 145 public void addedTask(Task t) { 146 if (t.getParent() == parent) { 147 refreshKeys(); 148 } 149 } 150 151 public void removedTask(Task pt, Task t, int index) { 152 if (t.getParent() == parent) { 153 refreshKeys(); 154 } 155 } 156 157 public void structureChanged(Task t) { 158 if (t == null || t.isParentOf(parent)) { 159 refreshKeys(); 160 } 161 } 162 163 } 164 } 165 | Popular Tags |