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