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