KickJava   Java API By Example, From Geeks To Geeks.

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


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
20 package org.netbeans.modules.j2ee.sun.share.config;
21
22 import java.lang.reflect.InvocationTargetException JavaDoc;
23
24 import javax.enterprise.deploy.spi.exceptions.ConfigurationException JavaDoc;
25
26 import org.openide.ErrorManager;
27 import org.openide.cookies.OpenCookie;
28 import org.openide.cookies.EditCookie;
29 import org.openide.loaders.DataNode;
30 import org.openide.nodes.Children;
31 import org.openide.nodes.PropertySupport;
32 import org.openide.nodes.Sheet;
33 import org.openide.util.NbBundle;
34
35 import org.netbeans.modules.j2ee.sun.share.configbean.ASDDVersion;
36 import org.netbeans.modules.j2ee.sun.share.configbean.SunONEDeploymentConfiguration;
37
38
39 /** Simple node to represent a deployment plan file.
40  * @author Pavel Buzek
41  */

42 public class ConfigDataNode extends DataNode {
43
44     private ConfigDataObject dataObject;
45     
46     public ConfigDataNode (ConfigDataObject obj) {
47         this (obj, Children.LEAF);
48         this.dataObject = obj;
49     }
50
51     public ConfigDataNode (ConfigDataObject obj, Children ch) {
52         super (obj, ch);
53         setIconBaseWithExtension("org/netbeans/modules/j2ee/sun/share/config/ui/resources/ConfigFile.gif"); // NOI18N
54
}
55
56
57     public void destroy() throws java.io.IOException JavaDoc {
58         this.dataObject = null;
59         super.destroy();
60     }
61
62     // Support for appserver version property
63
protected org.openide.nodes.Sheet createSheet() {
64         Sheet sheet = super.createSheet();
65         Sheet.Set ss = new Sheet.Set();
66
67         ss.setName("deploymentdescriptor"); // NOI18N
68
ss.setDisplayName(NbBundle.getBundle(ConfigDataNode.class).getString("LBL_ConfigPropertiesName")); // NOI18N
69
ss.setShortDescription(NbBundle.getBundle(ConfigDataNode.class).getString("LBL_ConfigPropertiesDescription")); // NOI18N
70
ss.put(new VersionProperty());
71
72         sheet.put(ss);
73         return sheet;
74     }
75     
76     /** Property to allow editing of the version of the deployment descriptor file.
77      * e.g. from 2.4.0 to 2.4.1 (SJSAS 8.0 -> SJSAS 8.1), etc.
78      */

79     private final class VersionProperty extends PropertySupport {
80         
81         public VersionProperty() {
82             super("DDVersion" /*NOI18N*/, VersionEditor.class,
83                 NbBundle.getBundle(ConfigDataNode.class).getString("LBL_ConfigVersionPropertyName"), // NOI18N
84
NbBundle.getBundle(ConfigDataNode.class).getString("LBL_ConfigVersionPropertyDescription"), // NOI18N
85
true, false);
86         }
87
88         public Object JavaDoc getValue() throws IllegalAccessException JavaDoc, InvocationTargetException JavaDoc {
89             String JavaDoc result = ASDDVersion.SUN_APPSERVER_8_1.toString();
90             
91             try {
92                 SunONEDeploymentConfiguration config = dataObject.getDeploymentConfiguration();
93                 result = config.getAppServerVersion().toString();
94             } catch(ConfigurationException JavaDoc ex) {
95                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
96             }
97             
98             return result;
99         }
100
101         public void setValue(Object JavaDoc val) throws IllegalAccessException JavaDoc, IllegalArgumentException JavaDoc, InvocationTargetException JavaDoc {
102             if(val instanceof String JavaDoc) {
103                 try {
104                     ASDDVersion asDDVersion = ASDDVersion.getASDDVersion((String JavaDoc) val);
105                     SunONEDeploymentConfiguration config = dataObject.getDeploymentConfiguration();
106                     config.setAppServerVersion(asDDVersion);
107                 } catch(ConfigurationException JavaDoc ex) {
108                     ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
109                 }
110             } else {
111                 throw new IllegalArgumentException JavaDoc("value must be non null and type String"); // NOI18N
112
}
113         }
114
115         public java.beans.PropertyEditor JavaDoc getPropertyEditor() {
116             VersionEditor result = null;
117             
118             try {
119                 SunONEDeploymentConfiguration config = dataObject.getDeploymentConfiguration();
120                 int minAS = VersionEditor.fromASDDVersion(config.getMinASVersion());
121                 int maxAS = VersionEditor.fromASDDVersion(config.getMaxASVersion());
122                 result = new VersionEditor(minAS, maxAS);
123             } catch (ConfigurationException JavaDoc ex) {
124                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
125             }
126         
127             return result;
128         }
129
130         public boolean canWrite() {
131             // If we can open either the configuration editor or the XML text editor
132
// then neither editor is open (they are exclusive). If neither editor
133
// is open, then this field is editable.
134
return dataObject.getCookie(OpenCookie.class) != null &&
135                 dataObject.getCookie(EditCookie.class) != null;
136         }
137
138         public boolean canRead() {
139             return true;
140         }
141
142     }
143 }
144
Popular Tags