KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > ui > basic > editors > AnyNamespaceEditor


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  * AnyNamespaceEditor.java
22  *
23  * Created on December 22, 2005, 12:58 PM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.modules.xml.schema.ui.basic.editors;
30
31 import java.beans.FeatureDescriptor JavaDoc;
32 import java.beans.PropertyEditorSupport JavaDoc;
33 import org.openide.explorer.propertysheet.ExPropertyEditor;
34 import org.openide.explorer.propertysheet.PropertyEnv;
35 import org.openide.util.NbBundle;
36
37 /**
38  *
39  * @author Ajit Bhate
40  *
41  */

42 public class AnyNamespaceEditor extends PropertyEditorSupport JavaDoc
43         implements ExPropertyEditor{
44         
45     /**
46      * Creates a new instance of AnyNamespaceEditor
47      */

48     public AnyNamespaceEditor() {
49     }
50     
51     public String JavaDoc[] getTags() {
52         return new String JavaDoc[] {NbBundle.getMessage(BooleanDefaultFalseEditor.class,"LBL_ANY"),
53             NbBundle.getMessage(BooleanDefaultFalseEditor.class,"LBL_Other"),
54             NbBundle.getMessage(BooleanDefaultFalseEditor.class,"LBL_TargetNamespace"),
55             NbBundle.getMessage(BooleanDefaultFalseEditor.class,"LBL_Local")};
56     }
57
58     public void setAsText(String JavaDoc text) throws IllegalArgumentException JavaDoc {
59         if (text.equalsIgnoreCase(NbBundle.getMessage(BooleanDefaultFalseEditor.class,
60                 "LBL_ANY"))){
61             setValue("##any");
62         }
63         else if (text.equalsIgnoreCase(NbBundle.getMessage(BooleanDefaultFalseEditor.class,
64                 "LBL_Other"))){
65             setValue("##other");
66         }
67         else if (text.equalsIgnoreCase(NbBundle.getMessage(BooleanDefaultFalseEditor.class,
68                 "LBL_TargetNamespace"))){
69             setValue("##targetNamespace");
70         }
71         else if (text.equalsIgnoreCase(NbBundle.getMessage(BooleanDefaultFalseEditor.class,
72                 "LBL_Local"))){
73             setValue("##local");
74         }
75         else {
76             setValue(text);
77         }
78         
79     }
80
81     public String JavaDoc getAsText() {
82         Object JavaDoc obj = getValue();
83         if (obj == null){
84             return NbBundle.getMessage(BooleanDefaultFalseEditor.class,"LBL_ANY");
85         }
86         if (obj instanceof String JavaDoc){
87             String JavaDoc val = (String JavaDoc)obj;
88             if(val.equals("##any"))
89                 return NbBundle.getMessage(BooleanDefaultFalseEditor.class,"LBL_ANY");
90             if(val.equals("##other"))
91                 return NbBundle.getMessage(BooleanDefaultFalseEditor.class,"LBL_Other");
92             if(val.equals("##targetNamespace"))
93                 return NbBundle.getMessage(BooleanDefaultFalseEditor.class,"LBL_TargetNamespace");
94             if(val.equals("##local"))
95                 return NbBundle.getMessage(BooleanDefaultFalseEditor.class,"LBL_Local");
96             return val;
97         }
98         // TODO how to display invalid values?
99
return NbBundle.getMessage(BooleanDefaultFalseEditor.class,"LBL_ANY");
100     }
101
102     /**
103      *
104      * implement ExPropertyEditor
105      *
106      */

107     public void attachEnv(PropertyEnv env ) {
108         FeatureDescriptor JavaDoc desc = env.getFeatureDescriptor();
109         // make this an editable combo tagged editor
110
desc.setValue("canEditAsText", Boolean.TRUE); // NOI18N
111
}
112 }
113
Popular Tags