KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > ui > views > View


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.debugger.ui.views;
21
22 import java.awt.BorderLayout JavaDoc;
23 import java.io.Externalizable JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.io.ObjectInput JavaDoc;
26 import java.io.ObjectOutput JavaDoc;
27 import javax.swing.JComponent JavaDoc;
28 import org.netbeans.spi.viewmodel.Models;
29
30 import org.netbeans.modules.debugger.ui.Utils;
31
32 import org.openide.util.NbBundle;
33 import org.openide.windows.TopComponent;
34
35
36 // <RAVE>
37
// Implement HelpCtx.Provider interface to provide help ids for help system
38
// public class CallStackView extends TopComponent {
39
// ====
40
public class View extends TopComponent implements org.openide.util.HelpCtx.Provider {
41 // </RAVE>
42

43     public static final String JavaDoc BREAKPOINTS_VIEW_NAME = "BreakpointsView";
44     public static final String JavaDoc CALLSTACK_VIEW_NAME = "CallStackView";
45     public static final String JavaDoc LOCALS_VIEW_NAME = "LocalsView";
46     public static final String JavaDoc SESSIONS_VIEW_NAME = "SessionsView";
47     public static final String JavaDoc THREADS_VIEW_NAME = "ThreadsView";
48     public static final String JavaDoc WATCHES_VIEW_NAME = "WatchesView";
49     
50     private transient JComponent JavaDoc tree;
51     private transient ViewModelListener viewModelListener;
52     private String JavaDoc name; // Store just the name persistently, we'll create the component from that
53
private transient String JavaDoc helpID;
54     private transient String JavaDoc propertiesHelpID;
55     private transient String JavaDoc displayNameResource;
56     private transient String JavaDoc toolTipResource;
57     
58     private View (String JavaDoc icon, String JavaDoc name, String JavaDoc helpID, String JavaDoc propertiesHelpID,
59                   String JavaDoc displayNameResource, String JavaDoc toolTipResource) {
60         setIcon (Utils.getIcon(icon).getImage());
61         this.name = name;
62         this.helpID = helpID;
63         this.propertiesHelpID = propertiesHelpID;
64         this.displayNameResource = displayNameResource;
65         this.toolTipResource = toolTipResource;
66     }
67
68     protected String JavaDoc preferredID() {
69         return this.getClass().getPackage().getName() + "." + name;
70     }
71
72     protected void componentShowing () {
73         super.componentShowing ();
74         if (viewModelListener != null) {
75             viewModelListener.setUp();
76             return ;
77         }
78         if (tree == null) {
79             setLayout (new BorderLayout JavaDoc ());
80             tree = Models.createView (Models.EMPTY_MODEL);
81             tree.setName (NbBundle.getMessage (View.class, toolTipResource));
82             add (tree, "Center"); //NOI18N
83
}
84         // <RAVE> CR 6207738 - fix debugger help IDs
85
// Use the modified constructor that stores the propertiesHelpID
86
// for nodes in this view
87
// viewModelListener = new ViewModelListener (
88
// "ThreadsView",
89
// tree
90
// );
91
// ====
92
viewModelListener = new ViewModelListener (
93             name,
94             tree,
95             propertiesHelpID
96         );
97         // </RAVE>
98
}
99     
100     protected void componentHidden () {
101         super.componentHidden ();
102         if (viewModelListener != null) {
103             viewModelListener.destroy ();
104         }
105     }
106     
107     // <RAVE>
108
// Implement getHelpCtx() with the correct help ID
109
public org.openide.util.HelpCtx getHelpCtx() {
110         return new org.openide.util.HelpCtx(helpID);
111     }
112     // </RAVE>
113

114     public int getPersistenceType () {
115         return PERSISTENCE_ALWAYS;
116     }
117         
118     public boolean requestFocusInWindow () {
119         super.requestFocusInWindow ();
120         if (tree == null) return false;
121         return tree.requestFocusInWindow ();
122     }
123
124     public void requestActive() {
125         super.requestActive();
126         if (tree != null) {
127             tree.requestFocusInWindow ();
128         }
129     }
130     
131     public String JavaDoc getName () {
132         return NbBundle.getMessage (View.class, displayNameResource);
133     }
134     
135     public String JavaDoc getToolTipText () {
136         return NbBundle.getMessage (View.class, toolTipResource);// NOI18N
137
}
138     
139     public Object JavaDoc writeReplace() {
140         return new ResolvableHelper(name);
141     }
142      
143     
144     
145     /**
146      * The serializing class.
147      */

148     private static final class ResolvableHelper implements Externalizable JavaDoc {
149         
150         private String JavaDoc name;
151         
152         private static final long serialVersionUID = 1L;
153         
154         public ResolvableHelper(String JavaDoc name) {
155             this.name = name;
156         }
157         
158         public ResolvableHelper() {
159             // Just for the purpose of deserialization
160
}
161         
162         public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc {
163             out.writeObject(name);
164         }
165         
166         public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
167             name = (String JavaDoc) in.readObject();
168         }
169         
170         public Object JavaDoc readResolve() {
171             return View.getView(name);
172         }
173     }
174     
175     
176     /** Creates the view. Call from the module layer only!
177      * @deprecated Do not call.
178      */

