1 19 20 28 29 package org.netbeans.modules.xml.schema.abe.nodes; 30 31 import java.beans.PropertyEditorSupport ; 32 import java.util.ArrayList ; 33 import java.util.List ; 34 import org.netbeans.modules.xml.axi.AXIType; 35 import org.netbeans.modules.xml.axi.AbstractAttribute; 36 import org.netbeans.modules.xml.axi.AnyAttribute; 37 import org.netbeans.modules.xml.axi.Attribute; 38 import org.netbeans.modules.xml.axi.Element; 39 import org.netbeans.modules.xml.axi.datatype.Datatype; 40 import org.netbeans.modules.xml.schema.abe.InstanceUIContext; 41 import org.netbeans.modules.xml.schema.abe.StartTagPanel; 42 import org.netbeans.modules.xml.schema.abe.UIUtilities; 43 import org.netbeans.modules.xml.schema.abe.nodes.properties.BaseABENodeProperty; 44 import org.netbeans.modules.xml.schema.abe.nodes.properties.DefaultProperty; 45 import org.netbeans.modules.xml.schema.abe.nodes.properties.FixedProperty; 46 import org.netbeans.modules.xml.schema.abe.nodes.properties.FormPropertyEditor; 47 import org.netbeans.modules.xml.schema.abe.nodes.properties.GlobalReferenceProperty; 48 import org.netbeans.modules.xml.schema.abe.nodes.properties.NameProperty; 49 import org.netbeans.modules.xml.schema.model.Form; 50 import org.netbeans.modules.xml.schema.model.Attribute.Use; 51 import org.openide.nodes.Node; 52 import org.openide.nodes.PropertySupport; 53 import org.openide.nodes.Sheet; 54 import org.openide.util.NbBundle; 55 56 60 public class AttributeNode extends ABEAbstractNode { 61 62 63 66 public AttributeNode(AbstractAttribute attribute, InstanceUIContext context) { 67 super(attribute, context); 68 } 69 70 71 public AttributeNode(AbstractAttribute attribute) { 72 super(attribute, new ABENodeChildren(attribute)); 73 setIconBaseWithExtension( 74 "org/netbeans/modules/xml/schema/abe/resources/attribute.png"); 75 76 } 77 protected void populateProperties(Sheet sheet) { 78 if(getAXIComponent() instanceof AnyAttribute) 79 return; 81 Sheet.Set set = sheet.get(Sheet.PROPERTIES); 82 if(set == null) { 83 set = sheet.createPropertiesSet(); 84 } 85 86 boolean shared = false; 87 shared = getAXIComponent().isShared(); 88 boolean reference = false; 89 if(getAXIComponent() instanceof Attribute) 90 reference = ((Attribute)getAXIComponent()).isReference(); 91 92 Sheet.Set sharedSheet = null; 93 if(shared || reference){ 94 sharedSheet = getSharedSet(sheet); 96 }else{ 97 sharedSheet = set; 99 } 100 101 if(shared && ! reference){ 102 set = sharedSheet; 104 } 105 106 107 try { 108 Node.Property name = new NameProperty( 110 this, 111 String .class, 112 Attribute.PROP_NAME, 113 NbBundle.getMessage(AttributeNode.class, "PROP_AttributeNode_Name"), 114 NbBundle.getMessage(AttributeNode.class, "PROP_AttributeNode_NameDesc")); 115 sharedSheet.put(name); 116 117 Node.Property fixedProp = new FixedProperty( 119 getAXIComponent(), 120 NbBundle.getMessage(AttributeNode.class,"PROP_Fixed_DisplayName"), NbBundle.getMessage(AttributeNode.class,"PROP_Fixed_ShortDescription") ); 123 set.put(new SchemaModelFlushWrapper(getAXIComponent(),fixedProp, getContext())); 124 125 Node.Property defaultProp = new DefaultProperty( 127 getAXIComponent(), 128 NbBundle.getMessage(AttributeNode.class,"PROP_Default_DisplayName"), NbBundle.getMessage(AttributeNode.class,"PROP_Default_ShortDescription") ); 131 set.put(new SchemaModelFlushWrapper(getAXIComponent(),defaultProp, getContext())); 132 133 Node.Property useProp = new BaseABENodeProperty( 135 getAXIComponent(), 136 Use.class, Attribute.PROP_USE, NbBundle.getMessage(AttributeNode.class,"PROP_Use_DisplayName"), NbBundle.getMessage(AttributeNode.class,"PROP_Use_ShortDescription"), UseEditor.class 141 ); 142 set.put(new SchemaModelFlushWrapper(getAXIComponent(),useProp, getContext())); 143 144 Node.Property formProp = new BaseABENodeProperty( 146 getAXIComponent(), 147 Form.class, Attribute.PROP_FORM, NbBundle.getMessage(AttributeNode.class,"PROP_Form_DisplayName"), NbBundle.getMessage(AttributeNode.class,"PROP_Form_ElementShortDescription"), FormPropertyEditor.class 152 ); 153 set.put(new SchemaModelFlushWrapper(getAXIComponent(),formProp, getContext())); 154 155 List <Class > filterTypes = new ArrayList <Class >(); 157 filterTypes.add(Datatype.class); 158 filterTypes.add(Attribute.class); 159 Node.Property typeProp = new GlobalReferenceProperty( 160 getAXIComponent(), 161 Attribute.PROP_TYPE, 162 NbBundle.getMessage(AttributeNode.class, 163 "PROP_Type_DisplayName"), NbBundle.getMessage(AttributeNode.class, 165 "HINT_Type_ShortDesc"), NbBundle.getMessage(AttributeNode.class, 167 "LBL_AttributeNode_TypeDisplayName"), NbBundle.getMessage(AttributeNode.class, 169 "LBL_ContentModelNode_TypeDisplayName"), 170 AXIType.class, 171 filterTypes 172 ); 173 if(!getAXIComponent().isReadOnly()) 174 sharedSheet.put(new SchemaModelFlushWrapper(getAXIComponent(), typeProp, getContext())); 175 176 } catch (Exception ex) { 177 ex.printStackTrace(); 178 } 179 180 if(shared && !reference){ 181 sheet.put(set); 183 }else if(shared && reference){ 184 sheet.put(set); 186 sheet.put(sharedSheet); 187 }else{ 188 sheet.put(set); 189 } 190 } 191 192 public String getName(){ 193 if((AbstractAttribute) super.getAXIComponent() != null) 194 return ((AbstractAttribute) super.getAXIComponent()).getName(); 195 else 196 return ""; 197 } 198 199 protected String getTypeDisplayName() { 200 return NbBundle.getMessage(AttributeNode.class,"LBL_Attribute"); 201 } 202 203 public static class UseEditor extends PropertyEditorSupport { 204 205 208 public UseEditor() { 209 } 210 211 public String [] getTags() { 212 return new String [] {NbBundle.getMessage(AttributeNode.class,"LBL_Empty"), 213 NbBundle.getMessage(AttributeNode.class,"LBL_Prohibited"), 214 NbBundle.getMessage(AttributeNode.class,"LBL_Optional"), 215 NbBundle.getMessage(AttributeNode.class,"LBL_Required")}; 216 } 217 218 public void setAsText(String text) throws IllegalArgumentException { 219 if (text.equals(NbBundle.getMessage(AttributeNode.class,"LBL_Empty"))){ 220 setValue(null); 221 } else if (text.equals(NbBundle.getMessage(AttributeNode.class,"LBL_Prohibited"))){ 222 setValue(Use.PROHIBITED); 223 } else if (text.equals(NbBundle.getMessage(AttributeNode.class,"LBL_Optional"))){ 224 setValue(Use.OPTIONAL); 225 } else if (text.equals(NbBundle.getMessage(AttributeNode.class,"LBL_Required"))){ 226 setValue(Use.REQUIRED); 227 } 228 } 229 230 public String getAsText() { 231 Object val = getValue(); 232 if (val instanceof Use){ 233 if (Use.PROHIBITED.equals(val)) { 234 return NbBundle.getMessage(AttributeNode.class,"LBL_Prohibited"); 235 } else if (Use.OPTIONAL.equals(val)) { 236 return NbBundle.getMessage(AttributeNode.class,"LBL_Optional"); 237 } else if (Use.REQUIRED.equals(val)) { 238 return NbBundle.getMessage(AttributeNode.class,"LBL_Required"); 239 } 240 } 241 return NbBundle.getMessage(AttributeNode.class,"LBL_Empty"); 243 } 244 } 245 } 246 | Popular Tags |