1 /**********************************************************************
2 * Copyright (c) 2012 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
;
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
.ui
.Activator
;
18 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.Messages
;
19 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.IChannelInfo
;
20 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.ChannelInfo
;
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
.graphics
.Point
;
26 import org
.eclipse
.swt
.layout
.GridData
;
27 import org
.eclipse
.swt
.layout
.GridLayout
;
28 import org
.eclipse
.swt
.widgets
.Button
;
29 import org
.eclipse
.swt
.widgets
.Composite
;
30 import org
.eclipse
.swt
.widgets
.Control
;
31 import org
.eclipse
.swt
.widgets
.Group
;
32 import org
.eclipse
.swt
.widgets
.Label
;
33 import org
.eclipse
.swt
.widgets
.Shell
;
34 import org
.eclipse
.swt
.widgets
.Text
;
37 * <b><u>CreateChannelDialog</u></b>
39 * Dialog box for collecting channel creation information.
42 public class CreateChannelDialog
extends Dialog
implements ICreateChannelDialog
{
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
48 * The icon file for this dialog box.
50 public static final String ENABLE_CHANNEL_ICON_FILE
= "icons/elcl16/edit.gif"; //$NON-NLS-1$
52 // ------------------------------------------------------------------------
54 // ------------------------------------------------------------------------
56 * The dialog composite.
58 private Composite fDialogComposite
= null;
60 * The text widget for the channel name
62 private Text fChannelNameText
= null;
64 * The discard mode of the channel.
66 private Button fDiscardModeButton
= null;
68 * The overwrite mode of the channel.
70 private Button fOverwriteModeButton
= null;
72 * The sub-buffer size of the channel.
74 private Text fSubBufferSizeText
= null;
76 * The number of sub-buffers of the channel.
78 private Text fNumberOfSubBuffersText
= null;
80 * The switch timer interval of the channel.
82 private Text fSwitchTimerText
= null;
84 * The read timer interval of the channel.
86 private Text fReadTimerText
= null;
88 * Group composite for domain selection.
90 private Group fDomainGroup
= null;
92 * Radio button for selecting kernel domain.
94 private Button fKernelButton
= null;
96 * Radio button for selecting UST domain.
98 private Button fUstButton
= null;
100 * The parent domain component where the channel node should be added.
101 * Null in case of creation on session level.
103 private TraceDomainComponent fDomain
= null;
105 * Common verify listener for numeric text input.
107 private VerifyListener fVerifyListener
= null;
109 * Output channel information.
111 private IChannelInfo fChannelInfo
= null;
113 * Output domain information. True in case of Kernel domain. False for UST.
115 private boolean fIsKernel
;
117 // ------------------------------------------------------------------------
119 // ------------------------------------------------------------------------
123 * @param shell - a shell for the display of the dialog
125 public CreateChannelDialog(Shell shell
) {
129 // Common verify listener
130 fVerifyListener
= new VerifyListener() {
132 public void verifyText(VerifyEvent e
) {
133 // only numbers are allowed.
134 e
.doit
= e
.text
.matches("[0-9]*"); //$NON-NLS-1$
139 // ------------------------------------------------------------------------
141 // ------------------------------------------------------------------------
144 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelDialog#getChannelInfo()
147 public IChannelInfo
getChannelInfo() {
153 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelDialog#setDomainComponent(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent)
156 public void setDomainComponent(TraceDomainComponent domain
) {
158 if (fDomain
!= null) {
159 fIsKernel
= fDomain
.isKernel();
167 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelDialog#isKernel()
170 public boolean isKernel() {
174 // ------------------------------------------------------------------------
176 // ------------------------------------------------------------------------
179 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
182 protected void configureShell(Shell newShell
) {
183 super.configureShell(newShell
);
184 newShell
.setText(Messages
.TraceControl_EnableChannelDialogTitle
);
185 newShell
.setImage(Activator
.getDefault().loadIcon(ENABLE_CHANNEL_ICON_FILE
));
190 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
193 protected Control
createDialogArea(Composite parent
) {
196 fDialogComposite
= new Composite(parent
, SWT
.NONE
);
197 GridLayout layout
= new GridLayout(2, true);
198 fDialogComposite
.setLayout(layout
);
200 Label channelNameLabel
= new Label(fDialogComposite
, SWT
.RIGHT
);
201 channelNameLabel
.setText(Messages
.TraceControl_EnableChannelNameLabel
);
202 fChannelNameText
= new Text(fDialogComposite
, SWT
.NONE
);
203 fChannelNameText
.setToolTipText(Messages
.TraceControl_EnableChannelNameTooltip
);
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
);
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
);
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
);
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
);
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
);
234 fDiscardModeButton
= new Button(discardModeGroup
, SWT
.RADIO
);
235 fDiscardModeButton
.setText(Messages
.TraceControl_EnableChannelDiscardModeLabel
);
236 fDiscardModeButton
.setToolTipText(Messages
.TraceControl_EnableChannelDiscardModeTooltip
);
237 fDiscardModeButton
.setSelection(true);
239 fOverwriteModeButton
= new Button(discardModeGroup
, SWT
.RADIO
);
240 fOverwriteModeButton
.setText(Messages
.TraceControl_EnableChannelOverwriteModeLabel
);
241 fOverwriteModeButton
.setToolTipText(Messages
.TraceControl_EnableChannelOverwriteModeTooltip
);
242 fOverwriteModeButton
.setSelection(false);
244 fDomainGroup
= new Group(fDialogComposite
, SWT
.SHADOW_NONE
);
245 fDomainGroup
.setText(Messages
.TraceControl_DomainDisplayName
);
246 layout
= new GridLayout(2, true);
247 fDomainGroup
.setLayout(layout
);
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
);
256 if (fDomain
!= null) {
257 fKernelButton
.setEnabled(false);
258 fUstButton
.setEnabled(false);
262 GridData data
= new GridData(GridData
.FILL
, GridData
.CENTER
, false, false, 2, 1);
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
);
269 data
= new GridData(GridData
.FILL
, GridData
.CENTER
, false, false, 2, 1);
270 fDomainGroup
.setLayoutData(data
);
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
);
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;
282 fChannelNameText
.setLayoutData(data
);
283 fSubBufferSizeText
.setLayoutData(data
);
284 fNumberOfSubBuffersText
.setLayoutData(data
);
285 fSwitchTimerText
.setLayoutData(data
);
286 fReadTimerText
.setLayoutData(data
);
288 fSubBufferSizeText
.setText(""); //$NON-NLS-1$
292 return fDialogComposite
;
297 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
300 protected void createButtonsForButtonBar(Composite parent
) {
301 createButton(parent
, IDialogConstants
.DETAILS_ID
, "Default", true); //$NON-NLS-1$
302 createButton(parent
, IDialogConstants
.OK_ID
, "&Ok", true); //$NON-NLS-1$
307 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
310 protected void okPressed() {
311 // Set channel information
312 fChannelInfo
= new ChannelInfo(fChannelNameText
.getText());
313 fChannelInfo
.setSubBufferSize(Long
.parseLong(fSubBufferSizeText
.getText()));
314 fChannelInfo
.setNumberOfSubBuffers(Integer
.parseInt(fNumberOfSubBuffersText
.getText()));
315 fChannelInfo
.setSwitchTimer(Long
.parseLong(fSwitchTimerText
.getText()));
316 fChannelInfo
.setReadTimer(Long
.parseLong(fReadTimerText
.getText()));
317 fChannelInfo
.setOverwriteMode(fOverwriteModeButton
.getSelection());
319 fIsKernel
= fKernelButton
.getSelection();
321 // Check for invalid names
322 if (!fChannelInfo
.getName().matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$
323 MessageDialog
.openError(getShell(),
324 Messages
.TraceControl_EnableChannelDialogTitle
,
325 Messages
.TraceControl_InvalidChannelNameError
+ " (" + fChannelInfo
.getName() + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
329 // Check for duplicate names
330 if (fDomain
!= null && fDomain
.containsChild(fChannelInfo
.getName())) {
331 MessageDialog
.openError(getShell(),
332 Messages
.TraceControl_EnableChannelDialogTitle
,
333 Messages
.TraceControl_ChannelAlreadyExistsError
+ " (" + fChannelInfo
.getName() + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
337 // validation successful -> call super.okPressed()
343 * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
346 protected void buttonPressed(int buttonId
) {
347 if (buttonId
== IDialogConstants
.DETAILS_ID
) {
351 super.buttonPressed(buttonId
);
354 // ------------------------------------------------------------------------
356 // ------------------------------------------------------------------------
358 * Sets default value depending on Kernel or UST
360 private void setDefaults() {
361 fSwitchTimerText
.setText(String
.valueOf(IChannelInfo
.DEFAULT_SWITCH_TIMER
));
362 fReadTimerText
.setText(String
.valueOf(IChannelInfo
.DEFAULT_READ_TIMER
));
363 fOverwriteModeButton
.setSelection(IChannelInfo
.DEFAULT_OVERWRITE_MODE
);
364 if (fKernelButton
.getSelection()) {
365 fSubBufferSizeText
.setText(String
.valueOf(IChannelInfo
.DEFAULT_SUB_BUFFER_SIZE_KERNEL
));
366 fNumberOfSubBuffersText
.setText(String
.valueOf(IChannelInfo
.DEFAULT_NUMBER_OF_SUB_BUFFERS_KERNEL
));
368 fSubBufferSizeText
.setText(String
.valueOf(IChannelInfo
.DEFAULT_SUB_BUFFER_SIZE_UST
));
369 fNumberOfSubBuffersText
.setText(String
.valueOf(IChannelInfo
.DEFAULT_NUMBER_OF_SUB_BUFFERS_UST
));