KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > web > multiview > ReferencesMultiViewElement


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.multiview;
21
22 import org.netbeans.core.spi.multiview.*;
23 import org.openide.nodes.*;
24 import org.netbeans.modules.j2ee.dd.api.web.*;
25 import org.netbeans.modules.j2ee.ddloaders.web.*;
26 import org.netbeans.modules.xml.multiview.ui.*;
27 import org.netbeans.modules.xml.multiview.ToolBarMultiViewElement;
28 import org.netbeans.modules.xml.multiview.Error;
29 import org.openide.util.NbBundle;
30 import org.openide.util.RequestProcessor;
31 import org.openide.util.HelpCtx;
32
33 /** ResourcesMultiViewElement.java - Multi View Element for Resources :
34  * - env-entries
35  * - resource-refs
36  * - resource-env-refs
37  * - ejb-refs
38  * - message-destination-refs
39  *
40  * Created on April 11, 2005
41  * @author mkuchtiak
42  */

43 public class ReferencesMultiViewElement extends ToolBarMultiViewElement implements java.beans.PropertyChangeListener JavaDoc {
44     private SectionView view;
45     private ToolBarDesignEditor comp;
46     private DDDataObject dObj;
47     private WebApp webApp;
48     private ReferencesFactory factory;
49     private javax.swing.Action JavaDoc addAction, removeAction;
50     private boolean needInit=true;
51     private int index;
52     private RequestProcessor.Task repaintingTask;
53     private static final String JavaDoc REFERENCES_MV_ID=DDDataObject.DD_MULTIVIEW_PREFIX+DDDataObject.MULTIVIEW_REFERENCES;
54     private static final String JavaDoc HELP_ID_PREFIX=DDDataObject.HELP_ID_PREFIX_REFERENCES;
55     
56     /** Creates a new instance of DDMultiViewElement */
57     public ReferencesMultiViewElement(final DDDataObject dObj, int index) {
58         super(dObj);
59         this.dObj=dObj;
60         this.index=index;
61         comp = new ToolBarDesignEditor();
62         factory = new ReferencesFactory(comp, dObj);
63         setVisualEditor(comp);
64         repaintingTask = RequestProcessor.getDefault().create(new Runnable JavaDoc() {
65             public void run() {
66                 javax.swing.SwingUtilities.invokeLater(new Runnable JavaDoc() {
67                     public void run() {
68                         repaintView();
69                     }
70                 });
71             }
72         });
73     }
74     
75     public SectionView getSectionView() {
76         return view;
77     }
78     
79     public void componentShowing() {
80         super.componentShowing();
81         dObj.setLastOpenView(index);
82         if (needInit || !dObj.isDocumentParseable()) {
83             repaintView();
84             needInit=false;
85         }
86     }
87     
88     private void repaintView() {
89         webApp = dObj.getWebApp();
90         view = new ReferencesView(webApp);
91         comp.setContentView(view);
92         Object JavaDoc lastActive = comp.getLastActive();
93         if (lastActive!=null) {
94             ((SectionView)view).openPanel(lastActive);
95         } else {
96             ReferencesView referencesView = (ReferencesView)view;
97             Node initialNode = referencesView.getResRefsNode();
98             Children ch = initialNode.getChildren();
99             if (ch.getNodesCount()>0)
100                 initialNode = ch.getNodes()[0];
101             referencesView.selectNode(initialNode);
102         }
103         view.checkValidity();
104         dObj.checkParseable();
105         
106     }
107     
108     public void componentOpened() {
109         super.componentOpened();
110         dObj.getWebApp().addPropertyChangeListener(this);
111     }
112     
113     public void componentClosed() {
114         super.componentClosed();
115         dObj.getWebApp().removePropertyChangeListener(this);
116     }
117     
118     public void propertyChange(java.beans.PropertyChangeEvent JavaDoc evt) {
119         if (!dObj.isChangedFromUI()) {
120             String JavaDoc name = evt.getPropertyName();
121             if ( name.indexOf("Ref")>0 || name.indexOf("EnvEntry")>0) { //NOI18
122
// repaint view if the wiew is active and something is changed with references
123
if (REFERENCES_MV_ID.equals(dObj.getSelectedPerspective().preferredID())) {
124                     repaintingTask.schedule(100);
125                 } else {
126                     needInit=true;
127                 }
128             }
129         }
130     }
131
132     class ReferencesView extends SectionView {
133         private SectionContainer serviceRefCont;
134         private Node envEntriesNode, resRefsNode, resEnvRefsNode, ejbRefsNode, messageDestRefsNode;
135         private SectionPanel filterMappingSectionPanel;
136         
137         ReferencesView (WebApp webApp) {
138             super(factory);
139             envEntriesNode = new EnvEntriesNode();
140             addSection(new SectionPanel(this,envEntriesNode,"env_entries")); //NOI18N
141

142             resRefsNode = new ResRefsNode();
143             addSection(new SectionPanel(this,resRefsNode,"res_refs")); //NOI18N
144

145             resEnvRefsNode = new ResEnvRefsNode();
146             addSection(new SectionPanel(this,resEnvRefsNode,"res_env_refs")); //NOI18N
147

148             ejbRefsNode = new EjbRefsNode();
149             addSection(new SectionPanel(this,ejbRefsNode,"ejb_refs")); //NOI18N
150

151             messageDestRefsNode = new MessageDestRefsNode();
152             addSection(new SectionPanel(this,messageDestRefsNode,"message_dest_refs")); //NOI18N
153

154             Children rootChildren = new Children.Array();
155             rootChildren.add(new Node[]{envEntriesNode,resRefsNode,resEnvRefsNode,ejbRefsNode,messageDestRefsNode});
156             AbstractNode root = new AbstractNode(rootChildren);
157             setRoot(root);
158         }
159         
160         Node getEnvEntriesNode() {
161             return envEntriesNode;
162         }
163         
164         Node getResRefsNode() {
165             return resRefsNode;
166         }
167         
168         Node getResEnvRefsNode(){
169             return resEnvRefsNode;
170         }
171         
172         Node getEjbRefsNode() {
173             return ejbRefsNode;
174         }
175         
176         Node getMessageDestRefsNode() {
177             return messageDestRefsNode;
178         }
179     }
180     
181     private class EnvEntriesNode extends org.openide.nodes.AbstractNode {
182         EnvEntriesNode() {
183             super(org.openide.nodes.Children.LEAF);
184             setDisplayName(NbBundle.getMessage(ReferencesMultiViewElement.class,"TTL_EnvEntries"));
185             setIconBaseWithExtension("org/netbeans/modules/j2ee/ddloaders/web/multiview/resources/paramNode.gif"); //NOI18N
186
}
187         public HelpCtx getHelpCtx() {
188             return new HelpCtx(HELP_ID_PREFIX+"envEntriesNode"); //NOI18N
189
}
190     }
191     
192     private class ResRefsNode extends org.openide.nodes.AbstractNode {
193         ResRefsNode() {
194             super(org.openide.nodes.Children.LEAF);
195             setDisplayName(NbBundle.getMessage(ReferencesMultiViewElement.class,"TTL_ResRefs"));
196             setIconBaseWithExtension("org/netbeans/modules/j2ee/ddloaders/web/multiview/resources/paramNode.gif"); //NOI18N
197
}
198         public HelpCtx getHelpCtx() {
199             return new HelpCtx(HELP_ID_PREFIX+"resRefsNode"); //NOI18N
200
}
201     }
202     
203     private class ResEnvRefsNode extends org.openide.nodes.AbstractNode {
204         ResEnvRefsNode() {
205             super(org.openide.nodes.Children.LEAF);
206             setDisplayName(NbBundle.getMessage(ReferencesMultiViewElement.class,"TTL_ResEnvRefs"));
207             setIconBaseWithExtension("org/netbeans/modules/j2ee/ddloaders/web/multiview/resources/paramNode.gif"); //NOI18N
208
}
209         public HelpCtx getHelpCtx() {
210             return new HelpCtx(HELP_ID_PREFIX+"resEnvRefsNode"); //NOI18N
211
}
212     }
213     
214     private class EjbRefsNode extends org.openide.nodes.AbstractNode {
215         EjbRefsNode() {
216             super(org.openide.nodes.Children.LEAF);
217             setDisplayName(NbBundle.getMessage(ReferencesMultiViewElement.class,"TTL_EjbRefs"));
218             setIconBaseWithExtension("org/netbeans/modules/j2ee/ddloaders/web/multiview/resources/paramNode.gif"); //NOI18N
219
}
220         public HelpCtx getHelpCtx() {
221             return new HelpCtx(HELP_ID_PREFIX+"ejbRefsNode"); //NOI18N
222
}
223     }
224     
225     private class MessageDestRefsNode extends org.openide.nodes.AbstractNode {
226         MessageDestRefsNode() {
227             super(org.openide.nodes.Children.LEAF);
228             setDisplayName(NbBundle.getMessage(ReferencesMultiViewElement.class,"TTL_MessageDestRefs"));
229             setIconBaseWithExtension("org/netbeans/modules/j2ee/ddloaders/web/multiview/resources/paramNode.gif"); //NOI18N
230
}
231         public HelpCtx getHelpCtx() {
232             return new HelpCtx(HELP_ID_PREFIX+"messageDestRefsNode"); //NOI18N
233
}
234     }
235 }
236
Popular Tags