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 | *******************************************************************************/ | |
638eac44 | 14 | package org.eclipse.linuxtools.internal.lttng.ui.tracecontrol.dialogs; |
e8d771d5 BH |
15 | |
16 | import java.util.HashMap; | |
17 | import java.util.Map; | |
18 | import java.util.concurrent.TimeUnit; | |
19 | ||
5945cec9 FC |
20 | import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.TargetResource; |
21 | import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.service.ILttControllerService; | |
0977b009 | 22 | import org.eclipse.linuxtools.internal.lttng.ui.Activator; |
638eac44 FC |
23 | import org.eclipse.linuxtools.internal.lttng.ui.tracecontrol.Messages; |
24 | import org.eclipse.linuxtools.internal.lttng.ui.tracecontrol.TraceControlConstants; | |
25 | import org.eclipse.linuxtools.internal.lttng.ui.tracecontrol.subsystems.TraceSubSystem; | |
e8d771d5 BH |
26 | import org.eclipse.rse.services.clientserver.messages.SystemMessageException; |
27 | import org.eclipse.rse.ui.SystemBasePlugin; | |
28 | import org.eclipse.swt.SWT; | |
29 | import org.eclipse.swt.graphics.Point; | |
30 | import org.eclipse.swt.layout.FillLayout; | |
31 | import org.eclipse.swt.layout.GridData; | |
32 | import org.eclipse.swt.layout.GridLayout; | |
33 | import org.eclipse.swt.widgets.Button; | |
34 | import org.eclipse.swt.widgets.Composite; | |
35 | import org.eclipse.swt.widgets.Dialog; | |
36 | import org.eclipse.swt.widgets.Display; | |
37 | import org.eclipse.swt.widgets.Event; | |
38 | import org.eclipse.swt.widgets.Label; | |
39 | import org.eclipse.swt.widgets.Listener; | |
40 | import org.eclipse.swt.widgets.Shell; | |
41 | import org.eclipse.swt.widgets.Table; | |
42 | import org.eclipse.swt.widgets.TableColumn; | |
43 | import org.eclipse.swt.widgets.TableItem; | |
44 | import org.eclipse.tm.tcf.protocol.IToken; | |
45 | import org.eclipse.tm.tcf.util.TCFTask; | |
46 | ||
47 | /** | |
48 | * <b><u>ConfigureMarkersDialog</u></b> | |
49 | * <p> | |
50 | * Dialog box to configure markers for a given target resource. | |
51 | * </p> | |
52 | */ | |
53 | public class ConfigureMarkersDialog extends Dialog { | |
54 | ||
55 | // ------------------------------------------------------------------------ | |
56 | // Attributes | |
57 | // ------------------------------------------------------------------------ | |
58 | ||
59 | private String[] fMarkersList; | |
60 | private TargetResource fTarget; | |
61 | private Boolean fOkClicked; | |
62 | Map<String, Boolean> fMap; | |
63 | private TableItem[] fTableLines; | |
64 | private Boolean[] fInitialMarkersStates; | |
65 | ||
66 | private TraceSubSystem fSubSystem; | |
67 | ||
68 | // ------------------------------------------------------------------------ | |
69 | // Constructors | |
70 | // ------------------------------------------------------------------------ | |
71 | ||
72 | /** | |
73 | * Constructor | |
74 | * | |
75 | * @param parent The parent shell | |
76 | * @param subSystem The trace SubSystem | |
77 | */ | |
78 | public ConfigureMarkersDialog(Shell parent, TraceSubSystem subSystem) { | |
79 | super(parent); | |
80 | fOkClicked = false; | |
81 | fSubSystem = subSystem; | |
82 | } | |
83 | ||
84 | /** | |
85 | * Constructor | |
86 | * | |
87 | * @param parent The parent shell | |
88 | * @param style The dialog box style | |
89 | * @param subSystem The trace SubSystem | |
90 | ||
91 | */ | |
92 | public ConfigureMarkersDialog(Shell parent, int style, TraceSubSystem subSystem) { | |
93 | super(parent, style); | |
94 | fOkClicked = false; | |
95 | fSubSystem = subSystem; | |
96 | } | |
97 | ||
98 | // ------------------------------------------------------------------------ | |
99 | // Operations | |
100 | // ------------------------------------------------------------------------ | |
101 | public Map<String, Boolean> open(TargetResource aTarget) { | |
102 | fTarget = aTarget; | |
103 | ||
104 | Shell parent = getParent(); | |
105 | final Display display = parent.getDisplay(); | |
106 | final Shell shell = new Shell(parent, SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL | SWT.RESIZE); | |
107 | shell.setText(Messages.ConfigureMarkersDialog_Title); | |
638eac44 | 108 | shell.setImage(Activator.getDefault().getImage(Activator.ICON_ID_CONFIG_MARKERS)); |
e8d771d5 BH |
109 | shell.setLayout(new FillLayout()); |
110 | Composite composite = new Composite(shell, SWT.NONE); | |
111 | composite.setLayout(new GridLayout()); | |
112 | ||
113 | try { | |
114 | ||
115 | final ILttControllerService service = fSubSystem.getControllerService(); | |
116 | ||
117 | // Create future task | |
118 | fMarkersList = new TCFTask<String[]>() { | |
119 | @Override | |
120 | public void run() { | |
121 | ||
122 | // Get markers using Lttng controller service proxy | |
123 | service.getMarkers(fTarget.getParent().getName(), fTarget.getName(), new ILttControllerService.DoneGetMarkers() { | |
124 | ||
125 | @Override | |
126 | public void doneGetMarkers(IToken token, Exception error, String[] str) { | |
127 | if (error != null) { | |
128 | // Notify with error | |
129 | error(error); | |
130 | return; | |
131 | } | |
132 | ||
133 | // Notify about success | |
134 | done(str); | |
135 | } | |
136 | }); | |
137 | }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS); | |
138 | } catch (Exception e) { | |
139 | SystemMessageException sysExp; | |
140 | if (e instanceof SystemMessageException) { | |
141 | sysExp = (SystemMessageException)e; | |
142 | } else { | |
638eac44 | 143 | sysExp = new SystemMessageException(Activator.getDefault().getMessage(e)); |
e8d771d5 BH |
144 | } |
145 | SystemBasePlugin.logError(Messages.Lttng_Control_ErrorGetMarkers + " (" + //$NON-NLS-1$ | |
146 | Messages.Lttng_Resource_Target + ": " + fTarget.getName() + ")", sysExp); //$NON-NLS-1$ //$NON-NLS-2$ | |
147 | return null; | |
148 | } | |
149 | ||
150 | for (int i = 0; i < fMarkersList.length; i++) { | |
151 | fMarkersList[i] = fMarkersList[i].trim(); | |
152 | } | |
153 | final Table table = new Table(composite, SWT.BORDER | SWT.CHECK); | |
154 | TableColumn tc0 = new TableColumn(table, SWT.LEFT | SWT.CENTER); | |
155 | TableColumn tc1 = new TableColumn(table, SWT.LEFT); | |
156 | TableColumn tc2 = new TableColumn(table, SWT.LEFT); | |
157 | TableColumn tc3 = new TableColumn(table, SWT.LEFT); | |
158 | TableColumn tc4 = new TableColumn(table, SWT.LEFT); | |
159 | TableColumn tc5 = new TableColumn(table, SWT.LEFT); | |
160 | TableColumn tc6 = new TableColumn(table, SWT.LEFT); | |
161 | tc1.setText(Messages.ConfigureMarkersDialog_NameColumn); | |
162 | tc2.setText(Messages.ConfigureMarkersDialog_Location); | |
163 | tc3.setText(Messages.ConfigureMarkersDialog_Format); | |
164 | tc4.setText(Messages.ConfigureMarkersDialog_EventId); | |
165 | tc5.setText(Messages.ConfigureMarkersDialog_Call); | |
166 | tc6.setText(Messages.ConfigureMarkersDialog_Probe_Single); | |
167 | tc0.setWidth(25); | |
168 | tc1.setWidth(100); | |
169 | tc2.setWidth(100); | |
170 | tc3.setWidth(170); | |
171 | tc4.pack(); | |
172 | tc5.setWidth(100); | |
173 | tc6.setWidth(100); | |
174 | table.setHeaderVisible(true); | |
175 | table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); | |
176 | fTableLines = new TableItem[fMarkersList.length]; | |
177 | fInitialMarkersStates = new Boolean[fMarkersList.length]; | |
178 | ||
179 | for (int i = 0; i < fMarkersList.length; i++) { | |
180 | fTableLines[i] = new TableItem(table, SWT.NONE); | |
181 | String markerInfoResult = null; | |
182 | final String currentMarker = fMarkersList[i]; | |
183 | ||
184 | try { | |
185 | ||
186 | final ILttControllerService service = fSubSystem.getControllerService(); | |
187 | ||
188 | // Create future task | |
189 | markerInfoResult = new TCFTask<String>() { | |
190 | @Override | |
191 | public void run() { | |
192 | ||
193 | // Get marker info using Lttng controller service proxy | |
194 | service.getMarkerInfo(fTarget.getParent().getName(), fTarget.getName(), currentMarker, new ILttControllerService.DoneGetMarkerInfo() { | |
195 | ||
196 | @Override | |
197 | public void doneGetMarkerInfo(IToken token, Exception error, String str) { | |
198 | if (error != null) { | |
199 | // Notify with error | |
200 | error(error); | |
201 | return; | |
202 | } | |
203 | ||
204 | // Notify about success | |
205 | done(str); | |
206 | } | |
207 | }); | |
208 | }}.get(TraceControlConstants.DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS); | |
209 | } catch (Exception e) { | |
210 | SystemMessageException sysExp; | |
211 | if (e instanceof SystemMessageException) { | |
212 | sysExp = (SystemMessageException)e; | |
213 | } else { | |
638eac44 | 214 | sysExp = new SystemMessageException(Activator.getDefault().getMessage(e)); |
e8d771d5 BH |
215 | } |
216 | SystemBasePlugin.logError(Messages.Lttng_Control_ErrorGetMarkerInfo + " (" + //$NON-NLS-1$ | |
217 | Messages.Lttng_Resource_Target + ": " + fTarget.getName() + ", " + //$NON-NLS-1$ //$NON-NLS-2$ | |
218 | Messages.Lttng_Resource_Marker + ": " + currentMarker + ")", sysExp); //$NON-NLS-1$ //$NON-NLS-2$ | |
219 | return null; | |
220 | } | |
221 | ||
222 | String markerInfos = markerInfoResult.substring(1, markerInfoResult.length() - 1); | |
223 | // System.out.println("markerInfos " + markerInfos); | |
224 | ||
225 | // HACK!!! | |
226 | // BAD : payload CAN contain comma!!! | |
227 | /* | |
228 | * String[] infosList = markerInfos.split(","); for(int j=0 ; j<infosList.length ; j++) { infosList[j] = infosList[j].trim(); String[] tempTable = infosList[j].split("="); infosList[j] = tempTable[1]; System.out.print(infosList[j] + " "); | |
229 | * } System.out.println(""); | |
230 | */ | |
231 | ||
232 | // QUICK FIX : | |
233 | int nbOfEqualsHack = 0; | |
234 | for (int x = 0; x < markerInfos.length(); x++) { | |
235 | if (markerInfos.charAt(x) == '=') { | |
236 | nbOfEqualsHack++; | |
237 | } | |
238 | } | |
239 | ||
240 | if (nbOfEqualsHack > 0) { | |
241 | String[] infosList = new String[nbOfEqualsHack]; | |
e8d771d5 BH |
242 | String value = ""; //$NON-NLS-1$ |
243 | ||
244 | int prevPos = 0; | |
245 | int curPos = 0; | |
246 | int eqPos = 0; | |
247 | int nbDone = 0; | |
248 | ||
249 | while ((curPos < markerInfos.length()) && (eqPos >= 0)) { | |
250 | eqPos = markerInfos.indexOf("=", curPos); //$NON-NLS-1$ | |
251 | ||
252 | if (eqPos >= 0) { | |
e8d771d5 BH |
253 | prevPos = markerInfos.lastIndexOf(",", eqPos); //$NON-NLS-1$ |
254 | } else { | |
255 | prevPos = markerInfos.length() - 1; | |
256 | } | |
257 | ||
258 | if (prevPos >= 0) { | |
259 | value = markerInfos.substring(curPos, prevPos); | |
260 | ||
261 | infosList[nbDone] = value; | |
262 | nbDone++; | |
263 | } | |
264 | curPos = eqPos + 1; | |
265 | } | |
266 | ||
267 | fTableLines[i].setText(new String[] { null, fMarkersList[i], infosList[3], infosList[4], infosList[2], infosList[0], infosList[5] }); | |
268 | ||
269 | if (infosList[1].compareTo("1") == 0) { //$NON-NLS-1$ | |
270 | fTableLines[i].setChecked(true); | |
271 | fInitialMarkersStates[i] = true; | |
272 | } else { | |
273 | fTableLines[i].setForeground(display.getSystemColor(SWT.COLOR_DARK_GRAY)); | |
274 | fInitialMarkersStates[i] = false; | |
275 | } | |
276 | } | |
277 | } | |
278 | ||
279 | table.addListener(SWT.Selection, new Listener() { | |
280 | @Override | |
281 | public void handleEvent(Event event) { | |
282 | if (event.detail == SWT.CHECK) { | |
283 | TableItem ti = (TableItem) event.item; | |
284 | if (!ti.getChecked()) { | |
285 | ti.setForeground(display.getSystemColor(SWT.COLOR_DARK_GRAY)); | |
286 | } else { | |
287 | ti.setForeground(display.getSystemColor(SWT.COLOR_BLACK)); | |
288 | } | |
289 | } | |
290 | } | |
291 | }); | |
292 | ||
293 | final Composite buttonComposite = new Composite(composite, SWT.NONE); | |
294 | buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); | |
295 | GridLayout gl = new GridLayout(4, false); | |
296 | gl.verticalSpacing = 10; | |
297 | buttonComposite.setLayout(gl); | |
298 | ||
299 | Label shadow_sep_h = new Label(buttonComposite, SWT.SEPARATOR | SWT.SHADOW_OUT | SWT.HORIZONTAL); | |
300 | GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1); | |
301 | shadow_sep_h.setLayoutData(gd); | |
302 | ||
303 | Button selectAllButton = new Button(buttonComposite, SWT.PUSH); | |
304 | selectAllButton.setText(Messages.ConfigureMarkersDialog_Select_All); | |
305 | gd = new GridData(SWT.CENTER, SWT.CENTER, false, false); | |
306 | gd.widthHint = 100; | |
307 | selectAllButton.setLayoutData(gd); | |
308 | selectAllButton.addListener(SWT.Selection, new Listener() { | |
309 | @Override | |
310 | public void handleEvent(Event e) { | |
311 | for (int i = 0; i < fTableLines.length; i++) { | |
312 | fTableLines[i].setChecked(true); | |
313 | fTableLines[i].setForeground(display.getSystemColor(SWT.COLOR_BLACK)); | |
314 | } | |
315 | } | |
316 | }); | |
317 | ||
318 | Button deselectAllButton = new Button(buttonComposite, SWT.PUSH); | |
319 | deselectAllButton.setText(Messages.ConfigureMarkersDialog_Deselect_All); | |
320 | gd = new GridData(SWT.CENTER, SWT.CENTER, false, false); | |
321 | gd.widthHint = 100; | |
322 | deselectAllButton.setLayoutData(gd); | |
323 | deselectAllButton.addListener(SWT.Selection, new Listener() { | |
324 | @Override | |
325 | public void handleEvent(Event e) { | |
326 | for (int i = 0; i < fTableLines.length; i++) { | |
327 | fTableLines[i].setChecked(false); | |
328 | fTableLines[i].setForeground(display.getSystemColor(SWT.COLOR_DARK_GRAY)); | |
329 | } | |
330 | } | |
331 | }); | |
332 | ||
333 | Button cancelButton = new Button(buttonComposite, SWT.PUSH); | |
334 | cancelButton.setText(Messages.ConfigureMarkersDialog_Cancel); | |
335 | gd = new GridData(); | |
336 | gd = new GridData(SWT.RIGHT, SWT.CENTER, true, false); | |
337 | gd.widthHint = 100; | |
338 | cancelButton.setLayoutData(gd); | |
339 | cancelButton.addListener(SWT.Selection, new Listener() { | |
340 | @Override | |
341 | public void handleEvent(Event e) { | |
342 | fOkClicked = Boolean.valueOf(false); | |
343 | shell.dispose(); | |
344 | } | |
345 | }); | |
346 | ||
347 | Button okButton = new Button(buttonComposite, SWT.PUSH); | |
348 | okButton.setText(Messages.ConfigureMarkersDialog_Ok); | |
349 | gd = new GridData(SWT.CENTER, SWT.CENTER, false, false); | |
350 | gd.widthHint = 100; | |
351 | okButton.setLayoutData(gd); | |
352 | okButton.addListener(SWT.Selection, new Listener() { | |
353 | @Override | |
354 | public void handleEvent(Event e) { | |
355 | fOkClicked = Boolean.valueOf(true); | |
356 | fMap = new HashMap<String, Boolean>(); | |
357 | for (int k = 0; k < fTableLines.length; k++) { | |
358 | Boolean isChecked = fTableLines[k].getChecked(); | |
359 | if (isChecked.booleanValue() != fInitialMarkersStates[k].booleanValue()) { | |
360 | if (isChecked) { | |
361 | fMap.put(fMarkersList[k], Boolean.valueOf(true)); | |
362 | } else { | |
363 | fMap.put(fMarkersList[k], Boolean.valueOf(false)); | |
364 | } | |
365 | } | |
366 | } | |
367 | shell.dispose(); | |
368 | } | |
369 | }); | |
370 | ||
371 | shell.addListener(SWT.Traverse, new Listener() { | |
372 | @Override | |
373 | public void handleEvent(Event event) { | |
374 | if (event.detail == SWT.TRAVERSE_ESCAPE) { | |
375 | event.doit = false; | |
376 | } | |
377 | } | |
378 | }); | |
379 | ||
380 | TableItem[] items = table.getItems(); | |
381 | for (int i = 0; i < items.length; i++) { | |
382 | if ((i % 2) != 0) { | |
383 | items[i].setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND)); | |
384 | } | |
385 | } | |
386 | ||
387 | Point minSize = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT); | |
388 | shell.setMinimumSize(shell.computeSize(minSize.x, minSize.y).x, 200); | |
389 | shell.setSize(shell.computeSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, 300)); | |
390 | shell.open(); | |
391 | ||
392 | while (!shell.isDisposed()) { | |
393 | if (!display.readAndDispatch()) { | |
394 | display.sleep(); | |
395 | } | |
396 | } | |
397 | if (!fOkClicked) { | |
398 | return null; | |
399 | } | |
400 | ||
401 | return fMap; | |
402 | } | |
403 | } |