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 | **********************************************************************/ | |
12 | package org.eclipse.linuxtools.lttng.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.lttng.ui.LTTngUiPlugin; | |
18 | import org.eclipse.linuxtools.lttng.ui.views.control.Messages; | |
19 | import org.eclipse.linuxtools.lttng.ui.views.control.model.IChannelInfo; | |
20 | import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.ChannelInfo; | |
21 | import org.eclipse.linuxtools.lttng.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 ICreateChannelOnSessionDialog { | |
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; | |
67 | /** | |
68 | * The sub-buffer size of the channel. | |
69 | */ | |
70 | private Text fSubBufferSizeText; | |
71 | /** | |
72 | * The number of sub-buffers of the channel. | |
73 | */ | |
74 | private Text fNumberOfSubBuffersText; | |
75 | /** | |
76 | * The switch timer interval of the channel. | |
77 | */ | |
78 | private Text fSwitchTimerText; | |
79 | /** | |
80 | * The read timer interval of the channel. | |
81 | */ | |
82 | private Text fReadTimerText; | |
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; | |
91 | /** | |
92 | * Radio button for selecting UST domain. | |
93 | */ | |
94 | private Button fUstButton; | |
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; | |
100 | /** | |
101 | * Common verify listener for numeric text input. | |
102 | */ | |
103 | private VerifyListener fVerifyListener; | |
104 | /** | |
105 | * Output channel information. | |
106 | */ | |
107 | private IChannelInfo fChannelInfo; | |
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) { | |
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 | }; | |
133 | } | |
134 | ||
135 | // ------------------------------------------------------------------------ | |
136 | // Accessors | |
137 | // ------------------------------------------------------------------------ | |
138 | /* | |
139 | * (non-Javadoc) | |
140 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.ICreateChannelDialog#getChannelInfo() | |
141 | */ | |
142 | @Override | |
143 | public IChannelInfo getChannelInfo() { | |
144 | return fChannelInfo; | |
145 | } | |
146 | ||
d132bcc7 BH |
147 | /* |
148 | * (non-Javadoc) | |
149 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.ICreateChannelDialog#setDomainComponent(org.eclipse.linuxtools.lttng.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 | ||
bbb3538a BH |
161 | /* |
162 | * (non-Javadoc) | |
163 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.ICreateChannelOnSessionDialog#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(LTTngUiPlugin.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); | |
498704b3 | 199 | fChannelNameText.setToolTipText(Messages.TraceControl_EnableChannelNameTooltip); |
bbb3538a BH |
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 | if (fKernelButton.getSelection() == true) { | |
299 | fIsKernel = true; | |
300 | } else { | |
301 | fIsKernel = false; | |
302 | } | |
303 | ||
304 | // Check for invalid names | |
498704b3 | 305 | if (!fChannelInfo.getName().matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ |
bbb3538a BH |
306 | MessageDialog.openError(getShell(), |
307 | Messages.TraceControl_EnableChannelDialogTitle, | |
308 | Messages.TraceControl_InvalidChannelNameError + " (" + fChannelInfo.getName() + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ | |
309 | return; | |
310 | } | |
311 | ||
312 | // Check for duplicate names | |
313 | if (fDomain != null && fDomain.containsChild(fChannelInfo.getName())) { | |
314 | MessageDialog.openError(getShell(), | |
315 | Messages.TraceControl_EnableChannelDialogTitle, | |
316 | Messages.TraceControl_ChannelAlreadyExistsError + " (" + fChannelInfo.getName() + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ | |
317 | return; | |
318 | } | |
319 | ||
320 | // validation successful -> call super.okPressed() | |
321 | super.okPressed(); | |
322 | } | |
323 | ||
324 | /* | |
325 | * (non-Javadoc) | |
326 | * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int) | |
327 | */ | |
328 | @Override | |
329 | protected void buttonPressed(int buttonId) { | |
330 | if (buttonId == IDialogConstants.DETAILS_ID) { | |
331 | setDefaults(); | |
332 | return; | |
333 | } | |
334 | super.buttonPressed(buttonId); | |
335 | } | |
336 | ||
337 | // ------------------------------------------------------------------------ | |
338 | // Helper methods | |
339 | // ------------------------------------------------------------------------ | |
340 | /** | |
341 | * Sets default value depending on Kernel or UST | |
342 | */ | |
343 | private void setDefaults() { | |
344 | fSwitchTimerText.setText(String.valueOf(IChannelInfo.DEFAULT_SWITCH_TIMER)); | |
345 | fReadTimerText.setText(String.valueOf(IChannelInfo.DEFAULT_READ_TIMER)); | |
346 | fOverwriteModeButton.setSelection(IChannelInfo.DEFAULT_OVERWRITE_MODE); | |
347 | if (fKernelButton.getSelection()) { | |
348 | fSubBufferSizeText.setText(String.valueOf(IChannelInfo.DEFAULT_SUB_BUFFER_SIZE_KERNEL)); | |
349 | fNumberOfSubBuffersText.setText(String.valueOf(IChannelInfo.DEFAULT_NUMBER_OF_SUB_BUFFERS_KERNEL)); | |
350 | } else { | |
351 | fSubBufferSizeText.setText(String.valueOf(IChannelInfo.DEFAULT_SUB_BUFFER_SIZE_UST)); | |
352 | fNumberOfSubBuffersText.setText(String.valueOf(IChannelInfo.DEFAULT_NUMBER_OF_SUB_BUFFERS_UST)); | |
353 | } | |
354 | } | |
355 | } |