1 19 20 package org.netbeans.modules.xml.schema.ui.nodes.schema; 21 22 import java.beans.PropertyEditorSupport ; 23 import org.netbeans.modules.xml.schema.model.GlobalSimpleType; 24 import org.netbeans.modules.xml.schema.model.LocalAttribute; 25 import org.netbeans.modules.xml.schema.model.SchemaComponentReference; 26 import org.netbeans.modules.xml.schema.ui.nodes.*; 27 import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.BaseSchemaProperty; 28 import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.DefaultProperty; 29 import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.FixedProperty; 30 import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.FormProperty; 31 import org.openide.nodes.Children; 32 import org.openide.nodes.Node; 33 import org.openide.nodes.Sheet; 34 import org.openide.util.NbBundle; 35 39 public class LocalAttributeNode extends SchemaComponentNode<LocalAttribute> 40 { 41 45 public LocalAttributeNode(SchemaUIContext context, 46 SchemaComponentReference<LocalAttribute> reference, 47 Children children) { 48 super(context,reference,children); 49 50 setIconBaseWithExtension( 51 "org/netbeans/modules/xml/schema/ui/nodes/resources/"+ 52 "attribute.png"); 53 } 54 55 56 60 @Override 61 public String getTypeDisplayName() { 62 return NbBundle.getMessage(LocalAttributeNode.class, 63 "LBL_LocalAttributeNode_TypeDisplayName"); } 65 66 @Override 67 protected GlobalSimpleType getSuperDefinition() 68 { 69 LocalAttribute sc = getReference().get(); 70 GlobalSimpleType gt = null; 71 if(sc.getType()!=null) 72 gt = sc.getType().get(); 73 return gt; 74 } 75 76 @Override 77 protected Sheet createSheet() { 78 Sheet sheet = super.createSheet(); 79 Sheet.Set set = sheet.get(Sheet.PROPERTIES); 80 try { 81 83 Node.Property fixedProp = new FixedProperty( 85 getReference().get(), NbBundle.getMessage(LocalAttributeNode.class,"PROP_Fixed_DisplayName"), NbBundle.getMessage(LocalAttributeNode.class,"PROP_Fixed_ShortDescription") ); 89 set.put(new SchemaModelFlushWrapper(getReference().get(),fixedProp)); 90 91 Node.Property defaultProp = new DefaultProperty( 93 getReference().get(), NbBundle.getMessage(LocalAttributeNode.class,"PROP_Default_DisplayName"), NbBundle.getMessage(LocalAttributeNode.class,"PROP_Default_ShortDescription") ); 97 set.put(new SchemaModelFlushWrapper(getReference().get(),defaultProp)); 98 99 Node.Property useProp = new BaseSchemaProperty( 101 getReference().get(), LocalAttribute.Use.class, LocalAttribute.USE_PROPERTY, NbBundle.getMessage(LocalAttributeNode.class,"PROP_Use_DisplayName"), NbBundle.getMessage(LocalAttributeNode.class,"PROP_Use_ShortDescription"), UseEditor.class); 107 set.put(new SchemaModelFlushWrapper(getReference().get(),useProp)); 108 109 Node.Property formProp = new FormProperty( 111 getReference().get(), LocalAttribute.FORM_PROPERTY, NbBundle.getMessage(LocalAttributeNode.class,"PROP_Form_DisplayName"), NbBundle.getMessage(LocalAttributeNode.class,"PROP_Form_ElementShortDescription") ); 116 set.put(new SchemaModelFlushWrapper(getReference().get(),formProp)); 117 118 120 } catch (NoSuchMethodException nsme) { 121 assert false : "properties should be defined"; 122 } 123 124 return sheet; 125 } 126 127 public static class UseEditor extends PropertyEditorSupport { 128 129 132 public UseEditor() { 133 } 134 135 public String [] getTags() { 136 return new String [] {NbBundle.getMessage(LocalAttributeNode.class,"LBL_Empty"), 137 NbBundle.getMessage(LocalAttributeNode.class,"LBL_Prohibited"), 138 NbBundle.getMessage(LocalAttributeNode.class,"LBL_Optional"), 139 NbBundle.getMessage(LocalAttributeNode.class,"LBL_Required")}; 140 } 141 142 public void setAsText(String text) throws IllegalArgumentException { 143 if (text.equals(NbBundle.getMessage(LocalAttributeNode.class,"LBL_Empty"))){ 144 setValue(null); 145 } else if (text.equals(NbBundle.getMessage(LocalAttributeNode.class,"LBL_Prohibited"))){ 146 setValue(LocalAttribute.Use.PROHIBITED); 147 } else if (text.equals(NbBundle.getMessage(LocalAttributeNode.class,"LBL_Optional"))){ 148 setValue(LocalAttribute.Use.OPTIONAL); 149 } else if (text.equals(NbBundle.getMessage(LocalAttributeNode.class,"LBL_Required"))){ 150 setValue(LocalAttribute.Use.REQUIRED); 151 } 152 } 153 154 public String getAsText() { 155 Object val = getValue(); 156 if (val instanceof LocalAttribute.Use){ 157 if (LocalAttribute.Use.PROHIBITED.equals(val)) { 158 return NbBundle.getMessage(LocalAttributeNode.class,"LBL_Prohibited"); 159 } else if (LocalAttribute.Use.OPTIONAL.equals(val)) { 160 return NbBundle.getMessage(LocalAttributeNode.class,"LBL_Optional"); 161 } else if (LocalAttribute.Use.REQUIRED.equals(val)) { 162 return NbBundle.getMessage(LocalAttributeNode.class,"LBL_Required"); 163 } 164 } 165 return NbBundle.getMessage(LocalAttributeNode.class,"LBL_Empty"); 167 } 168 } 169 } 170 | Popular Tags |