TMF: Support for drag selection listeners in TimeGraphControl
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.ui / src / org / eclipse / linuxtools / internal / lttng2 / control / ui / views / dialogs / CreateSessionDialog.java
CommitLineData
bbb3538a 1/**********************************************************************
81d5dc3a 2 * Copyright (c) 2012, 2014 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
81d5dc3a 12 * Marc-Andre Laperle - Support for creating a live session
bbb3538a 13 **********************************************************************/
8e8c0226
AM
14
15package org.eclipse.linuxtools.internal.lttng2.control.ui.views.dialogs;
bbb3538a
BH
16
17import org.eclipse.core.runtime.NullProgressMonitor;
bbb3538a 18import org.eclipse.jface.dialogs.IDialogConstants;
abb1f9a7 19import org.eclipse.jface.dialogs.TitleAreaDialog;
8e8c0226
AM
20import org.eclipse.linuxtools.internal.lttng2.control.core.model.ISessionInfo;
21import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.SessionInfo;
22import org.eclipse.linuxtools.internal.lttng2.control.ui.Activator;
23import org.eclipse.linuxtools.internal.lttng2.control.ui.views.messages.Messages;
24import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent;
25import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceSessionGroup;
26import org.eclipse.linuxtools.internal.lttng2.control.ui.views.remote.IRemoteSystemProxy;
81d5dc3a 27import org.eclipse.linuxtools.internal.lttng2.control.ui.views.service.LTTngControlServiceConstants;
bbb3538a
BH
28import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
29import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSystem;
30import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
31import org.eclipse.swt.SWT;
f3b33d40 32import org.eclipse.swt.custom.CCombo;
81d5dc3a
MAL
33import org.eclipse.swt.events.FocusEvent;
34import org.eclipse.swt.events.FocusListener;
a30e79fe
BH
35import org.eclipse.swt.events.ModifyEvent;
36import org.eclipse.swt.events.ModifyListener;
f3b33d40
BH
37import org.eclipse.swt.events.SelectionAdapter;
38import org.eclipse.swt.events.SelectionEvent;
81d5dc3a
MAL
39import org.eclipse.swt.events.VerifyEvent;
40import org.eclipse.swt.events.VerifyListener;
bbb3538a
BH
41import org.eclipse.swt.layout.GridData;
42import org.eclipse.swt.layout.GridLayout;
f3b33d40 43import org.eclipse.swt.widgets.Button;
bbb3538a
BH
44import org.eclipse.swt.widgets.Composite;
45import org.eclipse.swt.widgets.Control;
f3b33d40 46import org.eclipse.swt.widgets.Group;
bbb3538a
BH
47import org.eclipse.swt.widgets.Label;
48import org.eclipse.swt.widgets.Shell;
49import org.eclipse.swt.widgets.Text;
50
51/**
bbb3538a
BH
52 * <p>
53 * Dialog box for collecting session creation information.
54 * </p>
f3b33d40 55 *
dbd4432d 56 * @author Bernd Hufmann
bbb3538a 57 */
abb1f9a7 58public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessionDialog {
bbb3538a
BH
59
60 // ------------------------------------------------------------------------
61 // Constants
62 // ------------------------------------------------------------------------
63 /**
64 * The icon file for this dialog box.
65 */
f3b33d40
BH
66 public static final String CREATE_SESSION_ICON_FILE = "icons/elcl16/add_button.gif"; //$NON-NLS-1$
67
81d5dc3a
MAL
68 /**
69 * To indicate that the default value will be used for this field
70 */
71 private static final String DEFAULT_TEXT = "<" + Messages.EnableChannelDialog_DefaultMessage + ">"; //$NON-NLS-1$ //$NON-NLS-2$
72
f3b33d40
BH
73 /**
74 * Supported network protocols for streaming
75 */
76 private enum StreamingProtocol {
77 /** Default network protocol for IPv4 (TCP)*/
78 net,
79 /** Default network protocol for IPv6 (TCP)*/
80 net6,
81 /** File */
82 file,
83 }
84
81d5dc3a
MAL
85 /**
86 * Supported network protocols for Live tracing
87 */
88 private enum LiveProtocol {
89 /** Default network protocol for IPv4 (TCP)*/
90 net,
91 /** Default network protocol for IPv6 (TCP)*/
92 net6
93 }
94
f3b33d40
BH
95 private enum StreamingProtocol2 {
96 /** Default network protocol for IPv4 (TCP)*/
97 net,
98 /** Default network protocol for IPv6 (TCP)*/
99 net6,
100 /** TCP network protocol for IPv4*/
101 tcp,
102 /** TCP network protocol for IPv6*/
103 tcp6 }
104
105 /**
106 * Index of last supported streaming protocol for common URL configuration.
107 */
77735e82 108 private static final int COMMON_URL_LAST_INDEX = 1;
f3b33d40
BH
109 /**
110 * Index of default streaming protocol.
111 */
77735e82 112 private static final int DEFAULT_URL_INDEX = 0;
bbb3538a
BH
113
114 // ------------------------------------------------------------------------
115 // Attributes
116 // ------------------------------------------------------------------------
117 /**
118 * The dialog composite.
119 */
120 private Composite fDialogComposite = null;
121 /**
122 * The text widget for the session name
123 */
124 private Text fSessionNameText = null;
a30e79fe
BH
125 /**
126 * The label widget for the session path.
127 */
128 private Label fSessionPathLabel = null;
bbb3538a 129 /**
f3b33d40 130 * The text widget for the session path.
bbb3538a
BH
131 */
132 private Text fSessionPathText = null;
81d5dc3a
MAL
133 /**
134 * The button widget to select a normal session
135 */
136 private Button fNormalModeButton = null;
589d0d33
BH
137 /**
138 * The button widget to select a snapshot session
139 */
140 private Button fSnapshotButton = null;
f3b33d40 141 /**
81d5dc3a
MAL
142 * The group that contains the mutually exclusive mode buttons
143 */
144 private Group fModeButtonGroup = null;
145 /**
146 * The button widget to select a live session
f3b33d40 147 */
81d5dc3a
MAL
148 private Button fLiveButton = null;
149
150 /**
151 * The text widget to set a live delay
152 */
153 private Text fLiveDelayText = null;
f3b33d40 154 /**
81d5dc3a 155 * The Group for advanced configuration.
f3b33d40 156 */
81d5dc3a
MAL
157 private Group fAdvancedGroup = null;
158 /**
159 * The button to show advanced options.
160 */
161 private Button fAdvancedButton = null;
f3b33d40
BH
162 /**
163 * The composite with streaming configuration parameter.
164 */
165 private Composite fStreamingComposite = null;
a30e79fe
BH
166 /**
167 * The text widget for the trace path.
168 */
169 private Text fTracePathText = null;
f3b33d40
BH
170 /**
171 * The button to link data protocol/Address with control protocol.
172 */
173 private Button fLinkDataWithControlButton = null;
174 /**
175 * The Combo box for channel protocol selection.
176 */
177 private CCombo fControlProtocolCombo = null;
178 /**
179 * A selection listener that copies the protocol from control to data when being linked.
180 */
181 private ControlProtocolSelectionListener fCopyProtocolSelectionListener;
a30e79fe
BH
182 /**
183 * A selection listener updates the control port text depending on the control protocol selected.
184 */
f3b33d40 185 private ProtocolComboSelectionListener fControlProtocolSelectionListener;
a30e79fe
BH
186 /**
187 * A selection listener updates the data port text depending on the data protocol selected.
188 */
f3b33d40 189 private ProtocolComboSelectionListener fDataProtocolSelectionListener;
f3b33d40
BH
190 /**
191 * The text box for the host/IP address of the control channel.
192 */
193 private Text fControlHostAddressText = null;
194 /**
195 * A key listener that copies the host address from control to data when being linked.
196 */
a30e79fe 197 private CopyModifyListener fControlUrlKeyListener;
abb1f9a7
MAL
198 /**
199 * A modify listener that updates the enablement of the dialog.
200 */
201 private UpdateEnablementModifyListener fUpdateEnablementModifyListener;
f3b33d40
BH
202 /**
203 * The text box for the control port.
204 */
205 private Text fControlPortText = null;
206 /**
207 * The Combo box for data protocol selection.
208 */
209 private CCombo fDataProtocolCombo = null;
210 /**
211 * The text box for the host/IP address of the data channel.
212 */
213 private Text fDataHostAddressText = null;
214 /**
215 * The text box for the data port.
216 */
217 private Text fDataPortText = null;
bbb3538a
BH
218 /**
219 * The parent where the new node should be added.
220 */
c56972bb 221 private TraceSessionGroup fParent = null;
bbb3538a
BH
222 /**
223 * The session name string.
224 */
aa254866 225 private String fSessionName = ""; //$NON-NLS-1$;
bbb3538a
BH
226 /**
227 * The session path string.
228 */
229 private String fSessionPath = null;
589d0d33 230 /**
abb1f9a7 231 * Flag whether the session is snapshot or not
589d0d33
BH
232 */
233 private boolean fIsSnapshot = false;
81d5dc3a
MAL
234 /**
235 * Flag whether the session is live or not
236 */
237 private boolean fIsLive = false;
238 /**
239 * The live delay
240 */
241 private Integer fLiveDelay = 0;
bbb3538a
BH
242 /**
243 * Flag whether default location (path) shall be used or not
244 */
245 private boolean fIsDefaultPath = true;
f3b33d40 246 /**
81d5dc3a 247 * Flag whether the advanced options are enabled or not
f3b33d40 248 */
81d5dc3a 249 private boolean fIsAdvancedEnabled = false;
f3b33d40
BH
250 /**
251 * The network URL in case control and data is configured together.
252 * If set, fControlUrl and fDataUrl will be null.
253 */
254 private String fNetworkUrl = null;
255 /**
256 * The control URL in case control and data is configured separately.
257 * If set, fDataUrl will be set too and fNetworkUrl will be null.
258 */
259 private String fControlUrl = null;
260 /**
261 * The data URL in case control and data is configured separately.
262 * If set, fControlUrl will be set too and fNetworkUrl will be null.
263 */
264 private String fDataUrl = null;
265 /**
a30e79fe 266 * The trace path string.
f3b33d40 267 */
a30e79fe 268 private String fTracePath = null;
81d5dc3a
MAL
269 /**
270 * The Group for advanced configuration of Live mode.
271 */
272 private Group fLiveGroup = null;
bbb3538a
BH
273
274 // ------------------------------------------------------------------------
275 // Constructors
276 // ------------------------------------------------------------------------
277 /**
278 * Constructor
279 * @param shell - a shell for the display of the dialog
bbb3538a 280 */
d132bcc7 281 public CreateSessionDialog(Shell shell) {
bbb3538a 282 super(shell);
8a396998 283 setShellStyle(SWT.RESIZE | getShellStyle());
bbb3538a
BH
284 }
285
286 // ------------------------------------------------------------------------
287 // Accessors
288 // ------------------------------------------------------------------------
11252342 289
d132bcc7 290 @Override
f3b33d40
BH
291 public void initialize(TraceSessionGroup group) {
292 fParent = group;
293 fStreamingComposite = null;
81d5dc3a
MAL
294 fLiveGroup = null;
295 fLiveButton = null;
296 fIsLive = false;
297 fSnapshotButton = null;
aa254866 298 fSessionName = ""; //$NON-NLS-1$
f3b33d40 299 fSessionPath = null;
589d0d33 300 fIsSnapshot = false;
f3b33d40 301 fIsDefaultPath = true;
81d5dc3a 302 fIsAdvancedEnabled = false;
f3b33d40
BH
303 fNetworkUrl = null;
304 fControlUrl = null;
305 fDataUrl = null;
f3b33d40 306 }
bbb3538a
BH
307 // ------------------------------------------------------------------------
308 // Operations
309 // ------------------------------------------------------------------------
f3b33d40 310
bbb3538a
BH
311 @Override
312 protected void configureShell(Shell newShell) {
313 super.configureShell(newShell);
314 newShell.setText(Messages.TraceControl_CreateSessionDialogTitle);
31a6a4e4 315 newShell.setImage(Activator.getDefault().loadIcon(CREATE_SESSION_ICON_FILE));
bbb3538a
BH
316 }
317
bbb3538a
BH
318 @Override
319 protected Control createDialogArea(Composite parent) {
abb1f9a7
MAL
320 Composite dialogAreaa = (Composite) super.createDialogArea(parent);
321 setTitle(Messages.TraceControl_CreateSessionDialogTitle);
322 setMessage(Messages.TraceControl_CreateSessionDialogMessage);
f3b33d40 323
bbb3538a 324 // Main dialog panel
abb1f9a7 325 fDialogComposite = new Composite(dialogAreaa, SWT.NONE);
f3b33d40 326 GridLayout layout = new GridLayout(1, true);
5f1f22f8
BH
327 fDialogComposite.setLayout(layout);
328 fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
bbb3538a 329
f3b33d40
BH
330 Group sessionGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
331 sessionGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
332 sessionGroup.setLayout(new GridLayout(4, true));
333
abb1f9a7
MAL
334 fUpdateEnablementModifyListener = new UpdateEnablementModifyListener();
335
f3b33d40 336 Label sessionNameLabel = new Label(sessionGroup, SWT.RIGHT);
bbb3538a 337 sessionNameLabel.setText(Messages.TraceControl_CreateSessionNameLabel);
f3b33d40 338 fSessionNameText = new Text(sessionGroup, SWT.NONE);
bbb3538a 339 fSessionNameText.setToolTipText(Messages.TraceControl_CreateSessionNameTooltip);
abb1f9a7 340 fSessionNameText.addModifyListener(fUpdateEnablementModifyListener);
81d5dc3a
MAL
341 GridData data = new GridData(GridData.FILL_HORIZONTAL);
342 data.horizontalSpan = 3;
343 fSessionNameText.setLayoutData(data);
f3b33d40 344
a30e79fe
BH
345 fSessionPathLabel = new Label(sessionGroup, SWT.RIGHT);
346 fSessionPathLabel.setText(Messages.TraceControl_CreateSessionPathLabel);
f3b33d40 347 fSessionPathText = new Text(sessionGroup, SWT.NONE);
bbb3538a 348 fSessionPathText.setToolTipText(Messages.TraceControl_CreateSessionPathTooltip);
81d5dc3a
MAL
349 data = new GridData(GridData.FILL_HORIZONTAL);
350 data.horizontalSpan = 3;
351 fSessionPathText.setLayoutData(data);
abb1f9a7 352 fSessionPathText.addModifyListener(fUpdateEnablementModifyListener);
bbb3538a 353
81d5dc3a
MAL
354 if (fParent.isSnapshotSupported() || fParent.isLiveSupported()) {
355 fModeButtonGroup = new Group(sessionGroup, SWT.NONE);
356 data = new GridData(GridData.FILL_HORIZONTAL);
589d0d33 357 data.horizontalSpan = 4;
81d5dc3a
MAL
358 fModeButtonGroup.setLayoutData(data);
359 fModeButtonGroup.setLayout(new GridLayout(3, true));
360
361 SelectionAdapter modeChangedListener = new SelectionAdapter() {
56254dd4
BH
362 @Override
363 public void widgetSelected(SelectionEvent e) {
81d5dc3a
MAL
364 if (fLiveButton != null) {
365 if (fLiveButton.getSelection()) {
366 createAdvancedLiveGroup();
367 updateSessionPathEnablement();
368 updateProtocolComboItems();
369 } else {
370 disposeLiveGroup();
371 updateSessionPathEnablement();
372 updateProtocolComboItems();
373 }
374 }
56254dd4
BH
375 updateEnablement();
376 }
81d5dc3a
MAL
377 };
378
379 fNormalModeButton = new Button(fModeButtonGroup, SWT.RADIO);
380 fNormalModeButton.setText(Messages.TraceControl_CreateSessionNormalLabel);
381 fNormalModeButton.setToolTipText(Messages.TraceControl_CreateSessionNormalTooltip);
382 fNormalModeButton.setSelection(true);
383 fNormalModeButton.addSelectionListener(modeChangedListener);
384
385 if (fParent.isSnapshotSupported()) {
386 fSnapshotButton = new Button(fModeButtonGroup, SWT.RADIO);
387 fSnapshotButton.setText(Messages.TraceControl_CreateSessionSnapshotLabel);
388 fSnapshotButton.setToolTipText(Messages.TraceControl_CreateSessionSnapshotTooltip);
389 fSnapshotButton.addSelectionListener(modeChangedListener);
390 }
f3b33d40 391
81d5dc3a
MAL
392 if (fParent.isLiveSupported()) {
393 fLiveButton = new Button(fModeButtonGroup, SWT.RADIO);
394 fLiveButton.setText(Messages.TraceControl_CreateSessionLiveLabel);
395 fLiveButton.setToolTipText(Messages.TraceControl_CreateSessionLiveTooltip);
396 fLiveButton.addSelectionListener(modeChangedListener);
397 }
398 }
bbb3538a 399
81d5dc3a 400 if (fParent.isNetworkStreamingSupported() || fParent.isLiveSupported()) {
f3b33d40
BH
401 createAdvancedOptionsComposite();
402 }
403
bbb3538a
BH
404 return fDialogComposite;
405 }
406
f3b33d40
BH
407 private void createAdvancedOptionsComposite() {
408
81d5dc3a
MAL
409 fAdvancedGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
410 fAdvancedGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
411 fAdvancedGroup.setLayout(new GridLayout(1, true));
f3b33d40 412
81d5dc3a
MAL
413 fAdvancedButton = new Button(fAdvancedGroup, SWT.PUSH);
414 fAdvancedButton.setText(Messages.TraceControl_CreateSessionConfigureStreamingButtonText + " >>>"); //$NON-NLS-1$
415 fAdvancedButton.setToolTipText(Messages.TraceControl_CreateSessionConfigureStreamingButtonTooltip);
416 fAdvancedButton.addSelectionListener(new SelectionAdapter() {
f3b33d40
BH
417 @Override
418 public void widgetSelected(SelectionEvent e) {
81d5dc3a
MAL
419 if (fIsAdvancedEnabled) {
420 fIsAdvancedEnabled = false;
421 fAdvancedButton.setText(">>> " + Messages.TraceControl_CreateSessionConfigureStreamingButtonText); //$NON-NLS-1$
422 fAdvancedButton.setToolTipText(Messages.TraceControl_CreateSessionConfigureStreamingButtonTooltip);
423
424 if (fParent.isNetworkStreamingSupported()) {
425 updateSessionPathEnablement();
426 disposeConfigureStreamingComposite();
427 }
428
429 if (fParent.isLiveSupported()) {
430 disposeLiveGroup();
431 }
f3b33d40 432 } else {
81d5dc3a
MAL
433 fIsAdvancedEnabled = true;
434 fAdvancedButton.setText("<<< " + Messages.TraceControl_CreateSessionNoStreamingButtonText); //$NON-NLS-1$
435 fAdvancedButton.setToolTipText(Messages.TraceControl_CreateSessionNoStreamingButtonTooltip);
436
437 if (fParent.isNetworkStreamingSupported()) {
438 updateSessionPathEnablement();
439 createConfigureStreamingComposite();
440 }
441 if (fLiveButton != null && fLiveButton.getSelection()) {
442 createAdvancedLiveGroup();
443 }
f3b33d40
BH
444 }
445
abb1f9a7
MAL
446 updateEnablement();
447 getShell().pack();
f3b33d40
BH
448 }
449 });
450 }
451
81d5dc3a
MAL
452 private void updateSessionPathEnablement() {
453 if (fIsAdvancedEnabled || fIsLive) {
454 fSessionPathText.setEnabled(false);
455 fSessionPathText.setText(""); //$NON-NLS-1$
456 fSessionPathLabel.setText(""); //$NON-NLS-1$
457 } else {
458 fSessionPathText.setEnabled(true);
459 fSessionPathLabel.setText(Messages.TraceControl_CreateSessionPathLabel);
460 }
461 }
462
463 private void updateProtocolComboItems() {
464 if (fControlProtocolCombo == null || fControlProtocolCombo.isDisposed()) {
465 return;
466 }
467
468 int currentSelection = fControlProtocolCombo.getSelectionIndex() <= COMMON_URL_LAST_INDEX ?
469 fControlProtocolCombo.getSelectionIndex() : DEFAULT_URL_INDEX;
470
471 fControlProtocolCombo.removeAll();
472 Enum<? extends Enum<?>>[] values;
473 if (fIsLive) {
474 values = LiveProtocol.values();
475 } else if (fLinkDataWithControlButton.getSelection()) {
476 values = StreamingProtocol.values();
477 } else {
478 values = StreamingProtocol2.values();
479 }
480
481 String[] controlItems = new String[values.length];
482 for (int i = 0; i < controlItems.length; i++) {
483 controlItems[i] = values[i].name();
484 }
485 fControlProtocolCombo.setItems(controlItems);
486 fDataProtocolCombo.setItems(controlItems);
487
488 // Set selection
489 if (currentSelection != -1) {
490 fControlProtocolCombo.select(currentSelection);
491 fDataProtocolCombo.select(currentSelection);
492 }
493 }
494
f3b33d40
BH
495 private void createConfigureStreamingComposite() {
496 if (fStreamingComposite == null) {
81d5dc3a 497 fStreamingComposite = new Group(fAdvancedGroup, SWT.SHADOW_NONE);
f3b33d40
BH
498 GridLayout layout = new GridLayout(1, true);
499 fStreamingComposite.setLayout(layout);
500 fStreamingComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
501
f3b33d40 502 layout = new GridLayout(7, true);
81d5dc3a
MAL
503 fStreamingComposite.setLayout(layout);
504 fStreamingComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
f3b33d40 505
81d5dc3a 506 Label tracePathLabel = new Label(fStreamingComposite, SWT.RIGHT);
a30e79fe 507 tracePathLabel.setText(Messages.TraceControl_CreateSessionTracePathText);
81d5dc3a 508 fTracePathText = new Text(fStreamingComposite, SWT.NONE);
a30e79fe
BH
509 fTracePathText.setToolTipText(Messages.TraceControl_CreateSessionTracePathTooltip);
510
511 // layout widgets
512 GridData data = new GridData(GridData.FILL_HORIZONTAL);
513 data.horizontalSpan = 6;
514 fTracePathText.setLayoutData(data);
abb1f9a7 515 fTracePathText.addModifyListener(fUpdateEnablementModifyListener);
a30e79fe 516
81d5dc3a 517 fLinkDataWithControlButton = new Button(fStreamingComposite, SWT.CHECK);
f3b33d40
BH
518 fLinkDataWithControlButton.setText(Messages.TraceControl_CreateSessionLinkButtonText);
519 fLinkDataWithControlButton.setToolTipText(Messages.TraceControl_CreateSessionLinkButtonTooltip);
a30e79fe 520 data = new GridData(GridData.FILL_HORIZONTAL);
f3b33d40
BH
521 data.horizontalSpan = 7;
522 fLinkDataWithControlButton.setLayoutData(data);
523 fLinkDataWithControlButton.setSelection(true);
524
81d5dc3a 525 Label label = new Label(fStreamingComposite, SWT.NONE);
f3b33d40
BH
526 data = new GridData(GridData.FILL_HORIZONTAL);
527 data.horizontalSpan = 1;
528 label.setLayoutData(data);
529
81d5dc3a 530 label = new Label(fStreamingComposite, SWT.NONE);
f3b33d40
BH
531 label.setText(Messages.TraceControl_CreateSessionProtocolLabelText);
532 data = new GridData(GridData.FILL_HORIZONTAL);
533 data.horizontalSpan = 1;
534 label.setLayoutData(data);
535
81d5dc3a 536 label = new Label(fStreamingComposite, SWT.NONE);
f3b33d40
BH
537 label.setText(Messages.TraceControl_CreateSessionAddressLabelText);
538 data = new GridData(GridData.FILL_HORIZONTAL);
539 data.horizontalSpan = 4;
540 label.setLayoutData(data);
541
81d5dc3a 542 label = new Label(fStreamingComposite, SWT.NONE);
f3b33d40
BH
543 label.setText(Messages.TraceControl_CreateSessionPortLabelText);
544 data = new GridData(GridData.FILL_HORIZONTAL);
545 data.horizontalSpan = 1;
546 label.setLayoutData(data);
547
81d5dc3a 548 label = new Label(fStreamingComposite, SWT.RIGHT);
f3b33d40
BH
549 label.setText(Messages.TraceControl_CreateSessionControlUrlLabel);
550 data = new GridData(GridData.FILL_HORIZONTAL);
551 data.horizontalSpan = 1;
552 label.setLayoutData(data);
553
81d5dc3a 554 fControlProtocolCombo = new CCombo(fStreamingComposite, SWT.READ_ONLY);
f3b33d40
BH
555 fControlProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionCommonProtocolTooltip);
556 data = new GridData(GridData.FILL_HORIZONTAL);
557 data.horizontalSpan = 1;
558 fControlProtocolCombo.setLayoutData(data);
abb1f9a7 559 fControlProtocolCombo.addModifyListener(fUpdateEnablementModifyListener);
f3b33d40 560
81d5dc3a 561 fControlHostAddressText = new Text(fStreamingComposite, SWT.NONE);
f3b33d40
BH
562 fControlHostAddressText.setToolTipText(Messages.TraceControl_CreateSessionControlAddressTooltip);
563 data = new GridData(GridData.FILL_HORIZONTAL);
564 data.horizontalSpan = 4;
565 fControlHostAddressText.setLayoutData(data);
abb1f9a7 566 fControlHostAddressText.addModifyListener(fUpdateEnablementModifyListener);
f3b33d40 567
81d5dc3a 568 fControlPortText = new Text(fStreamingComposite, SWT.NONE);
f3b33d40
BH
569 fControlPortText.setToolTipText(Messages.TraceControl_CreateSessionControlPortTooltip);
570 data = new GridData(GridData.FILL_HORIZONTAL);
571 data.horizontalSpan = 1;
572 fControlPortText.setLayoutData(data);
abb1f9a7 573 fControlPortText.addModifyListener(fUpdateEnablementModifyListener);
f3b33d40 574
81d5dc3a 575 label = new Label(fStreamingComposite, SWT.RIGHT);
f3b33d40
BH
576 label.setText(Messages.TraceControl_CreateSessionDataUrlLabel);
577 data = new GridData(GridData.FILL_HORIZONTAL);
578 data.horizontalSpan = 1;
579 label.setLayoutData(data);
580
81d5dc3a 581 fDataProtocolCombo = new CCombo(fStreamingComposite, SWT.READ_ONLY);
f3b33d40
BH
582 fDataProtocolCombo.setEnabled(false);
583 fDataProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionProtocolTooltip);
584 data = new GridData(GridData.FILL_HORIZONTAL);
585 data.horizontalSpan = 1;
586 fDataProtocolCombo.setLayoutData(data);
abb1f9a7 587 fDataProtocolCombo.addModifyListener(fUpdateEnablementModifyListener);
f3b33d40 588
81d5dc3a 589 updateProtocolComboItems();
f3b33d40 590
81d5dc3a 591 fDataHostAddressText = new Text(fStreamingComposite, SWT.NONE);
f3b33d40
BH
592 fDataHostAddressText.setEnabled(false);
593 fDataHostAddressText.setToolTipText(Messages.TraceControl_CreateSessionDataAddressTooltip);
594 data = new GridData(GridData.FILL_HORIZONTAL);
595 data.horizontalSpan = 4;
596 fDataHostAddressText.setLayoutData(data);
abb1f9a7 597 fDataHostAddressText.addModifyListener(fUpdateEnablementModifyListener);
f3b33d40 598
81d5dc3a 599 fDataPortText = new Text(fStreamingComposite, SWT.NONE);
f3b33d40
BH
600 fDataPortText.setEnabled(true);
601 fDataPortText.setToolTipText(Messages.TraceControl_CreateSessionDataPortTooltip);
602 data = new GridData(GridData.FILL_HORIZONTAL);
603 data.horizontalSpan = 1;
604 fDataPortText.setLayoutData(data);
abb1f9a7 605 fDataPortText.addModifyListener(fUpdateEnablementModifyListener);
f3b33d40
BH
606
607 fCopyProtocolSelectionListener = new ControlProtocolSelectionListener();
608 fControlProtocolSelectionListener = new ProtocolComboSelectionListener(fControlProtocolCombo, fControlPortText);
609 fDataProtocolSelectionListener = new ProtocolComboSelectionListener(fDataProtocolCombo, fDataPortText);
610
611 fControlProtocolCombo.addSelectionListener(fCopyProtocolSelectionListener);
612
a30e79fe
BH
613 fControlUrlKeyListener = new CopyModifyListener(fControlHostAddressText, fDataHostAddressText);
614 fControlHostAddressText.addModifyListener(fControlUrlKeyListener);
615
f3b33d40
BH
616 fControlProtocolCombo.select(DEFAULT_URL_INDEX);
617 fDataProtocolCombo.select(DEFAULT_URL_INDEX);
618
619 fLinkDataWithControlButton.addSelectionListener(new SelectionAdapter() {
620 @Override
621 public void widgetSelected(SelectionEvent e) {
622 if (fLinkDataWithControlButton.getSelection()) {
623 // Set enablement control data channel inputs
624 fDataProtocolCombo.setEnabled(false);
625 fDataHostAddressText.setEnabled(false);
626 fControlPortText.setEnabled(true);
627 fDataPortText.setEnabled(true);
628
629 // Update listeners
630 fControlProtocolCombo.removeSelectionListener(fControlProtocolSelectionListener);
631 fDataProtocolCombo.removeSelectionListener(fDataProtocolSelectionListener);
632 fControlProtocolCombo.addSelectionListener(fCopyProtocolSelectionListener);
a30e79fe 633 fControlHostAddressText.addModifyListener(fControlUrlKeyListener);
f3b33d40 634
81d5dc3a 635 updateProtocolComboItems();
f3b33d40 636
f3b33d40
BH
637 fDataHostAddressText.setText(fControlHostAddressText.getText());
638
639 // Update tool tips
640 fControlProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionCommonProtocolTooltip);
641 } else {
642 // Enable data channel inputs
643 fDataProtocolCombo.setEnabled(true);
644 fDataHostAddressText.setEnabled(true);
645
646 // Update listeners
647 fControlProtocolCombo.removeSelectionListener(fCopyProtocolSelectionListener);
648 fControlProtocolCombo.addSelectionListener(fControlProtocolSelectionListener);
649 fDataProtocolCombo.addSelectionListener(fDataProtocolSelectionListener);
a30e79fe 650 fControlHostAddressText.removeModifyListener(fControlUrlKeyListener);
f3b33d40 651
81d5dc3a 652 updateProtocolComboItems();
f3b33d40
BH
653
654 // Update tool tips
655 fDataProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionProtocolTooltip);
656 fControlProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionProtocolTooltip);
657
658 // Update control/data port enablement and input
659 if (fControlProtocolCombo.getItem(fControlProtocolCombo.getSelectionIndex()).equals(StreamingProtocol.net.name()) ||
660 fControlProtocolCombo.getItem(fControlProtocolCombo.getSelectionIndex()).equals(StreamingProtocol.net6.name())) {
661 fControlPortText.setText(""); //$NON-NLS-1$
662 fControlPortText.setEnabled(false);
663 } else {
664 fControlPortText.setEnabled(true);
665 }
666
667 if (fDataProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()).equals(StreamingProtocol.net.name()) ||
668 fDataProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()).equals(StreamingProtocol.net6.name())) {
669 fDataPortText.setText(""); //$NON-NLS-1$
670 fDataPortText.setEnabled(false);
671 } else {
672 fDataPortText.setEnabled(true);
673 }
674 }
675 }
676 });
677 }
678 }
679
81d5dc3a
MAL
680 private void createAdvancedLiveGroup() {
681 if (fLiveGroup == null && fIsAdvancedEnabled) {
682 GridLayout layout = new GridLayout(7, true);
683 fLiveGroup = new Group(fAdvancedGroup, SWT.NONE);
684 fLiveGroup.setLayout(layout);
685 GridData layoutData = new GridData(GridData.FILL_BOTH);
686 fLiveGroup.setLayoutData(layoutData);
687
688 Label liveDelayLabel = new Label(fLiveGroup, SWT.RIGHT);
689 layoutData = new GridData(GridData.FILL_HORIZONTAL);
690 liveDelayLabel.setText(Messages.TraceControl_CreateSessionLiveDelayLabel);
691 liveDelayLabel.setLayoutData(layoutData);
692 fLiveDelayText = new Text(fLiveGroup, SWT.NONE);
693 fLiveDelayText.setText(DEFAULT_TEXT);
694 fLiveDelayText.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY));
695 fLiveDelayText.setToolTipText(Messages.TraceControl_CreateSessionLiveDelayTooltip);
696 fLiveDelayText.addVerifyListener(new VerifyListener() {
697 @Override
698 public void verifyText(VerifyEvent e) {
699 // only numbers and default are allowed.
700 e.doit = e.text.matches("[0-9]*") || e.text.matches(DEFAULT_TEXT); //$NON-NLS-1$
701 updateEnablement();
702 }
703 });
704 fLiveDelayText.addModifyListener(new ModifyListener() {
705 @Override
706 public void modifyText(ModifyEvent event) {
707 updateEnablement();
708 }
709 });
710
711 fLiveDelayText.addFocusListener(new FocusListener() {
712
713 @Override
714 public void focusLost(FocusEvent e) {
715 Text focusLostWidget = (Text) e.widget;
716 if (focusLostWidget.getText().isEmpty()) {
717 focusLostWidget.setText(DEFAULT_TEXT);
718 focusLostWidget.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY));
719 }
720 }
721
722 @Override
723 public void focusGained(FocusEvent e) {
724 Text focusGainedWidget = (Text) e.widget;
725 if (focusGainedWidget.getText().equals(DEFAULT_TEXT)) {
726 focusGainedWidget.setText(""); //$NON-NLS-1$
727 focusGainedWidget.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_BLACK));
728 }
729 }
730 });
731
732 layoutData = new GridData(GridData.FILL_HORIZONTAL);
733 layoutData.grabExcessHorizontalSpace = true;
734 layoutData.horizontalSpan = 6;
735 fLiveDelayText.setLayoutData(layoutData);
736 getShell().pack();
737 }
738 }
739
740 private void disposeLiveGroup() {
741 if (fLiveGroup != null) {
742 fLiveGroup.dispose();
743 fLiveGroup = null;
744 getShell().pack();
745 }
746 }
747
f3b33d40
BH
748 private void disposeConfigureStreamingComposite() {
749 if (fStreamingComposite != null) {
750 fStreamingComposite.dispose();
751 fStreamingComposite = null;
752 }
753 }
754
bbb3538a
BH
755 @Override
756 protected void createButtonsForButtonBar(Composite parent) {
79c3db85 757 createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$
bbb3538a
BH
758 createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$
759 }
760
abb1f9a7
MAL
761 private void updateEnablement() {
762 validate();
763 getButton(IDialogConstants.OK_ID).setEnabled(getErrorMessage() == null);
764 }
765
766 private void validate() {
bbb3538a
BH
767 // Validate input data
768 fSessionName = fSessionNameText.getText();
769 fSessionPath = fSessionPathText.getText();
abb1f9a7 770 setErrorMessage(null);
bbb3538a 771
81d5dc3a
MAL
772 if (fParent.isLiveSupported() && fLiveButton != null) {
773 fIsLive = fLiveButton.getSelection();
774 fLiveDelay = LTTngControlServiceConstants.UNUSED_VALUE;
775 }
776
bbb3538a
BH
777 if (!"".equals(fSessionPath)) { //$NON-NLS-1$
778 // validate sessionPath
81d5dc3a 779 if (!fIsAdvancedEnabled && !fIsLive) {
f3b33d40
BH
780 TargetNodeComponent node = (TargetNodeComponent)fParent.getParent();
781 IRemoteSystemProxy proxy = node.getRemoteSystemProxy();
782 IFileServiceSubSystem fsss = proxy.getFileServiceSubSystem();
783 if (fsss != null) {
784 try {
785 IRemoteFile remoteFolder = fsss.getRemoteFileObject(fSessionPath, new NullProgressMonitor());
b68f311b
BH
786
787 if (remoteFolder == null) {
abb1f9a7 788 setErrorMessage(Messages.TraceControl_InvalidSessionPathError + " (" + fSessionPath + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
b68f311b
BH
789 return;
790 }
791
f3b33d40 792 if (remoteFolder.exists()) {
abb1f9a7 793 setErrorMessage(Messages.TraceControl_SessionPathAlreadyExistsError + " (" + fSessionPath + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
f3b33d40
BH
794 return;
795 }
796 } catch (SystemMessageException e) {
abb1f9a7 797 setErrorMessage(Messages.TraceControl_FileSubSystemError + "\n" + e); //$NON-NLS-1$
bbb3538a
BH
798 return;
799 }
f3b33d40 800 }
bbb3538a
BH
801 }
802 fIsDefaultPath = false;
803 }
804
abb1f9a7 805 if (fParent.isSnapshotSupported()) {
589d0d33
BH
806 fIsSnapshot = fSnapshotButton.getSelection();
807 }
808
f3b33d40
BH
809 fNetworkUrl = null;
810 fControlUrl = null;
811 fDataUrl = null;
812
81d5dc3a 813 if (fIsAdvancedEnabled && fStreamingComposite != null) {
a30e79fe 814 // Validate input data
81d5dc3a
MAL
815
816 if (fIsLive && fLiveGroup != null) {
817 String liveDelayText = fLiveDelayText.getText();
818 try {
819 fLiveDelay = liveDelayText.equals(DEFAULT_TEXT) ? LTTngControlServiceConstants.UNUSED_VALUE : Integer.valueOf(liveDelayText);
820 } catch (NumberFormatException e) {
821 setErrorMessage(Messages.TraceControl_InvalidLiveDelayError);
822 return;
823 }
824 }
825
a30e79fe
BH
826 fTracePath = fTracePathText.getText();
827
f3b33d40 828 if (fControlProtocolCombo.getSelectionIndex() < 0) {
abb1f9a7 829 setErrorMessage("Control Protocol Text is empty\n"); //$NON-NLS-1$
f3b33d40
BH
830 return;
831 }
832
833 if ("".equals(fControlHostAddressText.getText())) { //$NON-NLS-1$
abb1f9a7 834 setErrorMessage("Control Address Text is empty\n"); //$NON-NLS-1$
f3b33d40
BH
835 return;
836 }
837
abb1f9a7 838 if (!fLinkDataWithControlButton.getSelection()) {
f3b33d40 839 if (fDataProtocolCombo.getSelectionIndex() < 0) {
abb1f9a7 840 setErrorMessage("Data Protocol Text is empty\n"); //$NON-NLS-1$
f3b33d40
BH
841 return;
842 }
843
844 if ("".equals(fDataHostAddressText.getText())) { //$NON-NLS-1$
abb1f9a7 845 setErrorMessage("Data Address Text is empty\n"); //$NON-NLS-1$
f3b33d40
BH
846 return;
847 }
848
849 fControlUrl = getUrlString(fControlProtocolCombo.getItem(fControlProtocolCombo.getSelectionIndex()),
850 fControlHostAddressText.getText(),
851 fControlPortText.getText(),
852 null,
a30e79fe 853 fTracePath);
f3b33d40 854
abb1f9a7 855 fDataUrl = getUrlString(fDataProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()),
f3b33d40
BH
856 fDataHostAddressText.getText(),
857 null,
858 fDataPortText.getText(),
a30e79fe 859 fTracePath);
f3b33d40 860 } else {
abb1f9a7 861 fNetworkUrl = getUrlString(fControlProtocolCombo.getItem(fControlProtocolCombo.getSelectionIndex()),
f3b33d40
BH
862 fControlHostAddressText.getText(),
863 fControlPortText.getText(),
864 fDataPortText.getText(),
a30e79fe 865 fTracePath);
f3b33d40 866 }
bbb3538a
BH
867 }
868
81d5dc3a
MAL
869 if (fIsLive && fNetworkUrl == null && fControlUrl == null && fDataUrl == null) {
870 fNetworkUrl = SessionInfo.DEFAULT_LIVE_NETWORK_URK;
871 }
872
bbb3538a 873 // Check for invalid names
f3b33d40 874 if (!"".equals(fSessionName) && !fSessionName.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$
abb1f9a7 875 setErrorMessage(Messages.TraceControl_InvalidSessionNameError + " (" + fSessionName + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
bbb3538a
BH
876 return;
877 }
878
879 // Check if node with name already exists in parent
880 if(fParent.containsChild(fSessionName)) {
abb1f9a7 881 setErrorMessage(Messages.TraceControl_SessionAlreadyExistsError + " (" + fSessionName + ")"); //$NON-NLS-1$ //$NON-NLS-2$
bbb3538a
BH
882 return;
883 }
bbb3538a 884 }
f3b33d40
BH
885
886 private static String getUrlString(String proto, String host, String ctrlPort, String dataPort, String sessionPath) {
887 //proto://[HOST|IP][:PORT1[:PORT2]][/TRACE_PATH]
888 StringBuilder stringBuilder = new StringBuilder();
889 stringBuilder.append(proto);
890 stringBuilder.append("://"); //$NON-NLS-1$
891 stringBuilder.append(host);
892
893 if ((ctrlPort != null) && (!"".equals(ctrlPort))) { //$NON-NLS-1$
894 stringBuilder.append(":"); //$NON-NLS-1$
895 stringBuilder.append(ctrlPort);
896 }
897
898 if ((dataPort != null) && (!"".equals(dataPort))) { //$NON-NLS-1$
899 stringBuilder.append(":"); //$NON-NLS-1$
900 stringBuilder.append(dataPort);
901 }
902
903 if ((sessionPath != null) && (!"".equals(sessionPath))) { //$NON-NLS-1$
904 stringBuilder.append("/"); //$NON-NLS-1$
905 stringBuilder.append(sessionPath);
906 }
907 return stringBuilder.toString();
908 }
909
a30e79fe 910 private static class CopyModifyListener implements ModifyListener {
f3b33d40
BH
911 private Text fSource;
912 private Text fDestination;
913
a30e79fe 914 public CopyModifyListener(Text source, Text destination) {
f3b33d40
BH
915 fSource = source;
916 fDestination = destination;
917 }
918
919 @Override
a30e79fe 920 public void modifyText(ModifyEvent e) {
f3b33d40
BH
921 fDestination.setText(fSource.getText());
922 }
923 }
924
925 private class ControlProtocolSelectionListener extends SelectionAdapter {
926
927 @Override
928 public void widgetSelected(SelectionEvent e) {
929 fDataProtocolCombo.select(fControlProtocolCombo.getSelectionIndex());
930 if (fControlProtocolCombo.getItem(fControlProtocolCombo.getSelectionIndex()).equals(StreamingProtocol.file.name())) {
931 fControlPortText.setText(""); //$NON-NLS-1$
932 fDataPortText.setText(""); //$NON-NLS-1$
933 fControlPortText.setEnabled(false);
934 fDataPortText.setEnabled(false);
935 } else {
936 fControlPortText.setEnabled(true);
937 fDataPortText.setEnabled(true);
938 }
939 }
940 }
941
942 private class ProtocolComboSelectionListener extends SelectionAdapter {
943
944 private CCombo fCombo;
945 private Text fPortText;
946
947 public ProtocolComboSelectionListener(CCombo combo, Text portText) {
948 fCombo = combo;
949 fPortText = portText;
950 }
951
952 @Override
953 public void widgetSelected(SelectionEvent e) {
954 if (fCombo.getItem(fCombo.getSelectionIndex()).equals(StreamingProtocol.net.name()) ||
955 fCombo.getItem(fCombo.getSelectionIndex()).equals(StreamingProtocol.net6.name())) {
956 fPortText.setText(""); //$NON-NLS-1$
957 fPortText.setEnabled(false);
958 } else {
959 fPortText.setEnabled(true);
960 }
961 }
962 }
963
f7d4d450
MAL
964 @Override
965 public ISessionInfo getParameters() {
966 ISessionInfo sessionInfo = new SessionInfo(fSessionName);
967
81d5dc3a
MAL
968 boolean isStreaming = (fIsAdvancedEnabled && fStreamingComposite != null) || fIsLive;
969 if (isStreaming) {
f7d4d450
MAL
970 sessionInfo.setNetworkUrl(fNetworkUrl);
971 sessionInfo.setControlUrl(fControlUrl);
972 sessionInfo.setDataUrl(fDataUrl);
973 sessionInfo.setStreamedTrace(true);
974 } else if (!fIsDefaultPath) {
975 sessionInfo.setSessionPath(fSessionPath);
976 }
977
81d5dc3a
MAL
978 sessionInfo.setLive(fIsLive);
979 sessionInfo.setLiveDelay(fLiveDelay);
f7d4d450
MAL
980 sessionInfo.setSnapshot(fIsSnapshot);
981
982 return sessionInfo;
983 }
abb1f9a7
MAL
984
985 private final class UpdateEnablementModifyListener implements ModifyListener {
986 @Override
987 public void modifyText(ModifyEvent e) {
988 updateEnablement();
989 }
990 }
bbb3538a 991}
This page took 0.096283 seconds and 5 git commands to generate.