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