KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > client > ClientDataNode


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.client;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import org.openide.util.NbBundle;
25 import org.netbeans.modules.xml.multiview.XmlMultiViewDataObject;
26 import org.openide.loaders.DataNode;
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
33 /** A node to represent this ejb-jar.xml object.
34  *
35  * @author Ludovic Champenois
36  * @version 1.0
37  */

38 public class ClientDataNode extends DataNode {
39     
40     private static final String JavaDoc DEPLOYMENT = "deployment"; // NOI18N
41
private static final java.awt.Image JavaDoc ERROR_BADGE =
42         org.openide.util.Utilities.loadImage( "org/netbeans/modules/j2ee/ddloaders/client/error-badge.gif" ); //NOI18N
43
private static final java.awt.Image JavaDoc CLIETN_XML =
44         org.openide.util.Utilities.loadImage( "org/netbeans/modules/j2ee/ddloaders/client/DDDataIcon.gif" ); //NOI18N
45

46     private ClientDataObject dataObject;
47    
48     /** Name of property for spec version */
49     public static final String JavaDoc PROPERTY_DOCUMENT_TYPE = "documentType"; // NOI18N
50

51     /** Listener on dataobject */
52     private PropertyChangeListener JavaDoc ddListener;
53     
54     public ClientDataNode (ClientDataObject obj) {
55         this (obj, Children.LEAF);
56     }
57
58     public ClientDataNode (ClientDataObject obj, Children ch) {
59         super (obj, ch);
60         dataObject=obj;
61         initListeners();
62     }
63
64     /** Initialize listening on adding/removing server so it is
65      * possible to add/remove property sheets
66      */

67     private void initListeners(){
68         ddListener = new PropertyChangeListener JavaDoc () {
69             
70             public void propertyChange (PropertyChangeEvent JavaDoc evt) {
71                 String JavaDoc propertyName = evt.getPropertyName ();
72                 Object JavaDoc newValue = evt.getNewValue ();
73                 Object JavaDoc oldValue = evt.getOldValue ();
74                 if (ClientDataObject.PROP_DOCUMENT_DTD.equals (propertyName)) {
75                     firePropertyChange (PROPERTY_DOCUMENT_TYPE, oldValue, newValue);
76                 }
77                 if (ClientDataObject.PROP_VALID.equals (propertyName)
78                 && Boolean.TRUE.equals (newValue)) {
79                     removePropertyChangeListener (ClientDataNode.this.ddListener);
80                 }
81                 if (Node.PROP_PROPERTY_SETS.equals (propertyName)) {
82                     firePropertySetsChange(null,null);
83                 }
84                 if (XmlMultiViewDataObject.PROP_SAX_ERROR.equals(propertyName)) {
85                     fireShortDescriptionChange((String JavaDoc) oldValue, (String JavaDoc) newValue);
86                 }
87             }
88             
89         };
90         getDataObject ().addPropertyChangeListener (ddListener);
91     }
92     
93     private ClientDataObject getDDDataObject () {
94         return (ClientDataObject) getDataObject ();
95     }
96    
97     protected Sheet createSheet () {
98         Sheet s = super.createSheet();
99         Sheet.Set ss = s.get(Sheet.PROPERTIES);
100
101         Node.Property p = new PropertySupport.ReadOnly (
102             PROPERTY_DOCUMENT_TYPE,
103             String JavaDoc.class,
104             NbBundle.getBundle(ClientDataNode.class).getString("PROP_documentDTD"),
105             NbBundle.getBundle(ClientDataNode.class).getString("HINT_documentDTD")
106         ) {
107             public Object JavaDoc getValue () {
108                 return dataObject.getAppClient().getVersion();
109             }
110         };
111         ss.put (p);
112         s.put (ss);
113         
114         return s;
115     }
116     
117     public HelpCtx getHelpCtx() {
118         return new HelpCtx("TBD application-client.xml file");//NOI18N
119
}
120
121     void iconChanged() {
122         fireIconChange();
123     }
124
125     public java.awt.Image JavaDoc getIcon(int type) {
126         if (dataObject.getSaxError()==null)
127             return CLIETN_XML;
128         else
129             return org.openide.util.Utilities.mergeImages(CLIETN_XML, ERROR_BADGE, 6, 6);
130     }
131     
132     public String JavaDoc getShortDescription() {
133         org.xml.sax.SAXException JavaDoc saxError = dataObject.getSaxError();
134         if (saxError==null) {
135             return NbBundle.getBundle(ClientDataNode.class).getString("HINT_web_dd");
136         } else {
137             return saxError.getMessage();
138         }
139     }
140
141 }
142
Popular Tags