1 19 20 package org.netbeans.modules.xml.schema.abe.nodes; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyEditorSupport ; 24 import org.netbeans.modules.xml.axi.Compositor; 25 import org.netbeans.modules.xml.axi.Compositor.CompositorType; 26 import org.netbeans.modules.xml.schema.abe.CompositorPanel; 27 import org.netbeans.modules.xml.schema.abe.InstanceUIContext; 28 import org.netbeans.modules.xml.schema.abe.nodes.properties.*; 29 import org.openide.nodes.Node; 30 import org.openide.nodes.Node.Property; 31 import org.openide.nodes.Sheet; 32 import org.openide.util.NbBundle; 33 34 38 public class CompositorNode extends ABEAbstractNode { 39 40 41 44 public CompositorNode(Compositor compositor, InstanceUIContext context) { 45 super(compositor, context); 46 } 47 48 public CompositorNode(Compositor compositor) { 49 super(compositor, new ABENodeChildren(compositor)); 50 CompositorType type = compositor.getType(); 51 switch (type) { 52 case ALL: { 53 setIconBaseWithExtension( 54 "org/netbeans/modules/xml/schema/abe/resources/all.png"); 55 break; 56 } 57 case CHOICE: { 58 setIconBaseWithExtension( 59 "org/netbeans/modules/xml/schema/abe/resources/choice.png"); 60 break; 61 } 62 case SEQUENCE: { 63 setIconBaseWithExtension( 64 "org/netbeans/modules/xml/schema/abe/resources/sequence.png"); 65 break; 66 } 67 default : 68 assert false; 69 } 70 } 71 72 73 public void propertyChange(PropertyChangeEvent evt) { 74 if ( (evt.getSource() == getAXIComponent()) && 75 evt.getPropertyName().equals(Compositor.PROP_TYPE)) { 76 Object oldValue = evt.getOldValue(); 77 String oldDisplayName = oldValue == null ? null : oldValue.toString(); 78 fireDisplayNameChange(oldDisplayName, getDisplayName()); 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 try { 89 Node.Property useProp = new BaseABENodeProperty( 91 getAXIComponent(), 92 CompositorType.class, "type", NbBundle.getMessage(CompositorNode.class,"PROP_CompositorNode_Name"), NbBundle.getMessage(CompositorNode.class,"PROP_CompositorNode_NameDesc"), CompositorTypeEditor.class 97 ); 98 set.put(new SchemaModelFlushWrapper(getAXIComponent(),useProp, getContext()){ 99 public java.beans.PropertyEditor getPropertyEditor() { 100 java.beans.PropertyEditor ped = super.getPropertyEditor(); 101 if(ped instanceof CompositorNode.CompositorTypeEditor){ 102 ((CompositorNode.CompositorTypeEditor)ped).setCompositor((Compositor)getAXIComponent()); 103 } 104 return ped; 105 } 106 }); 107 108 if(getAXIComponent().supportsCardinality()) { 109 Property minOccursProp = new MinOccursProperty( 111 getAXIComponent(), 112 String .class, 113 Compositor.PROP_MINOCCURS, 114 NbBundle.getMessage(CompositorNode.class,"PROP_MinOccurs_DisplayName"), NbBundle.getMessage(CompositorNode.class,"PROP_MinOccurs_ShortDescription") ); 117 set.put(new SchemaModelFlushWrapper(getAXIComponent(), minOccursProp, getContext())); 118 119 if (((Compositor)getAXIComponent()).allowsFullMultiplicity()) { 121 Property maxOccursProp = new BaseABENodeProperty( 122 getAXIComponent(), 123 String .class, 124 Compositor.PROP_MAXOCCURS, 125 NbBundle.getMessage(CompositorNode.class,"PROP_MaxOccurs_DisplayName"), NbBundle.getMessage(CompositorNode.class,"PROP_MaxOccurs_ShortDescription"), MaxOccursEditor.class 128 ); 129 set.put(new SchemaModelFlushWrapper(getAXIComponent(), maxOccursProp, getContext())); 130 } 131 } 132 } catch (Exception ex) { 133 } 134 135 sheet.put(set); 136 } 137 138 public String getName(){ 139 if((Compositor) super.getAXIComponent() != null && 140 ((Compositor) super.getAXIComponent()).getType() != null) 141 return ((Compositor) super.getAXIComponent()).getType().getName(); 142 else 143 return ""; 144 } 145 146 protected String getTypeDisplayName() { 147 return NbBundle.getMessage(AttributeNode.class,"LBL_Compositor"); 148 } 149 150 151 public static class CompositorTypeEditor extends PropertyEditorSupport { 152 153 156 Compositor comp; 157 public CompositorTypeEditor() { 158 } 159 160 public String [] getTags() { 161 166 CompositorType[] types = CompositorPanel.filterAllIfNeeded(comp); 167 String ret[] = new String [types.length]; 168 for(int i = 0; i<types.length; i++) 169 ret[i] = types[i].getName(); 170 return ret; 171 172 } 173 174 public void setAsText(String text) throws IllegalArgumentException { 175 if (text.equals(Compositor.CompositorType.SEQUENCE.getName())){ 176 setValue(CompositorType.SEQUENCE); 177 } else if (text.equals(Compositor.CompositorType.CHOICE.getName())){ 178 setValue(CompositorType.CHOICE); 179 } else if (text.equals(Compositor.CompositorType.ALL.getName())){ 180 setValue(CompositorType.ALL); 181 } 182 } 183 184 public void setCompositor(Compositor comp){ 185 this.comp = comp; 186 } 187 188 189 public Object getValue(){ 190 return super.getValue(); 191 } 192 193 public void setValue(Object obj){ 194 super.setValue(obj); 195 } 196 197 public void setSource(Object obj){ 198 super.setSource(obj); 199 } 200 public String getAsText() { 201 Object val = getValue(); 202 if (val instanceof CompositorType){ 203 return val.toString(); 204 } 205 return NbBundle.getMessage(CompositorNode.class,"LBL_Empty"); 207 } 208 209 } 210 } 211 | Popular Tags |