gdbtrace: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.ui / src / org / eclipse / linuxtools / internal / lttng2 / control / ui / views / 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 **********************************************************************/
8e8c0226 13package org.eclipse.linuxtools.internal.lttng2.control.ui.views.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;
8e8c0226
AM
20import org.eclipse.linuxtools.internal.lttng2.control.ui.Activator;
21import org.eclipse.linuxtools.internal.lttng2.control.ui.views.messages.Messages;
22import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceChannelComponent;
23import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceDomainComponent;
24import org.eclipse.linuxtools.internal.lttng2.control.ui.views.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 // ------------------------------------------------------------------------
6503ae0f
BH
58 /**
59 * The session combo box.
60 */
61 private CCombo fSessionsCombo = null;
62 /**
63 * The channel combo box.
64 */
65 private CCombo fChannelsCombo = null;
d4514365
BH
66 /**
67 * The filter text
68 */
69 private Text fFilterText;
6503ae0f
BH
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 /**
7ce7e4af 83 * The Channel where the events should be enabled.
6503ae0f
BH
84 */
85 private TraceChannelComponent fChannel;
86 /**
87 * List of available channels of the selected session.
88 */
89 private TraceChannelComponent[] fChannels;
d4514365
BH
90 /**
91 * The filter expression
92 */
93 private String fFilterExpression;
6503ae0f
BH
94
95 // ------------------------------------------------------------------------
96 // Constructors
97 // ------------------------------------------------------------------------
98 /**
99 * Constructor of dialog box.
100 * @param shell - the shell for the dialog box
6503ae0f 101 */
d132bcc7 102 public GetEventInfoDialog(Shell shell) {
6503ae0f 103 super(shell);
8a396998 104 setShellStyle(SWT.RESIZE | getShellStyle());
6503ae0f
BH
105 }
106
107 // ------------------------------------------------------------------------
108 // Accessors
109 // ------------------------------------------------------------------------
11252342 110
6503ae0f
BH
111 @Override
112 public TraceSessionComponent getSession() {
113 return fSessions[fSessionIndex];
114 }
115
6503ae0f
BH
116 @Override
117 public TraceChannelComponent getChannel() {
118 return fChannel;
119 }
120
d132bcc7
BH
121 @Override
122 public void setIsKernel(boolean isKernel) {
123 fIsKernel = isKernel;
124 }
7ce7e4af 125
d132bcc7
BH
126 @Override
127 public void setSessions(TraceSessionComponent[] sessions) {
128 fSessions = Arrays.copyOf(sessions, sessions.length);
129 }
11252342 130
d4514365
BH
131 @Override
132 public String getFilterExpression() {
133 return fFilterExpression;
134 }
d132bcc7 135
6503ae0f
BH
136 // ------------------------------------------------------------------------
137 // Operations
138 // ------------------------------------------------------------------------
11252342 139
6503ae0f
BH
140 @Override
141 protected void configureShell(Shell newShell) {
142 super.configureShell(newShell);
143 newShell.setText(Messages.TraceControl_EnableEventsDialogTitle);
31a6a4e4 144 newShell.setImage(Activator.getDefault().loadIcon(TARGET_NEW_CONNECTION_ICON_FILE));
6503ae0f
BH
145 }
146
6503ae0f
BH
147 @Override
148 protected Control createDialogArea(Composite parent) {
7ce7e4af 149
6503ae0f 150 // Main dialog panel
046b6849 151 Composite dialogComposite = new Composite(parent, SWT.NONE);
6503ae0f 152 GridLayout layout = new GridLayout(1, true);
046b6849
BH
153 dialogComposite.setLayout(layout);
154 dialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
7ce7e4af 155
046b6849
BH
156 Group sessionsGroup = new Group(dialogComposite, SWT.SHADOW_NONE);
157 sessionsGroup.setText(Messages.TraceControl_EnableEventsSessionGroupName);
6503ae0f 158 layout = new GridLayout(1, true);
046b6849 159 sessionsGroup.setLayout(layout);
6503ae0f 160 GridData data = new GridData(GridData.FILL_HORIZONTAL);
046b6849 161 sessionsGroup.setLayoutData(data);
6503ae0f 162
046b6849 163 fSessionsCombo = new CCombo(sessionsGroup, SWT.READ_ONLY);
6503ae0f
BH
164 fSessionsCombo.setToolTipText(Messages.TraceControl_EnableEventsSessionsTooltip);
165 fSessionsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
7ce7e4af 166
6503ae0f
BH
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);
7ce7e4af 174
046b6849
BH
175 Group channelsGroup = new Group(dialogComposite, SWT.SHADOW_NONE);
176 channelsGroup.setText(Messages.TraceControl_EnableEventsChannelGroupName);
6503ae0f 177 layout = new GridLayout(1, true);
046b6849 178 channelsGroup.setLayout(layout);
6503ae0f 179 data = new GridData(GridData.FILL_HORIZONTAL);
046b6849 180 channelsGroup.setLayoutData(data);
7ce7e4af 181
046b6849 182 fChannelsCombo = new CCombo(channelsGroup, SWT.READ_ONLY);
6503ae0f 183 fChannelsCombo.setToolTipText(Messages.TraceControl_EnableEventsChannelsTooltip);
6503ae0f
BH
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();
7ce7e4af 191
6503ae0f
BH
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();
ea21cd65
AM
205 String selectionItems[] = new String[fChannels.length];
206 for (int i = 0; i < selectionItems.length; i++) {
207 selectionItems[i] = String.valueOf(fChannels[i].getName());
6503ae0f 208 }
ea21cd65 209 fChannelsCombo.setItems(selectionItems);
6503ae0f 210 fChannelsCombo.setEnabled(fChannels.length > 0);
7ce7e4af 211 } else {
6503ae0f
BH
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 });
7ce7e4af 224
d4514365
BH
225 // take first session to test whether events filtering is supported or not
226 if (fSessions[0].isEventFilteringSupported() && !fIsKernel) {
046b6849 227 Group filterMainGroup = new Group(dialogComposite, SWT.SHADOW_NONE);
d4514365
BH
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
c56972bb 240 getShell().setMinimumSize(new Point(300, 200));
7ce7e4af 241
046b6849 242 return dialogComposite;
6503ae0f
BH
243 }
244
6503ae0f
BH
245 @Override
246 protected void createButtonsForButtonBar(Composite parent) {
79c3db85 247 createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$
6503ae0f
BH
248 createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$
249 }
250
6503ae0f
BH
251 @Override
252 protected void okPressed() {
7ce7e4af 253
6503ae0f
BH
254 if (fSessionsCombo.getSelectionIndex() < 0) {
255 MessageDialog.openError(getShell(),
256 Messages.TraceControl_EnableEventsDialogTitle,
7ce7e4af 257 Messages.TraceControl_EnableEventsNoSessionError);
6503ae0f
BH
258 return;
259 }
260
261 fSessionIndex = fSessionsCombo.getSelectionIndex();
262
d4514365 263 // if no channel is available or no channel is selected use default channel indicated by fChannel=null
7ce7e4af 264 fChannel = null;
d4514365 265 if ((fChannels != null) && (fChannelsCombo.getSelectionIndex() >= 0)) {
6503ae0f
BH
266 fChannel = fChannels[fChannelsCombo.getSelectionIndex()];
267 }
268
d4514365
BH
269 // initialize filter with null
270 fFilterExpression = null;
271 if (fSessions[0].isEventFilteringSupported() && !fIsKernel) {
272 String tempFilter = fFilterText.getText();
273
c371fa43 274 if(!tempFilter.isEmpty() && !tempFilter.matches("\\s*")) { //$NON-NLS-1$
d4514365
BH
275 fFilterExpression = tempFilter;
276 }
277 }
278
6503ae0f
BH
279 super.okPressed();
280 }
281}
This page took 0.063288 seconds and 5 git commands to generate.