62af2122e10077edea6d399a3310646a9e0676dc
[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 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 **********************************************************************/
12 package org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs;
13
14 import java.util.Arrays;
15
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;
36
37 /**
38 * <p>
39 * Dialog box for collecting information about the events to enable.
40 * </p>
41 *
42 * @author Bernd Hufmann
43 */
44 public class GetEventInfoDialog extends Dialog implements IGetEventInfoDialog {
45
46 // ------------------------------------------------------------------------
47 // Constants
48 // ------------------------------------------------------------------------
49 /**
50 * The icon file for this dialog box.
51 */
52 public static final String TARGET_NEW_CONNECTION_ICON_FILE = "icons/elcl16/enable_event.gif"; //$NON-NLS-1$
53
54 // ------------------------------------------------------------------------
55 // Attributes
56 // ------------------------------------------------------------------------
57 /**
58 * The dialog composite.
59 */
60 private Composite fDialogComposite = null;
61 /**
62 * The Group for the session combo box.
63 */
64 private Group fSessionsGroup = null;
65 /**
66 * The Group for the channel combo box.
67 */
68 private Group fChannelsGroup = null;
69 /**
70 * The session combo box.
71 */
72 private CCombo fSessionsCombo = null;
73 /**
74 * The channel combo box.
75 */
76 private CCombo fChannelsCombo = null;
77 /**
78 * The filter text
79 */
80 private Text fFilterText;
81 /**
82 * The list of available sessions.
83 */
84 private TraceSessionComponent[] fSessions;
85 /**
86 * True for kernel, false for UST.
87 */
88 private boolean fIsKernel;
89 /**
90 * Index in session array (selected session).
91 */
92 private int fSessionIndex = 0;
93 /**
94 * The Channel where the events should be enabled.
95 */
96 private TraceChannelComponent fChannel;
97 /**
98 * List of available channels of the selected session.
99 */
100 private TraceChannelComponent[] fChannels;
101 /**
102 * The filter expression
103 */
104 private String fFilterExpression;
105
106 // ------------------------------------------------------------------------
107 // Constructors
108 // ------------------------------------------------------------------------
109 /**
110 * Constructor of dialog box.
111 * @param shell - the shell for the dialog box
112 */
113 public GetEventInfoDialog(Shell shell) {
114 super(shell);
115 setShellStyle(SWT.RESIZE);
116 }
117
118 // ------------------------------------------------------------------------
119 // Accessors
120 // ------------------------------------------------------------------------
121 /*
122 * (non-Javadoc)
123 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableEventsDialog#getSession()
124 */
125 @Override
126 public TraceSessionComponent getSession() {
127 return fSessions[fSessionIndex];
128 }
129
130 /*
131 * (non-Javadoc)
132 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableEventsDialog#getChannel()
133 */
134 @Override
135 public TraceChannelComponent getChannel() {
136 return fChannel;
137 }
138
139 /*
140 * (non-Javadoc)
141 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IGetEventInfoDialog#setIsKernel(boolean)
142 */
143 @Override
144 public void setIsKernel(boolean isKernel) {
145 fIsKernel = isKernel;
146 }
147
148 /*
149 * (non-Javadoc)
150 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IGetEventInfoDialog#setSessions(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent[])
151 */
152 @Override
153 public void setSessions(TraceSessionComponent[] sessions) {
154 fSessions = Arrays.copyOf(sessions, sessions.length);
155 }
156 /*
157 * (non-Javadoc)
158 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IGetEventInfoDialog#getFilterExpression()
159 */
160 @Override
161 public String getFilterExpression() {
162 return fFilterExpression;
163 }
164
165 // ------------------------------------------------------------------------
166 // Operations
167 // ------------------------------------------------------------------------
168 /*
169 * (non-Javadoc)
170 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
171 */
172 @Override
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));
177 }
178
179 /*
180 * (non-Javadoc)
181 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
182 */
183 @Override
184 protected Control createDialogArea(Composite parent) {
185
186 // Main dialog panel
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));
191
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);
198
199 fSessionsCombo = new CCombo(fSessionsGroup, SWT.READ_ONLY);
200 fSessionsCombo.setToolTipText(Messages.TraceControl_EnableEventsSessionsTooltip);
201 fSessionsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
202
203 String items[] = new String[fSessions.length];
204 for (int i = 0; i < items.length; i++) {
205 items[i] = String.valueOf(fSessions[i].getName());
206 }
207
208 fSessionsCombo.setItems(items);
209 fSessionsCombo.setEnabled(fSessions.length > 0);
210
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);
217
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);
222
223 fSessionsCombo.addSelectionListener(new SelectionListener() {
224 @Override
225 public void widgetSelected(SelectionEvent e) {
226 fSessionIndex = fSessionsCombo.getSelectionIndex();
227
228 if (fSessionIndex >= 0) {
229 TraceDomainComponent domain = null;
230 TraceDomainComponent[] domains = fSessions[fSessionIndex].getDomains();
231 for (int i = 0; i < domains.length; i++) {
232
233 if (domains[i].isKernel() == fIsKernel) {
234 domain = domains[i];
235 break;
236 }
237 }
238
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());
244 }
245 fChannelsCombo.setItems(selectionItems);
246 fChannelsCombo.setEnabled(fChannels.length > 0);
247 } else {
248 fChannelsCombo.setItems(new String[0]);
249 fChannelsCombo.setEnabled(false);
250 fChannels = null;
251 }
252 fChannelsCombo.getParent().getParent().layout();
253 }
254 }
255
256 @Override
257 public void widgetDefaultSelected(SelectionEvent e) {
258 }
259 });
260
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);
269
270 fFilterText = new Text(filterMainGroup, SWT.LEFT);
271 fFilterText.setToolTipText(Messages.TraceControl_EnableEventsFilterTooltip);
272 data = new GridData(GridData.FILL_HORIZONTAL);
273 fFilterText.setLayoutData(data);
274 }
275
276 getShell().setMinimumSize(new Point(300, 200));
277
278 return fDialogComposite;
279 }
280
281 /*
282 * (non-Javadoc)
283 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
284 */
285 @Override
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$
289 }
290
291 /*
292 * (non-Javadoc)
293 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
294 */
295 @Override
296 protected void okPressed() {
297
298 if (fSessionsCombo.getSelectionIndex() < 0) {
299 MessageDialog.openError(getShell(),
300 Messages.TraceControl_EnableEventsDialogTitle,
301 Messages.TraceControl_EnableEventsNoSessionError);
302 return;
303 }
304
305 fSessionIndex = fSessionsCombo.getSelectionIndex();
306
307 // if no channel is available or no channel is selected use default channel indicated by fChannel=null
308 fChannel = null;
309 if ((fChannels != null) && (fChannelsCombo.getSelectionIndex() >= 0)) {
310 fChannel = fChannels[fChannelsCombo.getSelectionIndex()];
311 }
312
313 // initialize filter with null
314 fFilterExpression = null;
315 if (fSessions[0].isEventFilteringSupported() && !fIsKernel) {
316 String tempFilter = fFilterText.getText();
317
318 if(!tempFilter.matches("\\s*")) { //$NON-NLS-1$
319 fFilterExpression = tempFilter;
320 }
321 }
322
323 super.okPressed();
324 }
325 }
This page took 0.037535 seconds and 4 git commands to generate.