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