KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > config > VersionEditor


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.j2ee.sun.share.config;
20
21 import java.beans.PropertyEditor JavaDoc;
22 import java.beans.PropertyEditorSupport JavaDoc;
23 import java.awt.Component JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import javax.swing.JComponent JavaDoc;
26 import javax.swing.KeyStroke JavaDoc;
27 import org.netbeans.modules.j2ee.sun.share.configbean.ASDDVersion;
28
29 import org.openide.explorer.propertysheet.ExPropertyEditor;
30 import org.openide.explorer.propertysheet.InplaceEditor;
31 import org.openide.explorer.propertysheet.PropertyEnv;
32
33
34 /** Custom Editor for version of server specific Deployment Descriptor
35  *
36  * This class badly needs to be merged/refactored into/with ASDDVersion. Too
37  * much duplication and maintenance. In particular, a VersionEditor that directly
38  * used ASDDVersion objects instead of converting them to/from strings would be
39  * infinitely better, but no time to research how to write such a beast right now.
40  *
41  * @author Peter Williams
42  */

43 public class VersionEditor extends PropertyEditorSupport JavaDoc implements ExPropertyEditor, InplaceEditor.Factory {
44
45     /** Used for min/max version constructor. Min version is whatever is required
46      * by the J2EE module in question (e.g. Servlet 2.4 requires 8.0 and newer).
47      * Max version is whatever the connected or installed server is (e.g. if 8.1
48      * is the installed server, 9.0 should not be a valid choice and if the file
49      * on disk that is loaded is 9.0, it should be downgraded w/ warning.)
50      */

51     public static final int APP_SERVER_7_0 = 0;
52 // public static final int APP_SERVER_7_1 = 1;
53
public static final int APP_SERVER_8_0 = 1;
54     public static final int APP_SERVER_8_1 = 2;
55     public static final int APP_SERVER_9_0 = 3;
56     
57     private String JavaDoc curr_Sel;
58     private String JavaDoc [] choices;
59     
60     public VersionEditor(final int minVersion, final int maxVersion) {
61         assert minVersion >= APP_SERVER_7_0 && minVersion <= APP_SERVER_9_0;
62         assert maxVersion >= APP_SERVER_7_0 && maxVersion <= APP_SERVER_9_0;
63         assert minVersion <= maxVersion;
64         
65         int numChoices = maxVersion - minVersion + 1;
66         curr_Sel = ASDDVersion.asDDVersions[APP_SERVER_8_1].toString();
67         choices = new String JavaDoc[numChoices];
68         for(int i = 0; i < numChoices; i++) {
69             choices[i] = ASDDVersion.asDDVersions[minVersion + i].toString();
70         }
71     }
72     
73     public String JavaDoc getAsText() {
74         return curr_Sel;
75     }
76     
77     public void setAsText(String JavaDoc string) throws IllegalArgumentException JavaDoc {
78         if((string == null) || (string.equals(""))) { // NOI18N
79
throw new IllegalArgumentException JavaDoc("text field cannot be empty"); // NOI18N
80
} else {
81             curr_Sel = string;
82         }
83         this.firePropertyChange();
84     }
85     
86     public void setValue(Object JavaDoc val) {
87         if (! (val instanceof String JavaDoc)) {
88             throw new IllegalArgumentException JavaDoc("value must be String"); // NOI18N
89
}
90         
91         curr_Sel = (String JavaDoc) val;
92         super.setValue(curr_Sel);
93     }
94     
95     public Object JavaDoc getValue() {
96         return curr_Sel;
97     }
98     
99     public String JavaDoc getJavaInitializationString() {
100         return getAsText();
101     }
102     
103     public String JavaDoc[] getTags() {
104         return choices;
105     }
106     
107     /** -----------------------------------------------------------------------
108      * Implementation of ExPropertyEditor interface
109      */

110     public void attachEnv(PropertyEnv env) {
111         env.registerInplaceEditorFactory(this);
112     }
113
114     /** -----------------------------------------------------------------------
115      * Implementation of InplaceEditor.Factory interface
116      */

117     public InplaceEditor getInplaceEditor() {
118         return null;
119     }
120
121     /** Convert ASDDVersion into one of the int types in this editor.
122      */

123     static int fromASDDVersion(ASDDVersion asDDVersion) {
124         int result = APP_SERVER_8_1;
125         
126         if(ASDDVersion.SUN_APPSERVER_7_0.equals(asDDVersion)) {
127             result = APP_SERVER_7_0;
128 // } else if(ASDDVersion.SUN_APPSERVER_7_1.equals(asDDVersion)) {
129
// result = APP_SERVER_7_1;
130
} else if(ASDDVersion.SUN_APPSERVER_8_0.equals(asDDVersion)) {
131             result = APP_SERVER_8_0;
132         } else if(ASDDVersion.SUN_APPSERVER_8_1.equals(asDDVersion)) {
133             result = APP_SERVER_8_1;
134         } else if(ASDDVersion.SUN_APPSERVER_9_0.equals(asDDVersion)) {
135             result = APP_SERVER_9_0;
136         } else {
137             throw new IllegalArgumentException JavaDoc("Unrecognized appserver version: " + asDDVersion);
138         }
139         
140         return result;
141     }
142 }
143
Popular Tags