Commit | Line | Data |
---|---|---|
bbb3538a BH |
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 | **********************************************************************/ | |
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> |
dbd4432d BH |
39 | * |
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 | */ | |
79c3db85 | 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 BH |
99 | /** |
100 | * The parent domain component where the channel node should be added. | |
101 | * Null in case of creation on session level. | |
102 | */ | |
c56972bb | 103 | private TraceDomainComponent fDomain = null; |
bbb3538a BH |
104 | /** |
105 | * Common verify listener for numeric text input. | |
106 | */ | |
c56972bb | 107 | private VerifyListener fVerifyListener = null; |
bbb3538a BH |
108 | /** |
109 | * Output channel information. | |
110 | */ | |
c56972bb | 111 | private IChannelInfo fChannelInfo = null; |
bbb3538a BH |
112 | /** |
113 | * Output domain information. True in case of Kernel domain. False for UST. | |
114 | */ | |
115 | private boolean fIsKernel; | |
116 | ||
117 | // ------------------------------------------------------------------------ | |
118 | // Constructors | |
119 | // ------------------------------------------------------------------------ | |
120 | ||
121 | /** | |
122 | * Constructor | |
123 | * @param shell - a shell for the display of the dialog | |
124 | */ | |
d62bfa55 | 125 | public EnableChannelDialog(Shell shell) { |
d132bcc7 BH |
126 | super(shell); |
127 | fIsKernel = true; | |
bbb3538a BH |
128 | |
129 | // Common verify listener | |
130 | fVerifyListener = new VerifyListener() { | |
131 | @Override | |
132 | public void verifyText(VerifyEvent e) { | |
133 | // only numbers are allowed. | |
134 | e.doit = e.text.matches("[0-9]*"); //$NON-NLS-1$ | |
135 | } | |
136 | }; | |
d62bfa55 | 137 | setShellStyle(SWT.RESIZE); |
bbb3538a BH |
138 | } |
139 | ||
140 | // ------------------------------------------------------------------------ | |
141 | // Accessors | |
142 | // ------------------------------------------------------------------------ | |
143 | /* | |
144 | * (non-Javadoc) | |
115b4a01 | 145 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelDialog#getChannelInfo() |
bbb3538a BH |
146 | */ |
147 | @Override | |
148 | public IChannelInfo getChannelInfo() { | |
149 | return fChannelInfo; | |
150 | } | |
151 | ||
d132bcc7 BH |
152 | /* |
153 | * (non-Javadoc) | |
115b4a01 | 154 | * @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 |
155 | */ |
156 | @Override | |
157 | public void setDomainComponent(TraceDomainComponent domain) { | |
158 | fDomain = domain; | |
159 | if (fDomain != null) { | |
160 | fIsKernel = fDomain.isKernel(); | |
161 | } else { | |
162 | fIsKernel = true; | |
163 | } | |
164 | } | |
165 | ||
bbb3538a BH |
166 | /* |
167 | * (non-Javadoc) | |
c56972bb | 168 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateChannelDialog#isKernel() |
bbb3538a BH |
169 | */ |
170 | @Override | |
171 | public boolean isKernel() { | |
172 | return fIsKernel; | |
173 | } | |
174 | ||
175 | // ------------------------------------------------------------------------ | |
176 | // Operations | |
177 | // ------------------------------------------------------------------------ | |
178 | /* | |
179 | * (non-Javadoc) | |
180 | * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) | |
181 | */ | |
182 | @Override | |
183 | protected void configureShell(Shell newShell) { | |
184 | super.configureShell(newShell); | |
185 | newShell.setText(Messages.TraceControl_EnableChannelDialogTitle); | |
31a6a4e4 | 186 | newShell.setImage(Activator.getDefault().loadIcon(ENABLE_CHANNEL_ICON_FILE)); |
bbb3538a BH |
187 | } |
188 | ||
189 | /* | |
190 | * (non-Javadoc) | |
191 | * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) | |
192 | */ | |
193 | @Override | |
194 | protected Control createDialogArea(Composite parent) { | |
195 | ||
196 | // Main dialog panel | |
197 | fDialogComposite = new Composite(parent, SWT.NONE); | |
d62bfa55 | 198 | GridLayout layout = new GridLayout(3, true); |
bbb3538a BH |
199 | fDialogComposite.setLayout(layout); |
200 | ||
201 | Label channelNameLabel = new Label(fDialogComposite, SWT.RIGHT); | |
202 | channelNameLabel.setText(Messages.TraceControl_EnableChannelNameLabel); | |
203 | fChannelNameText = new Text(fDialogComposite, SWT.NONE); | |
498704b3 | 204 | fChannelNameText.setToolTipText(Messages.TraceControl_EnableChannelNameTooltip); |
bbb3538a BH |
205 | |
206 | Label subBufferSizeLabel = new Label(fDialogComposite, SWT.RIGHT); | |
207 | subBufferSizeLabel.setText(Messages.TraceControl_SubBufferSizePropertyName); | |
208 | fSubBufferSizeText = new Text(fDialogComposite, SWT.NONE); | |
209 | fSubBufferSizeText.setToolTipText(Messages.TraceControl_EnableChannelSubBufferSizeTooltip); | |
210 | fSubBufferSizeText.addVerifyListener(fVerifyListener); | |
211 | ||
212 | Label numSubBufferLabel = new Label(fDialogComposite, SWT.RIGHT); | |
213 | numSubBufferLabel.setText(Messages.TraceControl_NbSubBuffersPropertyName); | |
214 | fNumberOfSubBuffersText = new Text(fDialogComposite, SWT.NONE); | |
215 | fNumberOfSubBuffersText.setToolTipText(Messages.TraceControl_EnableChannelNbSubBuffersTooltip); | |
216 | fNumberOfSubBuffersText.addVerifyListener(fVerifyListener); | |
217 | ||
218 | Label switchTimerLabel = new Label(fDialogComposite, SWT.RIGHT); | |
219 | switchTimerLabel.setText(Messages.TraceControl_SwitchTimerPropertyName); | |
220 | fSwitchTimerText = new Text(fDialogComposite, SWT.NONE); | |
221 | fSwitchTimerText.setToolTipText(Messages.TraceControl_EnableChannelSwitchTimerTooltip); | |
222 | fSwitchTimerText.addVerifyListener(fVerifyListener); | |
223 | ||
224 | Label readTimerLabel = new Label(fDialogComposite, SWT.RIGHT); | |
225 | readTimerLabel.setText(Messages.TraceControl_ReadTimerPropertyName); | |
226 | fReadTimerText = new Text(fDialogComposite, SWT.NONE); | |
227 | fReadTimerText.setToolTipText(Messages.TraceControl_EnableChannelReadTimerTooltip); | |
228 | fReadTimerText.addVerifyListener(fVerifyListener); | |
229 | ||
0886cf00 BH |
230 | Group discardModeGroup = new Group(fDialogComposite, SWT.SHADOW_NONE); |
231 | discardModeGroup.setText(Messages.TraceControl_EnableChannelDiscardModeGroupName); | |
232 | layout = new GridLayout(2, true); | |
233 | discardModeGroup.setLayout(layout); | |
234 | ||
235 | fDiscardModeButton = new Button(discardModeGroup, SWT.RADIO); | |
236 | fDiscardModeButton.setText(Messages.TraceControl_EnableChannelDiscardModeLabel); | |
237 | fDiscardModeButton.setToolTipText(Messages.TraceControl_EnableChannelDiscardModeTooltip); | |
238 | fDiscardModeButton.setSelection(true); | |
239 | ||
240 | fOverwriteModeButton = new Button(discardModeGroup, SWT.RADIO); | |
241 | fOverwriteModeButton.setText(Messages.TraceControl_EnableChannelOverwriteModeLabel); | |
bbb3538a | 242 | fOverwriteModeButton.setToolTipText(Messages.TraceControl_EnableChannelOverwriteModeTooltip); |
0886cf00 | 243 | fOverwriteModeButton.setSelection(false); |
bbb3538a BH |
244 | |
245 | fDomainGroup = new Group(fDialogComposite, SWT.SHADOW_NONE); | |
246 | fDomainGroup.setText(Messages.TraceControl_DomainDisplayName); | |
247 | layout = new GridLayout(2, true); | |
248 | fDomainGroup.setLayout(layout); | |
249 | ||
250 | fKernelButton = new Button(fDomainGroup, SWT.RADIO); | |
251 | fKernelButton.setText(Messages.TraceControl_KernelDomainDisplayName); | |
252 | fKernelButton.setSelection(fIsKernel); | |
253 | fUstButton = new Button(fDomainGroup, SWT.RADIO); | |
254 | fUstButton.setText(Messages.TraceControl_UstDisplayName); | |
255 | fUstButton.setSelection(!fIsKernel); | |
256 | ||
257 | if (fDomain != null) { | |
258 | fKernelButton.setEnabled(false); | |
259 | fUstButton.setEnabled(false); | |
260 | } | |
261 | ||
262 | // layout widgets | |
d62bfa55 | 263 | GridData data = new GridData(GridData.FILL, GridData.CENTER, false, false, 3, 1); |
0886cf00 BH |
264 | discardModeGroup.setLayoutData(data); |
265 | data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true); | |
266 | fDiscardModeButton.setLayoutData(data); | |
267 | data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true); | |
268 | fOverwriteModeButton.setLayoutData(data); | |
269 | ||
d62bfa55 | 270 | data = new GridData(GridData.FILL, GridData.CENTER, false, false, 3, 1); |
bbb3538a BH |
271 | fDomainGroup.setLayoutData(data); |
272 | ||
273 | data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true); | |
274 | fKernelButton.setLayoutData(data); | |
275 | data = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true); | |
276 | fUstButton.setLayoutData(data); | |
277 | ||
d62bfa55 BH |
278 | data = new GridData(GridData.FILL_HORIZONTAL); |
279 | data.horizontalSpan = 2; | |
bbb3538a BH |
280 | |
281 | fChannelNameText.setLayoutData(data); | |
282 | fSubBufferSizeText.setLayoutData(data); | |
283 | fNumberOfSubBuffersText.setLayoutData(data); | |
284 | fSwitchTimerText.setLayoutData(data); | |
285 | fReadTimerText.setLayoutData(data); | |
286 | ||
bbb3538a BH |
287 | setDefaults(); |
288 | ||
289 | return fDialogComposite; | |
290 | } | |
291 | ||
292 | /* | |
293 | * (non-Javadoc) | |
294 | * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) | |
295 | */ | |
296 | @Override | |
297 | protected void createButtonsForButtonBar(Composite parent) { | |
79c3db85 BH |
298 | createButton(parent, IDialogConstants.DETAILS_ID, "&Default", true); //$NON-NLS-1$ |
299 | createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$ | |
bbb3538a BH |
300 | createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$ |
301 | } | |
302 | ||
303 | /* | |
304 | * (non-Javadoc) | |
305 | * @see org.eclipse.jface.dialogs.Dialog#okPressed() | |
306 | */ | |
307 | @Override | |
308 | protected void okPressed() { | |
309 | // Set channel information | |
310 | fChannelInfo = new ChannelInfo(fChannelNameText.getText()); | |
311 | fChannelInfo.setSubBufferSize(Long.parseLong(fSubBufferSizeText.getText())); | |
312 | fChannelInfo.setNumberOfSubBuffers(Integer.parseInt(fNumberOfSubBuffersText.getText())); | |
313 | fChannelInfo.setSwitchTimer(Long.parseLong(fSwitchTimerText.getText())); | |
314 | fChannelInfo.setReadTimer(Long.parseLong(fReadTimerText.getText())); | |
315 | fChannelInfo.setOverwriteMode(fOverwriteModeButton.getSelection()); | |
316 | ||
c56972bb | 317 | fIsKernel = fKernelButton.getSelection(); |
bbb3538a BH |
318 | |
319 | // Check for invalid names | |
498704b3 | 320 | if (!fChannelInfo.getName().matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ |
bbb3538a BH |
321 | MessageDialog.openError(getShell(), |
322 | Messages.TraceControl_EnableChannelDialogTitle, | |
323 | Messages.TraceControl_InvalidChannelNameError + " (" + fChannelInfo.getName() + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ | |
324 | return; | |
325 | } | |
326 | ||
327 | // Check for duplicate names | |
328 | if (fDomain != null && fDomain.containsChild(fChannelInfo.getName())) { | |
329 | MessageDialog.openError(getShell(), | |
330 | Messages.TraceControl_EnableChannelDialogTitle, | |
331 | Messages.TraceControl_ChannelAlreadyExistsError + " (" + fChannelInfo.getName() + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ | |
332 | return; | |
333 | } | |
334 | ||
335 | // validation successful -> call super.okPressed() | |
336 | super.okPressed(); | |
337 | } | |
338 | ||
339 | /* | |
340 | * (non-Javadoc) | |
341 | * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int) | |
342 | */ | |
343 | @Override | |
344 | protected void buttonPressed(int buttonId) { | |
345 | if (buttonId == IDialogConstants.DETAILS_ID) { | |
346 | setDefaults(); | |
347 | return; | |
348 | } | |
349 | super.buttonPressed(buttonId); | |
350 | } | |
351 | ||
352 | // ------------------------------------------------------------------------ | |
353 | // Helper methods | |
354 | // ------------------------------------------------------------------------ | |
355 | /** | |
356 | * Sets default value depending on Kernel or UST | |
357 | */ | |
358 | private void setDefaults() { | |
359 | fSwitchTimerText.setText(String.valueOf(IChannelInfo.DEFAULT_SWITCH_TIMER)); | |
360 | fReadTimerText.setText(String.valueOf(IChannelInfo.DEFAULT_READ_TIMER)); | |
361 | fOverwriteModeButton.setSelection(IChannelInfo.DEFAULT_OVERWRITE_MODE); | |
362 | if (fKernelButton.getSelection()) { | |
363 | fSubBufferSizeText.setText(String.valueOf(IChannelInfo.DEFAULT_SUB_BUFFER_SIZE_KERNEL)); | |
364 | fNumberOfSubBuffersText.setText(String.valueOf(IChannelInfo.DEFAULT_NUMBER_OF_SUB_BUFFERS_KERNEL)); | |
365 | } else { | |
366 | fSubBufferSizeText.setText(String.valueOf(IChannelInfo.DEFAULT_SUB_BUFFER_SIZE_UST)); | |
367 | fNumberOfSubBuffersText.setText(String.valueOf(IChannelInfo.DEFAULT_NUMBER_OF_SUB_BUFFERS_UST)); | |
368 | } | |
369 | } | |
370 | } |