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
.dialogs
;
16 import java
.util
.HashMap
;
18 import java
.util
.concurrent
.TimeUnit
;
20 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.tracecontrol
.model
.TargetResource
;
21 import org
.eclipse
.linuxtools
.internal
.lttng
.core
.tracecontrol
.service
.ILttControllerService
;
22 import org
.eclipse
.linuxtools
.lttng
.ui
.LTTngUiPlugin
;
23 import org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.Messages
;
24 import org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.TraceControlConstants
;
25 import org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.subsystems
.TraceSubSystem
;
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
;
48 * <b><u>ConfigureMarkersDialog</u></b>
50 * Dialog box to configure markers for a given target resource.
53 public class ConfigureMarkersDialog
extends Dialog
{
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
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
;
66 private TraceSubSystem fSubSystem
;
68 // ------------------------------------------------------------------------
70 // ------------------------------------------------------------------------
75 * @param parent The parent shell
76 * @param subSystem The trace SubSystem
78 public ConfigureMarkersDialog(Shell parent
, TraceSubSystem subSystem
) {
81 fSubSystem
= subSystem
;
87 * @param parent The parent shell
88 * @param style The dialog box style
89 * @param subSystem The trace SubSystem
92 public ConfigureMarkersDialog(Shell parent
, int style
, TraceSubSystem subSystem
) {
95 fSubSystem
= subSystem
;
98 // ------------------------------------------------------------------------
100 // ------------------------------------------------------------------------
101 public Map
<String
, Boolean
> open(TargetResource aTarget
) {
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
);
108 shell
.setImage(LTTngUiPlugin
.getDefault().getImage(LTTngUiPlugin
.ICON_ID_CONFIG_MARKERS
));
109 shell
.setLayout(new FillLayout());
110 Composite composite
= new Composite(shell
, SWT
.NONE
);
111 composite
.setLayout(new GridLayout());
115 final ILttControllerService service
= fSubSystem
.getControllerService();
117 // Create future task
118 fMarkersList
= new TCFTask
<String
[]>() {
122 // Get markers using Lttng controller service proxy
123 service
.getMarkers(fTarget
.getParent().getName(), fTarget
.getName(), new ILttControllerService
.DoneGetMarkers() {
126 public void doneGetMarkers(IToken token
, Exception error
, String
[] str
) {
133 // Notify about success
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
;
143 sysExp
= new SystemMessageException(LTTngUiPlugin
.getDefault().getMessage(e
));
145 SystemBasePlugin
.logError(Messages
.Lttng_Control_ErrorGetMarkers
+ " (" + //$NON-NLS-1$
146 Messages
.Lttng_Resource_Target
+ ": " + fTarget
.getName() + ")", sysExp
); //$NON-NLS-1$ //$NON-NLS-2$
150 for (int i
= 0; i
< fMarkersList
.length
; i
++) {
151 fMarkersList
[i
] = fMarkersList
[i
].trim();
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
);
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
];
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
];
186 final ILttControllerService service
= fSubSystem
.getControllerService();
188 // Create future task
189 markerInfoResult
= new TCFTask
<String
>() {
193 // Get marker info using Lttng controller service proxy
194 service
.getMarkerInfo(fTarget
.getParent().getName(), fTarget
.getName(), currentMarker
, new ILttControllerService
.DoneGetMarkerInfo() {
197 public void doneGetMarkerInfo(IToken token
, Exception error
, String str
) {
204 // Notify about success
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
;
214 sysExp
= new SystemMessageException(LTTngUiPlugin
.getDefault().getMessage(e
));
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$
222 String markerInfos
= markerInfoResult
.substring(1, markerInfoResult
.length() - 1);
223 // System.out.println("markerInfos " + markerInfos);
226 // BAD : payload CAN contain comma!!!
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("");
233 int nbOfEqualsHack
= 0;
234 for (int x
= 0; x
< markerInfos
.length(); x
++) {
235 if (markerInfos
.charAt(x
) == '=') {
240 if (nbOfEqualsHack
> 0) {
241 String
[] infosList
= new String
[nbOfEqualsHack
];
242 String value
= ""; //$NON-NLS-1$
249 while ((curPos
< markerInfos
.length()) && (eqPos
>= 0)) {
250 eqPos
= markerInfos
.indexOf("=", curPos
); //$NON-NLS-1$
253 prevPos
= markerInfos
.lastIndexOf(",", eqPos
); //$NON-NLS-1$
255 prevPos
= markerInfos
.length() - 1;
259 value
= markerInfos
.substring(curPos
, prevPos
);
261 infosList
[nbDone
] = value
;
267 fTableLines
[i
].setText(new String
[] { null, fMarkersList
[i
], infosList
[3], infosList
[4], infosList
[2], infosList
[0], infosList
[5] });
269 if (infosList
[1].compareTo("1") == 0) { //$NON-NLS-1$
270 fTableLines
[i
].setChecked(true);
271 fInitialMarkersStates
[i
] = true;
273 fTableLines
[i
].setForeground(display
.getSystemColor(SWT
.COLOR_DARK_GRAY
));
274 fInitialMarkersStates
[i
] = false;
279 table
.addListener(SWT
.Selection
, new Listener() {
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
));
287 ti
.setForeground(display
.getSystemColor(SWT
.COLOR_BLACK
));
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
);
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
);
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);
307 selectAllButton
.setLayoutData(gd
);
308 selectAllButton
.addListener(SWT
.Selection
, new Listener() {
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
));
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);
322 deselectAllButton
.setLayoutData(gd
);
323 deselectAllButton
.addListener(SWT
.Selection
, new Listener() {
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
));
333 Button cancelButton
= new Button(buttonComposite
, SWT
.PUSH
);
334 cancelButton
.setText(Messages
.ConfigureMarkersDialog_Cancel
);
336 gd
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, true, false);
338 cancelButton
.setLayoutData(gd
);
339 cancelButton
.addListener(SWT
.Selection
, new Listener() {
341 public void handleEvent(Event e
) {
342 fOkClicked
= Boolean
.valueOf(false);
347 Button okButton
= new Button(buttonComposite
, SWT
.PUSH
);
348 okButton
.setText(Messages
.ConfigureMarkersDialog_Ok
);
349 gd
= new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false);
351 okButton
.setLayoutData(gd
);
352 okButton
.addListener(SWT
.Selection
, new Listener() {
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()) {
361 fMap
.put(fMarkersList
[k
], Boolean
.valueOf(true));
363 fMap
.put(fMarkersList
[k
], Boolean
.valueOf(false));
371 shell
.addListener(SWT
.Traverse
, new Listener() {
373 public void handleEvent(Event event
) {
374 if (event
.detail
== SWT
.TRAVERSE_ESCAPE
) {
380 TableItem
[] items
= table
.getItems();
381 for (int i
= 0; i
< items
.length
; i
++) {
383 items
[i
].setBackground(Display
.getDefault().getSystemColor(SWT
.COLOR_TITLE_INACTIVE_BACKGROUND
));
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));
392 while (!shell
.isDisposed()) {
393 if (!display
.readAndDispatch()) {