2ec434aeb01ecf54d23b9b152fe5144fb1acf922
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.ui / src / org / eclipse / linuxtools / internal / lttng2 / control / ui / views / 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.control.ui.views.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.control.ui.Activator;
21 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.messages.Messages;
22 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceChannelComponent;
23 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceDomainComponent;
24 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.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 session combo box.
60 */
61 private CCombo fSessionsCombo = null;
62 /**
63 * The channel combo box.
64 */
65 private CCombo fChannelsCombo = null;
66 /**
67 * The filter text
68 */
69 private Text fFilterText;
70 /**
71 * The list of available sessions.
72 */
73 private TraceSessionComponent[] fSessions;
74 /**
75 * True for kernel, false for UST.
76 */
77 private boolean fIsKernel;
78 /**
79 * Index in session array (selected session).
80 */
81 private int fSessionIndex = 0;
82 /**
83 * The Channel where the events should be enabled.
84 */
85 private TraceChannelComponent fChannel;
86 /**
87 * List of available channels of the selected session.
88 */
89 private TraceChannelComponent[] fChannels;
90 /**
91 * The filter expression
92 */
93 private String fFilterExpression;
94
95 // ------------------------------------------------------------------------
96 // Constructors
97 // ------------------------------------------------------------------------
98 /**
99 * Constructor of dialog box.
100 * @param shell - the shell for the dialog box
101 */
102 public GetEventInfoDialog(Shell shell) {
103 super(shell);
104 setShellStyle(SWT.RESIZE | getShellStyle());
105 }
106
107 // ------------------------------------------------------------------------
108 // Accessors
109 // ------------------------------------------------------------------------
110
111 @Override
112 public TraceSessionComponent getSession() {
113 return fSessions[fSessionIndex];
114 }
115
116 @Override
117 public TraceChannelComponent getChannel() {
118 return fChannel;
119 }
120
121 @Override
122 public void setIsKernel(boolean isKernel) {
123 fIsKernel = isKernel;
124 }
125
126 @Override
127 public void setSessions(TraceSessionComponent[] sessions) {
128 fSessions = Arrays.copyOf(sessions, sessions.length);
129 }
130
131 @Override
132 public String getFilterExpression() {
133 return fFilterExpression;
134 }
135
136 // ------------------------------------------------------------------------
137 // Operations
138 // ------------------------------------------------------------------------
139
140 @Override
141 protected void configureShell(Shell newShell) {
142 super.configureShell(newShell);
143 newShell.setText(Messages.TraceControl_EnableEventsDialogTitle);
144 newShell.setImage(Activator.getDefault().loadIcon(TARGET_NEW_CONNECTION_ICON_FILE));
145 }
146
147 @Override
148 protected Control createDialogArea(Composite parent) {
149
150 // Main dialog panel
151 Composite dialogComposite = new Composite(parent, SWT.NONE);
152 GridLayout layout = new GridLayout(1, true);
153 dialogComposite.setLayout(layout);
154 dialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
155
156 Group sessionsGroup = new Group(dialogComposite, SWT.SHADOW_NONE);
157 sessionsGroup.setText(Messages.TraceControl_EnableEventsSessionGroupName);
158 layout = new GridLayout(1, true);
159 sessionsGroup.setLayout(layout);
160 GridData data = new GridData(GridData.FILL_HORIZONTAL);
161 sessionsGroup.setLayoutData(data);
162
163 fSessionsCombo = new CCombo(sessionsGroup, SWT.READ_ONLY);
164 fSessionsCombo.setToolTipText(Messages.TraceControl_EnableEventsSessionsTooltip);
165 fSessionsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
166
167 String items[] = new String[fSessions.length];
168 for (int i = 0; i < items.length; i++) {
169 items[i] = String.valueOf(fSessions[i].getName());
170 }
171
172 fSessionsCombo.setItems(items);
173 fSessionsCombo.setEnabled(fSessions.length > 0);
174
175 Group channelsGroup = new Group(dialogComposite, SWT.SHADOW_NONE);
176 channelsGroup.setText(Messages.TraceControl_EnableEventsChannelGroupName);
177 layout = new GridLayout(1, true);
178 channelsGroup.setLayout(layout);
179 data = new GridData(GridData.FILL_HORIZONTAL);
180 channelsGroup.setLayoutData(data);
181
182 fChannelsCombo = new CCombo(channelsGroup, SWT.READ_ONLY);
183 fChannelsCombo.setToolTipText(Messages.TraceControl_EnableEventsChannelsTooltip);
184 fChannelsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
185 fChannelsCombo.setEnabled(false);
186
187 fSessionsCombo.addSelectionListener(new SelectionListener() {
188 @Override
189 public void widgetSelected(SelectionEvent e) {
190 fSessionIndex = fSessionsCombo.getSelectionIndex();
191
192 if (fSessionIndex >= 0) {
193 TraceDomainComponent domain = null;
194 TraceDomainComponent[] domains = fSessions[fSessionIndex].getDomains();
195 for (int i = 0; i < domains.length; i++) {
196
197 if (domains[i].isKernel() == fIsKernel) {
198 domain = domains[i];
199 break;
200 }
201 }
202
203 if (domain != null) {
204 fChannels = domain.getChannels();
205 String selectionItems[] = new String[fChannels.length];
206 for (int i = 0; i < selectionItems.length; i++) {
207 selectionItems[i] = String.valueOf(fChannels[i].getName());
208 }
209 fChannelsCombo.setItems(selectionItems);
210 fChannelsCombo.setEnabled(fChannels.length > 0);
211 } else {
212 fChannelsCombo.setItems(new String[0]);
213 fChannelsCombo.setEnabled(false);
214 fChannels = null;
215 }
216 fChannelsCombo.getParent().getParent().layout();
217 }
218 }
219
220 @Override
221 public void widgetDefaultSelected(SelectionEvent e) {
222 }
223 });
224
225 // take first session to test whether events filtering is supported or not
226 if (fSessions[0].isEventFilteringSupported() && !fIsKernel) {
227 Group filterMainGroup = new Group(dialogComposite, SWT.SHADOW_NONE);
228 filterMainGroup.setText(Messages.TraceControl_EnableEventsFilterGroupName);
229 layout = new GridLayout(2, false);
230 filterMainGroup.setLayout(layout);
231 data = new GridData(GridData.FILL_HORIZONTAL);
232 filterMainGroup.setLayoutData(data);
233
234 fFilterText = new Text(filterMainGroup, SWT.LEFT);
235 fFilterText.setToolTipText(Messages.TraceControl_EnableEventsFilterTooltip);
236 data = new GridData(GridData.FILL_HORIZONTAL);
237 fFilterText.setLayoutData(data);
238 }
239
240 getShell().setMinimumSize(new Point(300, 200));
241
242 return dialogComposite;
243 }
244
245 @Override
246 protected void createButtonsForButtonBar(Composite parent) {
247 createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$
248 createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$
249 }
250
251 @Override
252 protected void okPressed() {
253
254 if (fSessionsCombo.getSelectionIndex() < 0) {
255 MessageDialog.openError(getShell(),
256 Messages.TraceControl_EnableEventsDialogTitle,
257 Messages.TraceControl_EnableEventsNoSessionError);
258 return;
259 }
260
261 fSessionIndex = fSessionsCombo.getSelectionIndex();
262
263 // if no channel is available or no channel is selected use default channel indicated by fChannel=null
264 fChannel = null;
265 if ((fChannels != null) && (fChannelsCombo.getSelectionIndex() >= 0)) {
266 fChannel = fChannels[fChannelsCombo.getSelectionIndex()];
267 }
268
269 // initialize filter with null
270 fFilterExpression = null;
271 if (fSessions[0].isEventFilteringSupported() && !fIsKernel) {
272 String tempFilter = fFilterText.getText();
273
274 if(!tempFilter.isEmpty() && !tempFilter.matches("\\s*")) { //$NON-NLS-1$
275 fFilterExpression = tempFilter;
276 }
277 }
278
279 super.okPressed();
280 }
281 }
This page took 0.049428 seconds and 4 git commands to generate.