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