001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.j2ee.sun.share.config;
042:
043: import java.beans.PropertyEditor;
044: import java.beans.PropertyEditorSupport;
045: import java.awt.Component;
046: import java.awt.event.ActionListener;
047: import javax.swing.JComponent;
048: import javax.swing.KeyStroke;
049: import org.netbeans.modules.j2ee.sun.dd.api.ASDDVersion;
050:
051: import org.openide.explorer.propertysheet.ExPropertyEditor;
052: import org.openide.explorer.propertysheet.InplaceEditor;
053: import org.openide.explorer.propertysheet.PropertyEnv;
054:
055: /** Custom Editor for version of server specific Deployment Descriptor
056: *
057: * This class badly needs to be merged/refactored into/with ASDDVersion. Too
058: * much duplication and maintenance. In particular, a VersionEditor that directly
059: * used ASDDVersion objects instead of converting them to/from strings would be
060: * infinitely better, but no time to research how to write such a beast right now.
061: *
062: * @author Peter Williams
063: */
064: public class VersionEditor extends PropertyEditorSupport implements
065: ExPropertyEditor, InplaceEditor.Factory {
066:
067: /** Used for min/max version constructor. Min version is whatever is required
068: * by the J2EE module in question (e.g. Servlet 2.4 requires 8.0 and newer).
069: * Max version is whatever the connected or installed server is (e.g. if 8.1
070: * is the installed server, 9.0 should not be a valid choice and if the file
071: * on disk that is loaded is 9.0, it should be downgraded w/ warning.)
072: */
073: public static final int APP_SERVER_7_0 = 0;
074: // public static final int APP_SERVER_7_1 = 1;
075: public static final int APP_SERVER_8_0 = 1;
076: public static final int APP_SERVER_8_1 = 2;
077: public static final int APP_SERVER_9_0 = 3;
078:
079: private String curr_Sel;
080: private String[] choices;
081:
082: public VersionEditor(final int minVersion, final int maxVersion) {
083: assert minVersion >= APP_SERVER_7_0
084: && minVersion <= APP_SERVER_9_0;
085: assert maxVersion >= APP_SERVER_7_0
086: && maxVersion <= APP_SERVER_9_0;
087: assert minVersion <= maxVersion;
088:
089: int numChoices = maxVersion - minVersion + 1;
090: curr_Sel = ASDDVersion.asDDVersions[APP_SERVER_8_1].toString();
091: choices = new String[numChoices];
092: for (int i = 0; i < numChoices; i++) {
093: choices[i] = ASDDVersion.asDDVersions[minVersion + i]
094: .toString();
095: }
096: }
097:
098: public String getAsText() {
099: return curr_Sel;
100: }
101:
102: public void setAsText(String string)
103: throws IllegalArgumentException {
104: if ((string == null) || (string.equals(""))) { // NOI18N
105: throw new IllegalArgumentException(
106: "text field cannot be empty"); // NOI18N
107: } else {
108: curr_Sel = string;
109: }
110: this .firePropertyChange();
111: }
112:
113: public void setValue(Object val) {
114: if (!(val instanceof String)) {
115: throw new IllegalArgumentException("value must be String"); // NOI18N
116: }
117:
118: curr_Sel = (String) val;
119: super .setValue(curr_Sel);
120: }
121:
122: public Object getValue() {
123: return curr_Sel;
124: }
125:
126: public String getJavaInitializationString() {
127: return getAsText();
128: }
129:
130: public String[] getTags() {
131: return choices;
132: }
133:
134: /** -----------------------------------------------------------------------
135: * Implementation of ExPropertyEditor interface
136: */
137: public void attachEnv(PropertyEnv env) {
138: env.registerInplaceEditorFactory(this );
139: }
140:
141: /** -----------------------------------------------------------------------
142: * Implementation of InplaceEditor.Factory interface
143: */
144: public InplaceEditor getInplaceEditor() {
145: return null;
146: }
147:
148: /** Convert ASDDVersion into one of the int types in this editor.
149: */
150: static int fromASDDVersion(ASDDVersion asDDVersion) {
151: int result = APP_SERVER_8_1;
152:
153: if (ASDDVersion.SUN_APPSERVER_7_0.equals(asDDVersion)) {
154: result = APP_SERVER_7_0;
155: // } else if(ASDDVersion.SUN_APPSERVER_7_1.equals(asDDVersion)) {
156: // result = APP_SERVER_7_1;
157: } else if (ASDDVersion.SUN_APPSERVER_8_0.equals(asDDVersion)) {
158: result = APP_SERVER_8_0;
159: } else if (ASDDVersion.SUN_APPSERVER_8_1.equals(asDDVersion)) {
160: result = APP_SERVER_8_1;
161: } else if (ASDDVersion.SUN_APPSERVER_9_0.equals(asDDVersion)) {
162: result = APP_SERVER_9_0;
163: } else {
164: throw new IllegalArgumentException(
165: "Unrecognized appserver version: " + asDDVersion);
166: }
167:
168: return result;
169: }
170: }
|