1 19 20 package org.netbeans.modules.xml.schema.ui.nodes.schema; 21 22 import java.beans.PropertyEditorSupport ; 23 import java.util.MissingResourceException ; 24 import org.netbeans.modules.xml.schema.model.Whitespace; 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.BooleanProperty; 29 import org.openide.nodes.Children; 30 import org.openide.nodes.Node.Property; 31 import org.openide.nodes.Sheet; 32 import org.openide.util.NbBundle; 33 37 public class WhitespaceNode extends SchemaComponentNode<Whitespace> 38 { 39 private static final String NAME = "whitespace"; 40 41 45 public WhitespaceNode(SchemaUIContext context, 46 SchemaComponentReference<Whitespace> reference, 47 Children children) 48 { 49 super(context,reference,children); 50 } 51 52 53 57 @Override 58 public String getTypeDisplayName() 59 { 60 return NbBundle.getMessage(WhitespaceNode.class, 61 "LBL_WhitespaceNode_TypeDisplayName"); } 63 64 65 @Override 66 protected Sheet createSheet() { 67 Sheet sheet = super.createSheet(); 68 Sheet.Set set = sheet.get(Sheet.PROPERTIES); 69 try { 70 Property fixedProp = new BooleanProperty( 72 getReference().get(), Whitespace.FIXED_PROPERTY, NbBundle.getMessage(WhitespaceNode.class,"PROP_Facet_Fixed_DisplayName"), NbBundle.getMessage(WhitespaceNode.class,"PROP_Facet_Fixed_ShortDescription"), true ); 78 set.put(new SchemaModelFlushWrapper(getReference().get(), fixedProp)); 79 80 Property valueProp = new BaseSchemaProperty( 82 getReference().get(), Whitespace.Treatment.class, Whitespace.VALUE_PROPERTY, NbBundle.getMessage(WhitespaceNode.class,"PROP_Whitespace_Value_DisplayName"), NbBundle.getMessage(WhitespaceNode.class,"PROP_Whitespace_Value_ShortDescription"), WhitespaceValueEditor.class ){ 89 public boolean supportsDefaultValue() { return false; 91 } 92 }; 93 set.put(new SchemaModelFlushWrapper(getReference().get(), valueProp)); 94 } catch (NoSuchMethodException nsme) { 95 assert false : "properties should be defined"; 96 } 97 return sheet; 98 } 99 100 public static class WhitespaceValueEditor extends PropertyEditorSupport { 101 102 105 public WhitespaceValueEditor() { 106 } 107 108 public String [] getTags() { 109 return new String [] {NbBundle.getMessage(WhitespaceNode.class,"LBL_WhitespacePreserve"), 110 NbBundle.getMessage(WhitespaceNode.class,"LBL_WhitespaceReplace"), 111 NbBundle.getMessage(WhitespaceNode.class,"LBL_WhitespaceCollapse")}; 112 } 113 114 public void setAsText(String text) throws IllegalArgumentException { 115 if (text.equals(NbBundle.getMessage(WhitespaceNode.class,"LBL_WhitespacePreserve"))){ 116 setValue(Whitespace.Treatment.PRESERVE); 117 } else if (text.equals(NbBundle.getMessage(WhitespaceNode.class,"LBL_WhitespaceReplace"))){ 118 setValue(Whitespace.Treatment.REPLACE); 119 } else if (text.equals(NbBundle.getMessage(WhitespaceNode.class,"LBL_WhitespaceCollapse"))){ 120 setValue(Whitespace.Treatment.COLLAPSE); 121 } 122 } 123 124 public String getAsText() { 125 Object val = getValue(); 126 if (val instanceof Whitespace.Treatment){ 127 if (Whitespace.Treatment.PRESERVE.equals(val)) { 128 return NbBundle.getMessage(WhitespaceNode.class,"LBL_WhitespacePreserve"); 129 } else if (Whitespace.Treatment.REPLACE.equals(val)) { 130 return NbBundle.getMessage(WhitespaceNode.class,"LBL_WhitespaceReplace"); 131 } else if (Whitespace.Treatment.COLLAPSE.equals(val)) { 132 return NbBundle.getMessage(WhitespaceNode.class,"LBL_WhitespaceCollapse"); 133 } 134 } 135 return NbBundle.getMessage(WhitespaceNode.class,"LBL_Empty"); 137 } 138 } 139 } 140 | Popular Tags |