Update to session creation procedure
[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.ModifyEvent;
30 import org.eclipse.swt.events.ModifyListener;
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 label widget for the session path.
108 */
109 private Label fSessionPathLabel = null;
110 /**
111 * The text widget for the session path.
112 */
113 private Text fSessionPathText = null;
114 /**
115 * The Group for stream configuration.
116 */
117 private Group fMainStreamingGroup = null;
118 /**
119 * The button to show streaming options.
120 */
121 private Button fConfigureStreamingButton = null;
122 /**
123 * The composite with streaming configuration parameter.
124 */
125 private Composite fStreamingComposite = null;
126 /**
127 * The text widget for the trace path.
128 */
129 private Text fTracePathText = null;
130 /**
131 * The button to link data protocol/Address with control protocol.
132 */
133 private Button fLinkDataWithControlButton = null;
134 /**
135 * The Combo box for channel protocol selection.
136 */
137 private CCombo fControlProtocolCombo = null;
138 /**
139 * A selection listener that copies the protocol from control to data when being linked.
140 */
141 private ControlProtocolSelectionListener fCopyProtocolSelectionListener;
142 /**
143 * A selection listener updates the control port text depending on the control protocol selected.
144 */
145 private ProtocolComboSelectionListener fControlProtocolSelectionListener;
146 /**
147 * A selection listener updates the data port text depending on the data protocol selected.
148 */
149 private ProtocolComboSelectionListener fDataProtocolSelectionListener;
150 /**
151 * The text box for the host/IP address of the control channel.
152 */
153 private Text fControlHostAddressText = null;
154 /**
155 * A key listener that copies the host address from control to data when being linked.
156 */
157 private CopyModifyListener fControlUrlKeyListener;
158 /**
159 * The text box for the control port.
160 */
161 private Text fControlPortText = null;
162 /**
163 * The Combo box for data protocol selection.
164 */
165 private CCombo fDataProtocolCombo = null;
166 /**
167 * The text box for the host/IP address of the data channel.
168 */
169 private Text fDataHostAddressText = null;
170 /**
171 * The text box for the data port.
172 */
173 private Text fDataPortText = null;
174 /**
175 * The parent where the new node should be added.
176 */
177 private TraceSessionGroup fParent = null;
178 /**
179 * The session name string.
180 */
181 private String fSessionName = null;
182 /**
183 * The session path string.
184 */
185 private String fSessionPath = null;
186 /**
187 * Flag whether default location (path) shall be used or not
188 */
189 private boolean fIsDefaultPath = true;
190 /**
191 * Flag whether the trace is streamed or not
192 */
193 private boolean fIsStreamedTrace = false;
194 /**
195 * The network URL in case control and data is configured together.
196 * If set, fControlUrl and fDataUrl will be null.
197 */
198 private String fNetworkUrl = null;
199 /**
200 * The control URL in case control and data is configured separately.
201 * If set, fDataUrl will be set too and fNetworkUrl will be null.
202 */
203 private String fControlUrl = null;
204 /**
205 * The data URL in case control and data is configured separately.
206 * If set, fControlUrl will be set too and fNetworkUrl will be null.
207 */
208 private String fDataUrl = null;
209 /**
210 * The trace path string.
211 */
212 private String fTracePath = null;
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 }
272
273 @Override
274 public boolean isStreamedTrace() {
275 return fIsStreamedTrace;
276 }
277 @Override
278 public String getNetworkUrl() {
279 return fNetworkUrl;
280 }
281 @Override
282 public String getControlUrl() {
283 return fControlUrl;
284 }
285 @Override
286 public String getDataUrl() {
287 return fDataUrl;
288 }
289
290 // ------------------------------------------------------------------------
291 // Operations
292 // ------------------------------------------------------------------------
293
294
295 /* (non-Javadoc)
296 * @see org.eclipse.jface.dialogs.Dialog#createContents(org.eclipse.swt.widgets.Composite)
297 */
298 @Override
299 protected Control createContents(Composite parent) {
300 fControl = super.createContents(parent);
301
302 /* set the shell minimum size */
303 Point clientArea = fControl.computeSize(SWT.DEFAULT, SWT.DEFAULT);
304 Rectangle trim = getShell().computeTrim(0, 0, clientArea.x, clientArea.y);
305 getShell().setMinimumSize(trim.width, trim.height);
306
307 return fControl;
308 }
309 /*
310 * (non-Javadoc)
311 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
312 */
313 @Override
314 protected void configureShell(Shell newShell) {
315 super.configureShell(newShell);
316 newShell.setText(Messages.TraceControl_CreateSessionDialogTitle);
317 newShell.setImage(Activator.getDefault().loadIcon(CREATE_SESSION_ICON_FILE));
318 }
319
320 /*
321 * (non-Javadoc)
322 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
323 */
324 @Override
325 protected Control createDialogArea(Composite parent) {
326
327 // Main dialog panel
328 fDialogComposite = new Composite(parent, SWT.NONE);
329 GridLayout layout = new GridLayout(1, true);
330 fDialogComposite.setLayout(layout);
331 fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
332
333 Group sessionGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
334 sessionGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
335 sessionGroup.setLayout(new GridLayout(4, true));
336
337 Label sessionNameLabel = new Label(sessionGroup, SWT.RIGHT);
338 sessionNameLabel.setText(Messages.TraceControl_CreateSessionNameLabel);
339 fSessionNameText = new Text(sessionGroup, SWT.NONE);
340 fSessionNameText.setToolTipText(Messages.TraceControl_CreateSessionNameTooltip);
341
342 fSessionPathLabel = new Label(sessionGroup, SWT.RIGHT);
343 fSessionPathLabel.setText(Messages.TraceControl_CreateSessionPathLabel);
344 fSessionPathText = new Text(sessionGroup, SWT.NONE);
345 fSessionPathText.setToolTipText(Messages.TraceControl_CreateSessionPathTooltip);
346
347 // layout widgets
348 GridData data = new GridData(GridData.FILL_HORIZONTAL);
349 data.horizontalSpan = 3;
350
351 fSessionNameText.setLayoutData(data);
352
353 data = new GridData(GridData.FILL_HORIZONTAL);
354 data.horizontalSpan = 3;
355 fSessionPathText.setLayoutData(data);
356
357 if (fParent.isNetworkStreamingSupported()) {
358 createAdvancedOptionsComposite();
359 }
360
361 return fDialogComposite;
362 }
363
364 private void createAdvancedOptionsComposite() {
365
366 fMainStreamingGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
367 fMainStreamingGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
368 fMainStreamingGroup.setLayout(new GridLayout(1, true));
369
370 fConfigureStreamingButton = new Button(fMainStreamingGroup, SWT.PUSH);
371 fConfigureStreamingButton.setText(Messages.TraceControl_CreateSessionConfigureStreamingButtonText + " >>>"); //$NON-NLS-1$
372 fConfigureStreamingButton.setToolTipText(Messages.TraceControl_CreateSessionConfigureStreamingButtonTooltip);
373 fConfigureStreamingButton.addSelectionListener(new SelectionAdapter() {
374 @Override
375 public void widgetSelected(SelectionEvent e) {
376 if (fIsStreamedTrace) {
377 fIsStreamedTrace = false;
378 fConfigureStreamingButton.setText(">>> " + Messages.TraceControl_CreateSessionConfigureStreamingButtonText); //$NON-NLS-1$
379 fConfigureStreamingButton.setToolTipText(Messages.TraceControl_CreateSessionConfigureStreamingButtonTooltip);
380 fSessionPathText.setEnabled(true);
381 fSessionPathLabel.setText(Messages.TraceControl_CreateSessionPathLabel);
382 disposeConfigureStreamingComposite();
383 } else {
384 fIsStreamedTrace = true;
385 fConfigureStreamingButton.setText("<<< " + Messages.TraceControl_CreateSessionNoStreamingButtonText); //$NON-NLS-1$
386 fConfigureStreamingButton.setToolTipText(Messages.TraceControl_CreateSessionNoStreamingButtonTooltip);
387 fSessionPathText.setEnabled(false);
388 fSessionPathText.setText(""); //$NON-NLS-1$
389 fSessionPathLabel.setText(""); //$NON-NLS-1$
390 createConfigureStreamingComposite();
391 }
392
393 fDialogComposite.layout();
394
395 Point clientArea = fControl.computeSize(SWT.DEFAULT, SWT.DEFAULT);
396 Rectangle trim = getShell().computeTrim(0, 0, clientArea.x, clientArea.y);
397 getShell().setSize(trim.width, trim.height);
398 }
399 });
400 }
401
402 private void createConfigureStreamingComposite() {
403 if (fStreamingComposite == null) {
404 fStreamingComposite = new Composite(fMainStreamingGroup, SWT.NONE);
405 GridLayout layout = new GridLayout(1, true);
406 fStreamingComposite.setLayout(layout);
407 fStreamingComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
408
409 Group urlGroup = new Group(fStreamingComposite, SWT.SHADOW_NONE);
410 layout = new GridLayout(7, true);
411 urlGroup.setLayout(layout);
412 urlGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
413
414 Label tracePathLabel = new Label(urlGroup, SWT.RIGHT);
415 tracePathLabel.setText(Messages.TraceControl_CreateSessionTracePathText);
416 fTracePathText = new Text(urlGroup, SWT.NONE);
417 fTracePathText.setToolTipText(Messages.TraceControl_CreateSessionTracePathTooltip);
418
419 // layout widgets
420 GridData data = new GridData(GridData.FILL_HORIZONTAL);
421 data.horizontalSpan = 6;
422 fTracePathText.setLayoutData(data);
423
424 fLinkDataWithControlButton = new Button(urlGroup, SWT.CHECK);
425 fLinkDataWithControlButton.setText(Messages.TraceControl_CreateSessionLinkButtonText);
426 fLinkDataWithControlButton.setToolTipText(Messages.TraceControl_CreateSessionLinkButtonTooltip);
427 data = new GridData(GridData.FILL_HORIZONTAL);
428 data.horizontalSpan = 7;
429 fLinkDataWithControlButton.setLayoutData(data);
430 fLinkDataWithControlButton.setSelection(true);
431
432 Label label = new Label(urlGroup, SWT.NONE);
433 data = new GridData(GridData.FILL_HORIZONTAL);
434 data.horizontalSpan = 1;
435 label.setLayoutData(data);
436
437 label = new Label(urlGroup, SWT.NONE);
438 label.setText(Messages.TraceControl_CreateSessionProtocolLabelText);
439 data = new GridData(GridData.FILL_HORIZONTAL);
440 data.horizontalSpan = 1;
441 label.setLayoutData(data);
442
443 label = new Label(urlGroup, SWT.NONE);
444 label.setText(Messages.TraceControl_CreateSessionAddressLabelText);
445 data = new GridData(GridData.FILL_HORIZONTAL);
446 data.horizontalSpan = 4;
447 label.setLayoutData(data);
448
449 label = new Label(urlGroup, SWT.NONE);
450 label.setText(Messages.TraceControl_CreateSessionPortLabelText);
451 data = new GridData(GridData.FILL_HORIZONTAL);
452 data.horizontalSpan = 1;
453 label.setLayoutData(data);
454
455 label = new Label(urlGroup, SWT.RIGHT);
456 label.setText(Messages.TraceControl_CreateSessionControlUrlLabel);
457 data = new GridData(GridData.FILL_HORIZONTAL);
458 data.horizontalSpan = 1;
459 label.setLayoutData(data);
460
461 fControlProtocolCombo = new CCombo(urlGroup, SWT.READ_ONLY);
462 fControlProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionCommonProtocolTooltip);
463 data = new GridData(GridData.FILL_HORIZONTAL);
464 data.horizontalSpan = 1;
465 fControlProtocolCombo.setLayoutData(data);
466
467 fControlHostAddressText = new Text(urlGroup, SWT.NONE);
468 fControlHostAddressText.setToolTipText(Messages.TraceControl_CreateSessionControlAddressTooltip);
469 data = new GridData(GridData.FILL_HORIZONTAL);
470 data.horizontalSpan = 4;
471 fControlHostAddressText.setLayoutData(data);
472
473 fControlPortText = new Text(urlGroup, SWT.NONE);
474 fControlPortText.setToolTipText(Messages.TraceControl_CreateSessionControlPortTooltip);
475 data = new GridData(GridData.FILL_HORIZONTAL);
476 data.horizontalSpan = 1;
477 fControlPortText.setLayoutData(data);
478
479 label = new Label(urlGroup, SWT.RIGHT);
480 label.setText(Messages.TraceControl_CreateSessionDataUrlLabel);
481 data = new GridData(GridData.FILL_HORIZONTAL);
482 data.horizontalSpan = 1;
483 label.setLayoutData(data);
484
485 fDataProtocolCombo = new CCombo(urlGroup, SWT.READ_ONLY);
486 fDataProtocolCombo.setEnabled(false);
487 fDataProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionProtocolTooltip);
488 data = new GridData(GridData.FILL_HORIZONTAL);
489 data.horizontalSpan = 1;
490 fDataProtocolCombo.setLayoutData(data);
491
492 String items[] = new String[StreamingProtocol.values().length];
493 for (int i = 0; i < items.length; i++) {
494 items[i] = StreamingProtocol.values()[i].name();
495 }
496 fControlProtocolCombo.setItems(items);
497 fDataProtocolCombo.setItems(items);
498
499 fDataHostAddressText = new Text(urlGroup, SWT.NONE);
500 fDataHostAddressText.setEnabled(false);
501 fDataHostAddressText.setToolTipText(Messages.TraceControl_CreateSessionDataAddressTooltip);
502 data = new GridData(GridData.FILL_HORIZONTAL);
503 data.horizontalSpan = 4;
504 fDataHostAddressText.setLayoutData(data);
505
506 fDataPortText = new Text(urlGroup, SWT.NONE);
507 fDataPortText.setEnabled(true);
508 fDataPortText.setToolTipText(Messages.TraceControl_CreateSessionDataPortTooltip);
509 data = new GridData(GridData.FILL_HORIZONTAL);
510 data.horizontalSpan = 1;
511 fDataPortText.setLayoutData(data);
512
513 fCopyProtocolSelectionListener = new ControlProtocolSelectionListener();
514 fControlProtocolSelectionListener = new ProtocolComboSelectionListener(fControlProtocolCombo, fControlPortText);
515 fDataProtocolSelectionListener = new ProtocolComboSelectionListener(fDataProtocolCombo, fDataPortText);
516
517 fControlProtocolCombo.addSelectionListener(fCopyProtocolSelectionListener);
518
519 fControlUrlKeyListener = new CopyModifyListener(fControlHostAddressText, fDataHostAddressText);
520 fControlHostAddressText.addModifyListener(fControlUrlKeyListener);
521
522 fControlProtocolCombo.select(DEFAULT_URL_INDEX);
523 fDataProtocolCombo.select(DEFAULT_URL_INDEX);
524
525 fLinkDataWithControlButton.addSelectionListener(new SelectionAdapter() {
526 @Override
527 public void widgetSelected(SelectionEvent e) {
528 if (fLinkDataWithControlButton.getSelection()) {
529 // Set enablement control data channel inputs
530 fDataProtocolCombo.setEnabled(false);
531 fDataHostAddressText.setEnabled(false);
532 fControlPortText.setEnabled(true);
533 fDataPortText.setEnabled(true);
534
535 // Update listeners
536 fControlProtocolCombo.removeSelectionListener(fControlProtocolSelectionListener);
537 fDataProtocolCombo.removeSelectionListener(fDataProtocolSelectionListener);
538 fControlProtocolCombo.addSelectionListener(fCopyProtocolSelectionListener);
539 fControlHostAddressText.addModifyListener(fControlUrlKeyListener);
540
541 // Get previous selection and validate
542 int currentSelection = fControlProtocolCombo.getSelectionIndex() <= COMMON_URL_LAST_INDEX ?
543 fControlProtocolCombo.getSelectionIndex() : DEFAULT_URL_INDEX;
544
545 // Update combo box items
546 fControlProtocolCombo.removeAll();
547 String[] controlItems = new String[StreamingProtocol.values().length];
548 for (int i = 0; i < controlItems.length; i++) {
549 controlItems[i] = StreamingProtocol.values()[i].name();
550 }
551 fControlProtocolCombo.setItems(controlItems);
552 fDataProtocolCombo.setItems(controlItems);
553
554 // Set selection
555 fControlProtocolCombo.select(currentSelection);
556 fDataProtocolCombo.select(currentSelection);
557 fDataHostAddressText.setText(fControlHostAddressText.getText());
558
559 // Update tool tips
560 fControlProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionCommonProtocolTooltip);
561 } else {
562 // Enable data channel inputs
563 fDataProtocolCombo.setEnabled(true);
564 fDataHostAddressText.setEnabled(true);
565
566 // Update listeners
567 fControlProtocolCombo.removeSelectionListener(fCopyProtocolSelectionListener);
568 fControlProtocolCombo.addSelectionListener(fControlProtocolSelectionListener);
569 fDataProtocolCombo.addSelectionListener(fDataProtocolSelectionListener);
570 fControlHostAddressText.removeModifyListener(fControlUrlKeyListener);
571
572 // Update combo box items
573 int currentSelection = fControlProtocolCombo.getSelectionIndex();
574 fControlProtocolCombo.removeAll();
575 String[] controlItems = new String[StreamingProtocol2.values().length];
576 for (int i = 0; i < controlItems.length; i++) {
577 controlItems[i] = StreamingProtocol2.values()[i].name();
578 }
579 fControlProtocolCombo.setItems(controlItems);
580 fDataProtocolCombo.setItems(controlItems);
581
582 // Set selection
583 fControlProtocolCombo.select(currentSelection);
584 fDataProtocolCombo.select(currentSelection);
585
586 // Update tool tips
587 fDataProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionProtocolTooltip);
588 fControlProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionProtocolTooltip);
589
590 // Update control/data port enablement and input
591 if (fControlProtocolCombo.getItem(fControlProtocolCombo.getSelectionIndex()).equals(StreamingProtocol.net.name()) ||
592 fControlProtocolCombo.getItem(fControlProtocolCombo.getSelectionIndex()).equals(StreamingProtocol.net6.name())) {
593 fControlPortText.setText(""); //$NON-NLS-1$
594 fControlPortText.setEnabled(false);
595 } else {
596 fControlPortText.setEnabled(true);
597 }
598
599 if (fDataProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()).equals(StreamingProtocol.net.name()) ||
600 fDataProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()).equals(StreamingProtocol.net6.name())) {
601 fDataPortText.setText(""); //$NON-NLS-1$
602 fDataPortText.setEnabled(false);
603 } else {
604 fDataPortText.setEnabled(true);
605 }
606 }
607 }
608 });
609 }
610 }
611
612 private void disposeConfigureStreamingComposite() {
613 if (fStreamingComposite != null) {
614 fStreamingComposite.dispose();
615 fStreamingComposite = null;
616 }
617 }
618
619 /*
620 * (non-Javadoc)
621 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
622 */
623 @Override
624 protected void createButtonsForButtonBar(Composite parent) {
625 createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$
626 createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$
627 }
628
629 /*
630 * (non-Javadoc)
631 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
632 */
633 @Override
634 protected void okPressed() {
635 // Validate input data
636 fSessionName = fSessionNameText.getText();
637 fSessionPath = fSessionPathText.getText();
638
639 if (!"".equals(fSessionPath)) { //$NON-NLS-1$
640 // validate sessionPath
641 if (!fIsStreamedTrace) {
642 TargetNodeComponent node = (TargetNodeComponent)fParent.getParent();
643 IRemoteSystemProxy proxy = node.getRemoteSystemProxy();
644 IFileServiceSubSystem fsss = proxy.getFileServiceSubSystem();
645 if (fsss != null) {
646 try {
647 IRemoteFile remoteFolder = fsss.getRemoteFileObject(fSessionPath, new NullProgressMonitor());
648 if (remoteFolder.exists()) {
649 MessageDialog.openError(getShell(),
650 Messages.TraceControl_CreateSessionDialogTitle,
651 Messages.TraceControl_SessionPathAlreadyExistsError + " (" + fSessionPath + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
652 return;
653 }
654 } catch (SystemMessageException e) {
655 MessageDialog.openError(getShell(),
656 Messages.TraceControl_CreateSessionDialogTitle,
657 Messages.TraceControl_FileSubSystemError + "\n" + e); //$NON-NLS-1$
658 return;
659 }
660 }
661 }
662 fIsDefaultPath = false;
663 }
664
665 fNetworkUrl = null;
666 fControlUrl = null;
667 fDataUrl = null;
668
669 if (fIsStreamedTrace) {
670 // Validate input data
671 fTracePath = fTracePathText.getText();
672
673 if (fControlProtocolCombo.getSelectionIndex() < 0) {
674 MessageDialog.openError(getShell(),
675 Messages.TraceControl_CreateSessionDialogTitle,
676 "Control Protocol Text is empty\n"); //$NON-NLS-1$
677 return;
678 }
679
680 if ("".equals(fControlHostAddressText.getText())) { //$NON-NLS-1$
681 MessageDialog.openError(getShell(),
682 Messages.TraceControl_CreateSessionDialogTitle,
683 "Control Address Text is empty\n"); //$NON-NLS-1$
684 return;
685 }
686
687 if(!fLinkDataWithControlButton.getSelection()) {
688 if (fDataProtocolCombo.getSelectionIndex() < 0) {
689 MessageDialog.openError(getShell(),
690 Messages.TraceControl_CreateSessionDialogTitle,
691 "Control Protocol Text is empty\n"); //$NON-NLS-1$
692 return;
693 }
694
695 if ("".equals(fDataHostAddressText.getText())) { //$NON-NLS-1$
696 MessageDialog.openError(getShell(),
697 Messages.TraceControl_CreateSessionDialogTitle,
698 "Control Address Text is empty\n"); //$NON-NLS-1$
699 return;
700 }
701
702 fControlUrl = getUrlString(fControlProtocolCombo.getItem(fControlProtocolCombo.getSelectionIndex()),
703 fControlHostAddressText.getText(),
704 fControlPortText.getText(),
705 null,
706 fTracePath);
707
708 fDataUrl = getUrlString(fControlProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()),
709 fDataHostAddressText.getText(),
710 null,
711 fDataPortText.getText(),
712 fTracePath);
713 } else {
714 fNetworkUrl = getUrlString(fControlProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()),
715 fControlHostAddressText.getText(),
716 fControlPortText.getText(),
717 fDataPortText.getText(),
718 fTracePath);
719 }
720 }
721
722 // Check for invalid names
723 if (!"".equals(fSessionName) && !fSessionName.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$
724 MessageDialog.openError(getShell(),
725 Messages.TraceControl_CreateSessionDialogTitle,
726 Messages.TraceControl_InvalidSessionNameError + " (" + fSessionName + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
727 return;
728 }
729
730 // Check if node with name already exists in parent
731 if(fParent.containsChild(fSessionName)) {
732 MessageDialog.openError(getShell(),
733 Messages.TraceControl_CreateSessionDialogTitle,
734 Messages.TraceControl_SessionAlreadyExistsError + " (" + fSessionName + ")"); //$NON-NLS-1$ //$NON-NLS-2$
735 return;
736 }
737
738 // validation successful -> call super.okPressed()
739 super.okPressed();
740 }
741
742 private static String getUrlString(String proto, String host, String ctrlPort, String dataPort, String sessionPath) {
743 //proto://[HOST|IP][:PORT1[:PORT2]][/TRACE_PATH]
744 StringBuilder stringBuilder = new StringBuilder();
745 stringBuilder.append(proto);
746 stringBuilder.append("://"); //$NON-NLS-1$
747 stringBuilder.append(host);
748
749 if ((ctrlPort != null) && (!"".equals(ctrlPort))) { //$NON-NLS-1$
750 stringBuilder.append(":"); //$NON-NLS-1$
751 stringBuilder.append(ctrlPort);
752 }
753
754 if ((dataPort != null) && (!"".equals(dataPort))) { //$NON-NLS-1$
755 stringBuilder.append(":"); //$NON-NLS-1$
756 stringBuilder.append(dataPort);
757 }
758
759 if ((sessionPath != null) && (!"".equals(sessionPath))) { //$NON-NLS-1$
760 stringBuilder.append("/"); //$NON-NLS-1$
761 stringBuilder.append(sessionPath);
762 }
763 return stringBuilder.toString();
764 }
765
766 private static class CopyModifyListener implements ModifyListener {
767 private Text fSource;
768 private Text fDestination;
769
770 public CopyModifyListener(Text source, Text destination) {
771 fSource = source;
772 fDestination = destination;
773 }
774
775 @Override
776 public void modifyText(ModifyEvent e) {
777 fDestination.setText(fSource.getText());
778 }
779 }
780
781 private class ControlProtocolSelectionListener extends SelectionAdapter {
782
783 @Override
784 public void widgetSelected(SelectionEvent e) {
785 fDataProtocolCombo.select(fControlProtocolCombo.getSelectionIndex());
786 if (fControlProtocolCombo.getItem(fControlProtocolCombo.getSelectionIndex()).equals(StreamingProtocol.file.name())) {
787 fControlPortText.setText(""); //$NON-NLS-1$
788 fDataPortText.setText(""); //$NON-NLS-1$
789 fControlPortText.setEnabled(false);
790 fDataPortText.setEnabled(false);
791 } else {
792 fControlPortText.setEnabled(true);
793 fDataPortText.setEnabled(true);
794 }
795 }
796 }
797
798 private class ProtocolComboSelectionListener extends SelectionAdapter {
799
800 private CCombo fCombo;
801 private Text fPortText;
802
803 public ProtocolComboSelectionListener(CCombo combo, Text portText) {
804 fCombo = combo;
805 fPortText = portText;
806 }
807
808 @Override
809 public void widgetSelected(SelectionEvent e) {
810 if (fCombo.getItem(fCombo.getSelectionIndex()).equals(StreamingProtocol.net.name()) ||
811 fCombo.getItem(fCombo.getSelectionIndex()).equals(StreamingProtocol.net6.name())) {
812 fPortText.setText(""); //$NON-NLS-1$
813 fPortText.setEnabled(false);
814 } else {
815 fPortText.setEnabled(true);
816 }
817 }
818 }
819
820 }
This page took 0.074936 seconds and 6 git commands to generate.