1 /**********************************************************************
2 * Copyright (c) 2012 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 **********************************************************************/
12 package org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
;
14 import java
.util
.Arrays
;
16 import org
.eclipse
.jface
.dialogs
.Dialog
;
17 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
18 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
19 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.Activator
;
20 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.messages
.Messages
;
21 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceChannelComponent
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceDomainComponent
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceSessionComponent
;
24 import org
.eclipse
.swt
.SWT
;
25 import org
.eclipse
.swt
.custom
.CCombo
;
26 import org
.eclipse
.swt
.events
.SelectionEvent
;
27 import org
.eclipse
.swt
.events
.SelectionListener
;
28 import org
.eclipse
.swt
.graphics
.Point
;
29 import org
.eclipse
.swt
.layout
.GridData
;
30 import org
.eclipse
.swt
.layout
.GridLayout
;
31 import org
.eclipse
.swt
.widgets
.Composite
;
32 import org
.eclipse
.swt
.widgets
.Control
;
33 import org
.eclipse
.swt
.widgets
.Group
;
34 import org
.eclipse
.swt
.widgets
.Shell
;
35 import org
.eclipse
.swt
.widgets
.Text
;
39 * Dialog box for collecting information about the events to enable.
42 * @author Bernd Hufmann
44 public class GetEventInfoDialog
extends Dialog
implements IGetEventInfoDialog
{
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
50 * The icon file for this dialog box.
52 public static final String TARGET_NEW_CONNECTION_ICON_FILE
= "icons/elcl16/enable_event.gif"; //$NON-NLS-1$
54 // ------------------------------------------------------------------------
56 // ------------------------------------------------------------------------
58 * The dialog composite.
60 private Composite fDialogComposite
= null;
62 * The Group for the session combo box.
64 private Group fSessionsGroup
= null;
66 * The Group for the channel combo box.
68 private Group fChannelsGroup
= null;
70 * The session combo box.
72 private CCombo fSessionsCombo
= null;
74 * The channel combo box.
76 private CCombo fChannelsCombo
= null;
80 private Text fFilterText
;
82 * The list of available sessions.
84 private TraceSessionComponent
[] fSessions
;
86 * True for kernel, false for UST.
88 private boolean fIsKernel
;
90 * Index in session array (selected session).
92 private int fSessionIndex
= 0;
94 * The Channel where the events should be enabled.
96 private TraceChannelComponent fChannel
;
98 * List of available channels of the selected session.
100 private TraceChannelComponent
[] fChannels
;
102 * The filter expression
104 private String fFilterExpression
;
106 // ------------------------------------------------------------------------
108 // ------------------------------------------------------------------------
110 * Constructor of dialog box.
111 * @param shell - the shell for the dialog box
113 public GetEventInfoDialog(Shell shell
) {
115 setShellStyle(SWT
.RESIZE
);
118 // ------------------------------------------------------------------------
120 // ------------------------------------------------------------------------
123 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableEventsDialog#getSession()
126 public TraceSessionComponent
getSession() {
127 return fSessions
[fSessionIndex
];
132 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableEventsDialog#getChannel()
135 public TraceChannelComponent
getChannel() {
141 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IGetEventInfoDialog#setIsKernel(boolean)
144 public void setIsKernel(boolean isKernel
) {
145 fIsKernel
= isKernel
;
150 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IGetEventInfoDialog#setSessions(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent[])
153 public void setSessions(TraceSessionComponent
[] sessions
) {
154 fSessions
= Arrays
.copyOf(sessions
, sessions
.length
);
158 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IGetEventInfoDialog#getFilterExpression()
161 public String
getFilterExpression() {
162 return fFilterExpression
;
165 // ------------------------------------------------------------------------
167 // ------------------------------------------------------------------------
170 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
173 protected void configureShell(Shell newShell
) {
174 super.configureShell(newShell
);
175 newShell
.setText(Messages
.TraceControl_EnableEventsDialogTitle
);
176 newShell
.setImage(Activator
.getDefault().loadIcon(TARGET_NEW_CONNECTION_ICON_FILE
));
181 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
184 protected Control
createDialogArea(Composite parent
) {
187 fDialogComposite
= new Composite(parent
, SWT
.NONE
);
188 GridLayout layout
= new GridLayout(1, true);
189 fDialogComposite
.setLayout(layout
);
190 fDialogComposite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
192 fSessionsGroup
= new Group(fDialogComposite
, SWT
.SHADOW_NONE
);
193 fSessionsGroup
.setText(Messages
.TraceControl_EnableEventsSessionGroupName
);
194 layout
= new GridLayout(1, true);
195 fSessionsGroup
.setLayout(layout
);
196 GridData data
= new GridData(GridData
.FILL_HORIZONTAL
);
197 fSessionsGroup
.setLayoutData(data
);
199 fSessionsCombo
= new CCombo(fSessionsGroup
, SWT
.READ_ONLY
);
200 fSessionsCombo
.setToolTipText(Messages
.TraceControl_EnableEventsSessionsTooltip
);
201 fSessionsCombo
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
203 String items
[] = new String
[fSessions
.length
];
204 for (int i
= 0; i
< items
.length
; i
++) {
205 items
[i
] = String
.valueOf(fSessions
[i
].getName());
208 fSessionsCombo
.setItems(items
);
209 fSessionsCombo
.setEnabled(fSessions
.length
> 0);
211 fChannelsGroup
= new Group(fDialogComposite
, SWT
.SHADOW_NONE
);
212 fChannelsGroup
.setText(Messages
.TraceControl_EnableEventsChannelGroupName
);
213 layout
= new GridLayout(1, true);
214 fChannelsGroup
.setLayout(layout
);
215 data
= new GridData(GridData
.FILL_HORIZONTAL
);
216 fChannelsGroup
.setLayoutData(data
);
218 fChannelsCombo
= new CCombo(fChannelsGroup
, SWT
.READ_ONLY
);
219 fChannelsCombo
.setToolTipText(Messages
.TraceControl_EnableEventsChannelsTooltip
);
220 fChannelsCombo
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
221 fChannelsCombo
.setEnabled(false);
223 fSessionsCombo
.addSelectionListener(new SelectionListener() {
225 public void widgetSelected(SelectionEvent e
) {
226 fSessionIndex
= fSessionsCombo
.getSelectionIndex();
228 if (fSessionIndex
>= 0) {
229 TraceDomainComponent domain
= null;
230 TraceDomainComponent
[] domains
= fSessions
[fSessionIndex
].getDomains();
231 for (int i
= 0; i
< domains
.length
; i
++) {
233 if (domains
[i
].isKernel() == fIsKernel
) {
239 if (domain
!= null) {
240 fChannels
= domain
.getChannels();
241 String selectionItems
[] = new String
[fChannels
.length
];
242 for (int i
= 0; i
< selectionItems
.length
; i
++) {
243 selectionItems
[i
] = String
.valueOf(fChannels
[i
].getName());
245 fChannelsCombo
.setItems(selectionItems
);
246 fChannelsCombo
.setEnabled(fChannels
.length
> 0);
248 fChannelsCombo
.setItems(new String
[0]);
249 fChannelsCombo
.setEnabled(false);
252 fChannelsCombo
.getParent().getParent().layout();
257 public void widgetDefaultSelected(SelectionEvent e
) {
261 // take first session to test whether events filtering is supported or not
262 if (fSessions
[0].isEventFilteringSupported() && !fIsKernel
) {
263 Group filterMainGroup
= new Group(fDialogComposite
, SWT
.SHADOW_NONE
);
264 filterMainGroup
.setText(Messages
.TraceControl_EnableEventsFilterGroupName
);
265 layout
= new GridLayout(2, false);
266 filterMainGroup
.setLayout(layout
);
267 data
= new GridData(GridData
.FILL_HORIZONTAL
);
268 filterMainGroup
.setLayoutData(data
);
270 fFilterText
= new Text(filterMainGroup
, SWT
.LEFT
);
271 fFilterText
.setToolTipText(Messages
.TraceControl_EnableEventsFilterTooltip
);
272 data
= new GridData(GridData
.FILL_HORIZONTAL
);
273 fFilterText
.setLayoutData(data
);
276 getShell().setMinimumSize(new Point(300, 200));
278 return fDialogComposite
;
283 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
286 protected void createButtonsForButtonBar(Composite parent
) {
287 createButton(parent
, IDialogConstants
.CANCEL_ID
, "&Cancel", true); //$NON-NLS-1$
288 createButton(parent
, IDialogConstants
.OK_ID
, "&Ok", true); //$NON-NLS-1$
293 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
296 protected void okPressed() {
298 if (fSessionsCombo
.getSelectionIndex() < 0) {
299 MessageDialog
.openError(getShell(),
300 Messages
.TraceControl_EnableEventsDialogTitle
,
301 Messages
.TraceControl_EnableEventsNoSessionError
);
305 fSessionIndex
= fSessionsCombo
.getSelectionIndex();
307 // if no channel is available or no channel is selected use default channel indicated by fChannel=null
309 if ((fChannels
!= null) && (fChannelsCombo
.getSelectionIndex() >= 0)) {
310 fChannel
= fChannels
[fChannelsCombo
.getSelectionIndex()];
313 // initialize filter with null
314 fFilterExpression
= null;
315 if (fSessions
[0].isEventFilteringSupported() && !fIsKernel
) {
316 String tempFilter
= fFilterText
.getText();
318 if(!tempFilter
.matches("\\s*")) { //$NON-NLS-1$
319 fFilterExpression
= tempFilter
;