KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > netbeans > module > WSDLSettings


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.wsdl.ui.netbeans.module;
21
22 import java.io.IOException JavaDoc;
23 import java.io.ObjectInput JavaDoc;
24 import org.openide.util.HelpCtx;
25 import org.openide.util.NbBundle;
26 import org.openide.util.NbPreferences;
27
28 /**
29  * Manages the WSDL editor options.
30  *
31  * @author Nathan Fiedler
32  */

33 public class WSDLSettings {
34     /** Singleton instance of SchemaSettings */
35     private static WSDLSettings INSTANCE = new WSDLSettings();
36     /** Name of the connection timeout setting. */
37     public static final String JavaDoc PROP_VIEW_MODE = "viewMode";
38
39     /**
40      * The view mode of the editor (e.g. tree, column).
41      */

42     public static enum ViewMode {
43         TREE, COLUMN
44     };
45
46     public String JavaDoc displayName() {
47         return NbBundle.getMessage(WSDLSettings.class,
48                 "CTL_WSDLSettings_name");
49     }
50
51     private WSDLSettings() {
52         setDefaults();
53     }
54     
55     /**
56      * Returns the single instance of this class.
57      *
58      * @return the instance.
59      */

60     public static WSDLSettings getDefault() {
61         return INSTANCE;
62     }
63
64     public HelpCtx getHelpCtx() {
65         return HelpCtx.DEFAULT_HELP;
66     }
67
68     /**
69      * Retrieves the view mode value.
70      *
71      * @return view mode.
72      */

73     public ViewMode getViewMode() {
74         String JavaDoc mode = (String JavaDoc) getProperty(PROP_VIEW_MODE);
75         if(mode == null)
76             return ViewMode.COLUMN;
77         
78         return ViewMode.valueOf(mode);
79     }
80
81     public void readExternal(ObjectInput JavaDoc in) throws
82             IOException JavaDoc, ClassNotFoundException JavaDoc {
83         //super.readExternal(in);
84
// Upgrade the restored instance to include the latest settings.
85
setDefaults();
86     }
87
88     /**
89      * For those properties that have null values, set them to the default.
90      */

91     private void setDefaults() {
92         if (getProperty(PROP_VIEW_MODE) == null) {
93             putProperty(PROP_VIEW_MODE, ViewMode.TREE.toString());
94         }
95     }
96
97     /**
98      * Sets the view mode value.
99      *
100      * @param mode new view mode value.
101      */

102     public void setViewMode(ViewMode mode) {
103         // Store the enum as a String.
104
putProperty(PROP_VIEW_MODE, mode.toString());
105     }
106     
107     protected final String JavaDoc putProperty(String JavaDoc key, String JavaDoc value) {
108         String JavaDoc retval = NbPreferences.forModule(WSDLSettings.class).get(key, null);
109         if (value != null) {
110             NbPreferences.forModule(WSDLSettings.class).put(key, value);
111         } else {
112             NbPreferences.forModule(WSDLSettings.class).remove(key);
113         }
114         return retval;
115     }
116     
117     protected final String JavaDoc getProperty(String JavaDoc key) {
118         return NbPreferences.forModule(WSDLSettings.class).get(key, ViewMode.TREE.toString());
119     }
120 }
121
Popular Tags