1 19 20 package org.netbeans.modules.xml.schema.ui.nodes.categorized; 21 22 import java.util.Collections ; 23 import java.util.List ; 24 import org.netbeans.modules.xml.schema.model.Import; 25 import org.netbeans.modules.xml.schema.ui.nodes.ReadOnlyCookie; 26 import org.netbeans.modules.xml.xam.locator.CatalogModelException; 27 import org.openide.nodes.AbstractNode; 28 import org.openide.nodes.Children; 29 import org.openide.nodes.Node; 30 import org.openide.util.NbBundle; 31 import org.netbeans.modules.xml.schema.model.SchemaComponentReference; 32 import org.netbeans.modules.xml.schema.model.SchemaModel; 33 import org.netbeans.modules.xml.schema.model.SchemaModelReference; 34 import org.netbeans.modules.xml.schema.ui.nodes.SchemaUIContext; 35 import org.netbeans.modules.xml.xam.Model; 36 37 41 public class ReferencedSchemaModelChildren<C extends SchemaModelReference> 42 extends CategorizedChildren<C> 43 { 44 48 public ReferencedSchemaModelChildren(SchemaUIContext context, 49 SchemaComponentReference<C> reference) 50 { 51 super(context,reference); 52 } 53 54 55 @Override 56 protected void removeNotify() 57 { 58 setKeys(Collections.emptyList()); 59 } 60 61 @Override 62 protected void addNotify() 63 { 64 Children.MUTEX.postWriteRequest(new Runnable () 65 { 66 public void run() 67 { 68 setKeys(createKeys()); 69 } 70 }); 71 } 72 73 @Override 74 public void refreshChildren() 75 { 76 Children.MUTEX.postWriteRequest(new Runnable () 77 { 78 public void run() 79 { 80 setKeys(createKeys()); 81 } 82 }); 83 } 84 85 86 90 protected List <Node> createKeys() 91 { 92 List <Node> keys=super.createKeys(); 93 94 ReadOnlyCookie roc = (ReadOnlyCookie) getContext().getLookup().lookup( 96 ReadOnlyCookie.class); 97 if(roc!=null && roc.isReadOnly()) return keys; 98 99 C component = getReference().get(); 100 if(component instanceof Import && 101 component.getModel()!=getContext().getModel()) 102 return keys; 103 SchemaModel refModel; 104 try 105 { 106 refModel = component.resolveReferencedModel(); 107 } catch (CatalogModelException ex) 108 { 109 refModel = null; 110 } 111 if (refModel != null && refModel.getState() != Model.State.NOT_WELL_FORMED) 112 { 113 Node refNode = getContext().getFactory().createNode(refModel.getSchema()); 114 Node dummyNode = new DummySchemaNode(refNode); 115 for(Node child:dummyNode.getChildren().getNodes()) 116 { 117 keys.add(new ReadOnlySchemaComponentNode(child)); 118 } 119 } 120 else 121 { 122 AbstractNode node=new AbstractNode(Children.LEAF); 123 node.setIconBaseWithExtension( 124 "org/netbeans/modules/xml/schema/core/resources/Schema_File.png"); node.setDisplayName( 126 NbBundle.getMessage(ReferencedSchemaModelChildren.class, 127 "LBL_BrokenReference")); keys.add(node); 129 } 130 return keys; 131 } 132 } 133 | Popular Tags |