KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > web > DDDataNode


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.web;
21
22 import org.openide.loaders.*;
23 import org.openide.nodes.*;
24 import org.openide.util.NbBundle;
25 import java.beans.*;
26
27 import org.netbeans.modules.xml.multiview.XmlMultiViewDataObject;
28
29 /** A node to represent this object.
30  *
31  * @author mkuchtiak
32  * @version 1.0
33  */

34 public class DDDataNode extends DataNode {
35
36     private DDDataObject dataObject;
37
38     /** Name of property for spec version */
39     public static final String JavaDoc PROPERTY_DOCUMENT_TYPE = "documentType"; // NOI18N
40

41     /** Listener on dataobject */
42     private PropertyChangeListener ddListener;
43     
44     public DDDataNode (DDDataObject obj) {
45         this (obj, Children.LEAF);
46     }
47
48     public DDDataNode (DDDataObject obj, Children ch) {
49         super (obj, ch);
50         dataObject=obj;
51         initListeners();
52     }
53     
54     private static final java.awt.Image JavaDoc ERROR_BADGE =
55         org.openide.util.Utilities.loadImage( "org/netbeans/modules/j2ee/ddloaders/web/resources/error-badge.gif" ); //NOI18N
56
private static final java.awt.Image JavaDoc WEB_XML =
57         org.openide.util.Utilities.loadImage( "org/netbeans/modules/j2ee/ddloaders/web/resources/DDDataIcon.gif" ); //NOI18N
58

59     public java.awt.Image JavaDoc getIcon(int type) {
60         if (dataObject.getSaxError()==null)
61             return WEB_XML;
62         else
63             return org.openide.util.Utilities.mergeImages(WEB_XML, ERROR_BADGE, 6, 6);
64     }
65     
66     public String JavaDoc getShortDescription() {
67         org.xml.sax.SAXException JavaDoc saxError = dataObject.getSaxError();
68         if (saxError==null) {
69             return NbBundle.getBundle(DDDataNode.class).getString("HINT_web_dd");
70         } else {
71             return saxError.getMessage();
72         }
73     }
74
75     void iconChanged() {
76         fireIconChange();
77     }
78   
79     /** Initialize listening on adding/removing server so it is
80      * possible to add/remove property sheets
81      */

82     private void initListeners(){
83         ddListener = new PropertyChangeListener () {
84             
85             public void propertyChange (PropertyChangeEvent evt) {
86                 String JavaDoc propertyName = evt.getPropertyName ();
87                 Object JavaDoc newValue = evt.getNewValue ();
88                 Object JavaDoc oldValue = evt.getOldValue ();
89                 if (DDDataObject.PROP_DOCUMENT_DTD.equals (propertyName)) {
90                     firePropertyChange (PROPERTY_DOCUMENT_TYPE, oldValue, newValue);
91                 }
92                 if (DataObject.PROP_VALID.equals (propertyName)
93                 && Boolean.TRUE.equals (newValue)) {
94                     removePropertyChangeListener (DDDataNode.this.ddListener);
95                 }
96                 if (Node.PROP_PROPERTY_SETS.equals (propertyName)) {
97                     firePropertySetsChange(null,null);
98                 }
99                 if (XmlMultiViewDataObject.PROP_SAX_ERROR.equals(propertyName)) {
100                     fireShortDescriptionChange((String JavaDoc) oldValue, (String JavaDoc) newValue);
101                 }
102             }
103             
104         };
105         getDataObject ().addPropertyChangeListener (ddListener);
106     }
107
108     protected Sheet createSheet () {
109         Sheet s = super.createSheet();
110         Sheet.Set ss = s.get(Sheet.PROPERTIES);
111
112         Node.Property p = new PropertySupport.ReadOnly (
113             PROPERTY_DOCUMENT_TYPE,
114             String JavaDoc.class,
115             NbBundle.getBundle(DDDataNode.class).getString("PROP_documentDTD"),
116             NbBundle.getBundle(DDDataNode.class).getString("HINT_documentDTD")
117         ) {
118             public Object JavaDoc getValue () {
119                 return dataObject.getWebApp().getVersion();
120             }
121         };
122         ss.put (p);
123         s.put (ss);
124         
125         return s;
126     }
127     
128 }
129
Popular Tags