Commit | Line | Data |
---|---|---|
bbb3538a BH |
1 | /********************************************************************** |
2 | * Copyright (c) 2012 Ericsson | |
a07c7629 | 3 | * |
bbb3538a BH |
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 | |
a07c7629 BH |
8 | * |
9 | * Contributors: | |
bbb3538a BH |
10 | * Bernd Hufmann - Initial API and implementation |
11 | **********************************************************************/ | |
115b4a01 | 12 | package org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs; |
bbb3538a BH |
13 | |
14 | import org.eclipse.jface.dialogs.Dialog; | |
15 | import org.eclipse.jface.dialogs.IDialogConstants; | |
16 | import org.eclipse.jface.dialogs.MessageDialog; | |
9315aeee BH |
17 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IChannelInfo; |
18 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.ChannelInfo; | |
115b4a01 | 19 | import org.eclipse.linuxtools.internal.lttng2.ui.Activator; |
9315aeee | 20 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages; |
115b4a01 | 21 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent; |
bbb3538a BH |
22 | import org.eclipse.swt.SWT; |
23 | import org.eclipse.swt.events.VerifyEvent; | |
24 | import org.eclipse.swt.events.VerifyListener; | |
bbb3538a BH |
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; | |
34 | ||
35 | /** | |
bbb3538a | 36 | * <p> |
d62bfa55 | 37 | * Dialog box for collecting channel information when enabling a channel (which will be created). |
bbb3538a | 38 | * </p> |
a07c7629 | 39 | * |
dbd4432d | 40 | * @author Bernd Hufmann |
bbb3538a | 41 | */ |
d62bfa55 | 42 | public class EnableChannelDialog extends Dialog implements IEnableChannelDialog { |
bbb3538a BH |
43 | |
44 | // ------------------------------------------------------------------------ | |
45 | // Constants | |
46 | // ------------------------------------------------------------------------ | |
47 | /** | |
48 | * The icon file for this dialog box. | |
49 | */ | |
a07c7629 | 50 | public static final String ENABLE_CHANNEL_ICON_FILE = "icons/elcl16/add_button.gif"; //$NON-NLS-1$ |
bbb3538a BH |
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; | |
0886cf00 BH |
63 | /** |
64 | * The discard mode of the channel. | |
65 | */ | |
66 | private Button fDiscardModeButton = null; | |
bbb3538a BH |
67 | /** |
68 | * The overwrite mode of the channel. | |
69 | */ | |
c56972bb | 70 | private Button fOverwriteModeButton = null; |
bbb3538a BH |
71 | /** |
72 | * The sub-buffer size of the channel. | |
73 | */ | |
c56972bb | 74 | private Text fSubBufferSizeText = null; |
bbb3538a BH |
75 | /** |
76 | * The number of sub-buffers of the channel. | |
77 | */ | |
c56972bb | 78 | private Text fNumberOfSubBuffersText = null; |
bbb3538a BH |
79 | /** |
80 | * The switch timer interval of the channel. | |
81 | */ | |
c56972bb | 82 | private Text fSwitchTimerText = null; |
bbb3538a BH |
83 | /** |
84 | * The read timer interval of the channel. | |
85 | */ | |
c56972bb | 86 | private Text fReadTimerText = null; |
bbb3538a BH |
87 | /** |
88 | * Group composite for domain selection. | |
89 | */ | |
90 | private Group fDomainGroup = null; | |
91 | /** | |
92 | * Radio button for selecting kernel domain. | |
93 | */ | |
c56972bb | 94 | private Button fKernelButton = null; |
bbb3538a BH |
95 | /** |
96 | * Radio button for selecting UST domain. | |
97 | */ | |
c56972bb | 98 | private Button fUstButton = null; |
bbb3538a | 99 | /** |
a07c7629 | 100 | * The parent domain component where the channel node should be added. |
bbb3538a BH |
101 | * Null in case of creation on session level. |
102 | */ | |
c56972bb | 103 | private TraceDomainComponent fDomain = null; |
bbb3538a | 104 | /** |
a07c7629 | 105 | * Common verify listener for numeric text input. |
bbb3538a | 106 | */ |
c56972bb | 107 | private VerifyListener fVerifyListener = null; |
bbb3538a BH |
108 | /** |
109 | * Output channel information. | |
110 | */ | |
c56972bb | 111 | private IChannelInfo fChannelInfo = null; |
bbb3538a | 112 | /** |
a07c7629 | 113 | * Output domain information. True in case of Kernel domain. False for UST. |
bbb3538a BH |
114 | */ |
115 | private boolean fIsKernel; | |
a07c7629 BH |
116 | /** |
117 | * Flag which indicates whether Kernel domain is available or not | |
118 | */ | |
119 | private boolean fHasKernel; | |
bbb3538a BH |
120 | |
121 | // ------------------------------------------------------------------------ | |
122 | // Constructors | |
123 | // ------------------------------------------------------------------------ | |
124 | ||
125 | /** | |
126 | * Constructor | |
127 | * @param shell - a shell for the display of the dialog | |
128 | */ | |
d62bfa55 | 129 | public EnableChannelDialog(Shell shell) { |
d132bcc7 BH |
130 | super(shell); |
131 | fIsKernel = true; | |
bbb3538a BH |
132 | |
133 | // Common verify listener | |
134 | fVerifyListener = new VerifyListener() { | |
135 | @Override | |
136 | public void verifyText(VerifyEvent e) { | |
137 | // only numbers are allowed. | |
138 | e.doit = e.text.matches("[0-9]*"); //$NON-NLS-1$ | |
139 | } | |
140 | }; | |
d62bfa55 | 141 | setShellStyle(SWT.RESIZE); |
bbb3538a BH |
142 | } |
143 | ||
144 | // ------------------------------------------------------------------------ | |
145 | // Accessors | |
146 | // ------------------------------------------------------------------------ | |
147 | /* | |
148 | * (non-Javadoc) | |
115b4a01 | 149 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelDialog#getChannelInfo() |
bbb3538a BH |
150 | */ |
151 | @Override | |
152 | public IChannelInfo getChannelInfo() { | |
153 | return fChannelInfo; | |
154 | } | |
155 | ||
d132bcc7 BH |
156 | /* |
157 | * (non-Javadoc) | |
115b4a01 | 158 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelDialog#setDomainComponent(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent) |
d132bcc7 BH |
159 | */ |
160 | @Override | |
161 | public void setDomainComponent(TraceDomainComponent domain) { | |
162 | fDomain = domain; | |
163 | if (fDomain != null) { | |
164 | fIsKernel = fDomain.isKernel(); | |
165 | } else { | |
166 | fIsKernel = true; | |
167 | } | |
168 | } | |
169 | ||
bbb3538a BH |
170 | /* |
171 | * (non-Javadoc) | |
c56972bb | 172 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelDialog#isKernel() |
bbb3538a BH |
173 | */ |
174 | @Override | |
175 | public boolean isKernel() { | |
176 | return fIsKernel; | |
177 | } | |
178 | ||
a07c7629 BH |
179 | /* |
180 | * (non-Javadoc) | |
181 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableChannelDialog#setHasKernel(boolean) | |
182 | */ | |
183 | @Override | |
184 | public void setHasKernel(boolean hasKernel) { | |
185 | if (fDomain != null) { | |
186 | fIsKernel = fDomain.isKernel(); | |
187 | } else { | |
188 | fIsKernel = hasKernel; | |
189 | } | |
190 | ||
191 | fHasKernel = hasKernel; | |
192 | } | |
193 | ||
bbb3538a BH |
194 | // ------------------------------------------------------------------------ |
195 | // Operations | |
196 | // ------------------------------------------------------------------------ | |
197 | /* | |
198 | * (non-Javadoc) | |
199 | * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) | |
200 | */ | |
201 | @Override | |
202 | protected void configureShell(Shell newShell) { | |
203 | super.configureShell(newShell); | |
204 | newShell.setText(Messages.TraceControl_EnableChannelDialogTitle); | |
31a6a4e4 | 205 | newShell.setImage(Activator.getDefault().loadIcon(ENABLE_CHANNEL_ICON_FILE)); |
bbb3538a BH |
206 | } |
207 | ||
208 | /* | |
209 | * (non-Javadoc) | |
210 | * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) | |
211 | */ | |
212 | @Override | |
213 | protected Control createDialogArea(Composite parent) { | |
a07c7629 | 214 | |
bbb3538a BH |
215 | // Main dialog panel |
216 | fDialogComposite = new Composite(parent, SWT.NONE); | |
d62bfa55 | 217 | GridLayout layout = new GridLayout(3, true); |
a07c7629 | 218 | fDialogComposite.setLayout(layout); |
bbb3538a BH |
219 | |
220 | Label channelNameLabel = new Label(fDialogComposite, SWT.RIGHT); | |
221 | channelNameLabel.setText(Messages.TraceControl_EnableChannelNameLabel); | |
222 | fChannelNameText = new Text(fDialogComposite, SWT.NONE); | |
498704b3 | 223 | fChannelNameText.setToolTipText(Messages.TraceControl_EnableChannelNameTooltip); |
a07c7629 | 224 | |
bbb3538a BH |
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); | |
a07c7629 | 230 | |
bbb3538a BH |
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); | |
236 | ||
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); | |
242 | ||
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); | |
248 | ||
0886cf00 BH |
249 | Group discardModeGroup = new Group(fDialogComposite, SWT.SHADOW_NONE); |
250 | discardModeGroup.setText(Messages.TraceControl_EnableChannelDiscardModeGroupName); | |
251 | layout = new GridLayout(2, true); | |
a07c7629 | 252 | discardModeGroup.setLayout(layout); |
0886cf00 BH |
253 | |
254 | fDiscardModeButton = new Button(discardModeGroup, SWT.RADIO); | |
255 | fDiscardModeButton.setText(Messages.TraceControl_EnableChannelDiscardModeLabel); | |
256 | fDiscardModeButton.setToolTipText(Messages.TraceControl_EnableChannelDiscardModeTooltip); | |
257 | fDiscardModeButton.setSelection(true); | |
a07c7629 | 258 | |
0886cf00 BH |
259 | fOverwriteModeButton = new Button(discardModeGroup, SWT.RADIO); |
260 | fOverwriteModeButton.setText(Messages.TraceControl_EnableChannelOverwriteModeLabel); | |
bbb3538a | 261 | fOverwriteModeButton.setToolTipText(Messages.TraceControl_EnableChannelOverwriteModeTooltip); |
0886cf00 | 262 | fOverwriteModeButton.setSelection(false); |
bbb3538a BH |
263 | |
264 | fDomainGroup = new Group(fDialogComposite, SWT.SHADOW_NONE); | |
265 | fDomainGroup.setText(Messages.TraceControl_DomainDisplayName); | |
266 | layout = new GridLayout(2, true); | |
a07c7629 BH |
267 | fDomainGroup.setLayout(layout); |
268 | ||
bbb3538a BH |
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); | |
275 | ||
a07c7629 | 276 | if ((fDomain != null) || (!fHasKernel)) { |
bbb3538a BH |
277 | fKernelButton.setEnabled(false); |
278 | fUstButton.setEnabled(false); | |
279 | } | |
280 | ||
281 | // layout widgets | |
d62bfa55 | 282 | GridData data = new GridData(GridData.FILL, GridData.CENTER, false, false, 3, 1); |
0886cf00 BH |
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); | |
a07c7629 | 288 | |
d62bfa55 | 289 | data = new GridData(GridData.FILL, GridData.CENTER, false, false, 3, 1); |
bbb3538a BH |
290 | fDomainGroup.setLayoutData(data); |
291 | ||
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); | |
a07c7629 | 296 | |
d62bfa55 BH |
297 | data = new GridData(GridData.FILL_HORIZONTAL); |
298 | data.horizontalSpan = 2; | |
bbb3538a BH |
299 | |
300 | fChannelNameText.setLayoutData(data); | |
301 | fSubBufferSizeText.setLayoutData(data); | |
302 | fNumberOfSubBuffersText.setLayoutData(data); | |
303 | fSwitchTimerText.setLayoutData(data); | |
304 | fReadTimerText.setLayoutData(data); | |
305 | ||
bbb3538a BH |
306 | setDefaults(); |
307 | ||
308 | return fDialogComposite; | |
309 | } | |
310 | ||
311 | /* | |
312 | * (non-Javadoc) | |
313 | * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) | |
314 | */ | |
315 | @Override | |
316 | protected void createButtonsForButtonBar(Composite parent) { | |
79c3db85 BH |
317 | createButton(parent, IDialogConstants.DETAILS_ID, "&Default", true); //$NON-NLS-1$ |
318 | createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$ | |
bbb3538a BH |
319 | createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$ |
320 | } | |
321 | ||
322 | /* | |
323 | * (non-Javadoc) | |
324 | * @see org.eclipse.jface.dialogs.Dialog#okPressed() | |
325 | */ | |
326 | @Override | |
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()); | |
335 | ||
c56972bb | 336 | fIsKernel = fKernelButton.getSelection(); |
bbb3538a BH |
337 | |
338 | // Check for invalid names | |
498704b3 | 339 | if (!fChannelInfo.getName().matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ |
bbb3538a BH |
340 | MessageDialog.openError(getShell(), |
341 | Messages.TraceControl_EnableChannelDialogTitle, | |
342 | Messages.TraceControl_InvalidChannelNameError + " (" + fChannelInfo.getName() + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ | |
343 | return; | |
344 | } | |
345 | ||
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$ | |
351 | return; | |
352 | } | |
353 | ||
354 | // validation successful -> call super.okPressed() | |
355 | super.okPressed(); | |
356 | } | |
a07c7629 | 357 | |
bbb3538a BH |
358 | /* |
359 | * (non-Javadoc) | |
360 | * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int) | |
361 | */ | |
362 | @Override | |
363 | protected void buttonPressed(int buttonId) { | |
364 | if (buttonId == IDialogConstants.DETAILS_ID) { | |
365 | setDefaults(); | |
366 | return; | |
367 | } | |
368 | super.buttonPressed(buttonId); | |
369 | } | |
370 | ||
371 | // ------------------------------------------------------------------------ | |
372 | // Helper methods | |
373 | // ------------------------------------------------------------------------ | |
374 | /** | |
375 | * Sets default value depending on Kernel or UST | |
376 | */ | |
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)); | |
384 | } else { | |
385 | fSubBufferSizeText.setText(String.valueOf(IChannelInfo.DEFAULT_SUB_BUFFER_SIZE_UST)); | |
386 | fNumberOfSubBuffersText.setText(String.valueOf(IChannelInfo.DEFAULT_NUMBER_OF_SUB_BUFFERS_UST)); | |
387 | } | |
388 | } | |
389 | } |