KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > multiview > EjbJarMultiViewDataNode


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.ddloaders.multiview;
21
22 import java.awt.Image JavaDoc;
23 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
24 import org.netbeans.modules.xml.multiview.XmlMultiViewDataObject;
25 import org.openide.loaders.DataNode;
26 import org.openide.loaders.DataObject;
27 import org.openide.nodes.Children;
28 import org.openide.nodes.Node;
29 import org.openide.nodes.PropertySupport;
30 import org.openide.nodes.Sheet;
31 import org.openide.util.HelpCtx;
32 import org.openide.util.NbBundle;
33 import org.openide.util.Utilities;
34 import org.xml.sax.SAXException JavaDoc;
35
36 import java.beans.PropertyChangeEvent JavaDoc;
37 import java.beans.PropertyChangeListener JavaDoc;
38 import org.openide.util.NbBundle;
39
40 /**
41  * A node to represent this ejb-jar.xml object.
42  *
43  * @author pfiala
44  */

45 public class EjbJarMultiViewDataNode extends DataNode {
46     
47     private static final String JavaDoc DEPLOYMENT = "deployment"; // NOI18N
48

49     private EjbJarMultiViewDataObject dataObject;
50     
51     /**
52      * Name of property for spec version
53      */

54     public static final String JavaDoc PROPERTY_DOCUMENT_TYPE = "documentType"; // NOI18N
55

56     /**
57      * Listener on dataobject
58      */

59     private PropertyChangeListener JavaDoc ddListener;
60     
61     public EjbJarMultiViewDataNode(EjbJarMultiViewDataObject obj) {
62         this(obj, Children.LEAF);
63     }
64     
65     public EjbJarMultiViewDataNode(EjbJarMultiViewDataObject obj, Children ch) {
66         super(obj, ch);
67         dataObject = obj;
68         initListeners();
69         setIconBase(dataObject.getSaxError() == null);
70     }
71     
72     /**
73      * Initialize listening on adding/removing server so it is
74      * possible to add/remove property sheets
75      */

76     private void initListeners() {
77         ddListener = new PropertyChangeListener JavaDoc() {
78             
79             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
80                 String JavaDoc propertyName = evt.getPropertyName();
81                 Object JavaDoc oldValue = evt.getOldValue();
82                 Object JavaDoc newValue = evt.getNewValue();
83                 if (EjbJarMultiViewDataObject.PROP_DOCUMENT_DTD.equals(propertyName)) {
84                     firePropertyChange(PROPERTY_DOCUMENT_TYPE, oldValue, newValue);
85                 } else if (DataObject.PROP_VALID.equals(propertyName) && Boolean.TRUE.equals(newValue)) {
86                     removePropertyChangeListener(EjbJarMultiViewDataNode.this.ddListener);
87                 } else if (XmlMultiViewDataObject.PROP_DOCUMENT_VALID.equals(propertyName)) {
88                     setIconBase(Boolean.TRUE.equals(newValue));
89                 } else if (Node.PROP_PROPERTY_SETS.equals(propertyName)) {
90                     firePropertySetsChange(null, null);
91                 } else if (XmlMultiViewDataObject.PROP_SAX_ERROR.equals(propertyName)) {
92                     fireShortDescriptionChange((String JavaDoc) oldValue, (String JavaDoc) newValue);
93                 }
94             }
95             
96         };
97         getDataObject().addPropertyChangeListener(ddListener);
98     }
99     
100     private void setIconBase(final boolean valid) {
101         if (valid) {
102             setIconBaseWithExtension(dataObject.getIconBaseForValidDocument());
103         } else {
104             setIconBaseWithExtension(dataObject.getIconBaseForInvalidDocument());
105         }
106         fireIconChange();
107     }
108     
109     protected Sheet createSheet() {
110         Sheet s = new Sheet();
111         Sheet.Set ss = new Sheet.Set();
112         ss.setName(DEPLOYMENT);
113         ss.setDisplayName(NbBundle.getMessage(EjbJarMultiViewDataNode.class, "PROP_deploymentSet"));
114         ss.setShortDescription(NbBundle.getMessage(EjbJarMultiViewDataNode.class, "HINT_deploymentSet"));
115         ss.setValue("helpID", "TBD---Ludo ejbjar node"); // NOI18N
116

117         Property p = new PropertySupport.ReadWrite(PROPERTY_DOCUMENT_TYPE,
118                 String JavaDoc.class,
119                 NbBundle.getBundle(EjbJarMultiViewDataNode.class).getString("PROP_documentDTD"),
120                 NbBundle.getBundle(EjbJarMultiViewDataNode.class).getString("HINT_documentDTD")) {
121             public Object JavaDoc getValue() {
122                 java.math.BigDecimal JavaDoc version = dataObject.getEjbJar().getVersion();
123                 return (version == null ? "" : version.toString());
124             }
125             
126             public void setValue(Object JavaDoc value) {
127                 String JavaDoc val = (String JavaDoc) value;
128                 if (EjbJar.VERSION_2_1.equals(val) && !val.equals(dataObject.getEjbJar().getVersion().toString())) {
129                     dataObject.getEjbJar().setVersion(new java.math.BigDecimal JavaDoc(val));
130                     dataObject.modelUpdatedFromUI();
131                 }
132             }
133         };
134         ss.put(p);
135         s.put(ss);
136         
137         return s;
138     }
139     
140     public HelpCtx getHelpCtx() {
141         return HelpCtx.DEFAULT_HELP;
142     }
143     
144     public java.awt.Image JavaDoc getIcon(int type) {
145         Image JavaDoc ejbJarXmlIcon = Utilities.loadImage("org/netbeans/modules/j2ee/ddloaders/web/resources/DDDataIcon.gif"); //NOI18N
146

147         if (dataObject.getSaxError() == null){
148             return ejbJarXmlIcon;
149         }
150
151         Image JavaDoc errorBadgeIcon = Utilities.loadImage("org/netbeans/modules/j2ee/ddloaders/web/resources/error-badge.gif"); //NOI18N
152
return Utilities.mergeImages(ejbJarXmlIcon, errorBadgeIcon, 6, 6);
153     }
154     
155     void descriptionChanged(String JavaDoc oldDesc, String JavaDoc newDesc) {
156         setShortDescription(newDesc == null ? "Enterprise Bean deployment descriptor" : newDesc); //NOI18N
157
}
158     
159     public String JavaDoc getShortDescription() {
160         SAXException JavaDoc saxError = dataObject.getSaxError();
161         if (saxError==null) {
162             return Utils.getBundleMessage("HINT_ejb_dd");
163         } else {
164             return saxError.getMessage();
165         }
166     }
167 }
168
Popular Tags