Commit | Line | Data |
---|---|---|
bbb3538a | 1 | /********************************************************************** |
ba3a9bd2 | 2 | * Copyright (c) 2012, 2013 Ericsson |
f3b33d40 | 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 | |
f3b33d40 BH |
8 | * |
9 | * Contributors: | |
bbb3538a | 10 | * Bernd Hufmann - Initial API and implementation |
ba3a9bd2 | 11 | * Bernd Hufmann - Updated for support of LTTng Tools 2.1 |
bbb3538a | 12 | **********************************************************************/ |
115b4a01 | 13 | package org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs; |
bbb3538a BH |
14 | |
15 | import org.eclipse.core.runtime.NullProgressMonitor; | |
16 | import org.eclipse.jface.dialogs.Dialog; | |
17 | import org.eclipse.jface.dialogs.IDialogConstants; | |
18 | import org.eclipse.jface.dialogs.MessageDialog; | |
f7d4d450 MAL |
19 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.ISessionInfo; |
20 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.SessionInfo; | |
115b4a01 | 21 | import org.eclipse.linuxtools.internal.lttng2.ui.Activator; |
9315aeee | 22 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages; |
115b4a01 BH |
23 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent; |
24 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionGroup; | |
25 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.IRemoteSystemProxy; | |
bbb3538a BH |
26 | import org.eclipse.rse.services.clientserver.messages.SystemMessageException; |
27 | import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSystem; | |
28 | import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; | |
29 | import org.eclipse.swt.SWT; | |
f3b33d40 | 30 | import org.eclipse.swt.custom.CCombo; |
a30e79fe BH |
31 | import org.eclipse.swt.events.ModifyEvent; |
32 | import org.eclipse.swt.events.ModifyListener; | |
f3b33d40 BH |
33 | import org.eclipse.swt.events.SelectionAdapter; |
34 | import org.eclipse.swt.events.SelectionEvent; | |
bbb3538a | 35 | import org.eclipse.swt.graphics.Point; |
f3b33d40 | 36 | import org.eclipse.swt.graphics.Rectangle; |
bbb3538a BH |
37 | import org.eclipse.swt.layout.GridData; |
38 | import org.eclipse.swt.layout.GridLayout; | |
f3b33d40 | 39 | import org.eclipse.swt.widgets.Button; |
bbb3538a BH |
40 | import org.eclipse.swt.widgets.Composite; |
41 | import org.eclipse.swt.widgets.Control; | |
f3b33d40 | 42 | import org.eclipse.swt.widgets.Group; |
bbb3538a BH |
43 | import org.eclipse.swt.widgets.Label; |
44 | import org.eclipse.swt.widgets.Shell; | |
45 | import org.eclipse.swt.widgets.Text; | |
46 | ||
47 | /** | |
bbb3538a BH |
48 | * <p> |
49 | * Dialog box for collecting session creation information. | |
50 | * </p> | |
f3b33d40 | 51 | * |
dbd4432d | 52 | * @author Bernd Hufmann |
bbb3538a BH |
53 | */ |
54 | public class CreateSessionDialog extends Dialog implements ICreateSessionDialog { | |
55 | ||
56 | // ------------------------------------------------------------------------ | |
57 | // Constants | |
58 | // ------------------------------------------------------------------------ | |
59 | /** | |
60 | * The icon file for this dialog box. | |
61 | */ | |
f3b33d40 BH |
62 | public static final String CREATE_SESSION_ICON_FILE = "icons/elcl16/add_button.gif"; //$NON-NLS-1$ |
63 | ||
64 | /** | |
65 | * Supported network protocols for streaming | |
66 | */ | |
67 | private enum StreamingProtocol { | |
68 | /** Default network protocol for IPv4 (TCP)*/ | |
69 | net, | |
70 | /** Default network protocol for IPv6 (TCP)*/ | |
71 | net6, | |
72 | /** File */ | |
73 | file, | |
74 | } | |
75 | ||
76 | private enum StreamingProtocol2 { | |
77 | /** Default network protocol for IPv4 (TCP)*/ | |
78 | net, | |
79 | /** Default network protocol for IPv6 (TCP)*/ | |
80 | net6, | |
81 | /** TCP network protocol for IPv4*/ | |
82 | tcp, | |
83 | /** TCP network protocol for IPv6*/ | |
84 | tcp6 } | |
85 | ||
86 | /** | |
87 | * Index of last supported streaming protocol for common URL configuration. | |
88 | */ | |
77735e82 | 89 | private static final int COMMON_URL_LAST_INDEX = 1; |
f3b33d40 BH |
90 | /** |
91 | * Index of default streaming protocol. | |
92 | */ | |
77735e82 | 93 | private static final int DEFAULT_URL_INDEX = 0; |
bbb3538a BH |
94 | |
95 | // ------------------------------------------------------------------------ | |
96 | // Attributes | |
97 | // ------------------------------------------------------------------------ | |
f3b33d40 BH |
98 | |
99 | private Control fControl = null; | |
bbb3538a BH |
100 | /** |
101 | * The dialog composite. | |
102 | */ | |
103 | private Composite fDialogComposite = null; | |
104 | /** | |
105 | * The text widget for the session name | |
106 | */ | |
107 | private Text fSessionNameText = null; | |
a30e79fe BH |
108 | /** |
109 | * The label widget for the session path. | |
110 | */ | |
111 | private Label fSessionPathLabel = null; | |
bbb3538a | 112 | /** |
f3b33d40 | 113 | * The text widget for the session path. |
bbb3538a BH |
114 | */ |
115 | private Text fSessionPathText = null; | |
589d0d33 BH |
116 | /** |
117 | * The button widget to select a snapshot session | |
118 | */ | |
119 | private Button fSnapshotButton = null; | |
f3b33d40 BH |
120 | /** |
121 | * The Group for stream configuration. | |
122 | */ | |
123 | private Group fMainStreamingGroup = null; | |
124 | /** | |
125 | * The button to show streaming options. | |
126 | */ | |
127 | private Button fConfigureStreamingButton = null; | |
128 | /** | |
129 | * The composite with streaming configuration parameter. | |
130 | */ | |
131 | private Composite fStreamingComposite = null; | |
a30e79fe BH |
132 | /** |
133 | * The text widget for the trace path. | |
134 | */ | |
135 | private Text fTracePathText = null; | |
f3b33d40 BH |
136 | /** |
137 | * The button to link data protocol/Address with control protocol. | |
138 | */ | |
139 | private Button fLinkDataWithControlButton = null; | |
140 | /** | |
141 | * The Combo box for channel protocol selection. | |
142 | */ | |
143 | private CCombo fControlProtocolCombo = null; | |
144 | /** | |
145 | * A selection listener that copies the protocol from control to data when being linked. | |
146 | */ | |
147 | private ControlProtocolSelectionListener fCopyProtocolSelectionListener; | |
a30e79fe BH |
148 | /** |
149 | * A selection listener updates the control port text depending on the control protocol selected. | |
150 | */ | |
f3b33d40 | 151 | private ProtocolComboSelectionListener fControlProtocolSelectionListener; |
a30e79fe BH |
152 | /** |
153 | * A selection listener updates the data port text depending on the data protocol selected. | |
154 | */ | |
f3b33d40 | 155 | private ProtocolComboSelectionListener fDataProtocolSelectionListener; |
f3b33d40 BH |
156 | /** |
157 | * The text box for the host/IP address of the control channel. | |
158 | */ | |
159 | private Text fControlHostAddressText = null; | |
160 | /** | |
161 | * A key listener that copies the host address from control to data when being linked. | |
162 | */ | |
a30e79fe | 163 | private CopyModifyListener fControlUrlKeyListener; |
f3b33d40 BH |
164 | /** |
165 | * The text box for the control port. | |
166 | */ | |
167 | private Text fControlPortText = null; | |
168 | /** | |
169 | * The Combo box for data protocol selection. | |
170 | */ | |
171 | private CCombo fDataProtocolCombo = null; | |
172 | /** | |
173 | * The text box for the host/IP address of the data channel. | |
174 | */ | |
175 | private Text fDataHostAddressText = null; | |
176 | /** | |
177 | * The text box for the data port. | |
178 | */ | |
179 | private Text fDataPortText = null; | |
bbb3538a BH |
180 | /** |
181 | * The parent where the new node should be added. | |
182 | */ | |
c56972bb | 183 | private TraceSessionGroup fParent = null; |
bbb3538a BH |
184 | /** |
185 | * The session name string. | |
186 | */ | |
187 | private String fSessionName = null; | |
188 | /** | |
189 | * The session path string. | |
190 | */ | |
191 | private String fSessionPath = null; | |
589d0d33 BH |
192 | /** |
193 | * The session path string. | |
194 | */ | |
195 | private boolean fIsSnapshot = false; | |
bbb3538a BH |
196 | /** |
197 | * Flag whether default location (path) shall be used or not | |
198 | */ | |
199 | private boolean fIsDefaultPath = true; | |
f3b33d40 BH |
200 | /** |
201 | * Flag whether the trace is streamed or not | |
202 | */ | |
203 | private boolean fIsStreamedTrace = false; | |
204 | /** | |
205 | * The network URL in case control and data is configured together. | |
206 | * If set, fControlUrl and fDataUrl will be null. | |
207 | */ | |
208 | private String fNetworkUrl = null; | |
209 | /** | |
210 | * The control URL in case control and data is configured separately. | |
211 | * If set, fDataUrl will be set too and fNetworkUrl will be null. | |
212 | */ | |
213 | private String fControlUrl = null; | |
214 | /** | |
215 | * The data URL in case control and data is configured separately. | |
216 | * If set, fControlUrl will be set too and fNetworkUrl will be null. | |
217 | */ | |
218 | private String fDataUrl = null; | |
219 | /** | |
a30e79fe | 220 | * The trace path string. |
f3b33d40 | 221 | */ |
a30e79fe | 222 | private String fTracePath = null; |
bbb3538a BH |
223 | |
224 | // ------------------------------------------------------------------------ | |
225 | // Constructors | |
226 | // ------------------------------------------------------------------------ | |
227 | /** | |
228 | * Constructor | |
229 | * @param shell - a shell for the display of the dialog | |
bbb3538a | 230 | */ |
d132bcc7 | 231 | public CreateSessionDialog(Shell shell) { |
bbb3538a | 232 | super(shell); |
8a396998 | 233 | setShellStyle(SWT.RESIZE | getShellStyle()); |
bbb3538a BH |
234 | } |
235 | ||
236 | // ------------------------------------------------------------------------ | |
237 | // Accessors | |
238 | // ------------------------------------------------------------------------ | |
11252342 | 239 | |
d132bcc7 | 240 | @Override |
f3b33d40 BH |
241 | public void initialize(TraceSessionGroup group) { |
242 | fParent = group; | |
243 | fStreamingComposite = null; | |
244 | fSessionName = null; | |
245 | fSessionPath = null; | |
589d0d33 | 246 | fIsSnapshot = false; |
f3b33d40 BH |
247 | fIsDefaultPath = true; |
248 | fIsStreamedTrace = false; | |
249 | fNetworkUrl = null; | |
250 | fControlUrl = null; | |
251 | fDataUrl = null; | |
f3b33d40 | 252 | } |
bbb3538a BH |
253 | // ------------------------------------------------------------------------ |
254 | // Operations | |
255 | // ------------------------------------------------------------------------ | |
f3b33d40 | 256 | |
f3b33d40 BH |
257 | @Override |
258 | protected Control createContents(Composite parent) { | |
259 | fControl = super.createContents(parent); | |
260 | ||
261 | /* set the shell minimum size */ | |
262 | Point clientArea = fControl.computeSize(SWT.DEFAULT, SWT.DEFAULT); | |
263 | Rectangle trim = getShell().computeTrim(0, 0, clientArea.x, clientArea.y); | |
264 | getShell().setMinimumSize(trim.width, trim.height); | |
265 | ||
266 | return fControl; | |
267 | } | |
11252342 | 268 | |
bbb3538a BH |
269 | @Override |
270 | protected void configureShell(Shell newShell) { | |
271 | super.configureShell(newShell); | |
272 | newShell.setText(Messages.TraceControl_CreateSessionDialogTitle); | |
31a6a4e4 | 273 | newShell.setImage(Activator.getDefault().loadIcon(CREATE_SESSION_ICON_FILE)); |
bbb3538a BH |
274 | } |
275 | ||
bbb3538a BH |
276 | @Override |
277 | protected Control createDialogArea(Composite parent) { | |
f3b33d40 | 278 | |
bbb3538a BH |
279 | // Main dialog panel |
280 | fDialogComposite = new Composite(parent, SWT.NONE); | |
f3b33d40 | 281 | GridLayout layout = new GridLayout(1, true); |
5f1f22f8 BH |
282 | fDialogComposite.setLayout(layout); |
283 | fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); | |
bbb3538a | 284 | |
f3b33d40 BH |
285 | Group sessionGroup = new Group(fDialogComposite, SWT.SHADOW_NONE); |
286 | sessionGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); | |
287 | sessionGroup.setLayout(new GridLayout(4, true)); | |
288 | ||
289 | Label sessionNameLabel = new Label(sessionGroup, SWT.RIGHT); | |
bbb3538a | 290 | sessionNameLabel.setText(Messages.TraceControl_CreateSessionNameLabel); |
f3b33d40 | 291 | fSessionNameText = new Text(sessionGroup, SWT.NONE); |
bbb3538a | 292 | fSessionNameText.setToolTipText(Messages.TraceControl_CreateSessionNameTooltip); |
f3b33d40 | 293 | |
a30e79fe BH |
294 | fSessionPathLabel = new Label(sessionGroup, SWT.RIGHT); |
295 | fSessionPathLabel.setText(Messages.TraceControl_CreateSessionPathLabel); | |
f3b33d40 | 296 | fSessionPathText = new Text(sessionGroup, SWT.NONE); |
bbb3538a BH |
297 | fSessionPathText.setToolTipText(Messages.TraceControl_CreateSessionPathTooltip); |
298 | ||
589d0d33 BH |
299 | if (fParent.isSnapshotSupported()) { |
300 | fSnapshotButton = new Button(sessionGroup, SWT.CHECK); | |
301 | fSnapshotButton.setText(Messages.TraceControl_CreateSessionSnapshotLabel); | |
302 | fSnapshotButton.setToolTipText(Messages.TraceControl_CreateSessionSnapshotTooltip); | |
303 | GridData data = new GridData(GridData.FILL_HORIZONTAL); | |
304 | data.horizontalSpan = 4; | |
305 | fSnapshotButton.setData(data); | |
306 | } | |
307 | ||
bbb3538a | 308 | // layout widgets |
5f1f22f8 BH |
309 | GridData data = new GridData(GridData.FILL_HORIZONTAL); |
310 | data.horizontalSpan = 3; | |
f3b33d40 | 311 | |
bbb3538a | 312 | fSessionNameText.setLayoutData(data); |
f3b33d40 BH |
313 | |
314 | data = new GridData(GridData.FILL_HORIZONTAL); | |
315 | data.horizontalSpan = 3; | |
bbb3538a | 316 | fSessionPathText.setLayoutData(data); |
bbb3538a | 317 | |
f3b33d40 | 318 | if (fParent.isNetworkStreamingSupported()) { |
f3b33d40 BH |
319 | createAdvancedOptionsComposite(); |
320 | } | |
321 | ||
bbb3538a BH |
322 | return fDialogComposite; |
323 | } | |
324 | ||
f3b33d40 BH |
325 | private void createAdvancedOptionsComposite() { |
326 | ||
327 | fMainStreamingGroup = new Group(fDialogComposite, SWT.SHADOW_NONE); | |
328 | fMainStreamingGroup.setLayoutData(new GridData(GridData.FILL_BOTH)); | |
329 | fMainStreamingGroup.setLayout(new GridLayout(1, true)); | |
330 | ||
331 | fConfigureStreamingButton = new Button(fMainStreamingGroup, SWT.PUSH); | |
a30e79fe | 332 | fConfigureStreamingButton.setText(Messages.TraceControl_CreateSessionConfigureStreamingButtonText + " >>>"); //$NON-NLS-1$ |
f3b33d40 BH |
333 | fConfigureStreamingButton.setToolTipText(Messages.TraceControl_CreateSessionConfigureStreamingButtonTooltip); |
334 | fConfigureStreamingButton.addSelectionListener(new SelectionAdapter() { | |
335 | @Override | |
336 | public void widgetSelected(SelectionEvent e) { | |
337 | if (fIsStreamedTrace) { | |
338 | fIsStreamedTrace = false; | |
339 | fConfigureStreamingButton.setText(">>> " + Messages.TraceControl_CreateSessionConfigureStreamingButtonText); //$NON-NLS-1$ | |
340 | fConfigureStreamingButton.setToolTipText(Messages.TraceControl_CreateSessionConfigureStreamingButtonTooltip); | |
a30e79fe BH |
341 | fSessionPathText.setEnabled(true); |
342 | fSessionPathLabel.setText(Messages.TraceControl_CreateSessionPathLabel); | |
f3b33d40 BH |
343 | disposeConfigureStreamingComposite(); |
344 | } else { | |
345 | fIsStreamedTrace = true; | |
346 | fConfigureStreamingButton.setText("<<< " + Messages.TraceControl_CreateSessionNoStreamingButtonText); //$NON-NLS-1$ | |
347 | fConfigureStreamingButton.setToolTipText(Messages.TraceControl_CreateSessionNoStreamingButtonTooltip); | |
a30e79fe BH |
348 | fSessionPathText.setEnabled(false); |
349 | fSessionPathText.setText(""); //$NON-NLS-1$ | |
350 | fSessionPathLabel.setText(""); //$NON-NLS-1$ | |
f3b33d40 BH |
351 | createConfigureStreamingComposite(); |
352 | } | |
353 | ||
354 | fDialogComposite.layout(); | |
355 | ||
356 | Point clientArea = fControl.computeSize(SWT.DEFAULT, SWT.DEFAULT); | |
357 | Rectangle trim = getShell().computeTrim(0, 0, clientArea.x, clientArea.y); | |
358 | getShell().setSize(trim.width, trim.height); | |
359 | } | |
360 | }); | |
361 | } | |
362 | ||
363 | private void createConfigureStreamingComposite() { | |
364 | if (fStreamingComposite == null) { | |
365 | fStreamingComposite = new Composite(fMainStreamingGroup, SWT.NONE); | |
366 | GridLayout layout = new GridLayout(1, true); | |
367 | fStreamingComposite.setLayout(layout); | |
368 | fStreamingComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); | |
369 | ||
370 | Group urlGroup = new Group(fStreamingComposite, SWT.SHADOW_NONE); | |
371 | layout = new GridLayout(7, true); | |
372 | urlGroup.setLayout(layout); | |
373 | urlGroup.setLayoutData(new GridData(GridData.FILL_BOTH)); | |
374 | ||
a30e79fe BH |
375 | Label tracePathLabel = new Label(urlGroup, SWT.RIGHT); |
376 | tracePathLabel.setText(Messages.TraceControl_CreateSessionTracePathText); | |
377 | fTracePathText = new Text(urlGroup, SWT.NONE); | |
378 | fTracePathText.setToolTipText(Messages.TraceControl_CreateSessionTracePathTooltip); | |
379 | ||
380 | // layout widgets | |
381 | GridData data = new GridData(GridData.FILL_HORIZONTAL); | |
382 | data.horizontalSpan = 6; | |
383 | fTracePathText.setLayoutData(data); | |
384 | ||
f3b33d40 BH |
385 | fLinkDataWithControlButton = new Button(urlGroup, SWT.CHECK); |
386 | fLinkDataWithControlButton.setText(Messages.TraceControl_CreateSessionLinkButtonText); | |
387 | fLinkDataWithControlButton.setToolTipText(Messages.TraceControl_CreateSessionLinkButtonTooltip); | |
a30e79fe | 388 | data = new GridData(GridData.FILL_HORIZONTAL); |
f3b33d40 BH |
389 | data.horizontalSpan = 7; |
390 | fLinkDataWithControlButton.setLayoutData(data); | |
391 | fLinkDataWithControlButton.setSelection(true); | |
392 | ||
393 | Label label = new Label(urlGroup, SWT.NONE); | |
394 | data = new GridData(GridData.FILL_HORIZONTAL); | |
395 | data.horizontalSpan = 1; | |
396 | label.setLayoutData(data); | |
397 | ||
398 | label = new Label(urlGroup, SWT.NONE); | |
399 | label.setText(Messages.TraceControl_CreateSessionProtocolLabelText); | |
400 | data = new GridData(GridData.FILL_HORIZONTAL); | |
401 | data.horizontalSpan = 1; | |
402 | label.setLayoutData(data); | |
403 | ||
404 | label = new Label(urlGroup, SWT.NONE); | |
405 | label.setText(Messages.TraceControl_CreateSessionAddressLabelText); | |
406 | data = new GridData(GridData.FILL_HORIZONTAL); | |
407 | data.horizontalSpan = 4; | |
408 | label.setLayoutData(data); | |
409 | ||
410 | label = new Label(urlGroup, SWT.NONE); | |
411 | label.setText(Messages.TraceControl_CreateSessionPortLabelText); | |
412 | data = new GridData(GridData.FILL_HORIZONTAL); | |
413 | data.horizontalSpan = 1; | |
414 | label.setLayoutData(data); | |
415 | ||
416 | label = new Label(urlGroup, SWT.RIGHT); | |
417 | label.setText(Messages.TraceControl_CreateSessionControlUrlLabel); | |
418 | data = new GridData(GridData.FILL_HORIZONTAL); | |
419 | data.horizontalSpan = 1; | |
420 | label.setLayoutData(data); | |
421 | ||
422 | fControlProtocolCombo = new CCombo(urlGroup, SWT.READ_ONLY); | |
423 | fControlProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionCommonProtocolTooltip); | |
424 | data = new GridData(GridData.FILL_HORIZONTAL); | |
425 | data.horizontalSpan = 1; | |
426 | fControlProtocolCombo.setLayoutData(data); | |
427 | ||
428 | fControlHostAddressText = new Text(urlGroup, SWT.NONE); | |
429 | fControlHostAddressText.setToolTipText(Messages.TraceControl_CreateSessionControlAddressTooltip); | |
430 | data = new GridData(GridData.FILL_HORIZONTAL); | |
431 | data.horizontalSpan = 4; | |
432 | fControlHostAddressText.setLayoutData(data); | |
433 | ||
434 | fControlPortText = new Text(urlGroup, SWT.NONE); | |
435 | fControlPortText.setToolTipText(Messages.TraceControl_CreateSessionControlPortTooltip); | |
436 | data = new GridData(GridData.FILL_HORIZONTAL); | |
437 | data.horizontalSpan = 1; | |
438 | fControlPortText.setLayoutData(data); | |
439 | ||
440 | label = new Label(urlGroup, SWT.RIGHT); | |
441 | label.setText(Messages.TraceControl_CreateSessionDataUrlLabel); | |
442 | data = new GridData(GridData.FILL_HORIZONTAL); | |
443 | data.horizontalSpan = 1; | |
444 | label.setLayoutData(data); | |
445 | ||
446 | fDataProtocolCombo = new CCombo(urlGroup, SWT.READ_ONLY); | |
447 | fDataProtocolCombo.setEnabled(false); | |
448 | fDataProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionProtocolTooltip); | |
449 | data = new GridData(GridData.FILL_HORIZONTAL); | |
450 | data.horizontalSpan = 1; | |
451 | fDataProtocolCombo.setLayoutData(data); | |
452 | ||
453 | String items[] = new String[StreamingProtocol.values().length]; | |
454 | for (int i = 0; i < items.length; i++) { | |
455 | items[i] = StreamingProtocol.values()[i].name(); | |
456 | } | |
457 | fControlProtocolCombo.setItems(items); | |
458 | fDataProtocolCombo.setItems(items); | |
459 | ||
460 | fDataHostAddressText = new Text(urlGroup, SWT.NONE); | |
461 | fDataHostAddressText.setEnabled(false); | |
462 | fDataHostAddressText.setToolTipText(Messages.TraceControl_CreateSessionDataAddressTooltip); | |
463 | data = new GridData(GridData.FILL_HORIZONTAL); | |
464 | data.horizontalSpan = 4; | |
465 | fDataHostAddressText.setLayoutData(data); | |
466 | ||
467 | fDataPortText = new Text(urlGroup, SWT.NONE); | |
468 | fDataPortText.setEnabled(true); | |
469 | fDataPortText.setToolTipText(Messages.TraceControl_CreateSessionDataPortTooltip); | |
470 | data = new GridData(GridData.FILL_HORIZONTAL); | |
471 | data.horizontalSpan = 1; | |
472 | fDataPortText.setLayoutData(data); | |
473 | ||
474 | fCopyProtocolSelectionListener = new ControlProtocolSelectionListener(); | |
475 | fControlProtocolSelectionListener = new ProtocolComboSelectionListener(fControlProtocolCombo, fControlPortText); | |
476 | fDataProtocolSelectionListener = new ProtocolComboSelectionListener(fDataProtocolCombo, fDataPortText); | |
477 | ||
478 | fControlProtocolCombo.addSelectionListener(fCopyProtocolSelectionListener); | |
479 | ||
a30e79fe BH |
480 | fControlUrlKeyListener = new CopyModifyListener(fControlHostAddressText, fDataHostAddressText); |
481 | fControlHostAddressText.addModifyListener(fControlUrlKeyListener); | |
482 | ||
f3b33d40 BH |
483 | fControlProtocolCombo.select(DEFAULT_URL_INDEX); |
484 | fDataProtocolCombo.select(DEFAULT_URL_INDEX); | |
485 | ||
486 | fLinkDataWithControlButton.addSelectionListener(new SelectionAdapter() { | |
487 | @Override | |
488 | public void widgetSelected(SelectionEvent e) { | |
489 | if (fLinkDataWithControlButton.getSelection()) { | |
490 | // Set enablement control data channel inputs | |
491 | fDataProtocolCombo.setEnabled(false); | |
492 | fDataHostAddressText.setEnabled(false); | |
493 | fControlPortText.setEnabled(true); | |
494 | fDataPortText.setEnabled(true); | |
495 | ||
496 | // Update listeners | |
497 | fControlProtocolCombo.removeSelectionListener(fControlProtocolSelectionListener); | |
498 | fDataProtocolCombo.removeSelectionListener(fDataProtocolSelectionListener); | |
499 | fControlProtocolCombo.addSelectionListener(fCopyProtocolSelectionListener); | |
a30e79fe | 500 | fControlHostAddressText.addModifyListener(fControlUrlKeyListener); |
f3b33d40 BH |
501 | |
502 | // Get previous selection and validate | |
503 | int currentSelection = fControlProtocolCombo.getSelectionIndex() <= COMMON_URL_LAST_INDEX ? | |
504 | fControlProtocolCombo.getSelectionIndex() : DEFAULT_URL_INDEX; | |
505 | ||
506 | // Update combo box items | |
507 | fControlProtocolCombo.removeAll(); | |
508 | String[] controlItems = new String[StreamingProtocol.values().length]; | |
509 | for (int i = 0; i < controlItems.length; i++) { | |
510 | controlItems[i] = StreamingProtocol.values()[i].name(); | |
511 | } | |
512 | fControlProtocolCombo.setItems(controlItems); | |
513 | fDataProtocolCombo.setItems(controlItems); | |
514 | ||
515 | // Set selection | |
516 | fControlProtocolCombo.select(currentSelection); | |
517 | fDataProtocolCombo.select(currentSelection); | |
518 | fDataHostAddressText.setText(fControlHostAddressText.getText()); | |
519 | ||
520 | // Update tool tips | |
521 | fControlProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionCommonProtocolTooltip); | |
522 | } else { | |
523 | // Enable data channel inputs | |
524 | fDataProtocolCombo.setEnabled(true); | |
525 | fDataHostAddressText.setEnabled(true); | |
526 | ||
527 | // Update listeners | |
528 | fControlProtocolCombo.removeSelectionListener(fCopyProtocolSelectionListener); | |
529 | fControlProtocolCombo.addSelectionListener(fControlProtocolSelectionListener); | |
530 | fDataProtocolCombo.addSelectionListener(fDataProtocolSelectionListener); | |
a30e79fe | 531 | fControlHostAddressText.removeModifyListener(fControlUrlKeyListener); |
f3b33d40 BH |
532 | |
533 | // Update combo box items | |
534 | int currentSelection = fControlProtocolCombo.getSelectionIndex(); | |
535 | fControlProtocolCombo.removeAll(); | |
536 | String[] controlItems = new String[StreamingProtocol2.values().length]; | |
537 | for (int i = 0; i < controlItems.length; i++) { | |
538 | controlItems[i] = StreamingProtocol2.values()[i].name(); | |
539 | } | |
540 | fControlProtocolCombo.setItems(controlItems); | |
541 | fDataProtocolCombo.setItems(controlItems); | |
542 | ||
543 | // Set selection | |
544 | fControlProtocolCombo.select(currentSelection); | |
545 | fDataProtocolCombo.select(currentSelection); | |
546 | ||
547 | // Update tool tips | |
548 | fDataProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionProtocolTooltip); | |
549 | fControlProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionProtocolTooltip); | |
550 | ||
551 | // Update control/data port enablement and input | |
552 | if (fControlProtocolCombo.getItem(fControlProtocolCombo.getSelectionIndex()).equals(StreamingProtocol.net.name()) || | |
553 | fControlProtocolCombo.getItem(fControlProtocolCombo.getSelectionIndex()).equals(StreamingProtocol.net6.name())) { | |
554 | fControlPortText.setText(""); //$NON-NLS-1$ | |
555 | fControlPortText.setEnabled(false); | |
556 | } else { | |
557 | fControlPortText.setEnabled(true); | |
558 | } | |
559 | ||
560 | if (fDataProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()).equals(StreamingProtocol.net.name()) || | |
561 | fDataProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()).equals(StreamingProtocol.net6.name())) { | |
562 | fDataPortText.setText(""); //$NON-NLS-1$ | |
563 | fDataPortText.setEnabled(false); | |
564 | } else { | |
565 | fDataPortText.setEnabled(true); | |
566 | } | |
567 | } | |
568 | } | |
569 | }); | |
570 | } | |
571 | } | |
572 | ||
573 | private void disposeConfigureStreamingComposite() { | |
574 | if (fStreamingComposite != null) { | |
575 | fStreamingComposite.dispose(); | |
576 | fStreamingComposite = null; | |
577 | } | |
578 | } | |
579 | ||
bbb3538a BH |
580 | @Override |
581 | protected void createButtonsForButtonBar(Composite parent) { | |
79c3db85 | 582 | createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$ |
bbb3538a BH |
583 | createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$ |
584 | } | |
585 | ||
bbb3538a BH |
586 | @Override |
587 | protected void okPressed() { | |
588 | // Validate input data | |
589 | fSessionName = fSessionNameText.getText(); | |
590 | fSessionPath = fSessionPathText.getText(); | |
591 | ||
592 | if (!"".equals(fSessionPath)) { //$NON-NLS-1$ | |
593 | // validate sessionPath | |
f3b33d40 BH |
594 | if (!fIsStreamedTrace) { |
595 | TargetNodeComponent node = (TargetNodeComponent)fParent.getParent(); | |
596 | IRemoteSystemProxy proxy = node.getRemoteSystemProxy(); | |
597 | IFileServiceSubSystem fsss = proxy.getFileServiceSubSystem(); | |
598 | if (fsss != null) { | |
599 | try { | |
600 | IRemoteFile remoteFolder = fsss.getRemoteFileObject(fSessionPath, new NullProgressMonitor()); | |
b68f311b BH |
601 | |
602 | if (remoteFolder == null) { | |
603 | MessageDialog.openError(getShell(), | |
604 | Messages.TraceControl_CreateSessionDialogTitle, | |
605 | Messages.TraceControl_InvalidSessionPathError + " (" + fSessionPath + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ | |
606 | return; | |
607 | } | |
608 | ||
f3b33d40 BH |
609 | if (remoteFolder.exists()) { |
610 | MessageDialog.openError(getShell(), | |
611 | Messages.TraceControl_CreateSessionDialogTitle, | |
612 | Messages.TraceControl_SessionPathAlreadyExistsError + " (" + fSessionPath + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ | |
613 | return; | |
614 | } | |
615 | } catch (SystemMessageException e) { | |
bbb3538a BH |
616 | MessageDialog.openError(getShell(), |
617 | Messages.TraceControl_CreateSessionDialogTitle, | |
f3b33d40 | 618 | Messages.TraceControl_FileSubSystemError + "\n" + e); //$NON-NLS-1$ |
bbb3538a BH |
619 | return; |
620 | } | |
f3b33d40 | 621 | } |
bbb3538a BH |
622 | } |
623 | fIsDefaultPath = false; | |
624 | } | |
625 | ||
589d0d33 BH |
626 | if(fParent.isSnapshotSupported()) { |
627 | fIsSnapshot = fSnapshotButton.getSelection(); | |
628 | } | |
629 | ||
f3b33d40 BH |
630 | fNetworkUrl = null; |
631 | fControlUrl = null; | |
632 | fDataUrl = null; | |
633 | ||
634 | if (fIsStreamedTrace) { | |
a30e79fe BH |
635 | // Validate input data |
636 | fTracePath = fTracePathText.getText(); | |
637 | ||
f3b33d40 BH |
638 | if (fControlProtocolCombo.getSelectionIndex() < 0) { |
639 | MessageDialog.openError(getShell(), | |
640 | Messages.TraceControl_CreateSessionDialogTitle, | |
641 | "Control Protocol Text is empty\n"); //$NON-NLS-1$ | |
642 | return; | |
643 | } | |
644 | ||
645 | if ("".equals(fControlHostAddressText.getText())) { //$NON-NLS-1$ | |
646 | MessageDialog.openError(getShell(), | |
647 | Messages.TraceControl_CreateSessionDialogTitle, | |
648 | "Control Address Text is empty\n"); //$NON-NLS-1$ | |
649 | return; | |
650 | } | |
651 | ||
652 | if(!fLinkDataWithControlButton.getSelection()) { | |
653 | if (fDataProtocolCombo.getSelectionIndex() < 0) { | |
654 | MessageDialog.openError(getShell(), | |
655 | Messages.TraceControl_CreateSessionDialogTitle, | |
656 | "Control Protocol Text is empty\n"); //$NON-NLS-1$ | |
657 | return; | |
658 | } | |
659 | ||
660 | if ("".equals(fDataHostAddressText.getText())) { //$NON-NLS-1$ | |
661 | MessageDialog.openError(getShell(), | |
662 | Messages.TraceControl_CreateSessionDialogTitle, | |
663 | "Control Address Text is empty\n"); //$NON-NLS-1$ | |
664 | return; | |
665 | } | |
666 | ||
667 | fControlUrl = getUrlString(fControlProtocolCombo.getItem(fControlProtocolCombo.getSelectionIndex()), | |
668 | fControlHostAddressText.getText(), | |
669 | fControlPortText.getText(), | |
670 | null, | |
a30e79fe | 671 | fTracePath); |
f3b33d40 BH |
672 | |
673 | fDataUrl = getUrlString(fControlProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()), | |
674 | fDataHostAddressText.getText(), | |
675 | null, | |
676 | fDataPortText.getText(), | |
a30e79fe | 677 | fTracePath); |
f3b33d40 BH |
678 | } else { |
679 | fNetworkUrl = getUrlString(fControlProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()), | |
680 | fControlHostAddressText.getText(), | |
681 | fControlPortText.getText(), | |
682 | fDataPortText.getText(), | |
a30e79fe | 683 | fTracePath); |
f3b33d40 | 684 | } |
bbb3538a BH |
685 | } |
686 | ||
687 | // Check for invalid names | |
f3b33d40 | 688 | if (!"".equals(fSessionName) && !fSessionName.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$ |
bbb3538a BH |
689 | MessageDialog.openError(getShell(), |
690 | Messages.TraceControl_CreateSessionDialogTitle, | |
691 | Messages.TraceControl_InvalidSessionNameError + " (" + fSessionName + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$ | |
692 | return; | |
693 | } | |
694 | ||
695 | // Check if node with name already exists in parent | |
696 | if(fParent.containsChild(fSessionName)) { | |
697 | MessageDialog.openError(getShell(), | |
698 | Messages.TraceControl_CreateSessionDialogTitle, | |
699 | Messages.TraceControl_SessionAlreadyExistsError + " (" + fSessionName + ")"); //$NON-NLS-1$ //$NON-NLS-2$ | |
700 | return; | |
701 | } | |
f3b33d40 | 702 | |
bbb3538a BH |
703 | // validation successful -> call super.okPressed() |
704 | super.okPressed(); | |
705 | } | |
f3b33d40 BH |
706 | |
707 | private static String getUrlString(String proto, String host, String ctrlPort, String dataPort, String sessionPath) { | |
708 | //proto://[HOST|IP][:PORT1[:PORT2]][/TRACE_PATH] | |
709 | StringBuilder stringBuilder = new StringBuilder(); | |
710 | stringBuilder.append(proto); | |
711 | stringBuilder.append("://"); //$NON-NLS-1$ | |
712 | stringBuilder.append(host); | |
713 | ||
714 | if ((ctrlPort != null) && (!"".equals(ctrlPort))) { //$NON-NLS-1$ | |
715 | stringBuilder.append(":"); //$NON-NLS-1$ | |
716 | stringBuilder.append(ctrlPort); | |
717 | } | |
718 | ||
719 | if ((dataPort != null) && (!"".equals(dataPort))) { //$NON-NLS-1$ | |
720 | stringBuilder.append(":"); //$NON-NLS-1$ | |
721 | stringBuilder.append(dataPort); | |
722 | } | |
723 | ||
724 | if ((sessionPath != null) && (!"".equals(sessionPath))) { //$NON-NLS-1$ | |
725 | stringBuilder.append("/"); //$NON-NLS-1$ | |
726 | stringBuilder.append(sessionPath); | |
727 | } | |
728 | return stringBuilder.toString(); | |
729 | } | |
730 | ||
a30e79fe | 731 | private static class CopyModifyListener implements ModifyListener { |
f3b33d40 BH |
732 | private Text fSource; |
733 | private Text fDestination; | |
734 | ||
a30e79fe | 735 | public CopyModifyListener(Text source, Text destination) { |
f3b33d40 BH |
736 | fSource = source; |
737 | fDestination = destination; | |
738 | } | |
739 | ||
740 | @Override | |
a30e79fe | 741 | public void modifyText(ModifyEvent e) { |
f3b33d40 BH |
742 | fDestination.setText(fSource.getText()); |
743 | } | |
744 | } | |
745 | ||
746 | private class ControlProtocolSelectionListener extends SelectionAdapter { | |
747 | ||
748 | @Override | |
749 | public void widgetSelected(SelectionEvent e) { | |
750 | fDataProtocolCombo.select(fControlProtocolCombo.getSelectionIndex()); | |
751 | if (fControlProtocolCombo.getItem(fControlProtocolCombo.getSelectionIndex()).equals(StreamingProtocol.file.name())) { | |
752 | fControlPortText.setText(""); //$NON-NLS-1$ | |
753 | fDataPortText.setText(""); //$NON-NLS-1$ | |
754 | fControlPortText.setEnabled(false); | |
755 | fDataPortText.setEnabled(false); | |
756 | } else { | |
757 | fControlPortText.setEnabled(true); | |
758 | fDataPortText.setEnabled(true); | |
759 | } | |
760 | } | |
761 | } | |
762 | ||
763 | private class ProtocolComboSelectionListener extends SelectionAdapter { | |
764 | ||
765 | private CCombo fCombo; | |
766 | private Text fPortText; | |
767 | ||
768 | public ProtocolComboSelectionListener(CCombo combo, Text portText) { | |
769 | fCombo = combo; | |
770 | fPortText = portText; | |
771 | } | |
772 | ||
773 | @Override | |
774 | public void widgetSelected(SelectionEvent e) { | |
775 | if (fCombo.getItem(fCombo.getSelectionIndex()).equals(StreamingProtocol.net.name()) || | |
776 | fCombo.getItem(fCombo.getSelectionIndex()).equals(StreamingProtocol.net6.name())) { | |
777 | fPortText.setText(""); //$NON-NLS-1$ | |
778 | fPortText.setEnabled(false); | |
779 | } else { | |
780 | fPortText.setEnabled(true); | |
781 | } | |
782 | } | |
783 | } | |
784 | ||
f7d4d450 MAL |
785 | @Override |
786 | public ISessionInfo getParameters() { | |
787 | ISessionInfo sessionInfo = new SessionInfo(fSessionName); | |
788 | ||
789 | if (fIsStreamedTrace) { | |
790 | sessionInfo.setNetworkUrl(fNetworkUrl); | |
791 | sessionInfo.setControlUrl(fControlUrl); | |
792 | sessionInfo.setDataUrl(fDataUrl); | |
793 | sessionInfo.setStreamedTrace(true); | |
794 | } else if (!fIsDefaultPath) { | |
795 | sessionInfo.setSessionPath(fSessionPath); | |
796 | } | |
797 | ||
798 | sessionInfo.setSnapshot(fIsSnapshot); | |
799 | ||
800 | return sessionInfo; | |
801 | } | |
bbb3538a | 802 | } |