001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.debugger.ui.views;
043:
044: import java.awt.BorderLayout;
045: import java.io.Externalizable;
046: import java.io.IOException;
047: import java.io.ObjectInput;
048: import java.io.ObjectOutput;
049: import javax.swing.JComponent;
050: import org.netbeans.spi.viewmodel.Models;
051:
052: import org.netbeans.modules.debugger.ui.Utils;
053:
054: import org.openide.util.NbBundle;
055: import org.openide.util.Utilities;
056: import org.openide.windows.TopComponent;
057:
058: // <RAVE>
059: // Implement HelpCtx.Provider interface to provide help ids for help system
060: // public class CallStackView extends TopComponent {
061: // ====
062: public class View extends TopComponent implements
063: org.openide.util.HelpCtx.Provider {
064: // </RAVE>
065:
066: public static final String BREAKPOINTS_VIEW_NAME = "BreakpointsView";
067: public static final String CALLSTACK_VIEW_NAME = "CallStackView";
068: public static final String LOCALS_VIEW_NAME = "LocalsView";
069: public static final String SESSIONS_VIEW_NAME = "SessionsView";
070: public static final String THREADS_VIEW_NAME = "ThreadsView";
071: public static final String WATCHES_VIEW_NAME = "WatchesView";
072:
073: private transient JComponent tree;
074: private transient ViewModelListener viewModelListener;
075: private String name; // Store just the name persistently, we'll create the component from that
076: private transient String helpID;
077: private transient String propertiesHelpID;
078: private transient String displayNameResource;
079: private transient String toolTipResource;
080:
081: private View(String icon, String name, String helpID,
082: String propertiesHelpID, String displayNameResource,
083: String toolTipResource) {
084: setIcon(Utilities.loadImage(icon));
085: this .name = name;
086: this .helpID = helpID;
087: this .propertiesHelpID = propertiesHelpID;
088: this .displayNameResource = displayNameResource;
089: this .toolTipResource = toolTipResource;
090: }
091:
092: protected String preferredID() {
093: return this .getClass().getPackage().getName() + "." + name;
094: }
095:
096: protected void componentShowing() {
097: super .componentShowing();
098: if (viewModelListener != null) {
099: viewModelListener.setUp();
100: return;
101: }
102: if (tree == null) {
103: setLayout(new BorderLayout());
104: tree = Models.createView(Models.EMPTY_MODEL);
105: tree.setName(NbBundle.getMessage(View.class,
106: toolTipResource));
107: add(tree, "Center"); //NOI18N
108: }
109: // <RAVE> CR 6207738 - fix debugger help IDs
110: // Use the modified constructor that stores the propertiesHelpID
111: // for nodes in this view
112: // viewModelListener = new ViewModelListener (
113: // "ThreadsView",
114: // tree
115: // );
116: // ====
117: viewModelListener = new ViewModelListener(name, tree,
118: propertiesHelpID);
119: // </RAVE>
120: }
121:
122: protected void componentHidden() {
123: super .componentHidden();
124: if (viewModelListener != null) {
125: viewModelListener.destroy();
126: }
127: }
128:
129: // <RAVE>
130: // Implement getHelpCtx() with the correct help ID
131: public org.openide.util.HelpCtx getHelpCtx() {
132: return new org.openide.util.HelpCtx(helpID);
133: }
134:
135: // </RAVE>
136:
137: public int getPersistenceType() {
138: return PERSISTENCE_ALWAYS;
139: }
140:
141: public boolean requestFocusInWindow() {
142: super .requestFocusInWindow();
143: if (tree == null)
144: return false;
145: return tree.requestFocusInWindow();
146: }
147:
148: public void requestActive() {
149: super .requestActive();
150: if (tree != null) {
151: tree.requestFocusInWindow();
152: }
153: }
154:
155: public String getName() {
156: return NbBundle.getMessage(View.class, displayNameResource);
157: }
158:
159: public String getToolTipText() {
160: return NbBundle.getMessage(View.class, toolTipResource);// NOI18N
161: }
162:
163: public Object writeReplace() {
164: return new ResolvableHelper(name);
165: }
166:
167: /**
168: * The serializing class.
169: */
170: private static final class ResolvableHelper implements
171: Externalizable {
172:
173: private String name;
174:
175: private static final long serialVersionUID = 1L;
176:
177: public ResolvableHelper(String name) {
178: this .name = name;
179: }
180:
181: public ResolvableHelper() {
182: // Just for the purpose of deserialization
183: }
184:
185: public void writeExternal(ObjectOutput out) throws IOException {
186: out.writeObject(name);
187: }
188:
189: public void readExternal(ObjectInput in) throws IOException,
190: ClassNotFoundException {
191: name = (String) in.readObject();
192: }
193:
194: public Object readResolve() {
195: return View.getView(name);
196: }
197: }
198:
199: /** Creates the view. Call from the module layer only!
200: * @deprecated Do not call.
201: */
202: public static synchronized TopComponent getBreakpointsView() {
203: return new View(
204: "org/netbeans/modules/debugger/resources/breakpointsView/Breakpoint.gif",
205: BREAKPOINTS_VIEW_NAME,
206: "NetbeansDebuggerBreakpointNode", null,
207: "CTL_Breakpoints_view", "CTL_Breakpoints_view_tooltip");
208: }
209:
210: /** Creates the view. Call from the module layer only!
211: * @deprecated Do not call.
212: */
213: public static synchronized TopComponent getCallStackView() {
214: return new View(
215: "org/netbeans/modules/debugger/resources/allInOneView/CallStack.gif",
216: CALLSTACK_VIEW_NAME, "NetbeansDebuggerCallStackNode",
217: null, "CTL_Call_stack_view",
218: "CTL_Call_stack_view_tooltip");
219: }
220:
221: /** Creates the view. Call from the module layer only!
222: * @deprecated Do not call.
223: */
224: public static synchronized TopComponent getLocalsView() {
225: return new View(
226: "org/netbeans/modules/debugger/resources/localsView/local_variable_16.png",
227: LOCALS_VIEW_NAME, "NetbeansDebuggerVariableNode", null,
228: "CTL_Variables_view", "CTL_Locals_view_tooltip");
229: }
230:
231: /** Creates the view. Call from the module layer only!
232: * @deprecated Do not call.
233: */
234: public static synchronized TopComponent getSessionsView() {
235: return new View(
236: "org/netbeans/modules/debugger/resources/sessionsView/session_16.png",
237: SESSIONS_VIEW_NAME, "NetbeansDebuggerSessionNode",
238: "NetbeansDebuggerSessionsPropertiesSheet",
239: "CTL_Sessions_view", "CTL_Sessions_view_tooltip");
240: }
241:
242: /** Creates the view. Call from the module layer only!
243: * @deprecated Do not call.
244: */
245: public static synchronized TopComponent getThreadsView() {
246: return new View(
247: "org/netbeans/modules/debugger/resources/threadsView/RunningThread.gif",
248: THREADS_VIEW_NAME, "NetbeansDebuggerThreadNode",
249: "NetbeansDebuggerThreadsPropertiesSheet",
250: "CTL_Threads_view", "CTL_Threads_view_tooltip");
251: }
252:
253: /** Creates the view. Call from the module layer only!
254: * @deprecated Do not call.
255: */
256: public static synchronized TopComponent getWatchesView() {
257: return new View(
258: "org/netbeans/modules/debugger/resources/watchesView/watch_16.png",
259: WATCHES_VIEW_NAME, "NetbeansDebuggerWatchNode", null,
260: "CTL_Watches_view", "CTL_Watches_view_tooltip");
261: }
262:
263: private static TopComponent getView(String viewName) {
264: if (viewName.equals(BREAKPOINTS_VIEW_NAME)) {
265: return getBreakpointsView();
266: }
267: if (viewName.equals(CALLSTACK_VIEW_NAME)) {
268: return getCallStackView();
269: }
270: if (viewName.equals(LOCALS_VIEW_NAME)) {
271: return getLocalsView();
272: }
273: if (viewName.equals(SESSIONS_VIEW_NAME)) {
274: return getSessionsView();
275: }
276: if (viewName.equals(THREADS_VIEW_NAME)) {
277: return getThreadsView();
278: }
279: if (viewName.equals(WATCHES_VIEW_NAME)) {
280: return getWatchesView();
281: }
282: throw new IllegalArgumentException(viewName);
283: }
284:
285: }
|