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