1 19 20 21 package org.netbeans.modules.group; 22 23 import java.beans.PropertyChangeEvent ; 24 import java.beans.PropertyChangeListener ; 25 import java.util.Collections ; 26 import org.openide.loaders.DataObject; 27 import org.openide.nodes.Children; 28 import org.openide.nodes.Node; 29 import org.openide.util.RequestProcessor; 30 import org.openide.util.WeakListeners; 31 32 33 class GroupNodeChildren extends Children.Keys { 34 35 36 private final GroupShadow groupShadow; 37 38 private GroupContentListener groupContentListener; 39 43 private PropertyChangeListener propChangeListener; 44 45 51 public GroupNodeChildren(GroupShadow groupShadow) { 52 this.groupShadow = groupShadow; 53 } 54 55 60 private class GroupContentListener implements PropertyChangeListener { 61 public void propertyChange(PropertyChangeEvent e) { 62 String propName = e.getPropertyName(); 63 if (DataObject.Container.PROP_CHILDREN.equals(propName)) { 64 GroupNodeChildren.this.update(); 65 } 66 } 67 } 68 69 70 protected void addNotify() { 71 setKeys(Collections.EMPTY_SET); 72 RequestProcessor.postRequest(new Runnable () { 73 public void run() { 74 update(); 75 } 76 }); 77 groupContentListener = new GroupContentListener(); 78 groupShadow.addPropertyChangeListener( 79 propChangeListener = WeakListeners.propertyChange( 80 groupContentListener, 81 groupShadow)); 82 } 83 84 85 protected void removeNotify() { 86 setKeys(Collections.EMPTY_SET); 87 groupShadow.removePropertyChangeListener(propChangeListener); 88 propChangeListener = null; 89 groupContentListener = null; 90 } 91 92 96 void update() { 97 setKeys(groupShadow.getLinks()); 98 } 99 100 101 protected Node[] createNodes(Object key) { 102 Node nodes[] = new Node[1]; 103 104 if (key instanceof DataObject) { 105 nodes[0] = new LinkNode(groupShadow, 106 ((DataObject) key).getNodeDelegate()); 107 } else { 108 nodes[0] = new ErrorNode(groupShadow, (String ) key); 109 } 110 return nodes; 111 } 112 } 113 | Popular Tags |