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-2007 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: /*
043: * KillActionProvider.java
044: *
045: * Created on July 20, 2006, 0:25 AM
046: */
047:
048: package org.netbeans.modules.cnd.debugger.gdb.actions;
049:
050: import java.util.Arrays;
051: import java.util.Collections;
052: import java.util.HashSet;
053: import java.util.Iterator;
054: import java.util.List;
055: import java.util.Set;
056:
057: import org.openide.util.RequestProcessor;
058:
059: import org.netbeans.api.debugger.ActionsManager;
060: import org.netbeans.spi.debugger.ActionsProvider;
061: import org.netbeans.spi.debugger.ActionsProviderListener;
062: import org.netbeans.spi.debugger.ContextProvider;
063:
064: import org.netbeans.modules.cnd.debugger.gdb.GdbDebugger;
065: import org.netbeans.modules.cnd.debugger.gdb.GdbDebugger;
066:
067: /**
068: * Termination of a debugging session.
069: *
070: */
071: public class KillActionProvider extends ActionsProvider {
072:
073: private ContextProvider lookupProvider;
074: private GdbDebugger debuggerImpl;
075:
076: public KillActionProvider(ContextProvider lookupProvider) {
077: debuggerImpl = lookupProvider.lookupFirst(null,
078: GdbDebugger.class);
079: //super (debuggerImpl);
080: this .lookupProvider = lookupProvider;
081: }
082:
083: /**
084: * Returns set of actions supported by this ActionsProvider.
085: *
086: * @return set of actions supported by this ActionsProvider
087: */
088: public Set getActions() {
089: return new HashSet(Arrays
090: .asList(new Object[] { ActionsManager.ACTION_KILL }));
091: }
092:
093: /**
094: * Called when the action is called (action button is pressed).
095: *
096: * @param action an action which has been called
097: */
098: public void doAction(Object action) {
099: runAction(action);
100: }
101:
102: /**
103: * Runs the action. This method invokes the appropriate method in GdbDebugger
104: *
105: * @param action an action which has been called
106: */
107: public void runAction(final Object action) {
108: if (debuggerImpl != null) {
109: synchronized (debuggerImpl.LOCK) {
110: if (action == ActionsManager.ACTION_KILL) {
111: debuggerImpl.finish(true);
112: return;
113: }
114: }
115: }
116: }
117:
118: /**
119: * Post the action and let it process asynchronously.
120: * The default implementation just delegates to {@link #doAction}
121: * in a separate thread and returns immediately.
122: *
123: * @param action The action to post
124: * @param actionPerformedNotifier run this notifier after the action is
125: * done.
126: * @since 1.5
127: */
128: public void postAction(final Object action,
129: final Runnable actionPerformedNotifier) {
130: RequestProcessor.getDefault().post(new Runnable() {
131: public void run() {
132: try {
133: doAction(action);
134: } finally {
135: actionPerformedNotifier.run();
136: }
137: }
138: });
139: }
140:
141: /**
142: * Should return a state of given action.
143: *
144: * @param action action
145: */
146: public boolean isEnabled(Object action) {
147: if (debuggerImpl != null) {
148: synchronized (debuggerImpl.LOCK) {
149: return true;
150: }
151: }
152: return false;
153: }
154:
155: /**
156: * Adds property change listener.
157: *
158: * @param l new listener.
159: */
160: public void addActionsProviderListener(ActionsProviderListener l) {
161:
162: }
163:
164: /**
165: * Removes property change listener.
166: *
167: * @param l removed listener.
168: */
169: public void removeActionsProviderListener(ActionsProviderListener l) {
170:
171: }
172:
173: /* Not implemented yet.
174: protected void checkEnabled (int debuggerState) {
175: setEnabled (ActionsManager.ACTION_KILL, true);
176: }
177: **/
178: }
|