tmf/lttng: Remove unneeded (non-Javadoc) comments
[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 @Override
231 public String getSessionName() {
232 return fSessionName;
233 }
234
235 @Override
236 public String getSessionPath() {
237 return fSessionPath;
238 }
239
240 @Override
241 public boolean isDefaultSessionPath() {
242 return fIsDefaultPath;
243 }
244
245 @Override
246 public void initialize(TraceSessionGroup group) {
247 fParent = group;
248 fStreamingComposite = null;
249 fSessionName = null;
250 fSessionPath = null;
251 fIsDefaultPath = true;
252 fIsStreamedTrace = false;
253 fNetworkUrl = null;
254 fControlUrl = null;
255 fDataUrl = null;
256 }
257
258 @Override
259 public boolean isStreamedTrace() {
260 return fIsStreamedTrace;
261 }
262 @Override
263 public String getNetworkUrl() {
264 return fNetworkUrl;
265 }
266 @Override
267 public String getControlUrl() {
268 return fControlUrl;
269 }
270 @Override
271 public String getDataUrl() {
272 return fDataUrl;
273 }
274
275 // ------------------------------------------------------------------------
276 // Operations
277 // ------------------------------------------------------------------------
278
279 @Override
280 protected Control createContents(Composite parent) {
281 fControl = super.createContents(parent);
282
283 /* set the shell minimum size */
284 Point clientArea = fControl.computeSize(SWT.DEFAULT, SWT.DEFAULT);
285 Rectangle trim = getShell().computeTrim(0, 0, clientArea.x, clientArea.y);
286 getShell().setMinimumSize(trim.width, trim.height);
287
288 return fControl;
289 }
290
291 @Override
292 protected void configureShell(Shell newShell) {
293 super.configureShell(newShell);
294 newShell.setText(Messages.TraceControl_CreateSessionDialogTitle);
295 newShell.setImage(Activator.getDefault().loadIcon(CREATE_SESSION_ICON_FILE));
296 }
297
298 @Override
299 protected Control createDialogArea(Composite parent) {
300
301 // Main dialog panel
302 fDialogComposite = new Composite(parent, SWT.NONE);
303 GridLayout layout = new GridLayout(1, true);
304 fDialogComposite.setLayout(layout);
305 fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
306
307 Group sessionGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
308 sessionGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
309 sessionGroup.setLayout(new GridLayout(4, true));
310
311 Label sessionNameLabel = new Label(sessionGroup, SWT.RIGHT);
312 sessionNameLabel.setText(Messages.TraceControl_CreateSessionNameLabel);
313 fSessionNameText = new Text(sessionGroup, SWT.NONE);
314 fSessionNameText.setToolTipText(Messages.TraceControl_CreateSessionNameTooltip);
315
316 fSessionPathLabel = new Label(sessionGroup, SWT.RIGHT);
317 fSessionPathLabel.setText(Messages.TraceControl_CreateSessionPathLabel);
318 fSessionPathText = new Text(sessionGroup, SWT.NONE);
319 fSessionPathText.setToolTipText(Messages.TraceControl_CreateSessionPathTooltip);
320
321 // layout widgets
322 GridData data = new GridData(GridData.FILL_HORIZONTAL);
323 data.horizontalSpan = 3;
324
325 fSessionNameText.setLayoutData(data);
326
327 data = new GridData(GridData.FILL_HORIZONTAL);
328 data.horizontalSpan = 3;
329 fSessionPathText.setLayoutData(data);
330
331 if (fParent.isNetworkStreamingSupported()) {
332 createAdvancedOptionsComposite();
333 }
334
335 return fDialogComposite;
336 }
337
338 private void createAdvancedOptionsComposite() {
339
340 fMainStreamingGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
341 fMainStreamingGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
342 fMainStreamingGroup.setLayout(new GridLayout(1, true));
343
344 fConfigureStreamingButton = new Button(fMainStreamingGroup, SWT.PUSH);
345 fConfigureStreamingButton.setText(Messages.TraceControl_CreateSessionConfigureStreamingButtonText + " >>>"); //$NON-NLS-1$
346 fConfigureStreamingButton.setToolTipText(Messages.TraceControl_CreateSessionConfigureStreamingButtonTooltip);
347 fConfigureStreamingButton.addSelectionListener(new SelectionAdapter() {
348 @Override
349 public void widgetSelected(SelectionEvent e) {
350 if (fIsStreamedTrace) {
351 fIsStreamedTrace = false;
352 fConfigureStreamingButton.setText(">>> " + Messages.TraceControl_CreateSessionConfigureStreamingButtonText); //$NON-NLS-1$
353 fConfigureStreamingButton.setToolTipText(Messages.TraceControl_CreateSessionConfigureStreamingButtonTooltip);
354 fSessionPathText.setEnabled(true);
355 fSessionPathLabel.setText(Messages.TraceControl_CreateSessionPathLabel);
356 disposeConfigureStreamingComposite();
357 } else {
358 fIsStreamedTrace = true;
359 fConfigureStreamingButton.setText("<<< " + Messages.TraceControl_CreateSessionNoStreamingButtonText); //$NON-NLS-1$
360 fConfigureStreamingButton.setToolTipText(Messages.TraceControl_CreateSessionNoStreamingButtonTooltip);
361 fSessionPathText.setEnabled(false);
362 fSessionPathText.setText(""); //$NON-NLS-1$
363 fSessionPathLabel.setText(""); //$NON-NLS-1$
364 createConfigureStreamingComposite();
365 }
366
367 fDialogComposite.layout();
368
369 Point clientArea = fControl.computeSize(SWT.DEFAULT, SWT.DEFAULT);
370 Rectangle trim = getShell().computeTrim(0, 0, clientArea.x, clientArea.y);
371 getShell().setSize(trim.width, trim.height);
372 }
373 });
374 }
375
376 private void createConfigureStreamingComposite() {
377 if (fStreamingComposite == null) {
378 fStreamingComposite = new Composite(fMainStreamingGroup, SWT.NONE);
379 GridLayout layout = new GridLayout(1, true);
380 fStreamingComposite.setLayout(layout);
381 fStreamingComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
382
383 Group urlGroup = new Group(fStreamingComposite, SWT.SHADOW_NONE);
384 layout = new GridLayout(7, true);
385 urlGroup.setLayout(layout);
386 urlGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
387
388 Label tracePathLabel = new Label(urlGroup, SWT.RIGHT);
389 tracePathLabel.setText(Messages.TraceControl_CreateSessionTracePathText);
390 fTracePathText = new Text(urlGroup, SWT.NONE);
391 fTracePathText.setToolTipText(Messages.TraceControl_CreateSessionTracePathTooltip);
392
393 // layout widgets
394 GridData data = new GridData(GridData.FILL_HORIZONTAL);
395 data.horizontalSpan = 6;
396 fTracePathText.setLayoutData(data);
397
398 fLinkDataWithControlButton = new Button(urlGroup, SWT.CHECK);
399 fLinkDataWithControlButton.setText(Messages.TraceControl_CreateSessionLinkButtonText);
400 fLinkDataWithControlButton.setToolTipText(Messages.TraceControl_CreateSessionLinkButtonTooltip);
401 data = new GridData(GridData.FILL_HORIZONTAL);
402 data.horizontalSpan = 7;
403 fLinkDataWithControlButton.setLayoutData(data);
404 fLinkDataWithControlButton.setSelection(true);
405
406 Label label = new Label(urlGroup, SWT.NONE);
407 data = new GridData(GridData.FILL_HORIZONTAL);
408 data.horizontalSpan = 1;
409 label.setLayoutData(data);
410
411 label = new Label(urlGroup, SWT.NONE);
412 label.setText(Messages.TraceControl_CreateSessionProtocolLabelText);
413 data = new GridData(GridData.FILL_HORIZONTAL);
414 data.horizontalSpan = 1;
415 label.setLayoutData(data);
416
417 label = new Label(urlGroup, SWT.NONE);
418 label.setText(Messages.TraceControl_CreateSessionAddressLabelText);
419 data = new GridData(GridData.FILL_HORIZONTAL);
420 data.horizontalSpan = 4;
421 label.setLayoutData(data);
422
423 label = new Label(urlGroup, SWT.NONE);
424 label.setText(Messages.TraceControl_CreateSessionPortLabelText);
425 data = new GridData(GridData.FILL_HORIZONTAL);
426 data.horizontalSpan = 1;
427 label.setLayoutData(data);
428
429 label = new Label(urlGroup, SWT.RIGHT);
430 label.setText(Messages.TraceControl_CreateSessionControlUrlLabel);
431 data = new GridData(GridData.FILL_HORIZONTAL);
432 data.horizontalSpan = 1;
433 label.setLayoutData(data);
434
435 fControlProtocolCombo = new CCombo(urlGroup, SWT.READ_ONLY);
436 fControlProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionCommonProtocolTooltip);
437 data = new GridData(GridData.FILL_HORIZONTAL);
438 data.horizontalSpan = 1;
439 fControlProtocolCombo.setLayoutData(data);
440
441 fControlHostAddressText = new Text(urlGroup, SWT.NONE);
442 fControlHostAddressText.setToolTipText(Messages.TraceControl_CreateSessionControlAddressTooltip);
443 data = new GridData(GridData.FILL_HORIZONTAL);
444 data.horizontalSpan = 4;
445 fControlHostAddressText.setLayoutData(data);
446
447 fControlPortText = new Text(urlGroup, SWT.NONE);
448 fControlPortText.setToolTipText(Messages.TraceControl_CreateSessionControlPortTooltip);
449 data = new GridData(GridData.FILL_HORIZONTAL);
450 data.horizontalSpan = 1;
451 fControlPortText.setLayoutData(data);
452
453 label = new Label(urlGroup, SWT.RIGHT);
454 label.setText(Messages.TraceControl_CreateSessionDataUrlLabel);
455 data = new GridData(GridData.FILL_HORIZONTAL);
456 data.horizontalSpan = 1;
457 label.setLayoutData(data);
458
459 fDataProtocolCombo = new CCombo(urlGroup, SWT.READ_ONLY);
460 fDataProtocolCombo.setEnabled(false);
461 fDataProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionProtocolTooltip);
462 data = new GridData(GridData.FILL_HORIZONTAL);
463 data.horizontalSpan = 1;
464 fDataProtocolCombo.setLayoutData(data);
465
466 String items[] = new String[StreamingProtocol.values().length];
467 for (int i = 0; i < items.length; i++) {
468 items[i] = StreamingProtocol.values()[i].name();
469 }
470 fControlProtocolCombo.setItems(items);
471 fDataProtocolCombo.setItems(items);
472
473 fDataHostAddressText = new Text(urlGroup, SWT.NONE);
474 fDataHostAddressText.setEnabled(false);
475 fDataHostAddressText.setToolTipText(Messages.TraceControl_CreateSessionDataAddressTooltip);
476 data = new GridData(GridData.FILL_HORIZONTAL);
477 data.horizontalSpan = 4;
478 fDataHostAddressText.setLayoutData(data);
479
480 fDataPortText = new Text(urlGroup, SWT.NONE);
481 fDataPortText.setEnabled(true);
482 fDataPortText.setToolTipText(Messages.TraceControl_CreateSessionDataPortTooltip);
483 data = new GridData(GridData.FILL_HORIZONTAL);
484 data.horizontalSpan = 1;
485 fDataPortText.setLayoutData(data);
486
487 fCopyProtocolSelectionListener = new ControlProtocolSelectionListener();
488 fControlProtocolSelectionListener = new ProtocolComboSelectionListener(fControlProtocolCombo, fControlPortText);
489 fDataProtocolSelectionListener = new ProtocolComboSelectionListener(fDataProtocolCombo, fDataPortText);
490
491 fControlProtocolCombo.addSelectionListener(fCopyProtocolSelectionListener);
492
493 fControlUrlKeyListener = new CopyModifyListener(fControlHostAddressText, fDataHostAddressText);
494 fControlHostAddressText.addModifyListener(fControlUrlKeyListener);
495
496 fControlProtocolCombo.select(DEFAULT_URL_INDEX);
497 fDataProtocolCombo.select(DEFAULT_URL_INDEX);
498
499 fLinkDataWithControlButton.addSelectionListener(new SelectionAdapter() {
500 @Override
501 public void widgetSelected(SelectionEvent e) {
502 if (fLinkDataWithControlButton.getSelection()) {
503 // Set enablement control data channel inputs
504 fDataProtocolCombo.setEnabled(false);
505 fDataHostAddressText.setEnabled(false);
506 fControlPortText.setEnabled(true);
507 fDataPortText.setEnabled(true);
508
509 // Update listeners
510 fControlProtocolCombo.removeSelectionListener(fControlProtocolSelectionListener);
511 fDataProtocolCombo.removeSelectionListener(fDataProtocolSelectionListener);
512 fControlProtocolCombo.addSelectionListener(fCopyProtocolSelectionListener);
513 fControlHostAddressText.addModifyListener(fControlUrlKeyListener);
514
515 // Get previous selection and validate
516 int currentSelection = fControlProtocolCombo.getSelectionIndex() <= COMMON_URL_LAST_INDEX ?
517 fControlProtocolCombo.getSelectionIndex() : DEFAULT_URL_INDEX;
518
519 // Update combo box items
520 fControlProtocolCombo.removeAll();
521 String[] controlItems = new String[StreamingProtocol.values().length];
522 for (int i = 0; i < controlItems.length; i++) {
523 controlItems[i] = StreamingProtocol.values()[i].name();
524 }
525 fControlProtocolCombo.setItems(controlItems);
526 fDataProtocolCombo.setItems(controlItems);
527
528 // Set selection
529 fControlProtocolCombo.select(currentSelection);
530 fDataProtocolCombo.select(currentSelection);
531 fDataHostAddressText.setText(fControlHostAddressText.getText());
532
533 // Update tool tips
534 fControlProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionCommonProtocolTooltip);
535 } else {
536 // Enable data channel inputs
537 fDataProtocolCombo.setEnabled(true);
538 fDataHostAddressText.setEnabled(true);
539
540 // Update listeners
541 fControlProtocolCombo.removeSelectionListener(fCopyProtocolSelectionListener);
542 fControlProtocolCombo.addSelectionListener(fControlProtocolSelectionListener);
543 fDataProtocolCombo.addSelectionListener(fDataProtocolSelectionListener);
544 fControlHostAddressText.removeModifyListener(fControlUrlKeyListener);
545
546 // Update combo box items
547 int currentSelection = fControlProtocolCombo.getSelectionIndex();
548 fControlProtocolCombo.removeAll();
549 String[] controlItems = new String[StreamingProtocol2.values().length];
550 for (int i = 0; i < controlItems.length; i++) {
551 controlItems[i] = StreamingProtocol2.values()[i].name();
552 }
553 fControlProtocolCombo.setItems(controlItems);
554 fDataProtocolCombo.setItems(controlItems);
555
556 // Set selection
557 fControlProtocolCombo.select(currentSelection);
558 fDataProtocolCombo.select(currentSelection);
559
560 // Update tool tips
561 fDataProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionProtocolTooltip);
562 fControlProtocolCombo.setToolTipText(Messages.TraceControl_CreateSessionProtocolTooltip);
563
564 // Update control/data port enablement and input
565 if (fControlProtocolCombo.getItem(fControlProtocolCombo.getSelectionIndex()).equals(StreamingProtocol.net.name()) ||
566 fControlProtocolCombo.getItem(fControlProtocolCombo.getSelectionIndex()).equals(StreamingProtocol.net6.name())) {
567 fControlPortText.setText(""); //$NON-NLS-1$
568 fControlPortText.setEnabled(false);
569 } else {
570 fControlPortText.setEnabled(true);
571 }
572
573 if (fDataProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()).equals(StreamingProtocol.net.name()) ||
574 fDataProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()).equals(StreamingProtocol.net6.name())) {
575 fDataPortText.setText(""); //$NON-NLS-1$
576 fDataPortText.setEnabled(false);
577 } else {
578 fDataPortText.setEnabled(true);
579 }
580 }
581 }
582 });
583 }
584 }
585
586 private void disposeConfigureStreamingComposite() {
587 if (fStreamingComposite != null) {
588 fStreamingComposite.dispose();
589 fStreamingComposite = null;
590 }
591 }
592
593 @Override
594 protected void createButtonsForButtonBar(Composite parent) {
595 createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$
596 createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$
597 }
598
599 @Override
600 protected void okPressed() {
601 // Validate input data
602 fSessionName = fSessionNameText.getText();
603 fSessionPath = fSessionPathText.getText();
604
605 if (!"".equals(fSessionPath)) { //$NON-NLS-1$
606 // validate sessionPath
607 if (!fIsStreamedTrace) {
608 TargetNodeComponent node = (TargetNodeComponent)fParent.getParent();
609 IRemoteSystemProxy proxy = node.getRemoteSystemProxy();
610 IFileServiceSubSystem fsss = proxy.getFileServiceSubSystem();
611 if (fsss != null) {
612 try {
613 IRemoteFile remoteFolder = fsss.getRemoteFileObject(fSessionPath, new NullProgressMonitor());
614 if (remoteFolder.exists()) {
615 MessageDialog.openError(getShell(),
616 Messages.TraceControl_CreateSessionDialogTitle,
617 Messages.TraceControl_SessionPathAlreadyExistsError + " (" + fSessionPath + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
618 return;
619 }
620 } catch (SystemMessageException e) {
621 MessageDialog.openError(getShell(),
622 Messages.TraceControl_CreateSessionDialogTitle,
623 Messages.TraceControl_FileSubSystemError + "\n" + e); //$NON-NLS-1$
624 return;
625 }
626 }
627 }
628 fIsDefaultPath = false;
629 }
630
631 fNetworkUrl = null;
632 fControlUrl = null;
633 fDataUrl = null;
634
635 if (fIsStreamedTrace) {
636 // Validate input data
637 fTracePath = fTracePathText.getText();
638
639 if (fControlProtocolCombo.getSelectionIndex() < 0) {
640 MessageDialog.openError(getShell(),
641 Messages.TraceControl_CreateSessionDialogTitle,
642 "Control Protocol Text is empty\n"); //$NON-NLS-1$
643 return;
644 }
645
646 if ("".equals(fControlHostAddressText.getText())) { //$NON-NLS-1$
647 MessageDialog.openError(getShell(),
648 Messages.TraceControl_CreateSessionDialogTitle,
649 "Control Address Text is empty\n"); //$NON-NLS-1$
650 return;
651 }
652
653 if(!fLinkDataWithControlButton.getSelection()) {
654 if (fDataProtocolCombo.getSelectionIndex() < 0) {
655 MessageDialog.openError(getShell(),
656 Messages.TraceControl_CreateSessionDialogTitle,
657 "Control Protocol Text is empty\n"); //$NON-NLS-1$
658 return;
659 }
660
661 if ("".equals(fDataHostAddressText.getText())) { //$NON-NLS-1$
662 MessageDialog.openError(getShell(),
663 Messages.TraceControl_CreateSessionDialogTitle,
664 "Control Address Text is empty\n"); //$NON-NLS-1$
665 return;
666 }
667
668 fControlUrl = getUrlString(fControlProtocolCombo.getItem(fControlProtocolCombo.getSelectionIndex()),
669 fControlHostAddressText.getText(),
670 fControlPortText.getText(),
671 null,
672 fTracePath);
673
674 fDataUrl = getUrlString(fControlProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()),
675 fDataHostAddressText.getText(),
676 null,
677 fDataPortText.getText(),
678 fTracePath);
679 } else {
680 fNetworkUrl = getUrlString(fControlProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()),
681 fControlHostAddressText.getText(),
682 fControlPortText.getText(),
683 fDataPortText.getText(),
684 fTracePath);
685 }
686 }
687
688 // Check for invalid names
689 if (!"".equals(fSessionName) && !fSessionName.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$
690 MessageDialog.openError(getShell(),
691 Messages.TraceControl_CreateSessionDialogTitle,
692 Messages.TraceControl_InvalidSessionNameError + " (" + fSessionName + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
693 return;
694 }
695
696 // Check if node with name already exists in parent
697 if(fParent.containsChild(fSessionName)) {
698 MessageDialog.openError(getShell(),
699 Messages.TraceControl_CreateSessionDialogTitle,
700 Messages.TraceControl_SessionAlreadyExistsError + " (" + fSessionName + ")"); //$NON-NLS-1$ //$NON-NLS-2$
701 return;
702 }
703
704 // validation successful -> call super.okPressed()
705 super.okPressed();
706 }
707
708 private static String getUrlString(String proto, String host, String ctrlPort, String dataPort, String sessionPath) {
709 //proto://[HOST|IP][:PORT1[:PORT2]][/TRACE_PATH]
710 StringBuilder stringBuilder = new StringBuilder();
711 stringBuilder.append(proto);
712 stringBuilder.append("://"); //$NON-NLS-1$
713 stringBuilder.append(host);
714
715 if ((ctrlPort != null) && (!"".equals(ctrlPort))) { //$NON-NLS-1$
716 stringBuilder.append(":"); //$NON-NLS-1$
717 stringBuilder.append(ctrlPort);
718 }
719
720 if ((dataPort != null) && (!"".equals(dataPort))) { //$NON-NLS-1$
721 stringBuilder.append(":"); //$NON-NLS-1$
722 stringBuilder.append(dataPort);
723 }
724
725 if ((sessionPath != null) && (!"".equals(sessionPath))) { //$NON-NLS-1$
726 stringBuilder.append("/"); //$NON-NLS-1$
727 stringBuilder.append(sessionPath);
728 }
729 return stringBuilder.toString();
730 }
731
732 private static class CopyModifyListener implements ModifyListener {
733 private Text fSource;
734 private Text fDestination;
735
736 public CopyModifyListener(Text source, Text destination) {
737 fSource = source;
738 fDestination = destination;
739 }
740
741 @Override
742 public void modifyText(ModifyEvent e) {
743 fDestination.setText(fSource.getText());
744 }
745 }
746
747 private class ControlProtocolSelectionListener extends SelectionAdapter {
748
749 @Override
750 public void widgetSelected(SelectionEvent e) {
751 fDataProtocolCombo.select(fControlProtocolCombo.getSelectionIndex());
752 if (fControlProtocolCombo.getItem(fControlProtocolCombo.getSelectionIndex()).equals(StreamingProtocol.file.name())) {
753 fControlPortText.setText(""); //$NON-NLS-1$
754 fDataPortText.setText(""); //$NON-NLS-1$
755 fControlPortText.setEnabled(false);
756 fDataPortText.setEnabled(false);
757 } else {
758 fControlPortText.setEnabled(true);
759 fDataPortText.setEnabled(true);
760 }
761 }
762 }
763
764 private class ProtocolComboSelectionListener extends SelectionAdapter {
765
766 private CCombo fCombo;
767 private Text fPortText;
768
769 public ProtocolComboSelectionListener(CCombo combo, Text portText) {
770 fCombo = combo;
771 fPortText = portText;
772 }
773
774 @Override
775 public void widgetSelected(SelectionEvent e) {
776 if (fCombo.getItem(fCombo.getSelectionIndex()).equals(StreamingProtocol.net.name()) ||
777 fCombo.getItem(fCombo.getSelectionIndex()).equals(StreamingProtocol.net6.name())) {
778 fPortText.setText(""); //$NON-NLS-1$
779 fPortText.setEnabled(false);
780 } else {
781 fPortText.setEnabled(true);
782 }
783 }
784 }
785
786 }
This page took 0.048812 seconds and 6 git commands to generate.