KickJava   Java API By Example, From Geeks To Geeks.

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


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.NbBundle;
31 import org.openide.util.RequestProcessor;
32 import org.openide.util.HelpCtx;
33
34 /**
35  * @author mkuchtiak
36  */

37 public class OverviewMultiViewElement extends ToolBarMultiViewElement implements java.beans.PropertyChangeListener JavaDoc {
38     private SectionView view;
39     private ToolBarDesignEditor comp;
40     private DDDataObject dObj;
41     private WebApp webApp;
42     private OverviewFactory factory;
43     private boolean needInit=true;
44     private int index;
45     private RequestProcessor.Task repaintingTask;
46     private static final String JavaDoc OVERVIEW_MV_ID=DDDataObject.DD_MULTIVIEW_PREFIX+DDDataObject.MULTIVIEW_OVERVIEW;
47     private static final String JavaDoc HELP_ID_PREFIX=DDDataObject.HELP_ID_PREFIX_OVERVIEW;
48     
49     /** Creates a new instance of DDMultiViewElement */
50     public OverviewMultiViewElement(final DDDataObject dObj, int index) {
51         super(dObj);
52         this.dObj=dObj;
53         this.index=index;
54         comp = new ToolBarDesignEditor();
55         factory = new OverviewFactory(comp, dObj);
56         setVisualEditor(comp);
57         repaintingTask = RequestProcessor.getDefault().create(new Runnable JavaDoc() {
58             public void run() {
59                 javax.swing.SwingUtilities.invokeLater(new Runnable JavaDoc() {
60                     public void run() {
61                         repaintView();
62                     }
63                 });
64             }
65         });
66     }
67     
68     public SectionView getSectionView() {
69         return view;
70     }
71     
72     public void componentShowing() {
73         super.componentShowing();
74         dObj.setLastOpenView(index);
75         if (needInit || !dObj.isDocumentParseable()) {
76             repaintView();
77             needInit=false;
78         }
79     }
80     
81     private void repaintView() {
82         webApp = dObj.getWebApp();
83         view =new OverView(webApp);
84         comp.setContentView(view);
85         Object JavaDoc lastActive = comp.getLastActive();
86         if (lastActive!=null) {
87             ((SectionView)view).openPanel(lastActive);
88         } else {
89             ((SectionView)view).openPanel("overview"); //NOI18N
90
}
91         view.checkValidity();
92         dObj.checkParseable();
93     }
94
95     public void componentOpened() {
96         super.componentOpened();
97         dObj.getWebApp().addPropertyChangeListener(this);
98     }
99     
100     public void componentClosed() {
101         super.componentClosed();
102         dObj.getWebApp().removePropertyChangeListener(this);
103     }
104     
105     public void propertyChange(java.beans.PropertyChangeEvent JavaDoc evt) {
106         if (!dObj.isChangedFromUI()) {
107             String JavaDoc name = evt.getPropertyName();
108             if ( name.indexOf("/WebApp/DisplayName")>=0 || //NOI18N
109
name.indexOf("/WebApp/Description")>=0 || //NOI18N
110
name.indexOf("Distributable")>0 || //NOI18N
111
name.indexOf("ContextParam")>0 || //NOI18N
112
name.indexOf("Listener")>0 || //NOI18N
113
name.indexOf("SessionConfig")>0 ) { //NOI18N
114
// repaint view if the wiew is active and something is changed with elements listed above
115
if (OVERVIEW_MV_ID.equals(dObj.getSelectedPerspective().preferredID())) {
116                     repaintingTask.schedule(100);
117                 } else {
118                     needInit=true;
119                 }
120             }
121         }
122     }
123
124     class OverView extends SectionView {
125         private Node overviewNode, contextParamsNode, listenersNode;
126         OverView(WebApp webApp) {
127             super(factory);
128             overviewNode = new OverviewNode();
129             addSection(new SectionPanel(this,overviewNode,"overview")); //NOI18N
130

131             contextParamsNode = new ContextParamsNode();
132             addSection(new SectionPanel(this,contextParamsNode,"context_params")); //NOI18N
133

134             listenersNode = new ListenersNode();
135             addSection(new SectionPanel(this,listenersNode,"listeners")); //NOI18N
136

137             Children rootChildren = new Children.Array();
138             rootChildren.add(new Node[]{overviewNode,contextParamsNode,listenersNode});
139             AbstractNode root = new AbstractNode(rootChildren);
140             setRoot(root);
141         }
142         
143         Node getOverviewNode() {
144             return overviewNode;
145         }
146         
147         Node getContextParamsNode() {
148             return contextParamsNode;
149         }
150         
151         Node getListenersNode(){
152             return listenersNode;
153         }
154     }
155     
156     private class OverviewNode extends org.openide.nodes.AbstractNode {
157         OverviewNode() {
158             super(org.openide.nodes.Children.LEAF);
159             setDisplayName(NbBundle.getMessage(PagesMultiViewElement.class,"TTL_Overview"));
160             setIconBaseWithExtension("org/netbeans/modules/j2ee/ddloaders/web/multiview/resources/class.gif"); //NOI18N
161
}
162         public HelpCtx getHelpCtx() {
163             return new HelpCtx(HELP_ID_PREFIX+"overviewNode"); //NOI18N
164
}
165     }
166     
167     private class ContextParamsNode extends org.openide.nodes.AbstractNode {
168         ContextParamsNode() {
169             super(org.openide.nodes.Children.LEAF);
170             setDisplayName(NbBundle.getMessage(PagesMultiViewElement.class,"TTL_ContextParams"));
171             setIconBaseWithExtension("org/netbeans/modules/j2ee/ddloaders/web/multiview/resources/paramsNode.gif"); //NOI18N
172
}
173         public HelpCtx getHelpCtx() {
174             return new HelpCtx(HELP_ID_PREFIX+"contextParamsNode"); //NOI18N
175
}
176     }
177     
178     private class ListenersNode extends org.openide.nodes.AbstractNode {
179         ListenersNode() {
180             super(org.openide.nodes.Children.LEAF);
181             setDisplayName(NbBundle.getMessage(PagesMultiViewElement.class,"TTL_Listeners"));
182             setIconBaseWithExtension("org/netbeans/modules/j2ee/ddloaders/web/multiview/resources/class.gif"); //NOI18N
183
}
184         public HelpCtx getHelpCtx() {
185             return new HelpCtx(HELP_ID_PREFIX+"listenersNode"); //NOI18N
186
}
187     }
188 }
189
Popular Tags