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