1 19 20 package org.netbeans.modules.xml.schema.ui.nodes.categorized; 21 22 import java.beans.PropertyChangeEvent ; 23 import org.openide.nodes.Children; 24 import org.openide.nodes.Node; 25 import org.openide.nodes.Sheet; 26 import org.openide.nodes.Node.Property; 27 import org.openide.util.NbBundle; 28 import org.netbeans.modules.xml.xam.ComponentEvent; 29 import org.netbeans.modules.xml.axi.datatype.DatatypeFactory; 30 import org.netbeans.modules.xml.schema.model.BoundaryFacet; 31 import org.netbeans.modules.xml.schema.model.LengthFacet; 32 import org.netbeans.modules.xml.schema.model.SchemaComponent; 33 import org.netbeans.modules.xml.schema.model.GlobalSimpleType; 34 import org.netbeans.modules.xml.schema.model.SchemaComponentReference; 35 import org.netbeans.modules.xml.schema.model.SimpleTypeDefinition; 36 import org.netbeans.modules.xml.schema.model.SimpleTypeRestriction; 37 import org.netbeans.modules.xml.schema.model.List; 38 import org.netbeans.modules.xml.schema.model.Pattern; 39 import org.netbeans.modules.xml.schema.model.Whitespace; 40 import org.netbeans.modules.xml.schema.model.LocalSimpleType; 41 import org.netbeans.modules.xml.schema.model.Enumeration; 42 import org.netbeans.modules.xml.schema.ui.nodes.SchemaUIContext; 43 import org.netbeans.modules.xml.schema.ui.nodes.schema.LocalSimpleTypeNode; 44 import org.netbeans.modules.xml.schema.ui.nodes.SchemaModelFlushWrapper; 45 import org.netbeans.modules.xml.schema.ui.nodes.schema.WhitespaceNode; 46 import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.AdvancedFacetProperty; 47 import org.netbeans.modules.xml.schema.ui.nodes.schema.properties.AdvancedEnumerationProperty; 48 import org.netbeans.modules.xml.schema.ui.nodes.RefreshableChildren; 49 import org.netbeans.modules.xml.schema.ui.nodes.NewTypesFactory; 50 import org.netbeans.modules.xml.schema.ui.nodes.SchemaComponentNode; 51 import org.netbeans.modules.xml.schema.ui.nodes.categorized.customizer.SimpleTypeCustomizer; 52 import org.netbeans.modules.xml.xam.ui.customizer.Customizer; 53 import org.netbeans.modules.xml.xam.ui.customizer.CustomizerProvider; 54 55 59 public class AdvancedLocalSimpleTypeNode extends LocalSimpleTypeNode 60 { 61 65 public AdvancedLocalSimpleTypeNode(SchemaUIContext context, 66 SchemaComponentReference<LocalSimpleType> reference, 67 Children children) 68 { 69 super(context,reference,children); 70 71 } 72 73 74 @Override 75 public boolean hasCustomizer() 76 { 77 return isEditable(); 78 } 79 80 public CustomizerProvider getCustomizerProvider() 81 { 82 return new CustomizerProvider() 83 { 84 85 public Customizer getCustomizer() 86 { 87 return new SimpleTypeCustomizer<LocalSimpleType>(getReference()); 88 } 89 }; 90 } 91 92 @Override 93 protected Sheet createSheet() 94 { 95 Sheet sheet = super.createSheet(); 96 Sheet.Set set = sheet.get(Sheet.PROPERTIES); 97 LocalSimpleType lst = getReference().get(); 98 SimpleTypeDefinition typeDef = lst.getDefinition(); 99 if(typeDef instanceof SimpleTypeRestriction) 100 { 101 SimpleTypeRestriction str = (SimpleTypeRestriction)typeDef; 102 try 103 { 104 java.util.List <Class <? extends SchemaComponent>> facetTypes = 106 DatatypeFactory.getDefault(). 107 getApplicableSchemaFacets(getReference().get()); 108 for(Class <? extends SchemaComponent> facetType:facetTypes) 109 { 110 String facetTypeName = facetType.getSimpleName(); 111 if(facetType == Enumeration.class) 112 { 113 Property facetProperty = new AdvancedEnumerationProperty( 114 str, SimpleTypeRestriction.ENUMERATION_PROPERTY, 115 NbBundle.getMessage(AdvancedLocalSimpleTypeNode.class, 116 "PROP_"+facetTypeName+"_DisplayName"), NbBundle.getMessage(AdvancedLocalSimpleTypeNode.class, 118 "PROP_"+facetTypeName+"_ShortDescription"), isEditable()); 120 set.put(new SchemaModelFlushWrapper(getReference().get(), facetProperty)); 121 continue; 122 } 123 SchemaComponent facet = null; 124 java.util.List <? extends SchemaComponent> facets = 125 str.getChildren(facetType); 126 if(facets!=null && !facets.isEmpty()) facet = facets.get(0); 127 Class valueType = null; 128 String property = null; 129 Class propEditorClass = null; 130 if(BoundaryFacet.class.isAssignableFrom(facetType)) 131 { 132 valueType = String .class; 133 property = BoundaryFacet.VALUE_PROPERTY; 134 } 135 else if(LengthFacet.class.isAssignableFrom(facetType)) 136 { 137 valueType = int.class; 138 property = LengthFacet.VALUE_PROPERTY; 139 } 140 else if(Pattern.class.isAssignableFrom(facetType)) 141 { 142 valueType = String .class; 143 property = Pattern.VALUE_PROPERTY; 144 } 145 else if(Whitespace.class.isAssignableFrom(facetType)) 146 { 147 valueType = Whitespace.Treatment.class; 148 property = Whitespace.VALUE_PROPERTY; 149 propEditorClass = WhitespaceNode.WhitespaceValueEditor.class; 150 } 151 if (valueType!=null && property!=null) 152 { 153 Property facetProperty = new AdvancedFacetProperty( 154 str, facet, facetType, valueType, property, 155 NbBundle.getMessage(AdvancedLocalSimpleTypeNode.class, 156 "PROP_"+facetTypeName+"_DisplayName"), NbBundle.getMessage(AdvancedLocalSimpleTypeNode.class, 158 "PROP_"+facetTypeName+"_ShortDescription"), propEditorClass 160 ); 161 set.put(new SchemaModelFlushWrapper(getReference().get(), facetProperty)); 162 } 163 } 164 } 165 catch (NoSuchMethodException nsme) 166 { 167 assert false : "properties should be defined"; 168 } 169 } 170 return sheet; 171 } 172 173 protected NewTypesFactory getNewTypesFactory() 174 { 175 return new AdvancedNewTypesFactory(); 176 } 177 178 public void childrenDeleted(ComponentEvent evt) 179 { 180 super.childrenDeleted(evt); 181 if (isValid()) 182 { 183 Object source = evt.getSource(); 184 LocalSimpleType component = getReference().get(); 185 if (source == component.getDefinition()) 186 { 187 ((RefreshableChildren) getChildren()).refreshChildren(); 188 } 189 if (source == component || source == component.getDefinition()) 190 { 191 fireDisplayNameChange(null,getDisplayName()); 192 } 193 } 194 } 195 196 public void childrenAdded(ComponentEvent evt) 197 { 198 super.childrenAdded(evt); 199 if (isValid()) 200 { 201 Object source = evt.getSource(); 202 LocalSimpleType component = getReference().get(); 203 if (source == component.getDefinition()) 204 { 205 ((RefreshableChildren) getChildren()).refreshChildren(); 206 } 207 if(source == component || source == component.getDefinition()) 208 { 209 fireDisplayNameChange(null,getDisplayName()); 210 } 211 } 212 } 213 214 public void valueChanged(ComponentEvent evt) 215 { 216 super.valueChanged(evt); 217 if (isValid()) 218 { 219 SimpleTypeDefinition def = getReference().get().getDefinition(); 220 if(evt.getSource() == def) 221 { 222 ((RefreshableChildren) getChildren()).refreshChildren(); 223 fireDisplayNameChange(null,getDisplayName()); 224 } 225 } 226 } 227 228 public void propertyChange(PropertyChangeEvent event) 229 { 230 super.propertyChange(event); 231 if(!isValid()) return; 232 Object source = event.getSource(); 233 LocalSimpleType component = getReference().get(); 234 SimpleTypeDefinition def = component.getDefinition(); 235 if (source == component && event.getPropertyName().equals( 236 LocalSimpleType.DEFINITION_PROPERTY)) 237 { 238 updatePropertiesSet(); 239 } 240 else if(def instanceof SimpleTypeRestriction) 241 { 242 if(source==def) 243 { 244 updatePropertiesSet(); 245 } 246 else if(def.getChildren().contains(source) && event.getPropertyName(). 247 equals(BoundaryFacet.VALUE_PROPERTY)) 248 { 249 updatePropertiesSet(); 250 } 251 } 252 } 253 254 protected void updatePropertiesSet() 255 { 256 Sheet.Set oldSet = getSheet().get(Sheet.PROPERTIES); 257 if(oldSet!=null) 258 { 259 Sheet.Set newSet = createSheet().get(Sheet.PROPERTIES); 260 getSheet().put(newSet); 261 firePropertySetsChange(new Sheet.Set[]{oldSet}, new Sheet.Set[]{newSet}); 262 } 263 Node parent = getParentNode(); 264 if(parent == null) return; 265 SchemaComponentNode scn = (SchemaComponentNode) parent. 266 getCookie(SchemaComponentNode.class); 267 if(scn instanceof AdvancedLocalSimpleTypeNode) 268 { 269 ((AdvancedLocalSimpleTypeNode)scn).updatePropertiesSet(); 270 } 271 else if(scn instanceof AdvancedGlobalSimpleTypeNode) 272 { 273 ((AdvancedGlobalSimpleTypeNode)scn).updatePropertiesSet(); 274 } 275 } 276 277 public String getHtmlDisplayName() 278 { 279 GlobalSimpleType gst = getSuperDefinition(); 280 if(gst==null) return super.getHtmlDisplayName(); 281 282 String retValue = getDefaultDisplayName(); 283 SimpleTypeDefinition definition = getReference().get().getDefinition(); 284 String supertypeLabel = null; 285 286 if(definition instanceof SimpleTypeRestriction) 287 { 288 supertypeLabel = NbBundle.getMessage(AdvancedGlobalSimpleTypeNode.class, 289 "LBL_SimpleTypeChildren_RestrictionOf",gst.getName()); 290 } 291 if(definition instanceof List) 292 { 293 supertypeLabel = NbBundle.getMessage(AdvancedGlobalSimpleTypeNode.class, 294 "LBL_SimpleTypeChildren_ListOf",gst.getName()); 295 } 296 if(supertypeLabel!=null) 297 { 298 retValue = retValue+"<font color='#999999'> ("+supertypeLabel+")</font>"; 299 } 300 return applyHighlights(retValue); 301 } 302 } 303 | Popular Tags |