| 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 | **********************************************************************/ |
| 12 | package org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs; |
| 13 | |
| 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; |
| 35 | |
| 36 | /** |
| 37 | * <b><u>CreateChannelDialog</u></b> |
| 38 | * <p> |
| 39 | * Dialog box for collecting channel creation information. |
| 40 | * </p> |
| 41 | */ |
| 42 | public class CreateChannelDialog extends Dialog implements ICreateChannelDialog { |
| 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 = null; |
| 67 | /** |
| 68 | * The sub-buffer size of the channel. |
| 69 | */ |
| 70 | private Text fSubBufferSizeText = null; |
| 71 | /** |
| 72 | * The number of sub-buffers of the channel. |
| 73 | */ |
| 74 | private Text fNumberOfSubBuffersText = null; |
| 75 | /** |
| 76 | * The switch timer interval of the channel. |
| 77 | */ |
| 78 | private Text fSwitchTimerText = null; |
| 79 | /** |
| 80 | * The read timer interval of the channel. |
| 81 | */ |
| 82 | private Text fReadTimerText = null; |
| 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 = null; |
| 91 | /** |
| 92 | * Radio button for selecting UST domain. |
| 93 | */ |
| 94 | private Button fUstButton = null; |
| 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 = null; |
| 100 | /** |
| 101 | * Common verify listener for numeric text input. |
| 102 | */ |
| 103 | private VerifyListener fVerifyListener = null; |
| 104 | /** |
| 105 | * Output channel information. |
| 106 | */ |
| 107 | private IChannelInfo fChannelInfo = null; |
| 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 | super(shell); |
| 123 | fIsKernel = true; |
| 124 | |
| 125 | // Common verify listener |
| 126 | fVerifyListener = new VerifyListener() { |
| 127 | @Override |
| 128 | public void verifyText(VerifyEvent e) { |
| 129 | // only numbers are allowed. |
| 130 | e.doit = e.text.matches("[0-9]*"); //$NON-NLS-1$ |
| 131 | } |
| 132 | }; |
| 133 | } |
| 134 | |
| 135 | // ------------------------------------------------------------------------ |
| 136 | // Accessors |
| 137 | // ------------------------------------------------------------------------ |
| 138 | /* |
| 139 | * (non-Javadoc) |
| 140 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelDialog#getChannelInfo() |
| 141 | */ |
| 142 | @Override |
| 143 | public IChannelInfo getChannelInfo() { |
| 144 | return fChannelInfo; |
| 145 | } |
| 146 | |
| 147 | /* |
| 148 | * (non-Javadoc) |
| 149 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelDialog#setDomainComponent(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent) |
| 150 | */ |
| 151 | @Override |
| 152 | public void setDomainComponent(TraceDomainComponent domain) { |
| 153 | fDomain = domain; |
| 154 | if (fDomain != null) { |
| 155 | fIsKernel = fDomain.isKernel(); |
| 156 | } else { |
| 157 | fIsKernel = true; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | /* |
| 162 | * (non-Javadoc) |
| 163 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelDialog#isKernel() |
| 164 | */ |
| 165 | @Override |
| 166 | public boolean isKernel() { |
| 167 | return fIsKernel; |
| 168 | } |
| 169 | |
| 170 | // ------------------------------------------------------------------------ |
| 171 | // Operations |
| 172 | // ------------------------------------------------------------------------ |
| 173 | /* |
| 174 | * (non-Javadoc) |
| 175 | * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) |
| 176 | */ |
| 177 | @Override |
| 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)); |
| 182 | } |
| 183 | |
| 184 | /* |
| 185 | * (non-Javadoc) |
| 186 | * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) |
| 187 | */ |
| 188 | @Override |
| 189 | protected Control createDialogArea(Composite parent) { |
| 190 | |
| 191 | // Main dialog panel |
| 192 | fDialogComposite = new Composite(parent, SWT.NONE); |
| 193 | GridLayout layout = new GridLayout(2, true); |
| 194 | fDialogComposite.setLayout(layout); |
| 195 | |
| 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); |
| 200 | |
| 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); |
| 206 | |
| 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); |
| 212 | |
| 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); |
| 218 | |
| 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); |
| 224 | |
| 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); |
| 229 | |
| 230 | fDomainGroup = new Group(fDialogComposite, SWT.SHADOW_NONE); |
| 231 | fDomainGroup.setText(Messages.TraceControl_DomainDisplayName); |
| 232 | layout = new GridLayout(2, true); |
| 233 | fDomainGroup.setLayout(layout); |
| 234 | |
| 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); |
| 241 | |
| 242 | if (fDomain != null) { |
| 243 | fKernelButton.setEnabled(false); |
| 244 | fUstButton.setEnabled(false); |
| 245 | } |
| 246 | |
| 247 | // layout widgets |
| 248 | GridData data = new GridData(GridData.FILL, GridData.CENTER, false, false, 2, 1); |
| 249 | fDomainGroup.setLayoutData(data); |
| 250 | |
| 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); |
| 255 | |
| 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; |
| 260 | |
| 261 | fChannelNameText.setLayoutData(data); |
| 262 | fSubBufferSizeText.setLayoutData(data); |
| 263 | fNumberOfSubBuffersText.setLayoutData(data); |
| 264 | fSwitchTimerText.setLayoutData(data); |
| 265 | fReadTimerText.setLayoutData(data); |
| 266 | |
| 267 | fSubBufferSizeText.setText(""); //$NON-NLS-1$ |
| 268 | |
| 269 | setDefaults(); |
| 270 | |
| 271 | return fDialogComposite; |
| 272 | } |
| 273 | |
| 274 | /* |
| 275 | * (non-Javadoc) |
| 276 | * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) |
| 277 | */ |
| 278 | @Override |
| 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$ |
| 282 | } |
| 283 | |
| 284 | /* |
| 285 | * (non-Javadoc) |
| 286 | * @see org.eclipse.jface.dialogs.Dialog#okPressed() |
| 287 | */ |
| 288 | @Override |
| 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()); |
| 297 | |
| 298 | fIsKernel = fKernelButton.getSelection(); |
| 299 | |
| 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$ |
| 305 | return; |
| 306 | } |
| 307 | |
| 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$ |
| 313 | return; |
| 314 | } |
| 315 | |
| 316 | // validation successful -> call super.okPressed() |
| 317 | super.okPressed(); |
| 318 | } |
| 319 | |
| 320 | /* |
| 321 | * (non-Javadoc) |
| 322 | * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int) |
| 323 | */ |
| 324 | @Override |
| 325 | protected void buttonPressed(int buttonId) { |
| 326 | if (buttonId == IDialogConstants.DETAILS_ID) { |
| 327 | setDefaults(); |
| 328 | return; |
| 329 | } |
| 330 | super.buttonPressed(buttonId); |
| 331 | } |
| 332 | |
| 333 | // ------------------------------------------------------------------------ |
| 334 | // Helper methods |
| 335 | // ------------------------------------------------------------------------ |
| 336 | /** |
| 337 | * Sets default value depending on Kernel or UST |
| 338 | */ |
| 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)); |
| 346 | } else { |
| 347 | fSubBufferSizeText.setText(String.valueOf(IChannelInfo.DEFAULT_SUB_BUFFER_SIZE_UST)); |
| 348 | fNumberOfSubBuffersText.setText(String.valueOf(IChannelInfo.DEFAULT_NUMBER_OF_SUB_BUFFERS_UST)); |
| 349 | } |
| 350 | } |
| 351 | } |