Re-structure LTTng sub-project as per the Linux Tools guidelines
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / tracecontrol / actions / ConfigureMarkers.java
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.Map;
20 import java.util.concurrent.TimeUnit;
21
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.core.tracecontrol.model.TargetResource;
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.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;
44
45 /**
46 * <b><u>ConfigureMarkers</u></b>
47 * <p>
48 * Action implementation to configure markers.
49 * </p>
50 */
51 public class ConfigureMarkers implements IObjectActionDelegate, IWorkbenchWindowActionDelegate, IViewActionDelegate {
52
53 // ------------------------------------------------------------------------
54 // Attributes
55 // ------------------------------------------------------------------------
56
57 private List<TargetResource> fSelectedTargets;
58
59 // ------------------------------------------------------------------------
60 // Constructors
61 // ------------------------------------------------------------------------
62
63 public ConfigureMarkers() {
64 fSelectedTargets = new ArrayList<TargetResource>();
65 }
66
67 // ------------------------------------------------------------------------
68 // Operations
69 // ------------------------------------------------------------------------
70
71 /*
72 * (non-Javadoc)
73 * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
74 */
75 @Override
76 public void setActivePart(IAction action, IWorkbenchPart targetPart) {
77
78 }
79
80 /**
81 * Returns the first of all selected targets.
82 *
83 * @return first selected target.
84 */
85 protected TargetResource getFirstSelectedTarget() {
86 if (fSelectedTargets.size() > 0) {
87 return (TargetResource) fSelectedTargets.get(0);
88 }
89 return null;
90 }
91
92 /**
93 * Returns the SubSystem reference for the selected targets.
94 *
95 * @return Trace SubSystem
96 */
97 protected ISubSystem getSubSystem() {
98 return getFirstSelectedTarget().getSubSystem();
99 }
100
101 /*
102 * (non-Javadoc)
103 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
104 */
105 @Override
106 public void run(IAction arg0) {
107 Shell shell = getShell();
108
109 final TargetResource tr = (TargetResource) fSelectedTargets.get(0);
110 TraceSubSystem subSystem = (TraceSubSystem)tr.getSubSystem();
111
112 ConfigureMarkersDialog dialog = new ConfigureMarkersDialog(shell, subSystem);
113 Map<String, Boolean> map = dialog.open(tr);
114 if (map == null) {
115 return;
116 }
117
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();
121
122 final Boolean value = (Boolean) entry.getValue();
123
124 try {
125
126 final ILttControllerService service = subSystem.getControllerService();
127
128 // Create future task
129 @SuppressWarnings("unused")
130 Boolean ok = new TCFTask<Boolean>() {
131 @Override
132 public void run() {
133
134 // Set marker enable using Lttng controller service proxy
135 service.setMarkerEnable(tr.getParent().getName(), tr.getName(), key, value.booleanValue(), new ILttControllerService.DoneSetMarkerEnable() {
136
137 @Override
138 public void doneSetMarkerEnable(IToken token, Exception error, Object str) {
139 if (error != null) {
140 // Notify with error
141 error(error);
142 return;
143 }
144
145 // Notify about success
146 done(Boolean.valueOf(true));
147 }
148 });
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;
154 } else {
155 sysExp = new SystemMessageException(LTTngUiPlugin.getDefault().getMessage(e));
156 }
157 SystemBasePlugin.logError(Messages.Lttng_Control_ErrorConfigureMarkers + " (" + //$NON-NLS-1$
158 Messages.Lttng_Resource_Target + ": " + tr.getName() + ")", sysExp); //$NON-NLS-1$ //$NON-NLS-2$
159 }
160 }
161 }
162
163 /*
164 * (non-Javadoc)
165 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
166 */
167 @SuppressWarnings("unchecked")
168 @Override
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);
178 }
179 }
180 }
181 }
182
183 /**
184 * Returns the active workbench shell of this plug-in.
185 *
186 * @return active workbench shell.
187 */
188 protected Shell getShell() {
189 return SystemBasePlugin.getActiveWorkbenchShell();
190 }
191
192 /*
193 * (non-Javadoc)
194 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
195 */
196 @Override
197 public void init(IWorkbenchWindow window) {
198 }
199
200 /*
201 * (non-Javadoc)
202 * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
203 */
204 @Override
205 public void dispose() {
206 }
207
208 /*
209 * (non-Javadoc)
210 * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
211 */
212 @Override
213 public void init(IViewPart view) {
214 }
215 }
This page took 0.041147 seconds and 5 git commands to generate.