1 /**********************************************************************
2 * Copyright (c) 2012, 2014 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
.tracecompass
.internal
.lttng2
.control
.ui
.views
.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
.swt
.SWT
;
21 import org
.eclipse
.swt
.custom
.CCombo
;
22 import org
.eclipse
.swt
.events
.SelectionEvent
;
23 import org
.eclipse
.swt
.events
.SelectionListener
;
24 import org
.eclipse
.swt
.graphics
.Point
;
25 import org
.eclipse
.swt
.layout
.GridData
;
26 import org
.eclipse
.swt
.layout
.GridLayout
;
27 import org
.eclipse
.swt
.widgets
.Composite
;
28 import org
.eclipse
.swt
.widgets
.Control
;
29 import org
.eclipse
.swt
.widgets
.Group
;
30 import org
.eclipse
.swt
.widgets
.Shell
;
31 import org
.eclipse
.swt
.widgets
.Text
;
32 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceDomainType
;
33 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.Activator
;
34 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
35 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceChannelComponent
;
36 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceDomainComponent
;
37 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceSessionComponent
;
41 * Dialog box for collecting information about the events to enable.
44 * @author Bernd Hufmann
46 public class GetEventInfoDialog
extends Dialog
implements IGetEventInfoDialog
{
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
52 * The icon file for this dialog box.
54 public static final String TARGET_NEW_CONNECTION_ICON_FILE
= "icons/elcl16/enable_event.gif"; //$NON-NLS-1$
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
60 * The session combo box.
62 private CCombo fSessionsCombo
= null;
64 * The channel combo box.
66 private CCombo fChannelsCombo
= null;
70 private Text fFilterText
;
72 * The list of available sessions.
74 private TraceSessionComponent
[] fSessions
;
76 * The domain type ({@link TraceDomainType})
78 private TraceDomainType fDomain
;
80 * Index in session array (selected session).
82 private int fSessionIndex
= 0;
84 * The Channel where the events should be enabled.
86 private TraceChannelComponent fChannel
;
88 * List of available channels of the selected session.
90 private TraceChannelComponent
[] fChannels
;
92 * The filter expression
94 private String fFilterExpression
;
96 // ------------------------------------------------------------------------
98 // ------------------------------------------------------------------------
100 * Constructor of dialog box.
101 * @param shell - the shell for the dialog box
103 public GetEventInfoDialog(Shell shell
) {
105 setShellStyle(SWT
.RESIZE
| getShellStyle());
108 // ------------------------------------------------------------------------
110 // ------------------------------------------------------------------------
113 public TraceSessionComponent
getSession() {
114 return fSessions
[fSessionIndex
];
118 public TraceChannelComponent
getChannel() {
123 public void setDomain(TraceDomainType domain
) {
128 public void setSessions(TraceSessionComponent
[] sessions
) {
129 fSessions
= Arrays
.copyOf(sessions
, sessions
.length
);
133 public String
getFilterExpression() {
134 return fFilterExpression
;
137 // ------------------------------------------------------------------------
139 // ------------------------------------------------------------------------
142 protected void configureShell(Shell newShell
) {
143 super.configureShell(newShell
);
144 newShell
.setText(Messages
.TraceControl_EnableEventsDialogTitle
);
145 newShell
.setImage(Activator
.getDefault().loadIcon(TARGET_NEW_CONNECTION_ICON_FILE
));
149 protected Control
createDialogArea(Composite parent
) {
152 Composite dialogComposite
= new Composite(parent
, SWT
.NONE
);
153 GridLayout layout
= new GridLayout(1, true);
154 dialogComposite
.setLayout(layout
);
155 dialogComposite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
157 Group sessionsGroup
= new Group(dialogComposite
, SWT
.SHADOW_NONE
);
158 sessionsGroup
.setText(Messages
.TraceControl_EnableEventsSessionGroupName
);
159 layout
= new GridLayout(1, true);
160 sessionsGroup
.setLayout(layout
);
161 GridData data
= new GridData(GridData
.FILL_HORIZONTAL
);
162 sessionsGroup
.setLayoutData(data
);
164 fSessionsCombo
= new CCombo(sessionsGroup
, SWT
.READ_ONLY
);
165 fSessionsCombo
.setToolTipText(Messages
.TraceControl_EnableEventsSessionsTooltip
);
166 fSessionsCombo
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
168 String items
[] = new String
[fSessions
.length
];
169 for (int i
= 0; i
< items
.length
; i
++) {
170 items
[i
] = String
.valueOf(fSessions
[i
].getName());
173 fSessionsCombo
.setItems(items
);
174 fSessionsCombo
.setEnabled(fSessions
.length
> 0);
176 Group channelsGroup
= new Group(dialogComposite
, SWT
.SHADOW_NONE
);
177 channelsGroup
.setText(Messages
.TraceControl_EnableEventsChannelGroupName
);
178 layout
= new GridLayout(1, true);
179 channelsGroup
.setLayout(layout
);
180 data
= new GridData(GridData
.FILL_HORIZONTAL
);
181 channelsGroup
.setLayoutData(data
);
183 fChannelsCombo
= new CCombo(channelsGroup
, SWT
.READ_ONLY
);
184 fChannelsCombo
.setToolTipText(Messages
.TraceControl_EnableEventsChannelsTooltip
);
185 fChannelsCombo
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
186 fChannelsCombo
.setEnabled(false);
188 fSessionsCombo
.addSelectionListener(new SelectionListener() {
190 public void widgetSelected(SelectionEvent e
) {
191 fSessionIndex
= fSessionsCombo
.getSelectionIndex();
193 if (fSessionIndex
>= 0) {
194 TraceDomainComponent domain
= null;
195 TraceDomainComponent
[] domains
= fSessions
[fSessionIndex
].getDomains();
196 for (int i
= 0; i
< domains
.length
; i
++) {
198 if (domains
[i
].getDomain().equals(fDomain
)) {
204 if (domain
!= null) {
205 fChannels
= domain
.getChannels();
206 String selectionItems
[] = new String
[fChannels
.length
];
207 for (int i
= 0; i
< selectionItems
.length
; i
++) {
208 selectionItems
[i
] = String
.valueOf(fChannels
[i
].getName());
210 fChannelsCombo
.setItems(selectionItems
);
211 fChannelsCombo
.setEnabled(fChannels
.length
> 0);
213 fChannelsCombo
.setItems(new String
[0]);
214 fChannelsCombo
.setEnabled(false);
217 fChannelsCombo
.getParent().getParent().layout();
222 public void widgetDefaultSelected(SelectionEvent e
) {
226 // take first session to test whether events filtering is supported or not
227 if (fSessions
[0].isEventFilteringSupported(fDomain
)) {
228 Group filterMainGroup
= new Group(dialogComposite
, SWT
.SHADOW_NONE
);
229 filterMainGroup
.setText(Messages
.TraceControl_EnableEventsFilterGroupName
);
230 layout
= new GridLayout(2, false);
231 filterMainGroup
.setLayout(layout
);
232 data
= new GridData(GridData
.FILL_HORIZONTAL
);
233 filterMainGroup
.setLayoutData(data
);
235 fFilterText
= new Text(filterMainGroup
, SWT
.LEFT
);
236 fFilterText
.setToolTipText(Messages
.TraceControl_EnableEventsFilterTooltip
);
237 data
= new GridData(GridData
.FILL_HORIZONTAL
);
238 fFilterText
.setLayoutData(data
);
241 getShell().setMinimumSize(new Point(300, 200));
243 return dialogComposite
;
247 protected void createButtonsForButtonBar(Composite parent
) {
248 createButton(parent
, IDialogConstants
.CANCEL_ID
, "&Cancel", true); //$NON-NLS-1$
249 createButton(parent
, IDialogConstants
.OK_ID
, "&Ok", true); //$NON-NLS-1$
253 protected void okPressed() {
255 if (fSessionsCombo
.getSelectionIndex() < 0) {
256 MessageDialog
.openError(getShell(),
257 Messages
.TraceControl_EnableEventsDialogTitle
,
258 Messages
.TraceControl_EnableEventsNoSessionError
);
262 fSessionIndex
= fSessionsCombo
.getSelectionIndex();
264 // if no channel is available or no channel is selected use default channel indicated by fChannel=null
266 if ((fChannels
!= null) && (fChannelsCombo
.getSelectionIndex() >= 0)) {
267 fChannel
= fChannels
[fChannelsCombo
.getSelectionIndex()];
270 // initialize filter with null
271 fFilterExpression
= null;
272 if (fSessions
[0].isEventFilteringSupported(fDomain
)) {
273 String tempFilter
= fFilterText
.getText();
275 if(!tempFilter
.trim().isEmpty()) {
276 fFilterExpression
= tempFilter
;