1 /*******************************************************************************
2 * Copyright (c) 2011 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Polytechnique Montréal - Initial API and implementation
11 * Bernd Hufmann - Productification, enhancements and fixes
13 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.actions
;
16 import java
.util
.ArrayList
;
17 import java
.util
.Iterator
;
18 import java
.util
.List
;
19 import java
.util
.concurrent
.TimeUnit
;
21 import org
.eclipse
.jface
.action
.IAction
;
22 import org
.eclipse
.jface
.viewers
.ISelection
;
23 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
24 import org
.eclipse
.linuxtools
.lttng
.core
.tracecontrol
.model
.TraceResource
;
25 import org
.eclipse
.linuxtools
.lttng
.core
.tracecontrol
.model
.TraceResource
.TraceState
;
26 import org
.eclipse
.linuxtools
.lttng
.core
.tracecontrol
.service
.ILttControllerService
;
27 import org
.eclipse
.linuxtools
.lttng
.ui
.LTTngUiPlugin
;
28 import org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.Messages
;
29 import org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.TraceControlConstants
;
30 import org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.subsystems
.TraceSubSystem
;
31 import org
.eclipse
.rse
.core
.events
.ISystemRemoteChangeEvents
;
32 import org
.eclipse
.rse
.core
.model
.ISystemRegistry
;
33 import org
.eclipse
.rse
.core
.model
.SystemStartHere
;
34 import org
.eclipse
.rse
.services
.clientserver
.messages
.SystemMessageException
;
35 import org
.eclipse
.rse
.ui
.SystemBasePlugin
;
36 import org
.eclipse
.swt
.widgets
.Shell
;
37 import org
.eclipse
.tm
.tcf
.protocol
.IToken
;
38 import org
.eclipse
.tm
.tcf
.util
.TCFTask
;
39 import org
.eclipse
.ui
.IObjectActionDelegate
;
40 import org
.eclipse
.ui
.IViewActionDelegate
;
41 import org
.eclipse
.ui
.IViewPart
;
42 import org
.eclipse
.ui
.IWorkbenchPart
;
43 import org
.eclipse
.ui
.IWorkbenchWindow
;
44 import org
.eclipse
.ui
.IWorkbenchWindowActionDelegate
;
47 * <b><u>PauseTrace</u></b>
49 * Action implementation to pause a trace.
52 public class PauseTrace
implements IObjectActionDelegate
, IWorkbenchWindowActionDelegate
, IViewActionDelegate
{
54 // ------------------------------------------------------------------------
56 // ------------------------------------------------------------------------
58 private List
<TraceResource
> fSelectedTraces
;
60 // ------------------------------------------------------------------------
62 // ------------------------------------------------------------------------
65 fSelectedTraces
= new ArrayList
<TraceResource
>();
68 // ------------------------------------------------------------------------
70 // ------------------------------------------------------------------------
74 * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
77 public void setActivePart(IAction arg0
, IWorkbenchPart arg1
) {
82 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
85 public void run(IAction arg0
) {
86 for (int i
= 0; i
< fSelectedTraces
.size(); i
++) {
88 final TraceResource trace
= (TraceResource
) fSelectedTraces
.get(i
);
89 TraceSubSystem subSystem
= (TraceSubSystem
)trace
.getSubSystem();
92 final ILttControllerService service
= subSystem
.getControllerService();
95 @SuppressWarnings("unused")
96 Boolean success
= new TCFTask
<Boolean
>() {
100 // Setup trace using Lttng controller service proxy
101 service
.pauseTrace(trace
.getParent().getParent().getName(), trace
.getParent().getName(), trace
.getName(), new ILttControllerService
.DonePauseTrace() {
104 public void donePauseTrace(IToken token
, Exception error
, Object str
) {
111 // Notify about success
112 done(Boolean
.valueOf(true));
115 }}.get(TraceControlConstants
.DEFAULT_TCF_TASK_TIMEOUT
, TimeUnit
.SECONDS
);
117 trace
.setTraceState(TraceState
.PAUSED
);
119 ISystemRegistry registry
= SystemStartHere
.getSystemRegistry();
120 registry
.fireRemoteResourceChangeEvent(ISystemRemoteChangeEvents
.SYSTEM_REMOTE_RESOURCE_CHANGED
, trace
, trace
.getParent(), subSystem
, null);
122 } catch (Exception e
) {
123 SystemMessageException sysExp
;
124 if (e
instanceof SystemMessageException
) {
125 sysExp
= (SystemMessageException
)e
;
127 sysExp
= new SystemMessageException(LTTngUiPlugin
.getDefault().getMessage(e
));
129 SystemBasePlugin
.logError(Messages
.Lttng_Control_ErrorPause
+ " (" + //$NON-NLS-1$
130 Messages
.Lttng_Resource_Trace
+ ": " + trace
.getName() + ")", sysExp
); //$NON-NLS-1$ //$NON-NLS-2$
137 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
139 @SuppressWarnings("unchecked")
141 public void selectionChanged(IAction action
, ISelection selection
) {
142 if (selection
instanceof IStructuredSelection
) {
143 fSelectedTraces
.clear();
144 // store the selected targets to be used when running
145 Iterator
<IStructuredSelection
> theSet
= ((IStructuredSelection
) selection
).iterator();
146 while (theSet
.hasNext()) {
147 Object obj
= theSet
.next();
148 if (obj
instanceof TraceResource
) {
149 fSelectedTraces
.add((TraceResource
)obj
);
156 * Set selected traces
159 public void setSelectedTraces(List
<TraceResource
> traces
) {
160 fSelectedTraces
= traces
;
164 * Returns the active workbench shell of this plug-in.
166 * @return active workbench shell.
168 protected Shell
getShell() {
169 return SystemBasePlugin
.getActiveWorkbenchShell();
174 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
177 public void init(IWorkbenchWindow window
) {
182 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
185 public void dispose() {
190 * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
193 public void init(IViewPart view
) {