1 /**********************************************************************
2 * Copyright (c) 2012, 2013 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
11 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
12 **********************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
;
15 import java
.util
.Arrays
;
17 import org
.eclipse
.jface
.dialogs
.Dialog
;
18 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
19 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
20 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.Activator
;
21 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.messages
.Messages
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceChannelComponent
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceDomainComponent
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceSessionComponent
;
25 import org
.eclipse
.swt
.SWT
;
26 import org
.eclipse
.swt
.custom
.CCombo
;
27 import org
.eclipse
.swt
.events
.SelectionEvent
;
28 import org
.eclipse
.swt
.events
.SelectionListener
;
29 import org
.eclipse
.swt
.graphics
.Point
;
30 import org
.eclipse
.swt
.layout
.GridData
;
31 import org
.eclipse
.swt
.layout
.GridLayout
;
32 import org
.eclipse
.swt
.widgets
.Composite
;
33 import org
.eclipse
.swt
.widgets
.Control
;
34 import org
.eclipse
.swt
.widgets
.Group
;
35 import org
.eclipse
.swt
.widgets
.Shell
;
36 import org
.eclipse
.swt
.widgets
.Text
;
40 * Dialog box for collecting information about the events to enable.
43 * @author Bernd Hufmann
45 public class GetEventInfoDialog
extends Dialog
implements IGetEventInfoDialog
{
47 // ------------------------------------------------------------------------
49 // ------------------------------------------------------------------------
51 * The icon file for this dialog box.
53 public static final String TARGET_NEW_CONNECTION_ICON_FILE
= "icons/elcl16/enable_event.gif"; //$NON-NLS-1$
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
59 * The session combo box.
61 private CCombo fSessionsCombo
= null;
63 * The channel combo box.
65 private CCombo fChannelsCombo
= null;
69 private Text fFilterText
;
71 * The list of available sessions.
73 private TraceSessionComponent
[] fSessions
;
75 * True for kernel, false for UST.
77 private boolean fIsKernel
;
79 * Index in session array (selected session).
81 private int fSessionIndex
= 0;
83 * The Channel where the events should be enabled.
85 private TraceChannelComponent fChannel
;
87 * List of available channels of the selected session.
89 private TraceChannelComponent
[] fChannels
;
91 * The filter expression
93 private String fFilterExpression
;
95 // ------------------------------------------------------------------------
97 // ------------------------------------------------------------------------
99 * Constructor of dialog box.
100 * @param shell - the shell for the dialog box
102 public GetEventInfoDialog(Shell shell
) {
104 setShellStyle(SWT
.RESIZE
);
107 // ------------------------------------------------------------------------
109 // ------------------------------------------------------------------------
112 public TraceSessionComponent
getSession() {
113 return fSessions
[fSessionIndex
];
117 public TraceChannelComponent
getChannel() {
122 public void setIsKernel(boolean isKernel
) {
123 fIsKernel
= isKernel
;
127 public void setSessions(TraceSessionComponent
[] sessions
) {
128 fSessions
= Arrays
.copyOf(sessions
, sessions
.length
);
132 public String
getFilterExpression() {
133 return fFilterExpression
;
136 // ------------------------------------------------------------------------
138 // ------------------------------------------------------------------------
141 protected void configureShell(Shell newShell
) {
142 super.configureShell(newShell
);
143 newShell
.setText(Messages
.TraceControl_EnableEventsDialogTitle
);
144 newShell
.setImage(Activator
.getDefault().loadIcon(TARGET_NEW_CONNECTION_ICON_FILE
));
148 protected Control
createDialogArea(Composite parent
) {
151 Composite dialogComposite
= new Composite(parent
, SWT
.NONE
);
152 GridLayout layout
= new GridLayout(1, true);
153 dialogComposite
.setLayout(layout
);
154 dialogComposite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
156 Group sessionsGroup
= new Group(dialogComposite
, SWT
.SHADOW_NONE
);
157 sessionsGroup
.setText(Messages
.TraceControl_EnableEventsSessionGroupName
);
158 layout
= new GridLayout(1, true);
159 sessionsGroup
.setLayout(layout
);
160 GridData data
= new GridData(GridData
.FILL_HORIZONTAL
);
161 sessionsGroup
.setLayoutData(data
);
163 fSessionsCombo
= new CCombo(sessionsGroup
, SWT
.READ_ONLY
);
164 fSessionsCombo
.setToolTipText(Messages
.TraceControl_EnableEventsSessionsTooltip
);
165 fSessionsCombo
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
167 String items
[] = new String
[fSessions
.length
];
168 for (int i
= 0; i
< items
.length
; i
++) {
169 items
[i
] = String
.valueOf(fSessions
[i
].getName());
172 fSessionsCombo
.setItems(items
);
173 fSessionsCombo
.setEnabled(fSessions
.length
> 0);
175 Group channelsGroup
= new Group(dialogComposite
, SWT
.SHADOW_NONE
);
176 channelsGroup
.setText(Messages
.TraceControl_EnableEventsChannelGroupName
);
177 layout
= new GridLayout(1, true);
178 channelsGroup
.setLayout(layout
);
179 data
= new GridData(GridData
.FILL_HORIZONTAL
);
180 channelsGroup
.setLayoutData(data
);
182 fChannelsCombo
= new CCombo(channelsGroup
, SWT
.READ_ONLY
);
183 fChannelsCombo
.setToolTipText(Messages
.TraceControl_EnableEventsChannelsTooltip
);
184 fChannelsCombo
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
185 fChannelsCombo
.setEnabled(false);
187 fSessionsCombo
.addSelectionListener(new SelectionListener() {
189 public void widgetSelected(SelectionEvent e
) {
190 fSessionIndex
= fSessionsCombo
.getSelectionIndex();
192 if (fSessionIndex
>= 0) {
193 TraceDomainComponent domain
= null;
194 TraceDomainComponent
[] domains
= fSessions
[fSessionIndex
].getDomains();
195 for (int i
= 0; i
< domains
.length
; i
++) {
197 if (domains
[i
].isKernel() == fIsKernel
) {
203 if (domain
!= null) {
204 fChannels
= domain
.getChannels();
205 String selectionItems
[] = new String
[fChannels
.length
];
206 for (int i
= 0; i
< selectionItems
.length
; i
++) {
207 selectionItems
[i
] = String
.valueOf(fChannels
[i
].getName());
209 fChannelsCombo
.setItems(selectionItems
);
210 fChannelsCombo
.setEnabled(fChannels
.length
> 0);
212 fChannelsCombo
.setItems(new String
[0]);
213 fChannelsCombo
.setEnabled(false);
216 fChannelsCombo
.getParent().getParent().layout();
221 public void widgetDefaultSelected(SelectionEvent e
) {
225 // take first session to test whether events filtering is supported or not
226 if (fSessions
[0].isEventFilteringSupported() && !fIsKernel
) {
227 Group filterMainGroup
= new Group(dialogComposite
, SWT
.SHADOW_NONE
);
228 filterMainGroup
.setText(Messages
.TraceControl_EnableEventsFilterGroupName
);
229 layout
= new GridLayout(2, false);
230 filterMainGroup
.setLayout(layout
);
231 data
= new GridData(GridData
.FILL_HORIZONTAL
);
232 filterMainGroup
.setLayoutData(data
);
234 fFilterText
= new Text(filterMainGroup
, SWT
.LEFT
);
235 fFilterText
.setToolTipText(Messages
.TraceControl_EnableEventsFilterTooltip
);
236 data
= new GridData(GridData
.FILL_HORIZONTAL
);
237 fFilterText
.setLayoutData(data
);
240 getShell().setMinimumSize(new Point(300, 200));
242 return dialogComposite
;
246 protected void createButtonsForButtonBar(Composite parent
) {
247 createButton(parent
, IDialogConstants
.CANCEL_ID
, "&Cancel", true); //$NON-NLS-1$
248 createButton(parent
, IDialogConstants
.OK_ID
, "&Ok", true); //$NON-NLS-1$
252 protected void okPressed() {
254 if (fSessionsCombo
.getSelectionIndex() < 0) {
255 MessageDialog
.openError(getShell(),
256 Messages
.TraceControl_EnableEventsDialogTitle
,
257 Messages
.TraceControl_EnableEventsNoSessionError
);
261 fSessionIndex
= fSessionsCombo
.getSelectionIndex();
263 // if no channel is available or no channel is selected use default channel indicated by fChannel=null
265 if ((fChannels
!= null) && (fChannelsCombo
.getSelectionIndex() >= 0)) {
266 fChannel
= fChannels
[fChannelsCombo
.getSelectionIndex()];
269 // initialize filter with null
270 fFilterExpression
= null;
271 if (fSessions
[0].isEventFilteringSupported() && !fIsKernel
) {
272 String tempFilter
= fFilterText
.getText();
274 if(!tempFilter
.matches("\\s*")) { //$NON-NLS-1$
275 fFilterExpression
= tempFilter
;