Commit | Line | Data |
---|---|---|
bbb3538a | 1 | /********************************************************************** |
11252342 | 2 | * Copyright (c) 2012, 2013 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 | // ------------------------------------------------------------------------ | |
bbb3538a BH |
55 | /** |
56 | * The text widget for the channel name | |
57 | */ | |
58 | private Text fChannelNameText = null; | |
0886cf00 BH |
59 | /** |
60 | * The discard mode of the channel. | |
61 | */ | |
62 | private Button fDiscardModeButton = null; | |
bbb3538a BH |
63 | /** |
64 | * The overwrite mode of the channel. | |
65 | */ | |
c56972bb | 66 | private Button fOverwriteModeButton = null; |
bbb3538a BH |
67 | /** |
68 | * The sub-buffer size of the channel. | |
69 | */ | |
c56972bb | 70 | private Text fSubBufferSizeText = null; |
bbb3538a BH |
71 | /** |
72 | * The number of sub-buffers of the channel. | |
73 | */ | |
c56972bb | 74 | private Text fNumberOfSubBuffersText = null; |
bbb3538a BH |
75 | /** |
76 | * The switch timer interval of the channel. | |
77 | */ | |
c56972bb | 78 | private Text fSwitchTimerText = null; |
bbb3538a BH |
79 | /** |
80 | * The read timer interval of the channel. | |
81 | */ | |
c56972bb | 82 | private Text fReadTimerText = null; |
bbb3538a BH |
83 | /** |
84 | * Radio button for selecting kernel domain. | |
85 | */ | |
c56972bb | 86 | private Button fKernelButton = null; |
bbb3538a BH |
87 | /** |
88 | * Radio button for selecting UST domain. | |
89 | */ | |
c56972bb | 90 | private Button fUstButton = null; |
bbb3538a | 91 | /** |
a07c7629 | 92 | * The parent domain component where the channel node should be added. |
bbb3538a BH |
93 | * Null in case of creation on session level. |
94 | */ | |
c56972bb | 95 | private TraceDomainComponent fDomain = null; |
bbb3538a | 96 | /** |
a07c7629 | 97 | * Common verify listener for numeric text input. |
bbb3538a | 98 | */ |
c56972bb | 99 | private VerifyListener fVerifyListener = null; |
bbb3538a BH |
100 | /** |
101 | * Output channel information. | |
102 | */ | |
c56972bb | 103 | private IChannelInfo fChannelInfo = null; |
bbb3538a | 104 | /** |
a07c7629 | 105 | * Output domain information. True in case of Kernel domain. False for UST. |
bbb3538a BH |
106 | */ |
107 | private boolean fIsKernel; | |
a07c7629 BH |
108 | /** |
109 | * Flag which indicates whether Kernel domain is available or not | |
110 | */ | |
111 | private boolean fHasKernel; | |
bbb3538a BH |
112 | |
113 | // ------------------------------------------------------------------------ | |
114 | // Constructors | |
115 | // ------------------------------------------------------------------------ | |
116 | ||
117 | /** | |
118 | * Constructor | |
119 | * @param shell - a shell for the display of the dialog | |
120 | */ | |
d62bfa55 | 121 | public EnableChannelDialog(Shell shell) { |
d132bcc7 BH |
122 | super(shell); |
123 | fIsKernel = true; | |
bbb3538a BH |
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 | }; | |
d62bfa55 | 133 | setShellStyle(SWT.RESIZE); |
bbb3538a BH |
134 | } |
135 | ||
136 | // ------------------------------------------------------------------------ | |
137 | // Accessors | |
138 | // ------------------------------------------------------------------------ | |
11252342 | 139 | |
bbb3538a BH |
140 | @Override |
141 | public IChannelInfo getChannelInfo() { | |
142 | return fChannelInfo; | |
143 | } | |
144 | ||
d132bcc7 BH |
145 | @Override |
146 | public void setDomainComponent(TraceDomainComponent domain) { | |
147 | fDomain = domain; | |
148 | if (fDomain != null) { | |
149 | fIsKernel = fDomain.isKernel(); | |
150 | } else { | |
151 | fIsKernel = true; | |
152 | } | |
153 | } | |
154 | ||
bbb3538a BH |
155 | @Override |
156 | public boolean isKernel() { | |
157 | return fIsKernel; | |
158 | } | |
159 | ||
a07c7629 BH |
160 | @Override |
161 | public void setHasKernel(boolean hasKernel) { | |
162 | if (fDomain != null) { | |
163 | fIsKernel = fDomain.isKernel(); | |
164 | } else { | |
165 | fIsKernel = hasKernel; | |
166 | } | |
167 | ||
168 | fHasKernel = hasKernel; | |
169 | } | |
170 | ||
bbb3538a BH |
171 | // ------------------------------------------------------------------------ |
172 | // Operations | |
173 | // ------------------------------------------------------------------------ | |
11252342 | 174 | |
bbb3538a BH |
175 | @Override |
176 | protected void configureShell(Shell newShell) { | |
177 | super.configureShell(newShell); | |
178 | newShell.setText(Messages.TraceControl_EnableChannelDialogTitle); | |
31a6a4e4 | 179 | newShell.setImage(Activator.getDefault().loadIcon(ENABLE_CHANNEL_ICON_FILE)); |
bbb3538a BH |
180 | } |
181 | ||
bbb3538a BH |
182 | @Override |
183 | protected Control createDialogArea(Composite parent) { | |
a07c7629 | 184 | |
bbb3538a | 185 | // Main dialog panel |
046b6849 | 186 | Composite dialogComposite = new Composite(parent, SWT.NONE); |
d62bfa55 | 187 | GridLayout layout = new GridLayout(3, true); |
046b6849 | 188 | dialogComposite.setLayout(layout); |
bbb3538a | 189 | |
046b6849 | 190 | Label channelNameLabel = new Label(dialogComposite, SWT.RIGHT); |
bbb3538a | 191 | channelNameLabel.setText(Messages.TraceControl_EnableChannelNameLabel); |
046b6849 | 192 | fChannelNameText = new Text(dialogComposite, SWT.NONE); |
498704b3 | 193 | fChannelNameText.setToolTipText(Messages.TraceControl_EnableChannelNameTooltip); |
a07c7629 | 194 | |
046b6849 | 195 | Label subBufferSizeLabel = new Label(dialogComposite, SWT.RIGHT); |
bbb3538a | 196 | subBufferSizeLabel.setText(Messages.TraceControl_SubBufferSizePropertyName); |
046b6849 | 197 | fSubBufferSizeText = new Text(dialogComposite, SWT.NONE); |
bbb3538a BH |
198 | fSubBufferSizeText.setToolTipText(Messages.TraceControl_EnableChannelSubBufferSizeTooltip); |
199 | fSubBufferSizeText.addVerifyListener(fVerifyListener); | |
a07c7629 | 200 | |
046b6849 | 201 | Label numSubBufferLabel = new Label(dialogComposite, SWT.RIGHT); |
bbb3538a | 202 | numSubBufferLabel.setText(Messages.TraceControl_NbSubBuffersPropertyName); |
046b6849 | 203 | fNumberOfSubBuffersText = new Text(dialogComposite, SWT.NONE); |
bbb3538a BH |
204 | fNumberOfSubBuffersText.setToolTipText(Messages.TraceControl_EnableChannelNbSubBuffersTooltip); |
205 | fNumberOfSubBuffersText.addVerifyListener(fVerifyListener); | |
206 | ||
046b6849 | 207 | Label switchTimerLabel = new Label(dialogComposite, SWT.RIGHT); |
bbb3538a | 208 | switchTimerLabel.setText(Messages.TraceControl_SwitchTimerPropertyName); |
046b6849 | 209 | fSwitchTimerText = new Text(dialogComposite, SWT.NONE); |
bbb3538a BH |
210 | fSwitchTimerText.setToolTipText(Messages.TraceControl_EnableChannelSwitchTimerTooltip); |
211 | fSwitchTimerText.addVerifyListener(fVerifyListener); | |
212 | ||
046b6849 | 213 | Label readTimerLabel = new Label(dialogComposite, SWT.RIGHT); |
bbb3538a | 214 | readTimerLabel.setText(Messages.TraceControl_ReadTimerPropertyName); |
046b6849 | 215 | fReadTimerText = new Text(dialogComposite, SWT.NONE); |
bbb3538a BH |
216 | fReadTimerText.setToolTipText(Messages.TraceControl_EnableChannelReadTimerTooltip); |
217 | fReadTimerText.addVerifyListener(fVerifyListener); | |
218 | ||
046b6849 | 219 | Group discardModeGroup = new Group(dialogComposite, SWT.SHADOW_NONE); |
0886cf00 BH |
220 | discardModeGroup.setText(Messages.TraceControl_EnableChannelDiscardModeGroupName); |
221 | layout = new GridLayout(2, true); | |
a07c7629 | 222 | discardModeGroup.setLayout(layout); |
0886cf00 BH |
223 | |
224 | fDiscardModeButton = new Button(discardModeGroup, SWT.RADIO); | |
225 | fDiscardModeButton.setText(Messages.TraceControl_EnableChannelDiscardModeLabel); | |
226 | fDiscardModeButton.setToolTipText(Messages.TraceControl_EnableChannelDiscardModeTooltip); | |
227 | fDiscardModeButton.setSelection(true); | |
a07c7629 | 228 | |
0886cf00 BH |
229 | fOverwriteModeButton = new Button(discardModeGroup, SWT.RADIO); |
230 | fOverwriteModeButton.setText(Messages.TraceControl_EnableChannelOverwriteModeLabel); | |
bbb3538a | 231 | fOverwriteModeButton.setToolTipText(Messages.TraceControl_EnableChannelOverwriteModeTooltip); |
0886cf00 | 232 | fOverwriteModeButton.setSelection(false); |
bbb3538a | 233 | |
046b6849 BH |
234 | Group domainGroup = new Group(dialogComposite, SWT.SHADOW_NONE); |
235 | domainGroup.setText(Messages.TraceControl_DomainDisplayName); | |
bbb3538a | 236 | layout = new GridLayout(2, true); |
046b6849 | 237 | domainGroup.setLayout(layout); |
a07c7629 | 238 | |
046b6849 | 239 | fKernelButton = new Button(domainGroup, SWT.RADIO); |
bbb3538a BH |
240 | fKernelButton.setText(Messages.TraceControl_KernelDomainDisplayName); |
241 | fKernelButton.setSelection(fIsKernel); | |
046b6849 | 242 | fUstButton = new Button(domainGroup, SWT.RADIO); |
bbb3538a BH |
243 | fUstButton.setText(Messages.TraceControl_UstDisplayName); |
244 | fUstButton.setSelection(!fIsKernel); | |
245 | ||
a07c7629 | 246 | if ((fDomain != null) || (!fHasKernel)) { |
bbb3538a BH |
247 | fKernelButton.setEnabled(false); |
248 | fUstButton.setEnabled(false); | |
249 | } | |
250 | ||
251 | // layout widgets | |
d62bfa55 | 252 | GridData data = new GridData(GridData.FILL, GridData.CENTER, false, false, 3, 1); |
0886cf00 BH |
253 | discardModeGroup.setLayoutData(data); |
254 | data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true); | |
255 | fDiscardModeButton.setLayoutData(data); | |
256 | data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true); | |
257 | fOverwriteModeButton.setLayoutData(data); | |
a07c7629 | 258 | |
d62bfa55 | 259 | data = new GridData(GridData.FILL, GridData.CENTER, false, false, 3, 1); |
046b6849 | 260 | domainGroup.setLayoutData(data); |
bbb3538a BH |
261 | |
262 | data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true); | |
263 | fKernelButton.setLayoutData(data); | |
264 | data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true); | |
265 | fUstButton.setLayoutData(data); | |
a07c7629 | 266 | |
d62bfa55 BH |
267 | data = new GridData(GridData.FILL_HORIZONTAL); |
268 | data.horizontalSpan = 2; | |
bbb3538a BH |
269 | |
270 | fChannelNameText.setLayoutData(data); | |
271 | fSubBufferSizeText.setLayoutData(data); | |
272 | fNumberOfSubBuffersText.setLayoutData(data); | |
273 | fSwitchTimerText.setLayoutData(data); | |
274 | fReadTimerText.setLayoutData(data); | |
275 | ||
bbb3538a BH |
276 | setDefaults(); |
277 | ||
046b6849 | 278 | return dialogComposite; |
bbb3538a BH |
279 | } |
280 | ||
bbb3538a BH |
281 | @Override |
282 | protected void createButtonsForButtonBar(Composite parent) { | |
79c3db85 BH |
283 | createButton(parent, IDialogConstants.DETAILS_ID, "&Default", true); //$NON-NLS-1$ |
284 | createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$ | |
bbb3538a BH |
285 | createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$ |
286 | } | |
287 | ||
bbb3538a BH |
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 | ||
c56972bb | 298 | fIsKernel = fKernelButton.getSelection(); |
bbb3538a BH |
299 | |
300 | // Check for invalid names | |
498704b3 | 301 | if (!fChannelInfo.getName().matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ |
bbb3538a BH |
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 | } | |
a07c7629 | 319 | |
bbb3538a BH |
320 | @Override |
321 | protected void buttonPressed(int buttonId) { | |
322 | if (buttonId == IDialogConstants.DETAILS_ID) { | |
323 | setDefaults(); | |
324 | return; | |
325 | } | |
326 | super.buttonPressed(buttonId); | |
327 | } | |
328 | ||
329 | // ------------------------------------------------------------------------ | |
330 | // Helper methods | |
331 | // ------------------------------------------------------------------------ | |
11252342 | 332 | |
bbb3538a BH |
333 | /** |
334 | * Sets default value depending on Kernel or UST | |
335 | */ | |
336 | private void setDefaults() { | |
337 | fSwitchTimerText.setText(String.valueOf(IChannelInfo.DEFAULT_SWITCH_TIMER)); | |
338 | fReadTimerText.setText(String.valueOf(IChannelInfo.DEFAULT_READ_TIMER)); | |
339 | fOverwriteModeButton.setSelection(IChannelInfo.DEFAULT_OVERWRITE_MODE); | |
340 | if (fKernelButton.getSelection()) { | |
341 | fSubBufferSizeText.setText(String.valueOf(IChannelInfo.DEFAULT_SUB_BUFFER_SIZE_KERNEL)); | |
342 | fNumberOfSubBuffersText.setText(String.valueOf(IChannelInfo.DEFAULT_NUMBER_OF_SUB_BUFFERS_KERNEL)); | |
343 | } else { | |
344 | fSubBufferSizeText.setText(String.valueOf(IChannelInfo.DEFAULT_SUB_BUFFER_SIZE_UST)); | |
345 | fNumberOfSubBuffersText.setText(String.valueOf(IChannelInfo.DEFAULT_NUMBER_OF_SUB_BUFFERS_UST)); | |
346 | } | |
347 | } | |
348 | } |