lttng: Add support for creating a live session in Control view
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.ui / src / org / eclipse / linuxtools / internal / lttng2 / control / ui / views / dialogs / CreateSessionDialog.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2014 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
12 * Marc-Andre Laperle - Support for creating a live session
13 **********************************************************************/
14
15 package org.eclipse.linuxtools.internal.lttng2.control.ui.views.dialogs;
16
17 import org.eclipse.core.runtime.NullProgressMonitor;
18 import org.eclipse.jface.dialogs.IDialogConstants;
19 import org.eclipse.jface.dialogs.TitleAreaDialog;
20 import org.eclipse.linuxtools.internal.lttng2.control.core.model.ISessionInfo;
21 import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.SessionInfo;
22 import org.eclipse.linuxtools.internal.lttng2.control.ui.Activator;
23 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.messages.Messages;
24 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent;
25 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceSessionGroup;
26 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.remote.IRemoteSystemProxy;
27 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.service.LTTngControlServiceConstants;
28 import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
29 import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSystem;
30 import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
31 import org.eclipse.swt.SWT;
32 import org.eclipse.swt.custom.CCombo;
33 import org.eclipse.swt.events.FocusEvent;
34 import org.eclipse.swt.events.FocusListener;
35 import org.eclipse.swt.events.ModifyEvent;
36 import org.eclipse.swt.events.ModifyListener;
37 import org.eclipse.swt.events.SelectionAdapter;
38 import org.eclipse.swt.events.SelectionEvent;
39 import org.eclipse.swt.events.VerifyEvent;
40 import org.eclipse.swt.events.VerifyListener;
41 import org.eclipse.swt.layout.GridData;
42 import org.eclipse.swt.layout.GridLayout;
43 import org.eclipse.swt.widgets.Button;
44 import org.eclipse.swt.widgets.Composite;
45 import org.eclipse.swt.widgets.Control;
46 import org.eclipse.swt.widgets.Group;
47 import org.eclipse.swt.widgets.Label;
48 import org.eclipse.swt.widgets.Shell;
49 import org.eclipse.swt.widgets.Text;
50
51 /**
52 * <p>
53 * Dialog box for collecting session creation information.
54 * </p>
55 *
56 * @author Bernd Hufmann
57 */
58 public class CreateSessionDialog extends TitleAreaDialog implements ICreateSessionDialog {
59
60 // ------------------------------------------------------------------------
61 // Constants
62 // ------------------------------------------------------------------------
63 /**
64 * The icon file for this dialog box.
65 */
66 public static final String CREATE_SESSION_ICON_FILE = "icons/elcl16/add_button.gif"; //$NON-NLS-1$
67
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
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
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
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 */
108 private static final int COMMON_URL_LAST_INDEX = 1;
109 /**
110 * Index of default streaming protocol.
111 */
112 private static final int DEFAULT_URL_INDEX = 0;
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;
125 /**
126 * The label widget for the session path.
127 */
128 private Label fSessionPathLabel = null;
129 /**
130 * The text widget for the session path.
131 */
132 private Text fSessionPathText = null;
133 /**
134 * The button widget to select a normal session
135 */
136 private Button fNormalModeButton = null;
137 /**
138 * The button widget to select a snapshot session
139 */
140 private Button fSnapshotButton = null;
141 /**
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
147 */
148 private Button fLiveButton = null;
149
150 /**
151 * The text widget to set a live delay
152 */
153 private Text fLiveDelayText = null;
154 /**
155 * The Group for advanced configuration.
156 */
157 private Group fAdvancedGroup = null;
158 /**
159 * The button to show advanced options.
160 */
161 private Button fAdvancedButton = null;
162 /**
163 * The composite with streaming configuration parameter.
164 */
165 private Composite fStreamingComposite = null;
166 /**
167 * The text widget for the trace path.
168 */
169 private Text fTracePathText = null;
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;
182 /**
183 * A selection listener updates the control port text depending on the control protocol selected.
184 */
185 private ProtocolComboSelectionListener fControlProtocolSelectionListener;
186 /**
187 * A selection listener updates the data port text depending on the data protocol selected.
188 */
189 private ProtocolComboSelectionListener fDataProtocolSelectionListener;
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 */
197 private CopyModifyListener fControlUrlKeyListener;
198 /**
199 * A modify listener that updates the enablement of the dialog.
200 */
201 private UpdateEnablementModifyListener fUpdateEnablementModifyListener;
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;
218 /**
219 * The parent where the new node should be added.
220 */
221 private TraceSessionGroup fParent = null;
222 /**
223 * The session name string.
224 */
225 private String fSessionName = ""; //$NON-NLS-1$;
226 /**
227 * The session path string.
228 */
229 private String fSessionPath = null;
230 /**
231 * Flag whether the session is snapshot or not
232 */
233 private boolean fIsSnapshot = false;
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;
242 /**
243 * Flag whether default location (path) shall be used or not
244 */
245 private boolean fIsDefaultPath = true;
246 /**
247 * Flag whether the advanced options are enabled or not
248 */
249 private boolean fIsAdvancedEnabled = false;
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 /**
266 * The trace path string.
267 */
268 private String fTracePath = null;
269 /**
270 * The Group for advanced configuration of Live mode.
271 */
272 private Group fLiveGroup = null;
273
274 // ------------------------------------------------------------------------
275 // Constructors
276 // ------------------------------------------------------------------------
277 /**
278 * Constructor
279 * @param shell - a shell for the display of the dialog
280 */
281 public CreateSessionDialog(Shell shell) {
282 super(shell);
283 setShellStyle(SWT.RESIZE | getShellStyle());
284 }
285
286 // ------------------------------------------------------------------------
287 // Accessors
288 // ------------------------------------------------------------------------
289
290 @Override
291 public void initialize(TraceSessionGroup group) {
292 fParent = group;
293 fStreamingComposite = null;
294 fLiveGroup = null;
295 fLiveButton = null;
296 fIsLive = false;
297 fSnapshotButton = null;
298 fSessionName = ""; //$NON-NLS-1$
299 fSessionPath = null;
300 fIsSnapshot = false;
301 fIsDefaultPath = true;
302 fIsAdvancedEnabled = false;
303 fNetworkUrl = null;
304 fControlUrl = null;
305 fDataUrl = null;
306 }
307 // ------------------------------------------------------------------------
308 // Operations
309 // ------------------------------------------------------------------------
310
311 @Override
312 protected void configureShell(Shell newShell) {
313 super.configureShell(newShell);
314 newShell.setText(Messages.TraceControl_CreateSessionDialogTitle);
315 newShell.setImage(Activator.getDefault().loadIcon(CREATE_SESSION_ICON_FILE));
316 }
317
318 @Override
319 protected Control createDialogArea(Composite parent) {
320 Composite dialogAreaa = (Composite) super.createDialogArea(parent);
321 setTitle(Messages.TraceControl_CreateSessionDialogTitle);
322 setMessage(Messages.TraceControl_CreateSessionDialogMessage);
323
324 // Main dialog panel
325 fDialogComposite = new Composite(dialogAreaa, SWT.NONE);
326 GridLayout layout = new GridLayout(1, true);
327 fDialogComposite.setLayout(layout);
328 fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
329
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
334 fUpdateEnablementModifyListener = new UpdateEnablementModifyListener();
335
336 Label sessionNameLabel = new Label(sessionGroup, SWT.RIGHT);
337 sessionNameLabel.setText(Messages.TraceControl_CreateSessionNameLabel);
338 fSessionNameText = new Text(sessionGroup, SWT.NONE);
339 fSessionNameText.setToolTipText(Messages.TraceControl_CreateSessionNameTooltip);
340 fSessionNameText.addModifyListener(fUpdateEnablementModifyListener);
341 GridData data = new GridData(GridData.FILL_HORIZONTAL);
342 data.horizontalSpan = 3;
343 fSessionNameText.setLayoutData(data);
344
345 fSessionPathLabel = new Label(sessionGroup, SWT.RIGHT);
346 fSessionPathLabel.setText(Messages.TraceControl_CreateSessionPathLabel);
347 fSessionPathText = new Text(sessionGroup, SWT.NONE);
348 fSessionPathText.setToolTipText(Messages.TraceControl_CreateSessionPathTooltip);
349 data = new GridData(GridData.FILL_HORIZONTAL);
350 data.horizontalSpan = 3;
351 fSessionPathText.setLayoutData(data);
352 fSessionPathText.addModifyListener(fUpdateEnablementModifyListener);
353
354 if (fParent.isSnapshotSupported() || fParent.isLiveSupported()) {
355 fModeButtonGroup = new Group(sessionGroup, SWT.NONE);
356 data = new GridData(GridData.FILL_HORIZONTAL);
357 data.horizontalSpan = 4;
358 fModeButtonGroup.setLayoutData(data);
359 fModeButtonGroup.setLayout(new GridLayout(3, true));
360
361 SelectionAdapter modeChangedListener = new SelectionAdapter() {
362 @Override
363 public void widgetSelected(SelectionEvent e) {
364 if (fLiveButton != null) {
365 if (fLiveButton.getSelection()) {
366 createAdvancedLiveGroup();
367 updateSessionPathEnablement();
368 updateProtocolComboItems();
369 } else {
370 disposeLiveGroup();
371 updateSessionPathEnablement();
372 updateProtocolComboItems();
373 }
374 }
375 updateEnablement();
376 }
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 }
391
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 }
399
400 if (fParent.isNetworkStreamingSupported() || fParent.isLiveSupported()) {
401 createAdvancedOptionsComposite();
402 }
403
404 return fDialogComposite;
405 }
406
407 private void createAdvancedOptionsComposite() {
408
409 fAdvancedGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
410 fAdvancedGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
411 fAdvancedGroup.setLayout(new GridLayout(1, true));
412
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() {
417 @Override
418 public void widgetSelected(SelectionEvent e) {
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 }
432 } else {
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 }
444 }
445
446 updateEnablement();
447 getShell().pack();
448 }
449 });
450 }
451
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
495 private void createConfigureStreamingComposite() {
496 if (fStreamingComposite == null) {
497 fStreamingComposite = new Group(fAdvancedGroup, SWT.SHADOW_NONE);
498 GridLayout layout = new GridLayout(1, true);
499 fStreamingComposite.setLayout(layout);
500 fStreamingComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
501
502 layout = new GridLayout(7, true);
503 fStreamingComposite.setLayout(layout);
504 fStreamingComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
505
506 Label tracePathLabel = new Label(fStreamingComposite, SWT.RIGHT);
507 tracePathLabel.setText(Messages.TraceControl_CreateSessionTracePathText);
508 fTracePathText = new Text(fStreamingComposite, SWT.NONE);
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);
515 fTracePathText.addModifyListener(fUpdateEnablementModifyListener);
516
517 fLinkDataWithControlButton = new Button(fStreamingComposite, SWT.CHECK);
518 fLinkDataWithControlButton.setText(Messages.TraceControl_CreateSessionLinkButtonText);
519 fLinkDataWithControlButton.setToolTipText(Messages.TraceControl_CreateSessionLinkButtonTooltip);
520 data = new GridData(GridData.FILL_HORIZONTAL);
521 data.horizontalSpan = 7;
522 fLinkDataWithControlButton.setLayoutData(data);
523 fLinkDataWithControlButton.setSelection(true);
524
525 Label label = new Label(fStreamingComposite, SWT.NONE);
526 data = new GridData(GridData.FILL_HORIZONTAL);
527 data.horizontalSpan = 1;
528 label.setLayoutData(data);
529
530 label = new Label(fStreamingComposite, SWT.NONE);
531 label.setText(Messages.TraceControl_CreateSessionProtocolLabelText);
532 data = new GridData(GridData.FILL_HORIZONTAL);
533 data.horizontalSpan = 1;
534 label.setLayoutData(data);
535
536 label = new Label(fStreamingComposite, SWT.NONE);
537 label.setText(Messages.TraceControl_CreateSessionAddressLabelText);
538 data = new GridData(GridData.FILL_HORIZONTAL);
539 data.horizontalSpan = 4;
540 label.setLayoutData(data);
541
542 label = new Label(fStreamingComposite, SWT.NONE);
543 label.setText(Messages.TraceControl_CreateSessionPortLabelText);
544 data = new GridData(GridData.FILL_HORIZONTAL);
545 data.horizontalSpan = 1;
546 label.setLayoutData(data);
547
548 label = new Label(fStreamingComposite, SWT.RIGHT);
549 label.setText(Messages.TraceControl_CreateSessionControlUrlLabel);
550 data = new GridData(GridData.FILL_HORIZONTAL);
551 data.horizontalSpan = 1;
552 label.setLayoutData(data);
553
554 fControlProtocolCombo = new CCombo(fStreamingComposite, SWT.READ_ONLY);
555 fControlProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionCommonProtocolTooltip);
556 data = new GridData(GridData.FILL_HORIZONTAL);
557 data.horizontalSpan = 1;
558 fControlProtocolCombo.setLayoutData(data);
559 fControlProtocolCombo.addModifyListener(fUpdateEnablementModifyListener);
560
561 fControlHostAddressText = new Text(fStreamingComposite, SWT.NONE);
562 fControlHostAddressText.setToolTipText(Messages.TraceControl_CreateSessionControlAddressTooltip);
563 data = new GridData(GridData.FILL_HORIZONTAL);
564 data.horizontalSpan = 4;
565 fControlHostAddressText.setLayoutData(data);
566 fControlHostAddressText.addModifyListener(fUpdateEnablementModifyListener);
567
568 fControlPortText = new Text(fStreamingComposite, SWT.NONE);
569 fControlPortText.setToolTipText(Messages.TraceControl_CreateSessionControlPortTooltip);
570 data = new GridData(GridData.FILL_HORIZONTAL);
571 data.horizontalSpan = 1;
572 fControlPortText.setLayoutData(data);
573 fControlPortText.addModifyListener(fUpdateEnablementModifyListener);
574
575 label = new Label(fStreamingComposite, SWT.RIGHT);
576 label.setText(Messages.TraceControl_CreateSessionDataUrlLabel);
577 data = new GridData(GridData.FILL_HORIZONTAL);
578 data.horizontalSpan = 1;
579 label.setLayoutData(data);
580
581 fDataProtocolCombo = new CCombo(fStreamingComposite, SWT.READ_ONLY);
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);
587 fDataProtocolCombo.addModifyListener(fUpdateEnablementModifyListener);
588
589 updateProtocolComboItems();
590
591 fDataHostAddressText = new Text(fStreamingComposite, SWT.NONE);
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);
597 fDataHostAddressText.addModifyListener(fUpdateEnablementModifyListener);
598
599 fDataPortText = new Text(fStreamingComposite, SWT.NONE);
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);
605 fDataPortText.addModifyListener(fUpdateEnablementModifyListener);
606
607 fCopyProtocolSelectionListener = new ControlProtocolSelectionListener();
608 fControlProtocolSelectionListener = new ProtocolComboSelectionListener(fControlProtocolCombo, fControlPortText);
609 fDataProtocolSelectionListener = new ProtocolComboSelectionListener(fDataProtocolCombo, fDataPortText);
610
611 fControlProtocolCombo.addSelectionListener(fCopyProtocolSelectionListener);
612
613 fControlUrlKeyListener = new CopyModifyListener(fControlHostAddressText, fDataHostAddressText);
614 fControlHostAddressText.addModifyListener(fControlUrlKeyListener);
615
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);
633 fControlHostAddressText.addModifyListener(fControlUrlKeyListener);
634
635 updateProtocolComboItems();
636
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);
650 fControlHostAddressText.removeModifyListener(fControlUrlKeyListener);
651
652 updateProtocolComboItems();
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
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
748 private void disposeConfigureStreamingComposite() {
749 if (fStreamingComposite != null) {
750 fStreamingComposite.dispose();
751 fStreamingComposite = null;
752 }
753 }
754
755 @Override
756 protected void createButtonsForButtonBar(Composite parent) {
757 createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$
758 createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$
759 }
760
761 private void updateEnablement() {
762 validate();
763 getButton(IDialogConstants.OK_ID).setEnabled(getErrorMessage() == null);
764 }
765
766 private void validate() {
767 // Validate input data
768 fSessionName = fSessionNameText.getText();
769 fSessionPath = fSessionPathText.getText();
770 setErrorMessage(null);
771
772 if (fParent.isLiveSupported() && fLiveButton != null) {
773 fIsLive = fLiveButton.getSelection();
774 fLiveDelay = LTTngControlServiceConstants.UNUSED_VALUE;
775 }
776
777 if (!"".equals(fSessionPath)) { //$NON-NLS-1$
778 // validate sessionPath
779 if (!fIsAdvancedEnabled && !fIsLive) {
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());
786
787 if (remoteFolder == null) {
788 setErrorMessage(Messages.TraceControl_InvalidSessionPathError + " (" + fSessionPath + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
789 return;
790 }
791
792 if (remoteFolder.exists()) {
793 setErrorMessage(Messages.TraceControl_SessionPathAlreadyExistsError + " (" + fSessionPath + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
794 return;
795 }
796 } catch (SystemMessageException e) {
797 setErrorMessage(Messages.TraceControl_FileSubSystemError + "\n" + e); //$NON-NLS-1$
798 return;
799 }
800 }
801 }
802 fIsDefaultPath = false;
803 }
804
805 if (fParent.isSnapshotSupported()) {
806 fIsSnapshot = fSnapshotButton.getSelection();
807 }
808
809 fNetworkUrl = null;
810 fControlUrl = null;
811 fDataUrl = null;
812
813 if (fIsAdvancedEnabled && fStreamingComposite != null) {
814 // Validate input data
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
826 fTracePath = fTracePathText.getText();
827
828 if (fControlProtocolCombo.getSelectionIndex() < 0) {
829 setErrorMessage("Control Protocol Text is empty\n"); //$NON-NLS-1$
830 return;
831 }
832
833 if ("".equals(fControlHostAddressText.getText())) { //$NON-NLS-1$
834 setErrorMessage("Control Address Text is empty\n"); //$NON-NLS-1$
835 return;
836 }
837
838 if (!fLinkDataWithControlButton.getSelection()) {
839 if (fDataProtocolCombo.getSelectionIndex() < 0) {
840 setErrorMessage("Data Protocol Text is empty\n"); //$NON-NLS-1$
841 return;
842 }
843
844 if ("".equals(fDataHostAddressText.getText())) { //$NON-NLS-1$
845 setErrorMessage("Data Address Text is empty\n"); //$NON-NLS-1$
846 return;
847 }
848
849 fControlUrl = getUrlString(fControlProtocolCombo.getItem(fControlProtocolCombo.getSelectionIndex()),
850 fControlHostAddressText.getText(),
851 fControlPortText.getText(),
852 null,
853 fTracePath);
854
855 fDataUrl = getUrlString(fDataProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()),
856 fDataHostAddressText.getText(),
857 null,
858 fDataPortText.getText(),
859 fTracePath);
860 } else {
861 fNetworkUrl = getUrlString(fControlProtocolCombo.getItem(fControlProtocolCombo.getSelectionIndex()),
862 fControlHostAddressText.getText(),
863 fControlPortText.getText(),
864 fDataPortText.getText(),
865 fTracePath);
866 }
867 }
868
869 if (fIsLive && fNetworkUrl == null && fControlUrl == null && fDataUrl == null) {
870 fNetworkUrl = SessionInfo.DEFAULT_LIVE_NETWORK_URK;
871 }
872
873 // Check for invalid names
874 if (!"".equals(fSessionName) && !fSessionName.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$
875 setErrorMessage(Messages.TraceControl_InvalidSessionNameError + " (" + fSessionName + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
876 return;
877 }
878
879 // Check if node with name already exists in parent
880 if(fParent.containsChild(fSessionName)) {
881 setErrorMessage(Messages.TraceControl_SessionAlreadyExistsError + " (" + fSessionName + ")"); //$NON-NLS-1$ //$NON-NLS-2$
882 return;
883 }
884 }
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
910 private static class CopyModifyListener implements ModifyListener {
911 private Text fSource;
912 private Text fDestination;
913
914 public CopyModifyListener(Text source, Text destination) {
915 fSource = source;
916 fDestination = destination;
917 }
918
919 @Override
920 public void modifyText(ModifyEvent e) {
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
964 @Override
965 public ISessionInfo getParameters() {
966 ISessionInfo sessionInfo = new SessionInfo(fSessionName);
967
968 boolean isStreaming = (fIsAdvancedEnabled && fStreamingComposite != null) || fIsLive;
969 if (isStreaming) {
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
978 sessionInfo.setLive(fIsLive);
979 sessionInfo.setLiveDelay(fLiveDelay);
980 sessionInfo.setSnapshot(fIsSnapshot);
981
982 return sessionInfo;
983 }
984
985 private final class UpdateEnablementModifyListener implements ModifyListener {
986 @Override
987 public void modifyText(ModifyEvent e) {
988 updateEnablement();
989 }
990 }
991 }
This page took 0.066325 seconds and 6 git commands to generate.