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 * Bernd Hufmann - Initial API and implementation
12 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.wizards
;
15 import java
.util
.ArrayList
;
16 import java
.util
.List
;
18 import org
.eclipse
.jface
.action
.Action
;
19 import org
.eclipse
.jface
.action
.IMenuListener
;
20 import org
.eclipse
.jface
.action
.IMenuManager
;
21 import org
.eclipse
.jface
.action
.MenuManager
;
22 import org
.eclipse
.jface
.dialogs
.Dialog
;
23 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
24 import org
.eclipse
.jface
.viewers
.CellEditor
;
25 import org
.eclipse
.jface
.viewers
.CheckboxCellEditor
;
26 import org
.eclipse
.jface
.viewers
.TableViewer
;
27 import org
.eclipse
.jface
.viewers
.TextCellEditor
;
28 import org
.eclipse
.jface
.viewers
.Viewer
;
29 import org
.eclipse
.jface
.viewers
.ViewerComparator
;
30 import org
.eclipse
.jface
.window
.Window
;
31 import org
.eclipse
.jface
.wizard
.WizardPage
;
32 import org
.eclipse
.linuxtools
.lttng
.tracecontrol
.model
.TraceResource
.TraceState
;
33 import org
.eclipse
.linuxtools
.lttng
.tracecontrol
.model
.config
.TraceChannel
;
34 import org
.eclipse
.linuxtools
.lttng
.tracecontrol
.model
.config
.TraceChannels
;
35 import org
.eclipse
.linuxtools
.lttng
.ui
.LTTngUiPlugin
;
36 import org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.Messages
;
37 import org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.model
.config
.TraceChannelCellModifier
;
38 import org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.model
.config
.TraceChannelTableContentProvider
;
39 import org
.eclipse
.linuxtools
.lttng
.ui
.tracecontrol
.model
.config
.TraceChannelTableLabelProvider
;
40 import org
.eclipse
.swt
.SWT
;
41 import org
.eclipse
.swt
.events
.SelectionAdapter
;
42 import org
.eclipse
.swt
.events
.SelectionEvent
;
43 import org
.eclipse
.swt
.events
.VerifyEvent
;
44 import org
.eclipse
.swt
.events
.VerifyListener
;
45 import org
.eclipse
.swt
.layout
.GridData
;
46 import org
.eclipse
.swt
.layout
.GridLayout
;
47 import org
.eclipse
.swt
.widgets
.Button
;
48 import org
.eclipse
.swt
.widgets
.Composite
;
49 import org
.eclipse
.swt
.widgets
.Control
;
50 import org
.eclipse
.swt
.widgets
.Display
;
51 import org
.eclipse
.swt
.widgets
.Event
;
52 import org
.eclipse
.swt
.widgets
.Label
;
53 import org
.eclipse
.swt
.widgets
.Listener
;
54 import org
.eclipse
.swt
.widgets
.Menu
;
55 import org
.eclipse
.swt
.widgets
.Shell
;
56 import org
.eclipse
.swt
.widgets
.Table
;
57 import org
.eclipse
.swt
.widgets
.TableColumn
;
58 import org
.eclipse
.swt
.widgets
.TableItem
;
59 import org
.eclipse
.swt
.widgets
.Text
;
62 * <b><u>KernelTraceChannelConfigurationPage</u></b>
64 * Wizard page implementation to configure the kernel trace channels.
67 public class KernelTraceChannelConfigurationPage
extends WizardPage
implements ITraceChannelConfigurationPage
{
69 // ------------------------------------------------------------------------
71 // ------------------------------------------------------------------------
72 private TraceChannels fChannels
;
73 private TraceState fTraceState
;
74 private Composite container
;
75 private TableViewer tableViewer
;
76 List
<String
> fColumnNames
;
78 Action enableAllAction
;
79 Action disableAllAction
;
80 Action setOverrideAllAction
;
81 Action resetOverideAllAction
;
82 Action setNumSubbufAction
;
83 Action setSubbufSizeAction
;
84 Action setChanTimerAction
;
86 private ColumnData
[] columnDataList
= new ColumnData
[] {
87 new ColumnData(Messages
.ChannelConfigPage_ChannelName
, 150, SWT
.LEFT
, Messages
.ChannelConfigPage_ChannelNameTooltip
, new ViewerComparator() {
89 public int compare(Viewer viewer
, Object e1
, Object e2
) {
90 TraceChannel chan1
= (TraceChannel
) e1
;
91 TraceChannel chan2
= (TraceChannel
) e2
;
92 return chan1
.getName().compareTo(chan2
.getName());
95 new ColumnData(Messages
.ChannelConfigPage_ChannelEnabled
, 150, SWT
.LEFT
, Messages
.ChannelConfigPage_ChannelEnabledTooltip
, null),
96 new ColumnData(Messages
.ChannelConfigPage_ChannelOverride
, 150, SWT
.LEFT
, Messages
.ChannelConfigPage_BufferOverrideTooltip
, null),
97 new ColumnData(Messages
.ChannelConfigPage_NumSubBuf
, 175, SWT
.LEFT
, Messages
.ChannelConfigPage_NumSubBufTooltip
, null),
98 new ColumnData(Messages
.ChannelConfigPage_SubBufSize
, 150, SWT
.LEFT
, Messages
.ChannelConfigPage_SubBufSizeTooltip
, null),
99 new ColumnData(Messages
.ChannelConfigPage_ChannelTimer
, 150, SWT
.LEFT
, Messages
.ChannelConfigPage_ChannelTimerTooltip
, null)};
102 // ------------------------------------------------------------------------
104 // ------------------------------------------------------------------------
109 * @param channels The current channels information
110 * @param state The trace state
112 protected KernelTraceChannelConfigurationPage(TraceChannels channels
, TraceState state
) {
113 super("TraceChannelConfigurationPage"); //$NON-NLS-1$
114 fChannels
= channels
;
116 setTitle(Messages
.ChannelConfigPage_PageTitle
);
119 // ------------------------------------------------------------------------
121 // ------------------------------------------------------------------------
125 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
128 public void createControl(Composite parent
) {
129 container
= new Composite(parent
, SWT
.NULL
);
130 container
.setLayout(new GridLayout());
131 setControl(container
);
133 Composite headerComposite
= new Composite(container
, SWT
.FILL
);
134 GridLayout headerLayout
= new GridLayout(1, true);
135 headerLayout
.marginHeight
= 0;
136 headerLayout
.marginWidth
= 0;
137 headerComposite
.setLayout(headerLayout
);
138 headerComposite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
140 tableViewer
= new TableViewer(headerComposite
, SWT
.BORDER
| SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.FULL_SELECTION
);
141 tableViewer
.setUseHashlookup(true);
143 Table table
= tableViewer
.getTable();
144 table
.setHeaderVisible(true);
146 fColumnNames
= new ArrayList
<String
>();
147 for (int i
= 0; i
< columnDataList
.length
; i
++) {
149 final ColumnData columnData
= columnDataList
[i
];
150 fColumnNames
.add(columnData
.header
);
151 final TableColumn tableColumn
= new TableColumn(table
, SWT
.LEFT
);
152 tableColumn
.setText(columnData
.header
);
153 tableColumn
.setWidth(columnData
.width
);
154 tableColumn
.setAlignment(columnData
.alignment
);
155 tableColumn
.setToolTipText(columnData
.tooltip
);
156 tableColumn
.setMoveable(false);
157 if (columnData
.comparator
!= null) {
158 tableColumn
.addSelectionListener(new SelectionAdapter() {
160 public void widgetSelected(SelectionEvent e
) {
161 if (tableViewer
.getTable().getSortDirection() == SWT
.UP
|| (tableViewer
.getTable().getSortColumn() != tableColumn
)) {
162 tableViewer
.setComparator(columnData
.comparator
);
163 tableViewer
.getTable().setSortDirection(SWT
.DOWN
);
165 tableViewer
.setComparator(new ViewerComparator() {
167 public int compare(Viewer viewer
,Object e1
, Object e2
) {
168 return -1 * columnData
.comparator
.compare(viewer
, e1
,e2
);
171 tableViewer
.getTable().setSortDirection(SWT
.UP
);
173 tableViewer
.getTable().setSortColumn(tableColumn
);
179 tableViewer
.setColumnProperties(fColumnNames
.toArray(new String
[0]));
181 // Create the cell editors
182 CellEditor
[] editors
= new CellEditor
[columnDataList
.length
];
184 // Column 1 : Completed (Checkbox)
185 TextCellEditor textEditor
= new TextCellEditor(table
);
186 editors
[0] = textEditor
;
188 // Column 2 : Description (Free text)
189 editors
[1] = new CheckboxCellEditor(table
);
191 // Column 3 : Owner (Combo Box)
192 editors
[2] = new CheckboxCellEditor(table
);
194 // Column 4 : Percent complete (Text with digits only)
195 textEditor
= new TextCellEditor(table
);
196 ((Text
) textEditor
.getControl()).addVerifyListener(
198 new VerifyListener() {
201 public void verifyText(VerifyEvent e
) {
202 e
.doit
= e
.text
.matches("[0-9]*"); //$NON-NLS-1$
205 editors
[3] = textEditor
;
207 textEditor
= new TextCellEditor(table
);
208 ((Text
) textEditor
.getControl()).addVerifyListener(
210 new VerifyListener() {
213 public void verifyText(VerifyEvent e
) {
214 e
.doit
= e
.text
.matches("[0-9]*"); //$NON-NLS-1$
217 editors
[4] = textEditor
;
219 textEditor
= new TextCellEditor(table
);
220 ((Text
) textEditor
.getControl()).addVerifyListener(
222 new VerifyListener() {
225 public void verifyText(VerifyEvent e
) {
226 e
.doit
= e
.text
.matches("[0-9]*"); //$NON-NLS-1$
229 editors
[5] = textEditor
;
231 // Assign the cell editors to the viewer
232 tableViewer
.setCellEditors(editors
);
233 tableViewer
.setCellModifier(new TraceChannelCellModifier(this));
235 tableViewer
.setContentProvider(new TraceChannelTableContentProvider());
236 tableViewer
.setLabelProvider(new TraceChannelTableLabelProvider());
238 table
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true));
245 * @see org.eclipse.jface.dialogs.DialogPage#dispose()
248 public void dispose() {
253 * @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean)
256 public void setVisible(boolean visible
) {
257 if (visible
&& (fChannels
!= null)) {
258 // Get new channels configuration
259 tableViewer
.setInput(fChannels
);
261 Table table
= tableViewer
.getTable();
262 TableItem
[] items
= table
.getItems();
263 for (int i
= 0; i
< items
.length
; i
++) {
265 items
[i
].setBackground(Display
.getDefault().getSystemColor(SWT
.COLOR_TITLE_INACTIVE_BACKGROUND
));
268 if ((fTraceState
!= TraceState
.CREATED
) && (fTraceState
!= TraceState
.CONFIGURED
)) {
269 items
[i
].setForeground(Display
.getDefault().getSystemColor(SWT
.COLOR_DARK_GRAY
));
275 super.setVisible(visible
);
279 * Gets the list of column names.
281 * @return list of column names
283 public List
<String
> getColumnProperties() {
288 * Refreshes the table.
290 public void refresh() {
291 tableViewer
.refresh();
295 * Gets the trace state.
297 * @return trace state
299 public TraceState
getTraceState() {
304 * Gets if trace is a local trace (i.e. if trace output is stored on host
305 * where client is running)
307 * @return isLocalTrace
309 public boolean isLocalTrace() {
310 TraceConfigurationPage configPage
= (TraceConfigurationPage
) getPreviousPage();
311 return configPage
.isLocalTrace();
316 * @see org.eclipse.linuxtools.lttng.rse.ui.wizards.ITraceChannelConfigurationPage#getTraceChannels()
319 public TraceChannels
getTraceChannels() {
324 * Local class to configure table columns
326 final public class ColumnData
{
327 // Name of the column.
328 public final String header
;
329 // Width of the column.
330 public final int width
;
331 // Alignment of the column.
332 public final int alignment
;
333 // Tooltip of the column.
334 public final String tooltip
;
335 // Used to sort elements of this column. Can be null.
336 public final ViewerComparator comparator
;
338 public ColumnData(String h
, int w
, int a
, String t
, ViewerComparator c
) {
348 * Creates actions for context sensitive menu.
350 private void makeActions() {
352 // Create the context menu actions
353 enableAllAction
= new Action(Messages
.ChannelConfigPage_EnableAll
, LTTngUiPlugin
.getDefault().getImageDescriptor(LTTngUiPlugin
.ICON_ID_CHECKED
)) {
356 TableItem
[] items
= tableViewer
.getTable().getItems();
357 for (int i
= 0; i
< items
.length
; i
++) {
358 TraceChannel chan
= (TraceChannel
)items
[i
].getData();
359 chan
.setIsEnabled(true);
361 tableViewer
.refresh();
365 disableAllAction
= new Action(Messages
.ChannelConfigPage_DisableAll
, LTTngUiPlugin
.getDefault().getImageDescriptor(LTTngUiPlugin
.ICON_ID_UNCHECKED
)) {
368 TableItem
[] items
= tableViewer
.getTable().getItems();
369 for (int i
= 0; i
< items
.length
; i
++) {
370 TraceChannel chan
= (TraceChannel
)items
[i
].getData();
371 chan
.setIsEnabled(false);
373 tableViewer
.refresh();
376 setOverrideAllAction
= new Action(Messages
.ChannelConfigPage_EnableAllBufferOverride
, LTTngUiPlugin
.getDefault().getImageDescriptor(LTTngUiPlugin
.ICON_ID_CHECKED
)) {
379 TableItem
[] items
= tableViewer
.getTable().getItems();
380 for (int i
= 0; i
< items
.length
; i
++) {
381 TraceChannel chan
= (TraceChannel
)items
[i
].getData();
382 chan
.setIsChannelOverride(true);
384 tableViewer
.refresh();
387 resetOverideAllAction
= new Action(Messages
.ChannelConfigage_DisableAllBufferOverride
, LTTngUiPlugin
.getDefault().getImageDescriptor(LTTngUiPlugin
.ICON_ID_UNCHECKED
)) {
390 TableItem
[] items
= tableViewer
.getTable().getItems();
391 for (int i
= 0; i
< items
.length
; i
++) {
392 TraceChannel chan
= (TraceChannel
)items
[i
].getData();
393 chan
.setIsChannelOverride(false);
395 tableViewer
.refresh();
398 setNumSubbufAction
= new Action(Messages
.ChannelConfigPage_SetAllNumSubBuf
, LTTngUiPlugin
.getDefault().getImageDescriptor(LTTngUiPlugin
.ICON_ID_EDIT
)) {
401 TableItem
[] items
= tableViewer
.getTable().getItems();
402 SetDialog setDialog
= new SetDialog(getShell(), Messages
.ChannelConfigPage_NumSubBuf
);
403 if (setDialog
.open() == Window
.OK
) {
405 for (int i
= 0; i
< items
.length
; i
++) {
406 TraceChannel chan
= (TraceChannel
)items
[i
].getData();
407 chan
.setSubbufNum(setDialog
.getValue());
410 tableViewer
.refresh();
414 setSubbufSizeAction
= new Action(Messages
.channelConfigPage_SetAllSubBufSize
, LTTngUiPlugin
.getDefault().getImageDescriptor(LTTngUiPlugin
.ICON_ID_EDIT
)) {
417 TableItem
[] items
= tableViewer
.getTable().getItems();
418 SetDialog setDialog
= new SetDialog(getShell(), Messages
.ChannelConfigPage_SubBufSize
);
419 if (setDialog
.open() == Window
.OK
) {
421 for (int i
= 0; i
< items
.length
; i
++) {
422 TraceChannel chan
= (TraceChannel
)items
[i
].getData();
423 chan
.setSubbufSize(setDialog
.getValue());
426 tableViewer
.refresh();
430 setChanTimerAction
= new Action(Messages
.ChannelConfigPage_SetAllChannelTimer
, LTTngUiPlugin
.getDefault().getImageDescriptor("ICON_ID_EDIT")) { //$NON-NLS-1$
433 TableItem
[] items
= tableViewer
.getTable().getItems();
434 SetDialog setDialog
= new SetDialog(getShell(), Messages
.ChannelConfigPage_ChannelTimer
);
435 if (setDialog
.open() == Window
.OK
) {
437 for (int i
= 0; i
< items
.length
; i
++) {
438 TraceChannel chan
= (TraceChannel
)items
[i
].getData();
439 chan
.setTimer(setDialog
.getValue());
442 tableViewer
.refresh();
449 * Adds context sensitive menu to table.
451 private void addContextMenu() {
452 MenuManager manager
= new MenuManager("configChanPopupMenu"); //$NON-NLS-1$
453 manager
.setRemoveAllWhenShown(true);
454 manager
.addMenuListener(new IMenuListener() {
457 public void menuAboutToShow(IMenuManager manager
) {
459 if ((fTraceState
!= TraceState
.CREATED
) && (fTraceState
!= TraceState
.CONFIGURED
)) {
462 manager
.add(enableAllAction
);
463 manager
.add(disableAllAction
);
464 manager
.add(setOverrideAllAction
);
465 manager
.add(resetOverideAllAction
);
466 manager
.add(setNumSubbufAction
);
467 manager
.add(setSubbufSizeAction
);
468 manager
.add(setChanTimerAction
);
472 Menu menu
= manager
.createContextMenu(tableViewer
.getControl());
473 tableViewer
.getControl().setMenu(menu
);
477 * Local class dialog box implementation for setting values for all
478 * rows for a given column
480 public class SetDialog
extends Dialog
{
482 // ------------------------------------------------------------------------
484 // ------------------------------------------------------------------------
486 private String fWhat
= null;
487 private Text fValueText
= null;
488 private Long fValue
= null;
490 // ------------------------------------------------------------------------
492 // ------------------------------------------------------------------------
494 public SetDialog(Shell parentShell
, String what
) {
499 // ------------------------------------------------------------------------
501 // ------------------------------------------------------------------------
505 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
508 protected void configureShell(Shell newShell
) {
509 super.configureShell(newShell
);
510 newShell
.setText(Messages
.ChannelConfigPage_SetAll
);
511 newShell
.setImage(LTTngUiPlugin
.getDefault().getImage(LTTngUiPlugin
.ICON_ID_EDIT
));
516 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
519 protected Control
createDialogArea(Composite parent
) {
521 Composite composite
= new Composite(parent
, SWT
.RESIZE
);
522 GridLayout mainLayout
= new GridLayout(3, true);
523 composite
.setLayout(mainLayout
);
524 Label what
= new Label(composite
, SWT
.LEFT
);
525 what
.setLayoutData(new GridData(GridData
.FILL
, GridData
.CENTER
, true, false, 1, 1));
528 fValueText
= new Text(composite
, SWT
.LEFT
);
529 fValueText
.setLayoutData(new GridData(GridData
.FILL
, GridData
.CENTER
, true, false, 2, 1));
531 fValueText
.addVerifyListener(
532 new VerifyListener() {
535 public void verifyText(VerifyEvent e
) {
536 e
.doit
= e
.text
.matches("[0-9]*"); //$NON-NLS-1$
540 fValueText
.addListener(SWT
.Modify
, new Listener() {
542 public void handleEvent(Event event
) {
543 Button ok
= getButton(IDialogConstants
.OK_ID
);
544 ok
.setEnabled(validateInput(fValueText
.getText()));
553 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
556 protected void createButtonsForButtonBar(Composite parent
) {
557 Button ok
= createButton(parent
, IDialogConstants
.OK_ID
, IDialogConstants
.OK_LABEL
, true);
558 createButton(parent
, IDialogConstants
.CANCEL_ID
, IDialogConstants
.CANCEL_LABEL
, false);
560 ok
.setEnabled(false);
565 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
568 protected void okPressed() {
569 fValue
= Long
.valueOf(fValueText
.getText());
574 * Method to validate input.
576 private boolean validateInput(String path
) {
577 return (path
.trim().length() > 0);
581 * Gets value that the user input.
585 public Long
getValue() {