KickJava   Java API By Example, From Geeks To Geeks.

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


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 /*
21  * AdvancedEnumerationProperty.java
22  *
23  * Created on April 19, 2006, 11:53 AM
24  *
25  */

26
27 package org.netbeans.modules.xml.schema.ui.nodes.schema.properties;
28
29 import java.awt.Dialog JavaDoc;
30 import java.beans.FeatureDescriptor JavaDoc;
31 import java.beans.PropertyEditor JavaDoc;
32 import java.beans.PropertyEditorSupport JavaDoc;
33 import java.util.Collection JavaDoc;
34 import org.netbeans.modules.xml.schema.model.Enumeration;
35 import org.netbeans.modules.xml.schema.model.SchemaComponentReference;
36 import org.netbeans.modules.xml.schema.model.SimpleRestriction;
37 import org.netbeans.modules.xml.schema.ui.basic.UIUtilities;
38 import org.netbeans.modules.xml.schema.ui.nodes.categorized.customizer.EnumerationCustomizer;
39 import org.openide.DialogDescriptor;
40 import org.openide.DialogDisplayer;
41 import org.openide.explorer.propertysheet.ExPropertyEditor;
42 import org.openide.explorer.propertysheet.PropertyEnv;
43
44 /**
45  *
46  * @author Ajit Bhate
47  */

48 public class AdvancedEnumerationProperty extends BaseSchemaProperty
49 {
50
51     private boolean editable;
52     /** Creates a new instance of AdvancedEnumerationProperty */
53     public AdvancedEnumerationProperty(SimpleRestriction component,
54             String JavaDoc property,
55             String JavaDoc propDispName,
56             String JavaDoc propDesc,
57             boolean editable)
58             throws NoSuchMethodException JavaDoc
59     {
60         super(component,
61                 Collection JavaDoc.class,
62                 SimpleRestriction.class.getMethod(BaseSchemaProperty.
63                 firstLetterToUpperCase(property, "get"), new Class JavaDoc[0]),
64                 null,
65                 property,propDispName,propDesc,null);
66         this.editable = editable;
67     }
68     
69     public PropertyEditor JavaDoc getPropertyEditor()
70     {
71         return new EnumEditor((SimpleRestriction) getComponent(),
72                 getName(), canWrite());
73     }
74
75     @Override JavaDoc
76     public boolean canWrite()
77     {
78         if(editable) return super.canWrite();
79         return false;
80     }
81
82     @Override JavaDoc
83     public boolean supportsDefaultValue()
84     {
85         return false;
86     }
87
88     public static class EnumEditor
89             extends PropertyEditorSupport JavaDoc implements ExPropertyEditor
90     {
91         private SimpleRestriction sr;
92         private String JavaDoc name;
93         private boolean editable;
94         public EnumEditor(SimpleRestriction sr, String JavaDoc name, boolean editable)
95         {
96             this.sr = sr;
97             this.name = name;
98             this.editable = editable;
99         }
100         public boolean supportsCustomEditor()
101         {
102             return true;
103         }
104         
105         public java.awt.Component JavaDoc getCustomEditor()
106         {
107             DialogDescriptor descriptor = UIUtilities.getCustomizerDialog(new
108                     EnumerationCustomizer<SimpleRestriction>(
109                     SchemaComponentReference.create(sr)), name,editable);
110             Dialog JavaDoc dlg = DialogDisplayer.getDefault().createDialog(descriptor);
111             return dlg;
112         }
113         
114         public void attachEnv(PropertyEnv env)
115         {
116             FeatureDescriptor JavaDoc desc = env.getFeatureDescriptor();
117             desc.setValue("canEditAsText", Boolean.FALSE); // NOI18N
118
}
119
120         public String JavaDoc getAsText()
121         {
122             StringBuffer JavaDoc retValue = new StringBuffer JavaDoc();
123             Object JavaDoc obj = super.getValue();
124             if(obj instanceof Collection JavaDoc)
125             {
126                 Collection JavaDoc enums = (Collection JavaDoc)obj;
127                 boolean first = true;
128                 for(Object JavaDoc e:enums)
129                 {
130                     if(e instanceof Enumeration)
131                     {
132                         if(first)
133                             first = false;
134                         else
135                             retValue.append(", ");
136                         retValue.append(((Enumeration)e).getValue());
137                     }
138                 }
139             }
140             return retValue.toString();
141         }
142         
143     }
144 }
145
Popular Tags