KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > ui > nodes > schema > WhitespaceNode


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.schema.ui.nodes.schema;
21
22 import java.beans.PropertyEditorSupport JavaDoc;
23 import java.util.MissingResourceException JavaDoc;
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 /**
34  *
35  * @author Todd Fast, todd.fast@sun.com
36  */

37 public class WhitespaceNode extends SchemaComponentNode<Whitespace>
38 {
39     private static final String JavaDoc NAME = "whitespace";
40
41     /**
42      *
43      *
44      */

45     public WhitespaceNode(SchemaUIContext context,
46         SchemaComponentReference<Whitespace> reference,
47         Children children)
48     {
49         super(context,reference,children);
50     }
51
52
53     /**
54      *
55      *
56      */

57     @Override JavaDoc
58     public String JavaDoc getTypeDisplayName()
59     {
60         return NbBundle.getMessage(WhitespaceNode.class,
61             "LBL_WhitespaceNode_TypeDisplayName"); // NOI18N
62
}
63     
64     
65         @Override JavaDoc
66         protected Sheet createSheet() {
67             Sheet sheet = super.createSheet();
68             Sheet.Set set = sheet.get(Sheet.PROPERTIES);
69             try {
70                 //fixed property
71
Property fixedProp = new BooleanProperty(
72                         getReference().get(), // schema component
73
Whitespace.FIXED_PROPERTY, // property name
74
NbBundle.getMessage(WhitespaceNode.class,"PROP_Facet_Fixed_DisplayName"), // display name
75
NbBundle.getMessage(WhitespaceNode.class,"PROP_Facet_Fixed_ShortDescription"), // descr
76
true // default value is false
77
);
78                 set.put(new SchemaModelFlushWrapper(getReference().get(), fixedProp));
79
80                 //value property
81
Property valueProp = new BaseSchemaProperty(
82                         getReference().get(), // schema component
83
Whitespace.Treatment.class, // value type
84
Whitespace.VALUE_PROPERTY, // property name
85
NbBundle.getMessage(WhitespaceNode.class,"PROP_Whitespace_Value_DisplayName"), // display name
86
NbBundle.getMessage(WhitespaceNode.class,"PROP_Whitespace_Value_ShortDescription"), // descr
87
WhitespaceValueEditor.class // editor class
88
){
89                             public boolean supportsDefaultValue() { // does not support default
90
return false;
91                             }
92                 };
93                 set.put(new SchemaModelFlushWrapper(getReference().get(), valueProp));
94             } catch (NoSuchMethodException JavaDoc nsme) {
95                 assert false : "properties should be defined";
96             }
97             return sheet;
98         }
99         
100         public static class WhitespaceValueEditor extends PropertyEditorSupport JavaDoc {
101             
102             /**
103              * Creates a new instance of ProcessContentsEditor
104              */

105             public WhitespaceValueEditor() {
106             }
107             
108             public String JavaDoc[] getTags() {
109                 return new String JavaDoc[] {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 JavaDoc text) throws IllegalArgumentException JavaDoc {
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 JavaDoc getAsText() {
125                 Object JavaDoc 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                 // This should never happen
136
return NbBundle.getMessage(WhitespaceNode.class,"LBL_Empty");
137             }
138         }
139 }
140
Popular Tags