1 2 20 21 package org.netbeans.modules.xml.schema.abe.nodes; 22 23 import java.beans.PropertyChangeEvent ; 24 import java.beans.PropertyChangeListener ; 25 import java.util.ArrayList ; 26 import java.util.List ; 27 import org.netbeans.modules.xml.axi.AXIContainer; 28 import org.netbeans.modules.xml.axi.AXIType; 29 import org.netbeans.modules.xml.axi.AbstractElement; 30 import org.netbeans.modules.xml.axi.Compositor; 31 import org.netbeans.modules.xml.axi.ContentModel; 32 import org.netbeans.modules.xml.axi.Element; 33 import org.netbeans.modules.xml.axi.datatype.Datatype; 34 import org.netbeans.modules.xml.schema.abe.InstanceUIContext; 35 import org.netbeans.modules.xml.schema.abe.action.AttributeOnElementNewType; 36 import org.netbeans.modules.xml.schema.abe.action.CompositorOnElementNewType; 37 import org.netbeans.modules.xml.schema.abe.action.ElementOnElementNewType; 38 import org.netbeans.modules.xml.schema.abe.nodes.properties.*; 39 import org.netbeans.modules.xml.schema.model.Form; 40 import org.openide.nodes.Node; 41 import org.openide.nodes.Node.Property; 42 import org.openide.nodes.PropertySupport; 43 import org.openide.nodes.Sheet; 44 import org.openide.util.NbBundle; 45 import org.openide.util.datatransfer.NewType; 46 47 51 public class ElementNode extends ABEAbstractNode { 52 53 54 57 public ElementNode(AbstractElement element, InstanceUIContext context) { 58 super(element, context); 59 initialize(); 60 } 61 62 public ElementNode(AbstractElement element) { 63 super(element, new ABENodeChildren(element)); 64 setIconBaseWithExtension( 65 "org/netbeans/modules/xml/schema/abe/resources/element.png"); 66 67 } 68 69 private void initialize(){ 70 getAXIComponent().addPropertyChangeListener(new PropertyChangeListener (){ 71 public void propertyChange(PropertyChangeEvent evt) { 72 if(evt.getPropertyName().equals(Element.PROP_NAME)){ 73 ElementNode.this.fireNameChange((String ) evt.getOldValue(), (String ) evt.getNewValue()); 74 ElementNode.this.firePropertySetsChange(ElementNode.this.getPropertySets(), 75 ElementNode.this.getPropertySets()); 76 } 77 } 78 79 }); 80 } 81 82 protected void populateProperties(Sheet sheet) { 83 Sheet.Set set = sheet.get(Sheet.PROPERTIES); 84 if(set == null) { 85 set = sheet.createPropertiesSet(); 86 } 87 88 boolean shared = false; 89 shared = getAXIComponent().isShared(); 90 boolean reference = false; 91 if(getAXIComponent() instanceof Element) 92 reference = ((Element)getAXIComponent()).isReference(); 93 94 Sheet.Set sharedSheet = null; 95 if(shared || reference){ 96 sharedSheet = getSharedSet(sheet); 98 }else{ 99 sharedSheet = set; 101 } 102 103 if(shared && ! reference){ 104 set = sharedSheet; 106 } 107 108 try { 109 Node.Property name = new PropertySupport.Name( 111 this, 112 NbBundle.getMessage(ElementNode.class, "PROP_ElementNode_Name"), 113 NbBundle.getMessage(ElementNode.class, "PROP_ElementNode_NameDesc") 114 ); 115 sharedSheet.put(name); 116 117 Node.Property nillableProp = new BooleanProperty( 119 getAXIComponent(), 120 Element.PROP_NILLABLE, NbBundle.getMessage(ElementNode.class,"PROP_Nillable_DisplayName"), NbBundle.getMessage(ElementNode.class,"PROP_Nillable_ShortDescription"), true ); 125 set.put(new SchemaModelFlushWrapper(getAXIComponent(),nillableProp, getContext())); 126 127 Node.Property fixedProp = new FixedProperty( 129 getAXIComponent(), 130 NbBundle.getMessage(ElementNode.class,"PROP_Fixed_DisplayName"), NbBundle.getMessage(ElementNode.class,"PROP_Fixed_ShortDescription") ); 133 set.put(new SchemaModelFlushWrapper(getAXIComponent(),fixedProp, getContext())); 134 135 Node.Property defaultProp = new DefaultProperty( 137 getAXIComponent(), 138 NbBundle.getMessage(ElementNode.class,"PROP_Default_DisplayName"), NbBundle.getMessage(ElementNode.class,"PROP_Default_ShortDescription") ); 141 set.put(new SchemaModelFlushWrapper(getAXIComponent(),defaultProp, getContext())); 142 143 if(getAXIComponent().supportsCardinality()) { 144 Node.Property minOccursProp = new MinOccursProperty( 146 getAXIComponent(), 147 String .class, 148 Element.PROP_MINOCCURS, 149 NbBundle.getMessage(ElementNode.class,"PROP_MinOccurs_DisplayName"), NbBundle.getMessage(ElementNode.class,"PROP_MinOccurs_ShortDescription") ); 152 set.put(new SchemaModelFlushWrapper(getAXIComponent(), minOccursProp, getContext())); 153 154 if (getAXIComponent() instanceof AbstractElement && 156 ((AbstractElement)getAXIComponent()).allowsFullMultiplicity()) { 157 Property maxOccursProp = new BaseABENodeProperty( 158 getAXIComponent(), 159 String .class, 160 Element.PROP_MAXOCCURS, 161 NbBundle.getMessage(ElementNode.class,"PROP_MaxOccurs_DisplayName"), NbBundle.getMessage(ElementNode.class,"PROP_MaxOccurs_ShortDescription"), MaxOccursEditor.class 164 ); 165 set.put(new SchemaModelFlushWrapper(getAXIComponent(), maxOccursProp, getContext())); 166 } 167 } 168 169 Node.Property formProp = new BaseABENodeProperty( 171 getAXIComponent(), 172 Form.class, Element.PROP_FORM, NbBundle.getMessage(ElementNode.class,"PROP_Form_DisplayName"), NbBundle.getMessage(ElementNode.class,"PROP_Form_ElementShortDescription"), FormPropertyEditor.class 177 ); 178 set.put(new SchemaModelFlushWrapper(getAXIComponent(),formProp, getContext())); 179 180 List <Class > filterTypes = new ArrayList <Class >(); 182 filterTypes.add(Datatype.class); 183 filterTypes.add(ContentModel.class); 184 filterTypes.add(Element.class); 185 Node.Property typeProp = new GlobalReferenceProperty( 186 getAXIComponent(), 187 Element.PROP_TYPE, 188 NbBundle.getMessage(ElementNode.class, 189 "PROP_Type_DisplayName"), NbBundle.getMessage(ElementNode.class, 191 "HINT_Type_ShortDesc"), NbBundle.getMessage(ElementNode.class, 193 "LBL_ElementNode_TypeDisplayName"), NbBundle.getMessage(ElementNode.class, 195 "LBL_ContentModelNode_TypeDisplayName"), 196 AXIType.class, 197 filterTypes 198 ); 199 if(!getAXIComponent().isReadOnly()) 200 sharedSheet.put(new SchemaModelFlushWrapper(getAXIComponent(), typeProp, getContext())); 201 202 } catch (Exception ex) { 203 } 204 205 if(shared && !reference){ 206 sheet.put(set); 208 }else if(shared && reference){ 209 sheet.put(set); 211 sheet.put(sharedSheet); 212 }else{ 213 sheet.put(set); 214 } 215 216 } 217 218 public String getName(){ 219 if((AbstractElement) super.getAXIComponent() != null) 220 return ((AbstractElement) super.getAXIComponent()).getName(); 221 else 222 return ""; 223 } 224 225 public NewType[] getNewTypes() { 226 if(getAXIComponent().isReadOnly()) 227 return new NewType[0]; 228 List <NewType> ntl = new ArrayList <NewType>(); 229 NewType nt = new ElementOnElementNewType(getContext()); 230 ntl.add(nt); 231 nt = new AttributeOnElementNewType(getContext()); 232 ntl.add(nt); 233 if( ((AXIContainer)getAXIComponent()).getCompositor() == null ){ 234 nt = new CompositorOnElementNewType(getContext(), Compositor. 235 CompositorType.SEQUENCE); 236 ntl.add(nt); 237 nt = new CompositorOnElementNewType(getContext(), Compositor. 238 CompositorType.CHOICE); 239 ntl.add(nt); 240 nt = new CompositorOnElementNewType(getContext(), Compositor. 241 CompositorType.ALL); 242 ntl.add(nt); 243 } 244 return ntl.toArray(new NewType[ntl.size()]); 245 } 246 247 public boolean canRename() { 248 if(canWrite()) 249 return true; 250 return false; 251 } 252 253 protected String getTypeDisplayName() { 254 return NbBundle.getMessage(AttributeNode.class,"LBL_Element"); 255 } 256 257 } 258 | Popular Tags |