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