Update to session creation procedure
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / dialogs / GetEventInfoDialog.java
CommitLineData
6503ae0f 1/**********************************************************************
ba3a9bd2 2 * Copyright (c) 2012, 2013 Ericsson
7ce7e4af 3 *
6503ae0f
BH
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
7ce7e4af
BH
8 *
9 * Contributors:
6503ae0f 10 * Bernd Hufmann - Initial API and implementation
ba3a9bd2 11 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
6503ae0f 12 **********************************************************************/
115b4a01 13package org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs;
6503ae0f
BH
14
15import java.util.Arrays;
16
17import org.eclipse.jface.dialogs.Dialog;
18import org.eclipse.jface.dialogs.IDialogConstants;
19import org.eclipse.jface.dialogs.MessageDialog;
115b4a01 20import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
9315aeee 21import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages;
115b4a01
BH
22import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceChannelComponent;
23import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent;
24import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
6503ae0f
BH
25import org.eclipse.swt.SWT;
26import org.eclipse.swt.custom.CCombo;
27import org.eclipse.swt.events.SelectionEvent;
28import org.eclipse.swt.events.SelectionListener;
c56972bb 29import org.eclipse.swt.graphics.Point;
6503ae0f
BH
30import org.eclipse.swt.layout.GridData;
31import org.eclipse.swt.layout.GridLayout;
32import org.eclipse.swt.widgets.Composite;
33import org.eclipse.swt.widgets.Control;
34import org.eclipse.swt.widgets.Group;
6503ae0f 35import org.eclipse.swt.widgets.Shell;
d4514365 36import org.eclipse.swt.widgets.Text;
6503ae0f
BH
37
38/**
6503ae0f
BH
39 * <p>
40 * Dialog box for collecting information about the events to enable.
41 * </p>
7ce7e4af 42 *
dbd4432d 43 * @author Bernd Hufmann
6503ae0f
BH
44 */
45public class GetEventInfoDialog extends Dialog implements IGetEventInfoDialog {
46
47 // ------------------------------------------------------------------------
48 // Constants
49 // ------------------------------------------------------------------------
50 /**
51 * The icon file for this dialog box.
52 */
7ce7e4af 53 public static final String TARGET_NEW_CONNECTION_ICON_FILE = "icons/elcl16/enable_event.gif"; //$NON-NLS-1$
6503ae0f
BH
54
55 // ------------------------------------------------------------------------
56 // Attributes
57 // ------------------------------------------------------------------------
58 /**
59 * The dialog composite.
60 */
61 private Composite fDialogComposite = null;
62 /**
63 * The Group for the session combo box.
64 */
65 private Group fSessionsGroup = null;
66 /**
67 * The Group for the channel combo box.
68 */
69 private Group fChannelsGroup = null;
70 /**
71 * The session combo box.
72 */
73 private CCombo fSessionsCombo = null;
74 /**
75 * The channel combo box.
76 */
77 private CCombo fChannelsCombo = null;
d4514365
BH
78 /**
79 * The filter text
80 */
81 private Text fFilterText;
6503ae0f
BH
82 /**
83 * The list of available sessions.
84 */
85 private TraceSessionComponent[] fSessions;
86 /**
87 * True for kernel, false for UST.
88 */
89 private boolean fIsKernel;
90 /**
91 * Index in session array (selected session).
92 */
93 private int fSessionIndex = 0;
94 /**
7ce7e4af 95 * The Channel where the events should be enabled.
6503ae0f
BH
96 */
97 private TraceChannelComponent fChannel;
98 /**
99 * List of available channels of the selected session.
100 */
101 private TraceChannelComponent[] fChannels;
d4514365
BH
102 /**
103 * The filter expression
104 */
105 private String fFilterExpression;
6503ae0f
BH
106
107 // ------------------------------------------------------------------------
108 // Constructors
109 // ------------------------------------------------------------------------
110 /**
111 * Constructor of dialog box.
112 * @param shell - the shell for the dialog box
6503ae0f 113 */
d132bcc7 114 public GetEventInfoDialog(Shell shell) {
6503ae0f 115 super(shell);
498704b3 116 setShellStyle(SWT.RESIZE);
6503ae0f
BH
117 }
118
119 // ------------------------------------------------------------------------
120 // Accessors
121 // ------------------------------------------------------------------------
122 /*
123 * (non-Javadoc)
115b4a01 124 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableEventsDialog#getSession()
6503ae0f
BH
125 */
126 @Override
127 public TraceSessionComponent getSession() {
128 return fSessions[fSessionIndex];
129 }
130
131 /*
132 * (non-Javadoc)
115b4a01 133 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableEventsDialog#getChannel()
6503ae0f
BH
134 */
135 @Override
136 public TraceChannelComponent getChannel() {
137 return fChannel;
138 }
139
d132bcc7
BH
140 /*
141 * (non-Javadoc)
115b4a01 142 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IGetEventInfoDialog#setIsKernel(boolean)
d132bcc7
BH
143 */
144 @Override
145 public void setIsKernel(boolean isKernel) {
146 fIsKernel = isKernel;
147 }
7ce7e4af 148
d132bcc7
BH
149 /*
150 * (non-Javadoc)
115b4a01 151 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IGetEventInfoDialog#setSessions(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent[])
d132bcc7
BH
152 */
153 @Override
154 public void setSessions(TraceSessionComponent[] sessions) {
155 fSessions = Arrays.copyOf(sessions, sessions.length);
156 }
d4514365
BH
157 /*
158 * (non-Javadoc)
159 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IGetEventInfoDialog#getFilterExpression()
160 */
161 @Override
162 public String getFilterExpression() {
163 return fFilterExpression;
164 }
d132bcc7 165
6503ae0f
BH
166 // ------------------------------------------------------------------------
167 // Operations
168 // ------------------------------------------------------------------------
169 /*
170 * (non-Javadoc)
171 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
172 */
173 @Override
174 protected void configureShell(Shell newShell) {
175 super.configureShell(newShell);
176 newShell.setText(Messages.TraceControl_EnableEventsDialogTitle);
31a6a4e4 177 newShell.setImage(Activator.getDefault().loadIcon(TARGET_NEW_CONNECTION_ICON_FILE));
6503ae0f
BH
178 }
179
180 /*
181 * (non-Javadoc)
182 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
183 */
184 @Override
185 protected Control createDialogArea(Composite parent) {
7ce7e4af 186
6503ae0f
BH
187 // Main dialog panel
188 fDialogComposite = new Composite(parent, SWT.NONE);
189 GridLayout layout = new GridLayout(1, true);
498704b3
BH
190 fDialogComposite.setLayout(layout);
191 fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
7ce7e4af 192
6503ae0f
BH
193 fSessionsGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
194 fSessionsGroup.setText(Messages.TraceControl_EnableEventsSessionGroupName);
195 layout = new GridLayout(1, true);
7ce7e4af 196 fSessionsGroup.setLayout(layout);
6503ae0f
BH
197 GridData data = new GridData(GridData.FILL_HORIZONTAL);
198 fSessionsGroup.setLayoutData(data);
199
200 fSessionsCombo = new CCombo(fSessionsGroup, SWT.READ_ONLY);
201 fSessionsCombo.setToolTipText(Messages.TraceControl_EnableEventsSessionsTooltip);
202 fSessionsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
7ce7e4af 203
6503ae0f
BH
204 String items[] = new String[fSessions.length];
205 for (int i = 0; i < items.length; i++) {
206 items[i] = String.valueOf(fSessions[i].getName());
207 }
208
209 fSessionsCombo.setItems(items);
210 fSessionsCombo.setEnabled(fSessions.length > 0);
7ce7e4af 211
6503ae0f
BH
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);
6503ae0f 217 fChannelsGroup.setLayoutData(data);
7ce7e4af 218
6503ae0f
BH
219 fChannelsCombo = new CCombo(fChannelsGroup, SWT.READ_ONLY);
220 fChannelsCombo.setToolTipText(Messages.TraceControl_EnableEventsChannelsTooltip);
6503ae0f
BH
221 fChannelsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
222 fChannelsCombo.setEnabled(false);
223
224 fSessionsCombo.addSelectionListener(new SelectionListener() {
225 @Override
226 public void widgetSelected(SelectionEvent e) {
227 fSessionIndex = fSessionsCombo.getSelectionIndex();
7ce7e4af 228
6503ae0f
BH
229 if (fSessionIndex >= 0) {
230 TraceDomainComponent domain = null;
231 TraceDomainComponent[] domains = fSessions[fSessionIndex].getDomains();
232 for (int i = 0; i < domains.length; i++) {
233
234 if (domains[i].isKernel() == fIsKernel) {
235 domain = domains[i];
236 break;
237 }
238 }
239
240 if (domain != null) {
241 fChannels = domain.getChannels();
ea21cd65
AM
242 String selectionItems[] = new String[fChannels.length];
243 for (int i = 0; i < selectionItems.length; i++) {
244 selectionItems[i] = String.valueOf(fChannels[i].getName());
6503ae0f 245 }
ea21cd65 246 fChannelsCombo.setItems(selectionItems);
6503ae0f 247 fChannelsCombo.setEnabled(fChannels.length > 0);
7ce7e4af 248 } else {
6503ae0f
BH
249 fChannelsCombo.setItems(new String[0]);
250 fChannelsCombo.setEnabled(false);
251 fChannels = null;
252 }
253 fChannelsCombo.getParent().getParent().layout();
254 }
255 }
256
257 @Override
258 public void widgetDefaultSelected(SelectionEvent e) {
259 }
260 });
7ce7e4af 261
d4514365
BH
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);
270
271 fFilterText = new Text(filterMainGroup, SWT.LEFT);
272 fFilterText.setToolTipText(Messages.TraceControl_EnableEventsFilterTooltip);
273 data = new GridData(GridData.FILL_HORIZONTAL);
274 fFilterText.setLayoutData(data);
275 }
276
c56972bb 277 getShell().setMinimumSize(new Point(300, 200));
7ce7e4af 278
6503ae0f
BH
279 return fDialogComposite;
280 }
281
282 /*
283 * (non-Javadoc)
284 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
285 */
286 @Override
287 protected void createButtonsForButtonBar(Composite parent) {
79c3db85 288 createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$
6503ae0f
BH
289 createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$
290 }
291
292 /*
293 * (non-Javadoc)
294 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
295 */
296 @Override
297 protected void okPressed() {
7ce7e4af 298
6503ae0f
BH
299 if (fSessionsCombo.getSelectionIndex() < 0) {
300 MessageDialog.openError(getShell(),
301 Messages.TraceControl_EnableEventsDialogTitle,
7ce7e4af 302 Messages.TraceControl_EnableEventsNoSessionError);
6503ae0f
BH
303 return;
304 }
305
306 fSessionIndex = fSessionsCombo.getSelectionIndex();
307
d4514365 308 // if no channel is available or no channel is selected use default channel indicated by fChannel=null
7ce7e4af 309 fChannel = null;
d4514365 310 if ((fChannels != null) && (fChannelsCombo.getSelectionIndex() >= 0)) {
6503ae0f
BH
311 fChannel = fChannels[fChannelsCombo.getSelectionIndex()];
312 }
313
d4514365
BH
314 // initialize filter with null
315 fFilterExpression = null;
316 if (fSessions[0].isEventFilteringSupported() && !fIsKernel) {
317 String tempFilter = fFilterText.getText();
318
319 if(!tempFilter.matches("\\s*")) { //$NON-NLS-1$
320 fFilterExpression = tempFilter;
321 }
322 }
323
6503ae0f
BH
324 super.okPressed();
325 }
326}
This page took 0.046799 seconds and 5 git commands to generate.