LTTng: Support for LTTng Tools 2.2
[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, 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 * Simon Delisle - Updated for support of LTTng Tools 2.2
12 **********************************************************************/
13 package org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs;
14
15 import org.eclipse.jface.dialogs.Dialog;
16 import org.eclipse.jface.dialogs.IDialogConstants;
17 import org.eclipse.jface.dialogs.MessageDialog;
18 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IChannelInfo;
19 import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.ChannelInfo;
20 import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
21 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages;
22 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent;
23 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent;
24 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.LTTngControlServiceConstants;
25 import org.eclipse.swt.SWT;
26 import org.eclipse.swt.events.FocusEvent;
27 import org.eclipse.swt.events.FocusListener;
28 import org.eclipse.swt.events.SelectionAdapter;
29 import org.eclipse.swt.events.SelectionEvent;
30 import org.eclipse.swt.events.VerifyEvent;
31 import org.eclipse.swt.events.VerifyListener;
32 import org.eclipse.swt.layout.GridData;
33 import org.eclipse.swt.layout.GridLayout;
34 import org.eclipse.swt.widgets.Button;
35 import org.eclipse.swt.widgets.Composite;
36 import org.eclipse.swt.widgets.Control;
37 import org.eclipse.swt.widgets.Group;
38 import org.eclipse.swt.widgets.Label;
39 import org.eclipse.swt.widgets.Shell;
40 import org.eclipse.swt.widgets.Text;
41
42 /**
43 * <p>
44 * Dialog box for collecting channel information when enabling a channel (which will be created).
45 * </p>
46 *
47 * @author Bernd Hufmann
48 */
49 public class EnableChannelDialog extends Dialog implements IEnableChannelDialog {
50
51 // ------------------------------------------------------------------------
52 // Constants
53 // ------------------------------------------------------------------------
54 /**
55 * The icon file for this dialog box.
56 */
57 public static final String ENABLE_CHANNEL_ICON_FILE = "icons/elcl16/add_button.gif"; //$NON-NLS-1$
58
59 /**
60 * To indicate that the default value will be used for this field
61 */
62 private static final String DEFAULT_TEXT = "<" + Messages.EnableChannelDialog_DefaultMessage + ">"; //$NON-NLS-1$ //$NON-NLS-2$
63
64 // ------------------------------------------------------------------------
65 // Attributes
66 // ------------------------------------------------------------------------
67 /**
68 * The text widget for the channel name
69 */
70 private Text fChannelNameText = null;
71 /**
72 * The discard mode of the channel.
73 */
74 private Button fDiscardModeButton = null;
75 /**
76 * The overwrite mode of the channel.
77 */
78 private Button fOverwriteModeButton = null;
79 /**
80 * The sub-buffer size of the channel.
81 */
82 private Text fSubBufferSizeText = null;
83 /**
84 * The number of sub-buffers of the channel.
85 */
86 private Text fNumberOfSubBuffersText = null;
87 /**
88 * The switch timer interval of the channel.
89 */
90 private Text fSwitchTimerText = null;
91 /**
92 * The read timer interval of the channel.
93 */
94 private Text fReadTimerText = null;
95 /**
96 * Radio button for selecting kernel domain.
97 */
98 private Button fKernelButton = null;
99 /**
100 * Radio button for selecting UST domain.
101 */
102 private Button fUstButton = null;
103 /**
104 * The parent domain component where the channel node should be added.
105 * Null in case of creation on session level.
106 */
107 private TraceDomainComponent fDomain = null;
108 /**
109 * The target node component
110 */
111 private TargetNodeComponent fTargetNodeComponent = null;
112 /**
113 * Common verify listener for numeric text input.
114 */
115 private VerifyListener fVerifyListener = null;
116 /**
117 * Common focus listener
118 */
119 private FocusListener fFocusListener = null;
120 /**
121 * Output channel information.
122 */
123 private IChannelInfo fChannelInfo = null;
124 /**
125 * Output domain information. True in case of Kernel domain. False for UST.
126 */
127 private boolean fIsKernel;
128 /**
129 * Flag which indicates whether Kernel domain is available or not
130 */
131 private boolean fHasKernel;
132 /**
133 * Maximum size of trace files of the channel.
134 */
135 private Text fMaxSizeTraceText = null;
136 /**
137 * Maximum number of trace files of the channel.
138 */
139 private Text fMaxNumberTraceText = null;
140 /**
141 * CheckBox for selecting per UID buffers.
142 */
143 private Button fUIDBuffersButton = null;
144 /**
145 * CheckBox to configure metadata channel
146 */
147 private Button fMetadataChannelButton = null;
148 /**
149 * Previous channel name
150 */
151 private String fPreviousChannelName = null;
152
153
154 // ------------------------------------------------------------------------
155 // Constructors
156 // ------------------------------------------------------------------------
157
158 /**
159 * Constructor
160 * @param shell - a shell for the display of the dialog
161 */
162 public EnableChannelDialog(Shell shell) {
163 super(shell);
164 fIsKernel = true;
165
166 // Common verify listener
167 fVerifyListener = new VerifyListener() {
168 @Override
169 public void verifyText(VerifyEvent e) {
170 // only numbers and default are allowed.
171 e.doit = e.text.matches("[0-9]*") || e.text.matches(DEFAULT_TEXT); //$NON-NLS-1$
172 }
173 };
174
175 // Common focus listener
176 fFocusListener = new FocusListener() {
177
178 @Override
179 public void focusLost(FocusEvent e) {
180 Text focusLostWidget = (Text) e.widget;
181 if (focusLostWidget.getText().isEmpty()) {
182 focusLostWidget.setText(DEFAULT_TEXT);
183 focusLostWidget.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY));
184 }
185 }
186
187 @Override
188 public void focusGained(FocusEvent e) {
189 Text focusGainedWidget = (Text) e.widget;
190 if (focusGainedWidget.getText().equals(DEFAULT_TEXT)) {
191 focusGainedWidget.setText(""); //$NON-NLS-1$
192 focusGainedWidget.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_BLACK));
193 }
194 }
195 };
196
197 setShellStyle(SWT.RESIZE);
198 }
199
200 // ------------------------------------------------------------------------
201 // Accessors
202 // ------------------------------------------------------------------------
203
204 @Override
205 public IChannelInfo getChannelInfo() {
206 return fChannelInfo;
207 }
208
209 @Override
210 public void setDomainComponent(TraceDomainComponent domain) {
211 fDomain = domain;
212 if (fDomain != null) {
213 fIsKernel = fDomain.isKernel();
214 } else {
215 fIsKernel = true;
216 }
217 }
218
219 @Override
220 public boolean isKernel() {
221 return fIsKernel;
222 }
223
224 @Override
225 public void setHasKernel(boolean hasKernel) {
226 if (fDomain != null) {
227 fIsKernel = fDomain.isKernel();
228 } else {
229 fIsKernel = hasKernel;
230 }
231
232 fHasKernel = hasKernel;
233 }
234
235 @Override
236 public void setTargetNodeComponent(TargetNodeComponent node) {
237 fTargetNodeComponent = node;
238 }
239
240 // ------------------------------------------------------------------------
241 // Operations
242 // ------------------------------------------------------------------------
243
244 @Override
245 protected void configureShell(Shell newShell) {
246 super.configureShell(newShell);
247 newShell.setText(Messages.TraceControl_EnableChannelDialogTitle);
248 newShell.setImage(Activator.getDefault().loadIcon(ENABLE_CHANNEL_ICON_FILE));
249 }
250
251 @Override
252 protected Control createDialogArea(Composite parent) {
253
254 // Main dialog panel
255 Composite dialogComposite = new Composite(parent, SWT.NONE);
256 GridLayout layout = new GridLayout(3, true);
257 dialogComposite.setLayout(layout);
258
259 Label channelNameLabel = new Label(dialogComposite, SWT.RIGHT);
260 channelNameLabel.setText(Messages.TraceControl_EnableChannelNameLabel);
261 fChannelNameText = new Text(dialogComposite, SWT.NONE);
262 fChannelNameText.setToolTipText(Messages.TraceControl_EnableChannelNameTooltip);
263
264 Label subBufferSizeLabel = new Label(dialogComposite, SWT.RIGHT);
265 subBufferSizeLabel.setText(Messages.TraceControl_SubBufferSizePropertyName);
266 fSubBufferSizeText = new Text(dialogComposite, SWT.NONE);
267 fSubBufferSizeText.setToolTipText(Messages.TraceControl_EnableChannelSubBufferSizeTooltip);
268 fSubBufferSizeText.addVerifyListener(fVerifyListener);
269 fSubBufferSizeText.addFocusListener(fFocusListener);
270 fSubBufferSizeText.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY));
271
272 Label numSubBufferLabel = new Label(dialogComposite, SWT.RIGHT);
273 numSubBufferLabel.setText(Messages.TraceControl_NbSubBuffersPropertyName);
274 fNumberOfSubBuffersText = new Text(dialogComposite, SWT.NONE);
275 fNumberOfSubBuffersText.setToolTipText(Messages.TraceControl_EnableChannelNbSubBuffersTooltip);
276 fNumberOfSubBuffersText.addVerifyListener(fVerifyListener);
277 fNumberOfSubBuffersText.addFocusListener(fFocusListener);
278
279 Label switchTimerLabel = new Label(dialogComposite, SWT.RIGHT);
280 switchTimerLabel.setText(Messages.TraceControl_SwitchTimerPropertyName);
281 fSwitchTimerText = new Text(dialogComposite, SWT.NONE);
282 fSwitchTimerText.setToolTipText(Messages.TraceControl_EnableChannelSwitchTimerTooltip);
283 fSwitchTimerText.addVerifyListener(fVerifyListener);
284 fSwitchTimerText.addFocusListener(fFocusListener);
285
286 Label readTimerLabel = new Label(dialogComposite, SWT.RIGHT);
287 readTimerLabel.setText(Messages.TraceControl_ReadTimerPropertyName);
288 fReadTimerText = new Text(dialogComposite, SWT.NONE);
289 fReadTimerText.setToolTipText(Messages.TraceControl_EnableChannelReadTimerTooltip);
290 fReadTimerText.addVerifyListener(fVerifyListener);
291 fReadTimerText.addFocusListener(fFocusListener);
292
293 if (fTargetNodeComponent.isTraceFileRotationSupported()) {
294 Label maxSizeTraceFilesLabel = new Label(dialogComposite, SWT.RIGHT);
295 maxSizeTraceFilesLabel.setText(Messages.TraceControl_MaxSizeTraceFilesPropertyName);
296 fMaxSizeTraceText = new Text(dialogComposite, SWT.NONE);
297 fMaxSizeTraceText.setToolTipText(Messages.TraceControl_EnbleChannelMaxSizeTraceFilesTooltip);
298 fMaxSizeTraceText.addVerifyListener(fVerifyListener);
299 fMaxSizeTraceText.addFocusListener(fFocusListener);
300
301 Label maxNumTraceFilesLabel = new Label(dialogComposite, SWT.RIGHT);
302 maxNumTraceFilesLabel.setText(Messages.TraceControl_MaxNumTraceFilesPropertyName);
303 fMaxNumberTraceText = new Text(dialogComposite, SWT.NONE);
304 fMaxNumberTraceText.setToolTipText(Messages.TraceControl_EnbleChannelMaxNumTraceFilesTooltip);
305 fMaxNumberTraceText.addVerifyListener(fVerifyListener);
306 fMaxNumberTraceText.addFocusListener(fFocusListener);
307 }
308
309 if (fTargetNodeComponent.isPeriodicalMetadataFlushSupported()) {
310 fMetadataChannelButton = new Button(dialogComposite, SWT.CHECK);
311 fMetadataChannelButton.setText(Messages.TraceControl_ConfigureMetadataChannelName);
312 fMetadataChannelButton.setSelection(false);
313
314 fMetadataChannelButton.addSelectionListener(new SelectionAdapter() {
315 @Override
316 public void widgetSelected(SelectionEvent e) {
317 if (fMetadataChannelButton.getSelection()) {
318 fPreviousChannelName = fChannelNameText.getText();
319 fChannelNameText.setText("metadata"); //$NON-NLS-1$
320 fChannelNameText.setEnabled(false);
321 } else {
322 fChannelNameText.setText(fPreviousChannelName);
323 fChannelNameText.setEnabled(true);
324 }
325 }
326 });
327 }
328
329 Group discardModeGroup = new Group(dialogComposite, SWT.SHADOW_NONE);
330 discardModeGroup.setText(Messages.TraceControl_EnableChannelDiscardModeGroupName);
331 layout = new GridLayout(2, true);
332 discardModeGroup.setLayout(layout);
333
334 fDiscardModeButton = new Button(discardModeGroup, SWT.RADIO);
335 fDiscardModeButton.setText(Messages.TraceControl_EnableChannelDiscardModeLabel);
336 fDiscardModeButton.setToolTipText(Messages.TraceControl_EnableChannelDiscardModeTooltip);
337 fDiscardModeButton.setSelection(true);
338
339 fOverwriteModeButton = new Button(discardModeGroup, SWT.RADIO);
340 fOverwriteModeButton.setText(Messages.TraceControl_EnableChannelOverwriteModeLabel);
341 fOverwriteModeButton.setToolTipText(Messages.TraceControl_EnableChannelOverwriteModeTooltip);
342 fOverwriteModeButton.setSelection(false);
343
344 Group domainGroup = new Group(dialogComposite, SWT.SHADOW_NONE);
345 domainGroup.setText(Messages.TraceControl_DomainDisplayName);
346 layout = new GridLayout(2, true);
347 domainGroup.setLayout(layout);
348
349 fKernelButton = new Button(domainGroup, SWT.RADIO);
350 fKernelButton.setText(Messages.TraceControl_KernelDomainDisplayName);
351 fKernelButton.setSelection(fIsKernel);
352 fUstButton = new Button(domainGroup, SWT.RADIO);
353 fUstButton.setText(Messages.TraceControl_UstDisplayName);
354 fUstButton.setSelection(!fIsKernel);
355
356 if (fTargetNodeComponent.isPerUIDBuffersSupported()) {
357 Button fDummyButton = new Button(domainGroup, SWT.CHECK);
358 fDummyButton.setEnabled(false);
359 fDummyButton.setVisible(false);
360 fUIDBuffersButton = new Button(domainGroup, SWT.CHECK);
361 fUIDBuffersButton.setText(Messages.TraceControl_PerUidBuffersDisplayName);
362 fUIDBuffersButton.setSelection(false);
363 fUIDBuffersButton.setEnabled(!fIsKernel);
364
365 fUstButton.addSelectionListener(new SelectionAdapter() {
366 @Override
367 public void widgetSelected(SelectionEvent e) {
368 if (fUstButton.getSelection()) {
369 fUIDBuffersButton.setEnabled(true);
370 } else {
371 fUIDBuffersButton.setEnabled(false);
372 }
373 }
374 });
375 }
376
377 if ((fDomain != null) || (!fHasKernel)) {
378 fKernelButton.setEnabled(false);
379 fUstButton.setEnabled(false);
380 }
381
382 // layout widgets
383 GridData data = new GridData(GridData.FILL, GridData.CENTER, false, false, 3, 1);
384 discardModeGroup.setLayoutData(data);
385 data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true);
386 fDiscardModeButton.setLayoutData(data);
387 data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true);
388 fOverwriteModeButton.setLayoutData(data);
389
390 data = new GridData(GridData.FILL, GridData.CENTER, false, false, 3, 1);
391 domainGroup.setLayoutData(data);
392
393 data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true);
394 fKernelButton.setLayoutData(data);
395 data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true);
396 fUstButton.setLayoutData(data);
397 if (fTargetNodeComponent.isPerUIDBuffersSupported()) {
398 data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true);
399 fUIDBuffersButton.setLayoutData(data);
400 }
401 if (fTargetNodeComponent.isPeriodicalMetadataFlushSupported()) {
402 data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true);
403 fMetadataChannelButton.setLayoutData(data);
404 }
405
406 data = new GridData(GridData.FILL_HORIZONTAL);
407 data.horizontalSpan = 2;
408
409 fChannelNameText.setLayoutData(data);
410 fSubBufferSizeText.setLayoutData(data);
411 fNumberOfSubBuffersText.setLayoutData(data);
412 fSwitchTimerText.setLayoutData(data);
413 fReadTimerText.setLayoutData(data);
414 if (fTargetNodeComponent.isTraceFileRotationSupported()) {
415 fMaxNumberTraceText.setLayoutData(data);
416 fMaxSizeTraceText.setLayoutData(data);
417 }
418
419 setDefaults();
420
421 return dialogComposite;
422 }
423
424 @Override
425 protected void createButtonsForButtonBar(Composite parent) {
426 createButton(parent, IDialogConstants.DETAILS_ID, "&Default", true); //$NON-NLS-1$
427 createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$
428 createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$
429 }
430
431 @Override
432 protected void okPressed() {
433 // Set channel information
434 fChannelInfo = new ChannelInfo(fChannelNameText.getText());
435 fChannelInfo.setSubBufferSize(fSubBufferSizeText.getText().equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Long.parseLong(fSubBufferSizeText.getText()));
436 fChannelInfo.setNumberOfSubBuffers(fNumberOfSubBuffersText.getText().equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Integer.parseInt(fNumberOfSubBuffersText.getText()));
437 fChannelInfo.setSwitchTimer(fSwitchTimerText.getText().equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Long.parseLong(fSwitchTimerText.getText()));
438 fChannelInfo.setReadTimer(fReadTimerText.getText().equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Long.parseLong(fReadTimerText.getText()));
439 fChannelInfo.setOverwriteMode(fOverwriteModeButton.getSelection());
440 if (fTargetNodeComponent.isTraceFileRotationSupported()) {
441 fChannelInfo.setMaxSizeTraceFiles(fMaxSizeTraceText.getText().equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Integer.parseInt(fMaxSizeTraceText.getText()));
442 fChannelInfo.setMaxNumberTraceFiles(fMaxNumberTraceText.getText().equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Integer.parseInt(fMaxNumberTraceText.getText()));
443 }
444 if (fTargetNodeComponent.isPerUIDBuffersSupported()) {
445 fChannelInfo.setBuffersUID(fUIDBuffersButton.getSelection());
446 }
447
448 fIsKernel = fKernelButton.getSelection();
449
450 // Check for invalid names
451 if (!fChannelInfo.getName().matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$
452 MessageDialog.openError(getShell(),
453 Messages.TraceControl_EnableChannelDialogTitle,
454 Messages.TraceControl_InvalidChannelNameError + " (" + fChannelInfo.getName() + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
455 return;
456 }
457
458 // Check for duplicate names
459 if (fDomain != null && fDomain.containsChild(fChannelInfo.getName())) {
460 MessageDialog.openError(getShell(),
461 Messages.TraceControl_EnableChannelDialogTitle,
462 Messages.TraceControl_ChannelAlreadyExistsError + " (" + fChannelInfo.getName() + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
463 return;
464 }
465
466 // validation successful -> call super.okPressed()
467 super.okPressed();
468 }
469
470 @Override
471 protected void buttonPressed(int buttonId) {
472 if (buttonId == IDialogConstants.DETAILS_ID) {
473 setDefaults();
474 return;
475 }
476 super.buttonPressed(buttonId);
477 }
478
479 // ------------------------------------------------------------------------
480 // Helper methods
481 // ------------------------------------------------------------------------
482
483 /**
484 * Sets default value depending on Kernel or UST
485 */
486 private void setDefaults() {
487 fSwitchTimerText.setText(DEFAULT_TEXT);
488 fSwitchTimerText.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY));
489 fReadTimerText.setText(DEFAULT_TEXT);
490 fReadTimerText.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY));
491 fOverwriteModeButton.setSelection(IChannelInfo.DEFAULT_OVERWRITE_MODE);
492 if (fTargetNodeComponent.isTraceFileRotationSupported()) {
493 fMaxSizeTraceText.setText(DEFAULT_TEXT);
494 fMaxSizeTraceText.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY));
495 fMaxNumberTraceText.setText(DEFAULT_TEXT);
496 fMaxNumberTraceText.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY));
497 }
498 fSubBufferSizeText.setText(DEFAULT_TEXT);
499 fSubBufferSizeText.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY));
500 fNumberOfSubBuffersText.setText(DEFAULT_TEXT);
501 fNumberOfSubBuffersText.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY));
502 }
503 }
This page took 0.042063 seconds and 5 git commands to generate.