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