Commit | Line | Data |
---|---|---|
e8d771d5 BH |
1 | /******************************************************************************* |
2 | * Copyright (c) 2011 Ericsson | |
3 | * | |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Polytechnique Montréal - Initial API and implementation | |
11 | * Bernd Hufmann - Productification, enhancements and fixes | |
12 | * | |
13 | *******************************************************************************/ | |
14 | package org.eclipse.linuxtools.lttng.ui.tracecontrol.actions; | |
15 | ||
16 | import java.util.ArrayList; | |
17 | import java.util.Iterator; | |
18 | import java.util.List; | |
19 | import java.util.concurrent.TimeUnit; | |
20 | ||
21 | import org.eclipse.jface.action.IAction; | |
22 | import org.eclipse.jface.viewers.ISelection; | |
23 | import org.eclipse.jface.viewers.IStructuredSelection; | |
6c13869b FC |
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; | |
e8d771d5 BH |
27 | import org.eclipse.linuxtools.lttng.ui.LTTngUiPlugin; |
28 | import org.eclipse.linuxtools.lttng.ui.tracecontrol.TraceControlConstants; | |
29 | import org.eclipse.linuxtools.lttng.ui.tracecontrol.Messages; | |
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; | |
45 | ||
46 | /** | |
47 | * <b><u>PauseTrace</u></b> | |
48 | * <p> | |
49 | * Action implementation to pause a trace. | |
50 | * </p> | |
51 | */ | |
52 | public class PauseTrace implements IObjectActionDelegate, IWorkbenchWindowActionDelegate, IViewActionDelegate { | |
53 | ||
54 | // ------------------------------------------------------------------------ | |
55 | // Attributes | |
56 | // ------------------------------------------------------------------------ | |
57 | ||
58 | private List<TraceResource> fSelectedTraces; | |
59 | ||
60 | // ------------------------------------------------------------------------ | |
61 | // Constructors | |
62 | // ------------------------------------------------------------------------ | |
63 | ||
64 | public PauseTrace() { | |
65 | fSelectedTraces = new ArrayList<TraceResource>(); | |
66 | } | |
67 | ||
68 | // ------------------------------------------------------------------------ | |
69 | // Operations | |
70 | // ------------------------------------------------------------------------ | |
71 | ||
72 | /* | |
73 | * (non-Javadoc) | |
74 | * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart) | |
75 | */ | |
76 | @Override | |
77 | public void setActivePart(IAction arg0, IWorkbenchPart arg1) { | |
78 | } | |
79 | ||
80 | /* | |
81 | * (non-Javadoc) | |
82 | * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) | |
83 | */ | |
84 | @Override | |
85 | public void run(IAction arg0) { | |
86 | for (int i = 0; i < fSelectedTraces.size(); i++) { | |
87 | ||
88 | final TraceResource trace = (TraceResource) fSelectedTraces.get(i); | |
89 | TraceSubSystem subSystem = (TraceSubSystem)trace.getSubSystem(); | |
90 | ||
91 | try { | |
92 | final ILttControllerService service = subSystem.getControllerService(); | |
93 | ||
94 | // Create future task | |
95 | @SuppressWarnings("unused") | |
96 | Boolean success = new TCFTask<Boolean>() { | |
97 | @Override | |
98 | public void run() { | |
99 | ||
100 | // Setup trace using Lttng controller service proxy | |
101 | service.pauseTrace(trace.getParent().getParent().getName(), trace.getParent().getName(), trace.getName(), new ILttControllerService.DonePauseTrace() { | |
102 | ||
103 | @Override | |
104 | public void donePauseTrace(IToken token, Exception error, Object str) { | |
105 | if (error != null) { | |
106 | // Notify with error | |
107 | error(error); | |
108 | return; | |
109 | } | |
110 | ||
111 | // Notify about success | |
112 | done(Boolean.valueOf(true)); | |
113 | } | |
114 | }); | |
115 | }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS); | |
116 | ||
117 | trace.setTraceState(TraceState.PAUSED); | |
118 | ||
119 | ISystemRegistry registry = SystemStartHere.getSystemRegistry(); | |
120 | registry.fireRemoteResourceChangeEvent(ISystemRemoteChangeEvents.SYSTEM_REMOTE_RESOURCE_CHANGED, trace, trace.getParent(), subSystem, null); | |
121 | ||
122 | } catch (Exception e) { | |
123 | SystemMessageException sysExp; | |
124 | if (e instanceof SystemMessageException) { | |
125 | sysExp = (SystemMessageException)e; | |
126 | } else { | |
127 | sysExp = new SystemMessageException(LTTngUiPlugin.getDefault().getMessage(e)); | |
128 | } | |
129 | SystemBasePlugin.logError(Messages.Lttng_Control_ErrorPause + " (" + //$NON-NLS-1$ | |
130 | Messages.Lttng_Resource_Trace + ": " + trace.getName() + ")", sysExp); //$NON-NLS-1$ //$NON-NLS-2$ | |
131 | } | |
132 | } | |
133 | } | |
134 | ||
135 | /* | |
136 | * (non-Javadoc) | |
137 | * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) | |
138 | */ | |
139 | @SuppressWarnings("unchecked") | |
140 | @Override | |
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); | |
150 | } | |
151 | } | |
152 | } | |
153 | } | |
154 | ||
155 | /** | |
156 | * Set selected traces | |
157 | * @param traces | |
158 | */ | |
159 | public void setSelectedTraces(List<TraceResource> traces) { | |
160 | fSelectedTraces = traces; | |
161 | } | |
162 | ||
163 | /** | |
164 | * Returns the active workbench shell of this plug-in. | |
165 | * | |
166 | * @return active workbench shell. | |
167 | */ | |
168 | protected Shell getShell() { | |
169 | return SystemBasePlugin.getActiveWorkbenchShell(); | |
170 | } | |
171 | ||
172 | /* | |
173 | * (non-Javadoc) | |
174 | * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) | |
175 | */ | |
176 | @Override | |
177 | public void init(IWorkbenchWindow window) { | |
178 | } | |
179 | ||
180 | /* | |
181 | * (non-Javadoc) | |
182 | * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() | |
183 | */ | |
184 | @Override | |
185 | public void dispose() { | |
186 | } | |
187 | ||
188 | /* | |
189 | * (non-Javadoc) | |
190 | * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart) | |
191 | */ | |
192 | @Override | |
193 | public void init(IViewPart view) { | |
194 | } | |
195 | } |