1 19 20 package org.netbeans.modules.xml.schema.abe.nodes; 21 22 import java.util.ArrayList ; 23 import java.util.Collections ; 24 import java.util.List ; 25 import org.netbeans.modules.xml.axi.AXIComponent; 26 import org.netbeans.modules.xml.axi.AXIDocument; 27 import org.netbeans.modules.xml.axi.AXIModel; 28 import org.netbeans.modules.xml.axi.Attribute; 29 import org.netbeans.modules.xml.axi.ContentModel; 30 import org.netbeans.modules.xml.axi.Element; 31 import org.netbeans.modules.xml.axi.datatype.CustomDatatype; 32 import org.netbeans.modules.xml.axi.datatype.Datatype; 33 import org.netbeans.modules.xml.xam.ComponentEvent; 34 import org.netbeans.modules.xml.xam.ComponentListener; 35 import org.openide.nodes.Children; 36 import org.openide.nodes.Node; 37 38 42 public class CategorizedChildren extends Children.Keys 43 implements ComponentListener { 44 private ABEUIContext context; 45 private AXIDocument document; 46 private List <Class > childFilters; 47 48 49 public CategorizedChildren(ABEUIContext context, AXIDocument document, 50 List <Class > childFilters) { 51 this.context = context; 52 this.document = document; 53 this.childFilters = childFilters; 54 } 55 56 60 private boolean isChildAllowed(Class componentClass) { 61 if (getChildFilters()==null) 63 return true; 64 65 for (Class clazz: getChildFilters()) { 66 if (clazz.isAssignableFrom(componentClass)) 67 return true; 68 } 69 70 return false; 71 } 72 73 77 protected java.util.List <Node> createKeys() { 78 List <Node> keys=new ArrayList <Node>(); 79 80 if(document instanceof AXIDocument) { 82 if(isChildAllowed(Datatype.class)) 83 keys.add(new PrimitiveSimpleTypesNode(getContext())); 84 if(isChildAllowed(ContentModel.class)) 85 keys.add(new GlobalContentModelsNode(getContext(), document)); 86 if(isChildAllowed(CustomDatatype.class)) 87 keys.add(new SimpleTypesNode(getContext(), document)); 88 if(isChildAllowed(Attribute.class)) 89 keys.add(new GlobalAttributesNode(getContext(), document)); 90 if(isChildAllowed(Element.class)) 91 keys.add(new GlobalElementsNode(getContext(), document)); 92 List <AXIModel> refModels = getContext().getModel(). 93 getReferencedModels(); 94 if(refModels != null && refModels.size() != 0) { 95 keys.add(new ReferencedSchemasNode(getContext(), 96 document, childFilters)); 97 } 98 } else { 99 for (AXIComponent child: document.getChildren()) { 101 Node node=getContext().getFactory().createNode(getNode(), child); 102 keys.add(node); 103 } 104 } 105 106 return keys; 107 } 108 109 113 @Override 114 protected Node[] createNodes(Object key) { 115 Node[] result=null; 116 117 if (key instanceof Node) 118 result=new Node[] { (Node)key }; 119 120 return result; 121 } 122 123 private ABEUIContext getContext() { 124 return context; 125 } 126 127 private void refreshChildren() { 128 setKeys(createKeys()); 129 } 130 131 protected void addNotify() { 132 super.addNotify(); 133 refreshChildren(); 134 } 139 140 protected void removeNotify() { 141 super.removeNotify(); 142 setKeys(Collections.emptyList()); 143 } 144 145 public void valueChanged(ComponentEvent evt) { 146 } 147 148 public void childrenDeleted(ComponentEvent evt) { 149 if (evt.getSource() == document) { 150 refreshChildren(); 151 } 152 } 153 154 public void childrenAdded(ComponentEvent evt) { 155 if (evt.getSource() == document) { 156 refreshChildren(); 157 } 158 } 159 160 private List <Class > getChildFilters() { 161 return childFilters; 162 } 163 } 164 | Popular Tags |