179     public static synchronized TopComponent getBreakpointsView() {
180         return new View(
181             "org/netbeans/modules/debugger/resources/breakpointsView/Breakpoint",
182             BREAKPOINTS_VIEW_NAME,
183             "NetbeansDebuggerBreakpointNode",
184             null,
185             "CTL_Breakpoints_view",
186             "CTL_Breakpoints_view_tooltip"
187         );
188     }
189     
190     /** Creates the view. Call from the module layer only!
191      * @deprecated Do not call.
192      */

193     public static synchronized TopComponent getCallStackView() {
194         return new View(
195             "org/netbeans/modules/debugger/resources/allInOneView/CallStack",
196             CALLSTACK_VIEW_NAME,
197             "NetbeansDebuggerCallStackNode",
198             null,
199             "CTL_Call_stack_view",
200             "CTL_Call_stack_view_tooltip"
201         );
202     }
203     
204     /** Creates the view. Call from the module layer only!
205      * @deprecated Do not call.
206      */

207     public static synchronized TopComponent getLocalsView() {
208         return new View(
209             "org/netbeans/modules/debugger/resources/localsView/LocalVariable",
210             LOCALS_VIEW_NAME,
211             "NetbeansDebuggerVariableNode",
212             null,
213             "CTL_Variables_view",
214             "CTL_Locals_view_tooltip"
215         );
216     }
217     
218     /** Creates the view. Call from the module layer only!
219      * @deprecated Do not call.
220      */

221     public static synchronized TopComponent getSessionsView() {
222         return new View(
223             "org/netbeans/modules/debugger/resources/sessionsView/Session",
224             SESSIONS_VIEW_NAME,
225             "NetbeansDebuggerSessionNode",
226             "NetbeansDebuggerSessionsPropertiesSheet",
227             "CTL_Sessions_view",
228             "CTL_Sessions_view_tooltip"
229         );
230     }
231     
232     /** Creates the view. Call from the module layer only!
233      * @deprecated Do not call.
234      */

235     public static synchronized TopComponent getThreadsView() {
236         return new View(
237             "org/netbeans/modules/debugger/resources/threadsView/RunningThread",
238             THREADS_VIEW_NAME,
239             "NetbeansDebuggerThreadNode",
240             "NetbeansDebuggerThreadsPropertiesSheet",
241             "CTL_Threads_view",
242             "CTL_Threads_view_tooltip"
243         );
244     }
245     
246     /** Creates the view. Call from the module layer only!
247      * @deprecated Do not call.
248      */

249     public static synchronized TopComponent getWatchesView() {
250         return new View(
251             "org/netbeans/modules/debugger/resources/watchesView/Watch",
252             WATCHES_VIEW_NAME,
253             "NetbeansDebuggerWatchNode",
254             null,
255             "CTL_Watches_view",
256             "CTL_Watches_view_tooltip"
257         );
258     }
259     
260     private static TopComponent getView(String JavaDoc viewName) {
261         if (viewName.equals(BREAKPOINTS_VIEW_NAME)) {
262             return getBreakpointsView();
263         }
264         if (viewName.equals(CALLSTACK_VIEW_NAME)) {
265             return getCallStackView();
266         }
267         if (viewName.equals(LOCALS_VIEW_NAME)) {
268             return getLocalsView();
269         }
270         if (viewName.equals(SESSIONS_VIEW_NAME)) {
271             return getSessionsView();
272         }
273         if (viewName.equals(THREADS_VIEW_NAME)) {
274             return getThreadsView();
275         }
276         if (viewName.equals(WATCHES_VIEW_NAME)) {
277             return getWatchesView();
278         }
279         throw new IllegalArgumentException JavaDoc(viewName);
280     }
281     
282 }
283
Popular Tags