1 19 20 package org.netbeans.modules.xml.schema.ui.nodes; 21 import java.util.ArrayList ; 22 import java.util.List ; 23 import org.netbeans.modules.xml.schema.model.SchemaComponent; 24 import org.netbeans.modules.xml.schema.model.SchemaComponentReference; 25 import org.openide.nodes.Children; 26 import org.openide.nodes.Node; 27 28 37 public class SchemaComponentNodeChildren<T extends SchemaComponent> 38 extends RefreshableChildren 39 { 40 44 public SchemaComponentNodeChildren(SchemaUIContext context, 45 SchemaComponentReference<T> reference) 46 { 47 super(); 48 this.context=context; 49 this.reference=reference; 50 } 51 52 53 57 public SchemaUIContext getContext() 58 { 59 return context; 60 } 61 62 63 67 public SchemaComponentReference<T> getReference() 68 { 69 return reference; 70 } 71 72 73 77 @Override 78 protected void addNotify() 79 { 80 super.addNotify(); 81 refreshChildren(); 83 } 84 85 86 90 @Override 91 protected void removeNotify() 92 { 93 super.removeNotify(); 94 super.nodes.clear(); 95 refresh(); 96 } 98 99 100 104 @Override 105 public void refreshChildren() 106 { 107 T parentComponent=getReference().get(); 108 109 setKeys(parentComponent.getChildren()); 117 } 118 119 120 124 @Override 125 protected Node[] createNodes(Object key) 126 { 127 Node[] result=null; 128 129 assert key==null || key instanceof SchemaComponent: 130 "Key was not a SchemaComponent (key = \""+ 131 key+"\", class = "+key.getClass()+")"; 132 133 if (key instanceof SchemaComponent) 134 { 135 Node node=createChildNode(SchemaComponent.class.cast(key)); 136 if (node!=null) 137 result=new Node[] { node }; 138 } 139 140 return result; 141 } 142 143 144 149 protected <C extends SchemaComponent> Node createChildNode( 150 SchemaComponent component) 151 { 152 Node result=getContext().getFactory().createNode(component); 153 return result; 154 } 155 156 169 189 190 191 192 196 private SchemaUIContext context; 197 private SchemaComponentReference<T> reference; 198 } 200 | Popular Tags |