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