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
.core
.control
.model
.IChannelInfo
;
18 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.impl
.ChannelInfo
;
19 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.Activator
;
20 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.messages
.Messages
;
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
.layout
.GridData
;
26 import org
.eclipse
.swt
.layout
.GridLayout
;
27 import org
.eclipse
.swt
.widgets
.Button
;
28 import org
.eclipse
.swt
.widgets
.Composite
;
29 import org
.eclipse
.swt
.widgets
.Control
;
30 import org
.eclipse
.swt
.widgets
.Group
;
31 import org
.eclipse
.swt
.widgets
.Label
;
32 import org
.eclipse
.swt
.widgets
.Shell
;
33 import org
.eclipse
.swt
.widgets
.Text
;
37 * Dialog box for collecting channel information when enabling a channel (which will be created).
40 * @author Bernd Hufmann
42 public class EnableChannelDialog
extends Dialog
implements IEnableChannelDialog
{
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
48 * The icon file for this dialog box.
50 public static final String ENABLE_CHANNEL_ICON_FILE
= "icons/elcl16/add_button.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 * Flag which indicates whether Kernel domain is available or not
119 private boolean fHasKernel
;
121 // ------------------------------------------------------------------------
123 // ------------------------------------------------------------------------
127 * @param shell - a shell for the display of the dialog
129 public EnableChannelDialog(Shell shell
) {
133 // Common verify listener
134 fVerifyListener
= new VerifyListener() {
136 public void verifyText(VerifyEvent e
) {
137 // only numbers are allowed.
138 e
.doit
= e
.text
.matches("[0-9]*"); //$NON-NLS-1$
141 setShellStyle(SWT
.RESIZE
);
144 // ------------------------------------------------------------------------
146 // ------------------------------------------------------------------------
149 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelDialog#getChannelInfo()
152 public IChannelInfo
getChannelInfo() {
158 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelDialog#setDomainComponent(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent)
161 public void setDomainComponent(TraceDomainComponent domain
) {
163 if (fDomain
!= null) {
164 fIsKernel
= fDomain
.isKernel();
172 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelDialog#isKernel()
175 public boolean isKernel() {
181 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableChannelDialog#setHasKernel(boolean)
184 public void setHasKernel(boolean hasKernel
) {
185 if (fDomain
!= null) {
186 fIsKernel
= fDomain
.isKernel();
188 fIsKernel
= hasKernel
;
191 fHasKernel
= hasKernel
;
194 // ------------------------------------------------------------------------
196 // ------------------------------------------------------------------------
199 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
202 protected void configureShell(Shell newShell
) {
203 super.configureShell(newShell
);
204 newShell
.setText(Messages
.TraceControl_EnableChannelDialogTitle
);
205 newShell
.setImage(Activator
.getDefault().loadIcon(ENABLE_CHANNEL_ICON_FILE
));
210 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
213 protected Control
createDialogArea(Composite parent
) {
216 fDialogComposite
= new Composite(parent
, SWT
.NONE
);
217 GridLayout layout
= new GridLayout(3, true);
218 fDialogComposite
.setLayout(layout
);
220 Label channelNameLabel
= new Label(fDialogComposite
, SWT
.RIGHT
);
221 channelNameLabel
.setText(Messages
.TraceControl_EnableChannelNameLabel
);
222 fChannelNameText
= new Text(fDialogComposite
, SWT
.NONE
);
223 fChannelNameText
.setToolTipText(Messages
.TraceControl_EnableChannelNameTooltip
);
225 Label subBufferSizeLabel
= new Label(fDialogComposite
, SWT
.RIGHT
);
226 subBufferSizeLabel
.setText(Messages
.TraceControl_SubBufferSizePropertyName
);
227 fSubBufferSizeText
= new Text(fDialogComposite
, SWT
.NONE
);
228 fSubBufferSizeText
.setToolTipText(Messages
.TraceControl_EnableChannelSubBufferSizeTooltip
);
229 fSubBufferSizeText
.addVerifyListener(fVerifyListener
);
231 Label numSubBufferLabel
= new Label(fDialogComposite
, SWT
.RIGHT
);
232 numSubBufferLabel
.setText(Messages
.TraceControl_NbSubBuffersPropertyName
);
233 fNumberOfSubBuffersText
= new Text(fDialogComposite
, SWT
.NONE
);
234 fNumberOfSubBuffersText
.setToolTipText(Messages
.TraceControl_EnableChannelNbSubBuffersTooltip
);
235 fNumberOfSubBuffersText
.addVerifyListener(fVerifyListener
);
237 Label switchTimerLabel
= new Label(fDialogComposite
, SWT
.RIGHT
);
238 switchTimerLabel
.setText(Messages
.TraceControl_SwitchTimerPropertyName
);
239 fSwitchTimerText
= new Text(fDialogComposite
, SWT
.NONE
);
240 fSwitchTimerText
.setToolTipText(Messages
.TraceControl_EnableChannelSwitchTimerTooltip
);
241 fSwitchTimerText
.addVerifyListener(fVerifyListener
);
243 Label readTimerLabel
= new Label(fDialogComposite
, SWT
.RIGHT
);
244 readTimerLabel
.setText(Messages
.TraceControl_ReadTimerPropertyName
);
245 fReadTimerText
= new Text(fDialogComposite
, SWT
.NONE
);
246 fReadTimerText
.setToolTipText(Messages
.TraceControl_EnableChannelReadTimerTooltip
);
247 fReadTimerText
.addVerifyListener(fVerifyListener
);
249 Group discardModeGroup
= new Group(fDialogComposite
, SWT
.SHADOW_NONE
);
250 discardModeGroup
.setText(Messages
.TraceControl_EnableChannelDiscardModeGroupName
);
251 layout
= new GridLayout(2, true);
252 discardModeGroup
.setLayout(layout
);
254 fDiscardModeButton
= new Button(discardModeGroup
, SWT
.RADIO
);
255 fDiscardModeButton
.setText(Messages
.TraceControl_EnableChannelDiscardModeLabel
);
256 fDiscardModeButton
.setToolTipText(Messages
.TraceControl_EnableChannelDiscardModeTooltip
);
257 fDiscardModeButton
.setSelection(true);
259 fOverwriteModeButton
= new Button(discardModeGroup
, SWT
.RADIO
);
260 fOverwriteModeButton
.setText(Messages
.TraceControl_EnableChannelOverwriteModeLabel
);
261 fOverwriteModeButton
.setToolTipText(Messages
.TraceControl_EnableChannelOverwriteModeTooltip
);
262 fOverwriteModeButton
.setSelection(false);
264 fDomainGroup
= new Group(fDialogComposite
, SWT
.SHADOW_NONE
);
265 fDomainGroup
.setText(Messages
.TraceControl_DomainDisplayName
);
266 layout
= new GridLayout(2, true);
267 fDomainGroup
.setLayout(layout
);
269 fKernelButton
= new Button(fDomainGroup
, SWT
.RADIO
);
270 fKernelButton
.setText(Messages
.TraceControl_KernelDomainDisplayName
);
271 fKernelButton
.setSelection(fIsKernel
);
272 fUstButton
= new Button(fDomainGroup
, SWT
.RADIO
);
273 fUstButton
.setText(Messages
.TraceControl_UstDisplayName
);
274 fUstButton
.setSelection(!fIsKernel
);
276 if ((fDomain
!= null) || (!fHasKernel
)) {
277 fKernelButton
.setEnabled(false);
278 fUstButton
.setEnabled(false);
282 GridData data
= new GridData(GridData
.FILL
, GridData
.CENTER
, false, false, 3, 1);
283 discardModeGroup
.setLayoutData(data
);
284 data
= new GridData(SWT
.BEGINNING
, SWT
.BEGINNING
, true, true);
285 fDiscardModeButton
.setLayoutData(data
);
286 data
= new GridData(SWT
.BEGINNING
, SWT
.BEGINNING
, true, true);
287 fOverwriteModeButton
.setLayoutData(data
);
289 data
= new GridData(GridData
.FILL
, GridData
.CENTER
, false, false, 3, 1);
290 fDomainGroup
.setLayoutData(data
);
292 data
= new GridData(SWT
.BEGINNING
, SWT
.BEGINNING
, true, true);
293 fKernelButton
.setLayoutData(data
);
294 data
= new GridData(SWT
.BEGINNING
, SWT
.BEGINNING
, true, true);
295 fUstButton
.setLayoutData(data
);
297 data
= new GridData(GridData
.FILL_HORIZONTAL
);
298 data
.horizontalSpan
= 2;
300 fChannelNameText
.setLayoutData(data
);
301 fSubBufferSizeText
.setLayoutData(data
);
302 fNumberOfSubBuffersText
.setLayoutData(data
);
303 fSwitchTimerText
.setLayoutData(data
);
304 fReadTimerText
.setLayoutData(data
);
308 return fDialogComposite
;
313 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
316 protected void createButtonsForButtonBar(Composite parent
) {
317 createButton(parent
, IDialogConstants
.DETAILS_ID
, "&Default", true); //$NON-NLS-1$
318 createButton(parent
, IDialogConstants
.CANCEL_ID
, "&Cancel", true); //$NON-NLS-1$
319 createButton(parent
, IDialogConstants
.OK_ID
, "&Ok", true); //$NON-NLS-1$
324 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
327 protected void okPressed() {
328 // Set channel information
329 fChannelInfo
= new ChannelInfo(fChannelNameText
.getText());
330 fChannelInfo
.setSubBufferSize(Long
.parseLong(fSubBufferSizeText
.getText()));
331 fChannelInfo
.setNumberOfSubBuffers(Integer
.parseInt(fNumberOfSubBuffersText
.getText()));
332 fChannelInfo
.setSwitchTimer(Long
.parseLong(fSwitchTimerText
.getText()));
333 fChannelInfo
.setReadTimer(Long
.parseLong(fReadTimerText
.getText()));
334 fChannelInfo
.setOverwriteMode(fOverwriteModeButton
.getSelection());
336 fIsKernel
= fKernelButton
.getSelection();
338 // Check for invalid names
339 if (!fChannelInfo
.getName().matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$
340 MessageDialog
.openError(getShell(),
341 Messages
.TraceControl_EnableChannelDialogTitle
,
342 Messages
.TraceControl_InvalidChannelNameError
+ " (" + fChannelInfo
.getName() + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
346 // Check for duplicate names
347 if (fDomain
!= null && fDomain
.containsChild(fChannelInfo
.getName())) {
348 MessageDialog
.openError(getShell(),
349 Messages
.TraceControl_EnableChannelDialogTitle
,
350 Messages
.TraceControl_ChannelAlreadyExistsError
+ " (" + fChannelInfo
.getName() + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
354 // validation successful -> call super.okPressed()
360 * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
363 protected void buttonPressed(int buttonId
) {
364 if (buttonId
== IDialogConstants
.DETAILS_ID
) {
368 super.buttonPressed(buttonId
);
371 // ------------------------------------------------------------------------
373 // ------------------------------------------------------------------------
375 * Sets default value depending on Kernel or UST
377 private void setDefaults() {
378 fSwitchTimerText
.setText(String
.valueOf(IChannelInfo
.DEFAULT_SWITCH_TIMER
));
379 fReadTimerText
.setText(String
.valueOf(IChannelInfo
.DEFAULT_READ_TIMER
));
380 fOverwriteModeButton
.setSelection(IChannelInfo
.DEFAULT_OVERWRITE_MODE
);
381 if (fKernelButton
.getSelection()) {
382 fSubBufferSizeText
.setText(String
.valueOf(IChannelInfo
.DEFAULT_SUB_BUFFER_SIZE_KERNEL
));
383 fNumberOfSubBuffersText
.setText(String
.valueOf(IChannelInfo
.DEFAULT_NUMBER_OF_SUB_BUFFERS_KERNEL
));
385 fSubBufferSizeText
.setText(String
.valueOf(IChannelInfo
.DEFAULT_SUB_BUFFER_SIZE_UST
));
386 fNumberOfSubBuffersText
.setText(String
.valueOf(IChannelInfo
.DEFAULT_NUMBER_OF_SUB_BUFFERS_UST
));