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 overwrite mode of the channel.
66 private Button fOverwriteModeButton
= null;
68 * The sub-buffer size of the channel.
70 private Text fSubBufferSizeText
= null;
72 * The number of sub-buffers of the channel.
74 private Text fNumberOfSubBuffersText
= null;
76 * The switch timer interval of the channel.
78 private Text fSwitchTimerText
= null;
80 * The read timer interval of the channel.
82 private Text fReadTimerText
= null;
84 * Group composite for domain selection.
86 private Group fDomainGroup
= null;
88 * Radio button for selecting kernel domain.
90 private Button fKernelButton
= null;
92 * Radio button for selecting UST domain.
94 private Button fUstButton
= null;
96 * The parent domain component where the channel node should be added.
97 * Null in case of creation on session level.
99 private TraceDomainComponent fDomain
= null;
101 * Common verify listener for numeric text input.
103 private VerifyListener fVerifyListener
= null;
105 * Output channel information.
107 private IChannelInfo fChannelInfo
= null;
109 * Output domain information. True in case of Kernel domain. False for UST.
111 private boolean fIsKernel
;
113 // ------------------------------------------------------------------------
115 // ------------------------------------------------------------------------
119 * @param shell - a shell for the display of the dialog
121 public CreateChannelDialog(Shell shell
) {
125 // Common verify listener
126 fVerifyListener
= new VerifyListener() {
128 public void verifyText(VerifyEvent e
) {
129 // only numbers are allowed.
130 e
.doit
= e
.text
.matches("[0-9]*"); //$NON-NLS-1$
135 // ------------------------------------------------------------------------
137 // ------------------------------------------------------------------------
140 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelDialog#getChannelInfo()
143 public IChannelInfo
getChannelInfo() {
149 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelDialog#setDomainComponent(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent)
152 public void setDomainComponent(TraceDomainComponent domain
) {
154 if (fDomain
!= null) {
155 fIsKernel
= fDomain
.isKernel();
163 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelDialog#isKernel()
166 public boolean isKernel() {
170 // ------------------------------------------------------------------------
172 // ------------------------------------------------------------------------
175 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
178 protected void configureShell(Shell newShell
) {
179 super.configureShell(newShell
);
180 newShell
.setText(Messages
.TraceControl_EnableChannelDialogTitle
);
181 newShell
.setImage(Activator
.getDefault().loadIcon(ENABLE_CHANNEL_ICON_FILE
));
186 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
189 protected Control
createDialogArea(Composite parent
) {
192 fDialogComposite
= new Composite(parent
, SWT
.NONE
);
193 GridLayout layout
= new GridLayout(2, true);
194 fDialogComposite
.setLayout(layout
);
196 Label channelNameLabel
= new Label(fDialogComposite
, SWT
.RIGHT
);
197 channelNameLabel
.setText(Messages
.TraceControl_EnableChannelNameLabel
);
198 fChannelNameText
= new Text(fDialogComposite
, SWT
.NONE
);
199 fChannelNameText
.setToolTipText(Messages
.TraceControl_EnableChannelNameTooltip
);
201 Label subBufferSizeLabel
= new Label(fDialogComposite
, SWT
.RIGHT
);
202 subBufferSizeLabel
.setText(Messages
.TraceControl_SubBufferSizePropertyName
);
203 fSubBufferSizeText
= new Text(fDialogComposite
, SWT
.NONE
);
204 fSubBufferSizeText
.setToolTipText(Messages
.TraceControl_EnableChannelSubBufferSizeTooltip
);
205 fSubBufferSizeText
.addVerifyListener(fVerifyListener
);
207 Label numSubBufferLabel
= new Label(fDialogComposite
, SWT
.RIGHT
);
208 numSubBufferLabel
.setText(Messages
.TraceControl_NbSubBuffersPropertyName
);
209 fNumberOfSubBuffersText
= new Text(fDialogComposite
, SWT
.NONE
);
210 fNumberOfSubBuffersText
.setToolTipText(Messages
.TraceControl_EnableChannelNbSubBuffersTooltip
);
211 fNumberOfSubBuffersText
.addVerifyListener(fVerifyListener
);
213 Label switchTimerLabel
= new Label(fDialogComposite
, SWT
.RIGHT
);
214 switchTimerLabel
.setText(Messages
.TraceControl_SwitchTimerPropertyName
);
215 fSwitchTimerText
= new Text(fDialogComposite
, SWT
.NONE
);
216 fSwitchTimerText
.setToolTipText(Messages
.TraceControl_EnableChannelSwitchTimerTooltip
);
217 fSwitchTimerText
.addVerifyListener(fVerifyListener
);
219 Label readTimerLabel
= new Label(fDialogComposite
, SWT
.RIGHT
);
220 readTimerLabel
.setText(Messages
.TraceControl_ReadTimerPropertyName
);
221 fReadTimerText
= new Text(fDialogComposite
, SWT
.NONE
);
222 fReadTimerText
.setToolTipText(Messages
.TraceControl_EnableChannelReadTimerTooltip
);
223 fReadTimerText
.addVerifyListener(fVerifyListener
);
225 fOverwriteModeButton
= new Button(fDialogComposite
, SWT
.CHECK
);
226 fOverwriteModeButton
.setText(Messages
.TraceControl_OverwriteModePropertyName
);
227 fOverwriteModeButton
.setToolTipText(Messages
.TraceControl_EnableChannelOverwriteModeTooltip
);
228 new Label(fDialogComposite
, SWT
.RIGHT
);
230 fDomainGroup
= new Group(fDialogComposite
, SWT
.SHADOW_NONE
);
231 fDomainGroup
.setText(Messages
.TraceControl_DomainDisplayName
);
232 layout
= new GridLayout(2, true);
233 fDomainGroup
.setLayout(layout
);
235 fKernelButton
= new Button(fDomainGroup
, SWT
.RADIO
);
236 fKernelButton
.setText(Messages
.TraceControl_KernelDomainDisplayName
);
237 fKernelButton
.setSelection(fIsKernel
);
238 fUstButton
= new Button(fDomainGroup
, SWT
.RADIO
);
239 fUstButton
.setText(Messages
.TraceControl_UstDisplayName
);
240 fUstButton
.setSelection(!fIsKernel
);
242 if (fDomain
!= null) {
243 fKernelButton
.setEnabled(false);
244 fUstButton
.setEnabled(false);
248 GridData data
= new GridData(GridData
.FILL
, GridData
.CENTER
, false, false, 2, 1);
249 fDomainGroup
.setLayoutData(data
);
251 data
= new GridData(SWT
.BEGINNING
, SWT
.BEGINNING
, true, true);
252 fKernelButton
.setLayoutData(data
);
253 data
= new GridData(SWT
.BEGINNING
, SWT
.BEGINNING
, true, true);
254 fUstButton
.setLayoutData(data
);
256 data
= new GridData(GridData
.HORIZONTAL_ALIGN_FILL
);
257 fSubBufferSizeText
.setText("666.666.666.666"); //$NON-NLS-1$
258 Point minSize
= fSubBufferSizeText
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
, true);
259 data
.widthHint
= minSize
.x
+ 5;
261 fChannelNameText
.setLayoutData(data
);
262 fSubBufferSizeText
.setLayoutData(data
);
263 fNumberOfSubBuffersText
.setLayoutData(data
);
264 fSwitchTimerText
.setLayoutData(data
);
265 fReadTimerText
.setLayoutData(data
);
267 fSubBufferSizeText
.setText(""); //$NON-NLS-1$
271 return fDialogComposite
;
276 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
279 protected void createButtonsForButtonBar(Composite parent
) {
280 createButton(parent
, IDialogConstants
.DETAILS_ID
, "Default", true); //$NON-NLS-1$
281 createButton(parent
, IDialogConstants
.OK_ID
, "&Ok", true); //$NON-NLS-1$
286 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
289 protected void okPressed() {
290 // Set channel information
291 fChannelInfo
= new ChannelInfo(fChannelNameText
.getText());
292 fChannelInfo
.setSubBufferSize(Long
.parseLong(fSubBufferSizeText
.getText()));
293 fChannelInfo
.setNumberOfSubBuffers(Integer
.parseInt(fNumberOfSubBuffersText
.getText()));
294 fChannelInfo
.setSwitchTimer(Long
.parseLong(fSwitchTimerText
.getText()));
295 fChannelInfo
.setReadTimer(Long
.parseLong(fReadTimerText
.getText()));
296 fChannelInfo
.setOverwriteMode(fOverwriteModeButton
.getSelection());
298 fIsKernel
= fKernelButton
.getSelection();
300 // Check for invalid names
301 if (!fChannelInfo
.getName().matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$
302 MessageDialog
.openError(getShell(),
303 Messages
.TraceControl_EnableChannelDialogTitle
,
304 Messages
.TraceControl_InvalidChannelNameError
+ " (" + fChannelInfo
.getName() + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
308 // Check for duplicate names
309 if (fDomain
!= null && fDomain
.containsChild(fChannelInfo
.getName())) {
310 MessageDialog
.openError(getShell(),
311 Messages
.TraceControl_EnableChannelDialogTitle
,
312 Messages
.TraceControl_ChannelAlreadyExistsError
+ " (" + fChannelInfo
.getName() + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
316 // validation successful -> call super.okPressed()
322 * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
325 protected void buttonPressed(int buttonId
) {
326 if (buttonId
== IDialogConstants
.DETAILS_ID
) {
330 super.buttonPressed(buttonId
);
333 // ------------------------------------------------------------------------
335 // ------------------------------------------------------------------------
337 * Sets default value depending on Kernel or UST
339 private void setDefaults() {
340 fSwitchTimerText
.setText(String
.valueOf(IChannelInfo
.DEFAULT_SWITCH_TIMER
));
341 fReadTimerText
.setText(String
.valueOf(IChannelInfo
.DEFAULT_READ_TIMER
));
342 fOverwriteModeButton
.setSelection(IChannelInfo
.DEFAULT_OVERWRITE_MODE
);
343 if (fKernelButton
.getSelection()) {
344 fSubBufferSizeText
.setText(String
.valueOf(IChannelInfo
.DEFAULT_SUB_BUFFER_SIZE_KERNEL
));
345 fNumberOfSubBuffersText
.setText(String
.valueOf(IChannelInfo
.DEFAULT_NUMBER_OF_SUB_BUFFERS_KERNEL
));
347 fSubBufferSizeText
.setText(String
.valueOf(IChannelInfo
.DEFAULT_SUB_BUFFER_SIZE_UST
));
348 fNumberOfSubBuffersText
.setText(String
.valueOf(IChannelInfo
.DEFAULT_NUMBER_OF_SUB_BUFFERS_UST
));