d1dea91f061e0d28e9ddd7f5e9419efeaf54eae4
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / dialogs / EnableChannelDialog.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 org.eclipse.jface.dialogs.Dialog;
15 import org.eclipse.jface.dialogs.IDialogConstants;
16 import org.eclipse.jface.dialogs.MessageDialog;
17 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IChannelInfo;
18 import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.ChannelInfo;
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.TraceDomainComponent;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.events.VerifyEvent;
24 import org.eclipse.swt.events.VerifyListener;
25 import org.eclipse.swt.layout.GridData;
26 import org.eclipse.swt.layout.GridLayout;
27 import org.eclipse.swt.widgets.Button;
28 import org.eclipse.swt.widgets.Composite;
29 import org.eclipse.swt.widgets.Control;
30 import org.eclipse.swt.widgets.Group;
31 import org.eclipse.swt.widgets.Label;
32 import org.eclipse.swt.widgets.Shell;
33 import org.eclipse.swt.widgets.Text;
34
35 /**
36 * <p>
37 * Dialog box for collecting channel information when enabling a channel (which will be created).
38 * </p>
39 *
40 * @author Bernd Hufmann
41 */
42 public class EnableChannelDialog extends Dialog implements IEnableChannelDialog {
43
44 // ------------------------------------------------------------------------
45 // Constants
46 // ------------------------------------------------------------------------
47 /**
48 * The icon file for this dialog box.
49 */
50 public static final String ENABLE_CHANNEL_ICON_FILE = "icons/elcl16/add_button.gif"; //$NON-NLS-1$
51
52 // ------------------------------------------------------------------------
53 // Attributes
54 // ------------------------------------------------------------------------
55 /**
56 * The dialog composite.
57 */
58 private Composite fDialogComposite = null;
59 /**
60 * The text widget for the channel name
61 */
62 private Text fChannelNameText = null;
63 /**
64 * The discard mode of the channel.
65 */
66 private Button fDiscardModeButton = null;
67 /**
68 * The overwrite mode of the channel.
69 */
70 private Button fOverwriteModeButton = null;
71 /**
72 * The sub-buffer size of the channel.
73 */
74 private Text fSubBufferSizeText = null;
75 /**
76 * The number of sub-buffers of the channel.
77 */
78 private Text fNumberOfSubBuffersText = null;
79 /**
80 * The switch timer interval of the channel.
81 */
82 private Text fSwitchTimerText = null;
83 /**
84 * The read timer interval of the channel.
85 */
86 private Text fReadTimerText = null;
87 /**
88 * Group composite for domain selection.
89 */
90 private Group fDomainGroup = null;
91 /**
92 * Radio button for selecting kernel domain.
93 */
94 private Button fKernelButton = null;
95 /**
96 * Radio button for selecting UST domain.
97 */
98 private Button fUstButton = null;
99 /**
100 * The parent domain component where the channel node should be added.
101 * Null in case of creation on session level.
102 */
103 private TraceDomainComponent fDomain = null;
104 /**
105 * Common verify listener for numeric text input.
106 */
107 private VerifyListener fVerifyListener = null;
108 /**
109 * Output channel information.
110 */
111 private IChannelInfo fChannelInfo = null;
112 /**
113 * Output domain information. True in case of Kernel domain. False for UST.
114 */
115 private boolean fIsKernel;
116 /**
117 * Flag which indicates whether Kernel domain is available or not
118 */
119 private boolean fHasKernel;
120
121 // ------------------------------------------------------------------------
122 // Constructors
123 // ------------------------------------------------------------------------
124
125 /**
126 * Constructor
127 * @param shell - a shell for the display of the dialog
128 */
129 public EnableChannelDialog(Shell shell) {
130 super(shell);
131 fIsKernel = true;
132
133 // Common verify listener
134 fVerifyListener = new VerifyListener() {
135 @Override
136 public void verifyText(VerifyEvent e) {
137 // only numbers are allowed.
138 e.doit = e.text.matches("[0-9]*"); //$NON-NLS-1$
139 }
140 };
141 setShellStyle(SWT.RESIZE);
142 }
143
144 // ------------------------------------------------------------------------
145 // Accessors
146 // ------------------------------------------------------------------------
147 /*
148 * (non-Javadoc)
149 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelDialog#getChannelInfo()
150 */
151 @Override
152 public IChannelInfo getChannelInfo() {
153 return fChannelInfo;
154 }
155
156 /*
157 * (non-Javadoc)
158 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelDialog#setDomainComponent(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent)
159 */
160 @Override
161 public void setDomainComponent(TraceDomainComponent domain) {
162 fDomain = domain;
163 if (fDomain != null) {
164 fIsKernel = fDomain.isKernel();
165 } else {
166 fIsKernel = true;
167 }
168 }
169
170 /*
171 * (non-Javadoc)
172 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelDialog#isKernel()
173 */
174 @Override
175 public boolean isKernel() {
176 return fIsKernel;
177 }
178
179 /*
180 * (non-Javadoc)
181 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableChannelDialog#setHasKernel(boolean)
182 */
183 @Override
184 public void setHasKernel(boolean hasKernel) {
185 if (fDomain != null) {
186 fIsKernel = fDomain.isKernel();
187 } else {
188 fIsKernel = hasKernel;
189 }
190
191 fHasKernel = hasKernel;
192 }
193
194 // ------------------------------------------------------------------------
195 // Operations
196 // ------------------------------------------------------------------------
197 /*
198 * (non-Javadoc)
199 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
200 */
201 @Override
202 protected void configureShell(Shell newShell) {
203 super.configureShell(newShell);
204 newShell.setText(Messages.TraceControl_EnableChannelDialogTitle);
205 newShell.setImage(Activator.getDefault().loadIcon(ENABLE_CHANNEL_ICON_FILE));
206 }
207
208 /*
209 * (non-Javadoc)
210 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
211 */
212 @Override
213 protected Control createDialogArea(Composite parent) {
214
215 // Main dialog panel
216 fDialogComposite = new Composite(parent, SWT.NONE);
217 GridLayout layout = new GridLayout(3, true);
218 fDialogComposite.setLayout(layout);
219
220 Label channelNameLabel = new Label(fDialogComposite, SWT.RIGHT);
221 channelNameLabel.setText(Messages.TraceControl_EnableChannelNameLabel);
222 fChannelNameText = new Text(fDialogComposite, SWT.NONE);
223 fChannelNameText.setToolTipText(Messages.TraceControl_EnableChannelNameTooltip);
224
225 Label subBufferSizeLabel = new Label(fDialogComposite, SWT.RIGHT);
226 subBufferSizeLabel.setText(Messages.TraceControl_SubBufferSizePropertyName);
227 fSubBufferSizeText = new Text(fDialogComposite, SWT.NONE);
228 fSubBufferSizeText.setToolTipText(Messages.TraceControl_EnableChannelSubBufferSizeTooltip);
229 fSubBufferSizeText.addVerifyListener(fVerifyListener);
230
231 Label numSubBufferLabel = new Label(fDialogComposite, SWT.RIGHT);
232 numSubBufferLabel.setText(Messages.TraceControl_NbSubBuffersPropertyName);
233 fNumberOfSubBuffersText = new Text(fDialogComposite, SWT.NONE);
234 fNumberOfSubBuffersText.setToolTipText(Messages.TraceControl_EnableChannelNbSubBuffersTooltip);
235 fNumberOfSubBuffersText.addVerifyListener(fVerifyListener);
236
237 Label switchTimerLabel = new Label(fDialogComposite, SWT.RIGHT);
238 switchTimerLabel.setText(Messages.TraceControl_SwitchTimerPropertyName);
239 fSwitchTimerText = new Text(fDialogComposite, SWT.NONE);
240 fSwitchTimerText.setToolTipText(Messages.TraceControl_EnableChannelSwitchTimerTooltip);
241 fSwitchTimerText.addVerifyListener(fVerifyListener);
242
243 Label readTimerLabel = new Label(fDialogComposite, SWT.RIGHT);
244 readTimerLabel.setText(Messages.TraceControl_ReadTimerPropertyName);
245 fReadTimerText = new Text(fDialogComposite, SWT.NONE);
246 fReadTimerText.setToolTipText(Messages.TraceControl_EnableChannelReadTimerTooltip);
247 fReadTimerText.addVerifyListener(fVerifyListener);
248
249 Group discardModeGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
250 discardModeGroup.setText(Messages.TraceControl_EnableChannelDiscardModeGroupName);
251 layout = new GridLayout(2, true);
252 discardModeGroup.setLayout(layout);
253
254 fDiscardModeButton = new Button(discardModeGroup, SWT.RADIO);
255 fDiscardModeButton.setText(Messages.TraceControl_EnableChannelDiscardModeLabel);
256 fDiscardModeButton.setToolTipText(Messages.TraceControl_EnableChannelDiscardModeTooltip);
257 fDiscardModeButton.setSelection(true);
258
259 fOverwriteModeButton = new Button(discardModeGroup, SWT.RADIO);
260 fOverwriteModeButton.setText(Messages.TraceControl_EnableChannelOverwriteModeLabel);
261 fOverwriteModeButton.setToolTipText(Messages.TraceControl_EnableChannelOverwriteModeTooltip);
262 fOverwriteModeButton.setSelection(false);
263
264 fDomainGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
265 fDomainGroup.setText(Messages.TraceControl_DomainDisplayName);
266 layout = new GridLayout(2, true);
267 fDomainGroup.setLayout(layout);
268
269 fKernelButton = new Button(fDomainGroup, SWT.RADIO);
270 fKernelButton.setText(Messages.TraceControl_KernelDomainDisplayName);
271 fKernelButton.setSelection(fIsKernel);
272 fUstButton = new Button(fDomainGroup, SWT.RADIO);
273 fUstButton.setText(Messages.TraceControl_UstDisplayName);
274 fUstButton.setSelection(!fIsKernel);
275
276 if ((fDomain != null) || (!fHasKernel)) {
277 fKernelButton.setEnabled(false);
278 fUstButton.setEnabled(false);
279 }
280
281 // layout widgets
282 GridData data = new GridData(GridData.FILL, GridData.CENTER, false, false, 3, 1);
283 discardModeGroup.setLayoutData(data);
284 data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true);
285 fDiscardModeButton.setLayoutData(data);
286 data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true);
287 fOverwriteModeButton.setLayoutData(data);
288
289 data = new GridData(GridData.FILL, GridData.CENTER, false, false, 3, 1);
290 fDomainGroup.setLayoutData(data);
291
292 data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true);
293 fKernelButton.setLayoutData(data);
294 data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true);
295 fUstButton.setLayoutData(data);
296
297 data = new GridData(GridData.FILL_HORIZONTAL);
298 data.horizontalSpan = 2;
299
300 fChannelNameText.setLayoutData(data);
301 fSubBufferSizeText.setLayoutData(data);
302 fNumberOfSubBuffersText.setLayoutData(data);
303 fSwitchTimerText.setLayoutData(data);
304 fReadTimerText.setLayoutData(data);
305
306 setDefaults();
307
308 return fDialogComposite;
309 }
310
311 /*
312 * (non-Javadoc)
313 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
314 */
315 @Override
316 protected void createButtonsForButtonBar(Composite parent) {
317 createButton(parent, IDialogConstants.DETAILS_ID, "&Default", true); //$NON-NLS-1$
318 createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$
319 createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$
320 }
321
322 /*
323 * (non-Javadoc)
324 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
325 */
326 @Override
327 protected void okPressed() {
328 // Set channel information
329 fChannelInfo = new ChannelInfo(fChannelNameText.getText());
330 fChannelInfo.setSubBufferSize(Long.parseLong(fSubBufferSizeText.getText()));
331 fChannelInfo.setNumberOfSubBuffers(Integer.parseInt(fNumberOfSubBuffersText.getText()));
332 fChannelInfo.setSwitchTimer(Long.parseLong(fSwitchTimerText.getText()));
333 fChannelInfo.setReadTimer(Long.parseLong(fReadTimerText.getText()));
334 fChannelInfo.setOverwriteMode(fOverwriteModeButton.getSelection());
335
336 fIsKernel = fKernelButton.getSelection();
337
338 // Check for invalid names
339 if (!fChannelInfo.getName().matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$
340 MessageDialog.openError(getShell(),
341 Messages.TraceControl_EnableChannelDialogTitle,
342 Messages.TraceControl_InvalidChannelNameError + " (" + fChannelInfo.getName() + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
343 return;
344 }
345
346 // Check for duplicate names
347 if (fDomain != null && fDomain.containsChild(fChannelInfo.getName())) {
348 MessageDialog.openError(getShell(),
349 Messages.TraceControl_EnableChannelDialogTitle,
350 Messages.TraceControl_ChannelAlreadyExistsError + " (" + fChannelInfo.getName() + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
351 return;
352 }
353
354 // validation successful -> call super.okPressed()
355 super.okPressed();
356 }
357
358 /*
359 * (non-Javadoc)
360 * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
361 */
362 @Override
363 protected void buttonPressed(int buttonId) {
364 if (buttonId == IDialogConstants.DETAILS_ID) {
365 setDefaults();
366 return;
367 }
368 super.buttonPressed(buttonId);
369 }
370
371 // ------------------------------------------------------------------------
372 // Helper methods
373 // ------------------------------------------------------------------------
374 /**
375 * Sets default value depending on Kernel or UST
376 */
377 private void setDefaults() {
378 fSwitchTimerText.setText(String.valueOf(IChannelInfo.DEFAULT_SWITCH_TIMER));
379 fReadTimerText.setText(String.valueOf(IChannelInfo.DEFAULT_READ_TIMER));
380 fOverwriteModeButton.setSelection(IChannelInfo.DEFAULT_OVERWRITE_MODE);
381 if (fKernelButton.getSelection()) {
382 fSubBufferSizeText.setText(String.valueOf(IChannelInfo.DEFAULT_SUB_BUFFER_SIZE_KERNEL));
383 fNumberOfSubBuffersText.setText(String.valueOf(IChannelInfo.DEFAULT_NUMBER_OF_SUB_BUFFERS_KERNEL));
384 } else {
385 fSubBufferSizeText.setText(String.valueOf(IChannelInfo.DEFAULT_SUB_BUFFER_SIZE_UST));
386 fNumberOfSubBuffersText.setText(String.valueOf(IChannelInfo.DEFAULT_NUMBER_OF_SUB_BUFFERS_UST));
387 }
388 }
389 }
This page took 0.039499 seconds and 5 git commands to generate.