KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > core > settings > DefaultActionPropertyEditor


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.xml.core.settings;
20
21 import java.beans.*;
22 import java.util.*;
23
24 import org.openide.actions.*;
25 import org.openide.util.actions.*;
26
27 /**
28  * A simple property editor allowing to select class name of default action.
29  *
30  * @author Petr Kuzel
31  */

32 public final class DefaultActionPropertyEditor extends PropertyEditorSupport {
33
34     /** Action name to its class name map */
35     private static Map name2class = new TreeMap();
36
37     static {
38         String JavaDoc dname, cname;
39         dname = SystemAction.get(EditAction.class).getName();
40         cname = EditAction.class.getName();
41         name2class.put(dname, cname);
42         
43         dname = SystemAction.get(OpenAction.class).getName();
44         cname = OpenAction.class.getName();
45         name2class.put(dname, cname);
46
47 // dname = SystemAction.get(PopupAction.class).getName();
48
// cname = PopupAction.class.getName();
49
// name2class.put(dname, cname);
50

51         dname = SystemAction.get(ViewAction.class).getName();
52         cname = ViewAction.class.getName();
53         name2class.put(dname, cname);
54         
55         //??? some more actions as check would be handy. We should define them
56
// in core as a cookie actions
57

58     }
59     
60     /** Creates new DefaultActionPropertyEditor */
61     public DefaultActionPropertyEditor() {
62     }
63     
64     /**
65      * @return display names of suitable actions
66      */

67     public String JavaDoc[] getTags() {
68         Set names = name2class.keySet();
69         return (String JavaDoc[]) names.toArray(new String JavaDoc[names.size()]);
70     }
71     
72     public void setAsText(String JavaDoc action) {
73         String JavaDoc klass = (String JavaDoc) name2class.get(action);
74         if (klass != null) {
75             setValue(klass);
76         } else {
77             setValue(null); // we could findout whether it is not an action defined by class name
78
// it is a feature for experienced users that will be implemented by request
79
}
80     }
81
82     /**
83      * Represent propery value as a text.
84      */

85     public String JavaDoc getAsText() {
86         String JavaDoc className = (String JavaDoc) getValue();
87         if (className == null) {
88             return Util.THIS.getString("PROP_system_default_action");
89         } else {
90             Iterator it = name2class.keySet().iterator();
91             while (it.hasNext()) {
92                 String JavaDoc key = (String JavaDoc) it.next();
93                 String JavaDoc next = (String JavaDoc) name2class.get(key);
94                 if (next == null) continue;
95                 if (next.equals(className)) return key;
96             }
97             return className; // for diagnostics purposes
98
}
99     }
100     
101     public boolean supportsEditingTaggedValues () {
102         return false;
103     }
104     
105     public boolean hasInPlaceCustomEditor () {
106         return false;
107     }
108
109     public boolean isPaintable() {
110         return false;
111     }
112 }
113
Popular Tags