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
.lttng
.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
.lttng
.ui
.LTTngUiPlugin
;
18 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.Messages
;
19 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.IChannelInfo
;
20 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.ChannelInfo
;
21 import org
.eclipse
.linuxtools
.lttng
.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 ICreateChannelOnSessionDialog
{
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
;
68 * The sub-buffer size of the channel.
70 private Text fSubBufferSizeText
;
72 * The number of sub-buffers of the channel.
74 private Text fNumberOfSubBuffersText
;
76 * The switch timer interval of the channel.
78 private Text fSwitchTimerText
;
80 * The read timer interval of the channel.
82 private Text fReadTimerText
;
84 * Group composite for domain selection.
86 private Group fDomainGroup
= null;
88 * Radio button for selecting kernel domain.
90 private Button fKernelButton
;
92 * Radio button for selecting UST domain.
94 private Button fUstButton
;
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
;
101 * Common verify listener for numeric text input.
103 private VerifyListener fVerifyListener
;
105 * Output channel information.
107 private IChannelInfo fChannelInfo
;
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
) {
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.
131 public CreateChannelDialog(Shell shell
, TraceDomainComponent domain
) {
134 if (fDomain
!= null) {
135 fIsKernel
= fDomain
.isKernel();
140 // Common verify listener
141 fVerifyListener
= new VerifyListener() {
143 public void verifyText(VerifyEvent e
) {
144 // only numbers are allowed.
145 e
.doit
= e
.text
.matches("[0-9]*"); //$NON-NLS-1$
150 // ------------------------------------------------------------------------
152 // ------------------------------------------------------------------------
155 * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.ICreateChannelDialog#getChannelInfo()
158 public IChannelInfo
getChannelInfo() {
164 * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.ICreateChannelOnSessionDialog#isKernel()
167 public boolean isKernel() {
171 // ------------------------------------------------------------------------
173 // ------------------------------------------------------------------------
176 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
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
));
187 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
190 protected Control
createDialogArea(Composite parent
) {
193 fDialogComposite
= new Composite(parent
, SWT
.NONE
);
194 GridLayout layout
= new GridLayout(2, true);
195 fDialogComposite
.setLayout(layout
);
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_EnableChannelNameTooltip
);
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
);
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
);
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
);
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
);
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
);
231 fDomainGroup
= new Group(fDialogComposite
, SWT
.SHADOW_NONE
);
232 fDomainGroup
.setText(Messages
.TraceControl_DomainDisplayName
);
233 layout
= new GridLayout(2, true);
234 fDomainGroup
.setLayout(layout
);
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
);
243 if (fDomain
!= null) {
244 fKernelButton
.setEnabled(false);
245 fUstButton
.setEnabled(false);
249 GridData data
= new GridData(GridData
.FILL
, GridData
.CENTER
, false, false, 2, 1);
250 fDomainGroup
.setLayoutData(data
);
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
);
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;
262 fChannelNameText
.setLayoutData(data
);
263 fSubBufferSizeText
.setLayoutData(data
);
264 fNumberOfSubBuffersText
.setLayoutData(data
);
265 fSwitchTimerText
.setLayoutData(data
);
266 fReadTimerText
.setLayoutData(data
);
268 fSubBufferSizeText
.setText(""); //$NON-NLS-1$
272 return fDialogComposite
;
277 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
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$
287 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
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());
299 if (fKernelButton
.getSelection() == true) {
305 // Check for invalid names
306 if (!fChannelInfo
.getName().matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$
307 MessageDialog
.openError(getShell(),
308 Messages
.TraceControl_EnableChannelDialogTitle
,
309 Messages
.TraceControl_InvalidChannelNameError
+ " (" + fChannelInfo
.getName() + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
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$
321 // validation successful -> call super.okPressed()
327 * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
330 protected void buttonPressed(int buttonId
) {
331 if (buttonId
== IDialogConstants
.DETAILS_ID
) {
335 super.buttonPressed(buttonId
);
338 // ------------------------------------------------------------------------
340 // ------------------------------------------------------------------------
342 * Sets default value depending on Kernel or UST
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
));
352 fSubBufferSizeText
.setText(String
.valueOf(IChannelInfo
.DEFAULT_SUB_BUFFER_SIZE_UST
));
353 fNumberOfSubBuffersText
.setText(String
.valueOf(IChannelInfo
.DEFAULT_NUMBER_OF_SUB_BUFFERS_UST
));