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
;
20 import java
.util
.concurrent
.TimeUnit
;
22 import org
.eclipse
.jface
.action
.IAction
;
23 import org
.eclipse
.jface
.viewers
.ISelection
;
24 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
25 import org
.eclipse
.linuxtools
.lttng
.tracecontrol
.model
.TargetResource
;
26 import org
.eclipse
.linuxtools
.lttng
.tracecontrol
.service
.ILttControllerService
;
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
.dialogs
.ConfigureMarkersDialog
;
31 import org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.subsystems
.TraceSubSystem
;
32 import org
.eclipse
.rse
.core
.subsystems
.ISubSystem
;
33 import org
.eclipse
.rse
.services
.clientserver
.messages
.SystemMessageException
;
34 import org
.eclipse
.rse
.ui
.SystemBasePlugin
;
35 import org
.eclipse
.swt
.widgets
.Shell
;
36 import org
.eclipse
.tm
.tcf
.protocol
.IToken
;
37 import org
.eclipse
.tm
.tcf
.util
.TCFTask
;
38 import org
.eclipse
.ui
.IObjectActionDelegate
;
39 import org
.eclipse
.ui
.IViewActionDelegate
;
40 import org
.eclipse
.ui
.IViewPart
;
41 import org
.eclipse
.ui
.IWorkbenchPart
;
42 import org
.eclipse
.ui
.IWorkbenchWindow
;
43 import org
.eclipse
.ui
.IWorkbenchWindowActionDelegate
;
46 * <b><u>ConfigureMarkers</u></b>
48 * Action implementation to configure markers.
51 public class ConfigureMarkers
implements IObjectActionDelegate
, IWorkbenchWindowActionDelegate
, IViewActionDelegate
{
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
57 private List
<TargetResource
> fSelectedTargets
;
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
63 public ConfigureMarkers() {
64 fSelectedTargets
= new ArrayList
<TargetResource
>();
67 // ------------------------------------------------------------------------
69 // ------------------------------------------------------------------------
73 * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
76 public void setActivePart(IAction action
, IWorkbenchPart targetPart
) {
81 * Returns the first of all selected targets.
83 * @return first selected target.
85 protected TargetResource
getFirstSelectedTarget() {
86 if (fSelectedTargets
.size() > 0) {
87 return (TargetResource
) fSelectedTargets
.get(0);
93 * Returns the SubSystem reference for the selected targets.
95 * @return Trace SubSystem
97 protected ISubSystem
getSubSystem() {
98 return getFirstSelectedTarget().getSubSystem();
103 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
106 public void run(IAction arg0
) {
107 Shell shell
= getShell();
109 final TargetResource tr
= (TargetResource
) fSelectedTargets
.get(0);
110 TraceSubSystem subSystem
= (TraceSubSystem
)tr
.getSubSystem();
112 ConfigureMarkersDialog dialog
= new ConfigureMarkersDialog(shell
, subSystem
);
113 Map
<String
, Boolean
> map
= dialog
.open(tr
);
118 for (Iterator
<Map
.Entry
<String
, Boolean
>> it
= map
.entrySet().iterator(); it
.hasNext();) {
119 Map
.Entry
<String
, Boolean
> entry
= (Map
.Entry
<String
, Boolean
>) it
.next();
120 final String key
= (String
) entry
.getKey();
122 final Boolean value
= (Boolean
) entry
.getValue();
126 final ILttControllerService service
= subSystem
.getControllerService();
128 // Create future task
129 @SuppressWarnings("unused")
130 Boolean ok
= new TCFTask
<Boolean
>() {
134 // Set marker enable using Lttng controller service proxy
135 service
.setMarkerEnable(tr
.getParent().getName(), tr
.getName(), key
, value
.booleanValue(), new ILttControllerService
.DoneSetMarkerEnable() {
138 public void doneSetMarkerEnable(IToken token
, Exception error
, Object str
) {
145 // Notify about success
146 done(Boolean
.valueOf(true));
149 }}.get(TraceControlConstants
.DEFAULT_TCF_TASK_TIMEOUT
, TimeUnit
.SECONDS
);
150 } catch (Exception e
) {
151 SystemMessageException sysExp
;
152 if (e
instanceof SystemMessageException
) {
153 sysExp
= (SystemMessageException
)e
;
155 sysExp
= new SystemMessageException(LTTngUiPlugin
.getDefault().getMessage(e
));
157 SystemBasePlugin
.logError(Messages
.Lttng_Control_ErrorConfigureMarkers
+ " (" + //$NON-NLS-1$
158 Messages
.Lttng_Resource_Target
+ ": " + tr
.getName() + ")", sysExp
); //$NON-NLS-1$ //$NON-NLS-2$
165 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
167 @SuppressWarnings("unchecked")
169 public void selectionChanged(IAction action
, ISelection selection
) {
170 if (selection
instanceof IStructuredSelection
) {
171 fSelectedTargets
.clear();
172 // store the selected targets to be used when running
173 Iterator
<IStructuredSelection
> theSet
= ((IStructuredSelection
) selection
).iterator();
174 while (theSet
.hasNext()) {
175 Object obj
= theSet
.next();
176 if (obj
instanceof TargetResource
) {
177 fSelectedTargets
.add((TargetResource
)obj
);
184 * Returns the active workbench shell of this plug-in.
186 * @return active workbench shell.
188 protected Shell
getShell() {
189 return SystemBasePlugin
.getActiveWorkbenchShell();
194 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
197 public void init(IWorkbenchWindow window
) {
202 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
205 public void dispose() {
210 * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
213 public void init(IViewPart view
) {