01: /*
02: * The contents of this file are subject to the terms of the Common Development
03: * and Distribution License (the License). You may not use this file except in
04: * compliance with the License.
05: *
06: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
07: * or http://www.netbeans.org/cddl.txt.
08: *
09: * 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-2007 Sun
17: * Microsystems, Inc. All Rights Reserved.
18: */
19:
20: package org.netbeans.modules.bpel.debugger.action;
21:
22: import java.util.Collections;
23: import java.util.Set;
24: import org.netbeans.api.debugger.ActionsManager;
25: import org.netbeans.modules.bpel.debugger.api.BpelDebugger;
26: import org.netbeans.modules.bpel.debugger.api.AttachingCookie;
27: import org.netbeans.modules.bpel.debugger.api.DebugException;
28: import org.netbeans.modules.bpel.debugger.BpelDebuggerImpl;
29: import org.netbeans.spi.debugger.ActionsProviderSupport;
30: import org.netbeans.spi.debugger.ContextProvider;
31: import org.openide.util.RequestProcessor;
32:
33: /**
34: * Starts the debugger by attaching to a BPEL service engine.
35: */
36: public class AttachActionProvider extends ActionsProviderSupport {
37:
38: protected ContextProvider mLookupProvider;
39: private BpelDebuggerImpl mDebugger;
40:
41: public AttachActionProvider(ContextProvider lookupProvider) {
42: mLookupProvider = lookupProvider;
43: mDebugger = (BpelDebuggerImpl) mLookupProvider.lookupFirst(
44: null, BpelDebugger.class);
45: setEnabled(ActionsManager.ACTION_START, true);
46: }
47:
48: public Set getActions() {
49: return Collections.singleton(ActionsManager.ACTION_START);
50: }
51:
52: public void doAction(Object action) {
53: // awt version used instead - postAction
54: }
55:
56: public void postAction(Object action,
57: Runnable actionPerformedNotifier) {
58: AttachingCookie cookie = mLookupProvider.lookupFirst(null,
59: AttachingCookie.class);
60: final String host = cookie.getHost();
61: final int port = cookie.getPort();
62:
63: RequestProcessor.getDefault().post(new Runnable() {
64: public void run() {
65: mDebugger.setStartingThread(Thread.currentThread());
66: try {
67: mDebugger.setRunning(host, port);
68: } catch (Exception ex) {
69: mDebugger.setException(new DebugException(ex));
70: } finally {
71: mDebugger.unsetStartingThread();
72: }
73: }
74: });
75: if (actionPerformedNotifier != null) {
76: actionPerformedNotifier.run();
77: }
78: }
79: }
|