KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > app > EarDataNode


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.app;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.List JavaDoc;
26 import javax.swing.Action JavaDoc;
27 import org.openide.actions.OpenAction;
28 import org.openide.loaders.DataNode;
29 import org.openide.loaders.DataObject;
30 import org.openide.nodes.Children;
31 import org.openide.nodes.Node;
32 import org.openide.nodes.PropertySupport;
33 import org.openide.nodes.Sheet;
34 import org.openide.util.HelpCtx;
35 import org.openide.util.NbBundle;
36
37 /**
38  * A node to represent this ejb-jar.xml object.
39  *
40  * @author Ludovic Champenois
41  * @version 1.0
42  */

43 public final class EarDataNode extends DataNode {
44     
45     private static final String JavaDoc DEPLOYMENT="deployment"; // NOI18N
46

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

52     /** Listener on dataobject */
53     private PropertyChangeListener JavaDoc ddListener;
54
55     private Action JavaDoc[] filteredActions;
56     
57     public EarDataNode (EarDataObject obj) {
58         this (obj, Children.LEAF);
59     }
60
61     public EarDataNode (EarDataObject obj, Children ch) {
62         super (obj, ch);
63         dataObject=obj;
64         setIconBaseWithExtension(dataObject.getIconBaseForValidDocument());
65         initListeners();
66     }
67
68     /**
69      * <strong>Note:</strong> Temporary fix for #77261. Remove when MultiView
70      * editor is implemented for Enterprise Application deployment descriptor.
71      */

72     public Action JavaDoc[] getActions(boolean context) {
73         if (filteredActions == null) {
74             Action JavaDoc[] origActions = super.getActions(context);
75             List JavaDoc/*<Action>*/ actions = new ArrayList JavaDoc/*<Action>*/();
76             for (int i = 0; i < origActions.length; i++) {
77                 if (!(origActions[i] instanceof OpenAction)) {
78                     actions.add(origActions[i]);
79                 }
80             }
81             filteredActions = (Action JavaDoc[]) actions.toArray(new Action JavaDoc[actions.size()]);
82         }
83         return filteredActions;
84     }
85     
86     /** Initialize listening on adding/removing server so it is
87      * possible to add/remove property sheets
88      */

89     private void initListeners(){
90         ddListener = new PropertyChangeListener JavaDoc () {
91             
92             public void propertyChange (PropertyChangeEvent JavaDoc evt) {
93                 if (EarDataObject.PROP_DOCUMENT_DTD.equals (evt.getPropertyName ())) {
94                     firePropertyChange (PROPERTY_DOCUMENT_TYPE, evt.getOldValue (), evt.getNewValue ());
95                 }
96                 if (DataObject.PROP_VALID.equals (evt.getPropertyName ())
97                 && Boolean.TRUE.equals (evt.getNewValue ())) {
98                     removePropertyChangeListener (EarDataNode.this.ddListener);
99                 }
100                 if (EarDataObject.PROP_DOC_VALID.equals (evt.getPropertyName ())) {
101                     if (Boolean.TRUE.equals (evt.getNewValue ()))
102                         setIconBaseWithExtension(dataObject.getIconBaseForValidDocument());
103                     else
104                         setIconBaseWithExtension(dataObject.getIconBaseForInvalidDocument());
105                 }
106                 if (Node.PROP_PROPERTY_SETS.equals (evt.getPropertyName ())) {
107                     firePropertySetsChange(null,null);
108                 }
109             }
110             
111         };
112         getDataObject ().addPropertyChangeListener (ddListener);
113     }
114     
115     protected Sheet createSheet () {
116         Sheet s = new Sheet ();
117         Sheet.Set ss = new Sheet.Set ();
118         ss.setName (DEPLOYMENT);
119         ss.setDisplayName (NbBundle.getMessage (EarDataNode.class, "PROP_deploymentSet"));
120         ss.setShortDescription (NbBundle.getMessage (EarDataNode.class, "HINT_deploymentSet"));
121         ss.setValue ("helpID", "TBD---Ludo ejbjar node"); // NOI18N
122

123         Node.Property p = new PropertySupport.ReadOnly (
124             PROPERTY_DOCUMENT_TYPE,
125             String JavaDoc.class,
126             NbBundle.getBundle(EarDataNode.class).getString("PROP_documentDTD"),
127             NbBundle.getBundle(EarDataNode.class).getString("HINT_documentDTD")
128         ) {
129             public Object JavaDoc getValue () {
130                 return dataObject.getApplication().getVersion();
131             }
132         };
133         ss.put (p);
134         s.put (ss);
135         
136         return s;
137     }
138     
139     public HelpCtx getHelpCtx() {
140         return new HelpCtx("TBD ejbjar file");//NOI18N
141
}
142     
143 }
144
Popular Tags