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 dialog composite.
61 private Composite fDialogComposite
= null;
63 * The Group for the session combo box.
65 private Group fSessionsGroup
= null;
67 * The Group for the channel combo box.
69 private Group fChannelsGroup
= null;
71 * The session combo box.
73 private CCombo fSessionsCombo
= null;
75 * The channel combo box.
77 private CCombo fChannelsCombo
= null;
81 private Text fFilterText
;
83 * The list of available sessions.
85 private TraceSessionComponent
[] fSessions
;
87 * True for kernel, false for UST.
89 private boolean fIsKernel
;
91 * Index in session array (selected session).
93 private int fSessionIndex
= 0;
95 * The Channel where the events should be enabled.
97 private TraceChannelComponent fChannel
;
99 * List of available channels of the selected session.
101 private TraceChannelComponent
[] fChannels
;
103 * The filter expression
105 private String fFilterExpression
;
107 // ------------------------------------------------------------------------
109 // ------------------------------------------------------------------------
111 * Constructor of dialog box.
112 * @param shell - the shell for the dialog box
114 public GetEventInfoDialog(Shell shell
) {
116 setShellStyle(SWT
.RESIZE
);
119 // ------------------------------------------------------------------------
121 // ------------------------------------------------------------------------
124 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableEventsDialog#getSession()
127 public TraceSessionComponent
getSession() {
128 return fSessions
[fSessionIndex
];
133 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableEventsDialog#getChannel()
136 public TraceChannelComponent
getChannel() {
142 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IGetEventInfoDialog#setIsKernel(boolean)
145 public void setIsKernel(boolean isKernel
) {
146 fIsKernel
= isKernel
;
151 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IGetEventInfoDialog#setSessions(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent[])
154 public void setSessions(TraceSessionComponent
[] sessions
) {
155 fSessions
= Arrays
.copyOf(sessions
, sessions
.length
);
159 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IGetEventInfoDialog#getFilterExpression()
162 public String
getFilterExpression() {
163 return fFilterExpression
;
166 // ------------------------------------------------------------------------
168 // ------------------------------------------------------------------------
171 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
174 protected void configureShell(Shell newShell
) {
175 super.configureShell(newShell
);
176 newShell
.setText(Messages
.TraceControl_EnableEventsDialogTitle
);
177 newShell
.setImage(Activator
.getDefault().loadIcon(TARGET_NEW_CONNECTION_ICON_FILE
));
182 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
185 protected Control
createDialogArea(Composite parent
) {
188 fDialogComposite
= new Composite(parent
, SWT
.NONE
);
189 GridLayout layout
= new GridLayout(1, true);
190 fDialogComposite
.setLayout(layout
);
191 fDialogComposite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
193 fSessionsGroup
= new Group(fDialogComposite
, SWT
.SHADOW_NONE
);
194 fSessionsGroup
.setText(Messages
.TraceControl_EnableEventsSessionGroupName
);
195 layout
= new GridLayout(1, true);
196 fSessionsGroup
.setLayout(layout
);
197 GridData data
= new GridData(GridData
.FILL_HORIZONTAL
);
198 fSessionsGroup
.setLayoutData(data
);
200 fSessionsCombo
= new CCombo(fSessionsGroup
, SWT
.READ_ONLY
);
201 fSessionsCombo
.setToolTipText(Messages
.TraceControl_EnableEventsSessionsTooltip
);
202 fSessionsCombo
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
204 String items
[] = new String
[fSessions
.length
];
205 for (int i
= 0; i
< items
.length
; i
++) {
206 items
[i
] = String
.valueOf(fSessions
[i
].getName());
209 fSessionsCombo
.setItems(items
);
210 fSessionsCombo
.setEnabled(fSessions
.length
> 0);
212 fChannelsGroup
= new Group(fDialogComposite
, SWT
.SHADOW_NONE
);
213 fChannelsGroup
.setText(Messages
.TraceControl_EnableEventsChannelGroupName
);
214 layout
= new GridLayout(1, true);
215 fChannelsGroup
.setLayout(layout
);
216 data
= new GridData(GridData
.FILL_HORIZONTAL
);
217 fChannelsGroup
.setLayoutData(data
);
219 fChannelsCombo
= new CCombo(fChannelsGroup
, SWT
.READ_ONLY
);
220 fChannelsCombo
.setToolTipText(Messages
.TraceControl_EnableEventsChannelsTooltip
);
221 fChannelsCombo
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
222 fChannelsCombo
.setEnabled(false);
224 fSessionsCombo
.addSelectionListener(new SelectionListener() {
226 public void widgetSelected(SelectionEvent e
) {
227 fSessionIndex
= fSessionsCombo
.getSelectionIndex();
229 if (fSessionIndex
>= 0) {
230 TraceDomainComponent domain
= null;
231 TraceDomainComponent
[] domains
= fSessions
[fSessionIndex
].getDomains();
232 for (int i
= 0; i
< domains
.length
; i
++) {
234 if (domains
[i
].isKernel() == fIsKernel
) {
240 if (domain
!= null) {
241 fChannels
= domain
.getChannels();
242 String selectionItems
[] = new String
[fChannels
.length
];
243 for (int i
= 0; i
< selectionItems
.length
; i
++) {
244 selectionItems
[i
] = String
.valueOf(fChannels
[i
].getName());
246 fChannelsCombo
.setItems(selectionItems
);
247 fChannelsCombo
.setEnabled(fChannels
.length
> 0);
249 fChannelsCombo
.setItems(new String
[0]);
250 fChannelsCombo
.setEnabled(false);
253 fChannelsCombo
.getParent().getParent().layout();
258 public void widgetDefaultSelected(SelectionEvent e
) {
262 // take first session to test whether events filtering is supported or not
263 if (fSessions
[0].isEventFilteringSupported() && !fIsKernel
) {
264 Group filterMainGroup
= new Group(fDialogComposite
, SWT
.SHADOW_NONE
);
265 filterMainGroup
.setText(Messages
.TraceControl_EnableEventsFilterGroupName
);
266 layout
= new GridLayout(2, false);
267 filterMainGroup
.setLayout(layout
);
268 data
= new GridData(GridData
.FILL_HORIZONTAL
);
269 filterMainGroup
.setLayoutData(data
);
271 fFilterText
= new Text(filterMainGroup
, SWT
.LEFT
);
272 fFilterText
.setToolTipText(Messages
.TraceControl_EnableEventsFilterTooltip
);
273 data
= new GridData(GridData
.FILL_HORIZONTAL
);
274 fFilterText
.setLayoutData(data
);
277 getShell().setMinimumSize(new Point(300, 200));
279 return fDialogComposite
;
284 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
287 protected void createButtonsForButtonBar(Composite parent
) {
288 createButton(parent
, IDialogConstants
.CANCEL_ID
, "&Cancel", true); //$NON-NLS-1$
289 createButton(parent
, IDialogConstants
.OK_ID
, "&Ok", true); //$NON-NLS-1$
294 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
297 protected void okPressed() {
299 if (fSessionsCombo
.getSelectionIndex() < 0) {
300 MessageDialog
.openError(getShell(),
301 Messages
.TraceControl_EnableEventsDialogTitle
,
302 Messages
.TraceControl_EnableEventsNoSessionError
);
306 fSessionIndex
= fSessionsCombo
.getSelectionIndex();
308 // if no channel is available or no channel is selected use default channel indicated by fChannel=null
310 if ((fChannels
!= null) && (fChannelsCombo
.getSelectionIndex() >= 0)) {
311 fChannel
= fChannels
[fChannelsCombo
.getSelectionIndex()];
314 // initialize filter with null
315 fFilterExpression
= null;
316 if (fSessions
[0].isEventFilteringSupported() && !fIsKernel
) {
317 String tempFilter
= fFilterText
.getText();
319 if(!tempFilter
.matches("\\s*")) { //$NON-NLS-1$
320 fFilterExpression
= tempFilter
;