1 19 20 package org.netbeans.modules.apisupport.beanbrowser; 21 22 import java.awt.Container ; 23 import java.awt.event.ContainerEvent ; 24 import java.awt.event.ContainerListener ; 25 import java.util.Collections ; 26 import org.openide.nodes.Children; 27 import org.openide.nodes.Node; 28 29 30 public class ContainerKids extends Children.Keys { 31 32 private Container container; 33 private ContainerListener containerListener = null; 34 35 public ContainerKids(Container container) { 36 this.container = container; 37 } 38 39 protected void addNotify() { 40 updateKeys(); 41 if (containerListener == null) { 42 containerListener = new ContainerListener () { 43 public void componentAdded(ContainerEvent ev) { 44 updateKeys(); 45 } 46 public void componentRemoved(ContainerEvent ev) { 47 updateKeys(); 48 } 49 }; 50 container.addContainerListener(containerListener); 51 } 52 } 53 54 protected void removeNotify() { 55 if (containerListener != null) { 56 container.removeContainerListener(containerListener); 57 containerListener = null; 58 } 59 setKeys(Collections.EMPTY_SET); 60 } 61 62 private void updateKeys() { 63 setKeys(container.getComponents()); 64 } 65 66 protected Node[] createNodes(Object key) { 67 return new Node[] { PropSetKids.makeObjectNode(key) }; 68 } 69 70 } 71 | Popular Tags |