Update file headers in LTTng Control feature
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / dialogs / GetEventInfoDialog.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
3 *
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
8 *
9 * Contributors:
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;
14
15 import java.util.Arrays;
16
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;
37
38 /**
39 * <p>
40 * Dialog box for collecting information about the events to enable.
41 * </p>
42 *
43 * @author Bernd Hufmann
44 */
45 public class GetEventInfoDialog extends Dialog implements IGetEventInfoDialog {
46
47 // ------------------------------------------------------------------------
48 // Constants
49 // ------------------------------------------------------------------------
50 /**
51 * The icon file for this dialog box.
52 */
53 public static final String TARGET_NEW_CONNECTION_ICON_FILE = "icons/elcl16/enable_event.gif"; //$NON-NLS-1$
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;
78 /**
79 * The filter text
80 */
81 private Text fFilterText;
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 /**
95 * The Channel where the events should be enabled.
96 */
97 private TraceChannelComponent fChannel;
98 /**
99 * List of available channels of the selected session.
100 */
101 private TraceChannelComponent[] fChannels;
102 /**
103 * The filter expression
104 */
105 private String fFilterExpression;
106
107 // ------------------------------------------------------------------------
108 // Constructors
109 // ------------------------------------------------------------------------
110 /**
111 * Constructor of dialog box.
112 * @param shell - the shell for the dialog box
113 */
114 public GetEventInfoDialog(Shell shell) {
115 super(shell);
116 setShellStyle(SWT.RESIZE);
117 }
118
119 // ------------------------------------------------------------------------
120 // Accessors
121 // ------------------------------------------------------------------------
122 /*
123 * (non-Javadoc)
124 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableEventsDialog#getSession()
125 */
126 @Override
127 public TraceSessionComponent getSession() {
128 return fSessions[fSessionIndex];
129 }
130
131 /*
132 * (non-Javadoc)
133 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableEventsDialog#getChannel()
134 */
135 @Override
136 public TraceChannelComponent getChannel() {
137 return fChannel;
138 }
139
140 /*
141 * (non-Javadoc)
142 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IGetEventInfoDialog#setIsKernel(boolean)
143 */
144 @Override
145 public void setIsKernel(boolean isKernel) {
146 fIsKernel = isKernel;
147 }
148
149 /*
150 * (non-Javadoc)
151 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IGetEventInfoDialog#setSessions(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent[])
152 */
153 @Override
154 public void setSessions(TraceSessionComponent[] sessions) {
155 fSessions = Arrays.copyOf(sessions, sessions.length);
156 }
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 }
165
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);
177 newShell.setImage(Activator.getDefault().loadIcon(TARGET_NEW_CONNECTION_ICON_FILE));
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) {
186
187 // Main dialog panel
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));
192
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);
199
200 fSessionsCombo = new CCombo(fSessionsGroup, SWT.READ_ONLY);
201 fSessionsCombo.setToolTipText(Messages.TraceControl_EnableEventsSessionsTooltip);
202 fSessionsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
203
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);
211
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);
218
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);
223
224 fSessionsCombo.addSelectionListener(new SelectionListener() {
225 @Override
226 public void widgetSelected(SelectionEvent e) {
227 fSessionIndex = fSessionsCombo.getSelectionIndex();
228
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();
242 String selectionItems[] = new String[fChannels.length];
243 for (int i = 0; i < selectionItems.length; i++) {
244 selectionItems[i] = String.valueOf(fChannels[i].getName());
245 }
246 fChannelsCombo.setItems(selectionItems);
247 fChannelsCombo.setEnabled(fChannels.length > 0);
248 } else {
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 });
261
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
277 getShell().setMinimumSize(new Point(300, 200));
278
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) {
288 createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$
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() {
298
299 if (fSessionsCombo.getSelectionIndex() < 0) {
300 MessageDialog.openError(getShell(),
301 Messages.TraceControl_EnableEventsDialogTitle,
302 Messages.TraceControl_EnableEventsNoSessionError);
303 return;
304 }
305
306 fSessionIndex = fSessionsCombo.getSelectionIndex();
307
308 // if no channel is available or no channel is selected use default channel indicated by fChannel=null
309 fChannel = null;
310 if ((fChannels != null) && (fChannelsCombo.getSelectionIndex() >= 0)) {
311 fChannel = fChannels[fChannelsCombo.getSelectionIndex()];
312 }
313
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
324 super.okPressed();
325 }
326 }
This page took 0.038048 seconds and 5 git commands to generate.