Commit | Line | Data |
---|---|---|
bbb3538a | 1 | /********************************************************************** |
ba3a9bd2 | 2 | * Copyright (c) 2012, 2013 Ericsson |
f3b33d40 | 3 | * |
bbb3538a BH |
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 | |
f3b33d40 BH |
8 | * |
9 | * Contributors: | |
bbb3538a | 10 | * Bernd Hufmann - Initial API and implementation |
ba3a9bd2 | 11 | * Bernd Hufmann - Updated for support of LTTng Tools 2.1 |
bbb3538a | 12 | **********************************************************************/ |
115b4a01 | 13 | package org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs; |
bbb3538a BH |
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; | |
115b4a01 | 19 | import org.eclipse.linuxtools.internal.lttng2.ui.Activator; |
9315aeee | 20 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages; |
115b4a01 BH |
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; | |
bbb3538a BH |
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; | |
f3b33d40 | 28 | import org.eclipse.swt.custom.CCombo; |
a30e79fe BH |
29 | import org.eclipse.swt.events.ModifyEvent; |
30 | import org.eclipse.swt.events.ModifyListener; | |
f3b33d40 BH |
31 | import org.eclipse.swt.events.SelectionAdapter; |
32 | import org.eclipse.swt.events.SelectionEvent; | |
bbb3538a | 33 | import org.eclipse.swt.graphics.Point; |
f3b33d40 | 34 | import org.eclipse.swt.graphics.Rectangle; |
bbb3538a BH |
35 | import org.eclipse.swt.layout.GridData; |
36 | import org.eclipse.swt.layout.GridLayout; | |
f3b33d40 | 37 | import org.eclipse.swt.widgets.Button; |
bbb3538a BH |
38 | import org.eclipse.swt.widgets.Composite; |
39 | import org.eclipse.swt.widgets.Control; | |
f3b33d40 | 40 | import org.eclipse.swt.widgets.Group; |
bbb3538a BH |
41 | import org.eclipse.swt.widgets.Label; |
42 | import org.eclipse.swt.widgets.Shell; | |
43 | import org.eclipse.swt.widgets.Text; | |
44 | ||
45 | /** | |
bbb3538a BH |
46 | * <p> |
47 | * Dialog box for collecting session creation information. | |
48 | * </p> | |
f3b33d40 | 49 | * |
dbd4432d | 50 | * @author Bernd Hufmann |
bbb3538a BH |
51 | */ |
52 | public class CreateSessionDialog extends Dialog implements ICreateSessionDialog { | |
53 | ||
54 | // ------------------------------------------------------------------------ | |
55 | // Constants | |
56 | // ------------------------------------------------------------------------ | |
57 | /** | |
58 | * The icon file for this dialog box. | |
59 | */ | |
f3b33d40 BH |
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; | |
bbb3538a BH |
92 | |
93 | // ------------------------------------------------------------------------ | |
94 | // Attributes | |
95 | // ------------------------------------------------------------------------ | |
f3b33d40 BH |
96 | |
97 | private Control fControl = null; | |
bbb3538a BH |
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; | |
a30e79fe BH |
106 | /** |
107 | * The label widget for the session path. | |
108 | */ | |
109 | private Label fSessionPathLabel = null; | |
bbb3538a | 110 | /** |
f3b33d40 | 111 | * The text widget for the session path. |
bbb3538a BH |
112 | */ |
113 | private Text fSessionPathText = null; | |
f3b33d40 BH |
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; | |
a30e79fe BH |
126 | /** |
127 | * The text widget for the trace path. | |
128 | */ | |
129 | private Text fTracePathText = null; | |
f3b33d40 BH |
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; | |
a30e79fe BH |
142 | /** |
143 | * A selection listener updates the control port text depending on the control protocol selected. | |
144 | */ | |
f3b33d40 | 145 | private ProtocolComboSelectionListener fControlProtocolSelectionListener; |
a30e79fe BH |
146 | /** |
147 | * A selection listener updates the data port text depending on the data protocol selected. | |
148 | */ | |
f3b33d40 | 149 | private ProtocolComboSelectionListener fDataProtocolSelectionListener; |
f3b33d40 BH |
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 | */ | |
a30e79fe | 157 | private CopyModifyListener fControlUrlKeyListener; |
f3b33d40 BH |
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; | |
bbb3538a BH |
174 | /** |
175 | * The parent where the new node should be added. | |
176 | */ | |
c56972bb | 177 | private TraceSessionGroup fParent = null; |
bbb3538a BH |
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; | |
f3b33d40 BH |
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 | /** | |
a30e79fe | 210 | * The trace path string. |
f3b33d40 | 211 | */ |
a30e79fe | 212 | private String fTracePath = null; |
bbb3538a BH |
213 | |
214 | // ------------------------------------------------------------------------ | |
215 | // Constructors | |
216 | // ------------------------------------------------------------------------ | |
217 | /** | |
218 | * Constructor | |
219 | * @param shell - a shell for the display of the dialog | |
bbb3538a | 220 | */ |
d132bcc7 | 221 | public CreateSessionDialog(Shell shell) { |
bbb3538a | 222 | super(shell); |
5f1f22f8 | 223 | setShellStyle(SWT.RESIZE); |
bbb3538a BH |
224 | } |
225 | ||
226 | // ------------------------------------------------------------------------ | |
227 | // Accessors | |
228 | // ------------------------------------------------------------------------ | |
229 | /* | |
230 | * (non-Javadoc) | |
115b4a01 | 231 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog#getSessionName() |
bbb3538a BH |
232 | */ |
233 | @Override | |
234 | public String getSessionName() { | |
235 | return fSessionName; | |
236 | } | |
237 | ||
238 | /* | |
239 | * (non-Javadoc) | |
115b4a01 | 240 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog#getSessionPath() |
bbb3538a BH |
241 | */ |
242 | @Override | |
243 | public String getSessionPath() { | |
244 | return fSessionPath; | |
245 | } | |
f3b33d40 | 246 | |
bbb3538a BH |
247 | /* |
248 | * (non-Javadoc) | |
115b4a01 | 249 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog#isDefaultSessionPath() |
bbb3538a BH |
250 | */ |
251 | @Override | |
252 | public boolean isDefaultSessionPath() { | |
253 | return fIsDefaultPath; | |
254 | } | |
255 | ||
d132bcc7 BH |
256 | /* |
257 | * (non-Javadoc) | |
f3b33d40 | 258 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ICreateSessionDialog#initialze(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionGroup) |
d132bcc7 BH |
259 | */ |
260 | @Override | |
f3b33d40 BH |
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; | |
f3b33d40 BH |
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 | ||
bbb3538a BH |
290 | // ------------------------------------------------------------------------ |
291 | // Operations | |
292 | // ------------------------------------------------------------------------ | |
f3b33d40 BH |
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 | } | |
bbb3538a BH |
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); | |
31a6a4e4 | 317 | newShell.setImage(Activator.getDefault().loadIcon(CREATE_SESSION_ICON_FILE)); |
bbb3538a BH |
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) { | |
f3b33d40 | 326 | |
bbb3538a BH |
327 | // Main dialog panel |
328 | fDialogComposite = new Composite(parent, SWT.NONE); | |
f3b33d40 | 329 | GridLayout layout = new GridLayout(1, true); |
5f1f22f8 BH |
330 | fDialogComposite.setLayout(layout); |
331 | fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); | |
bbb3538a | 332 | |
f3b33d40 BH |
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); | |
bbb3538a | 338 | sessionNameLabel.setText(Messages.TraceControl_CreateSessionNameLabel); |
f3b33d40 | 339 | fSessionNameText = new Text(sessionGroup, SWT.NONE); |
bbb3538a | 340 | fSessionNameText.setToolTipText(Messages.TraceControl_CreateSessionNameTooltip); |
f3b33d40 | 341 | |
a30e79fe BH |
342 | fSessionPathLabel = new Label(sessionGroup, SWT.RIGHT); |
343 | fSessionPathLabel.setText(Messages.TraceControl_CreateSessionPathLabel); | |
f3b33d40 | 344 | fSessionPathText = new Text(sessionGroup, SWT.NONE); |
bbb3538a BH |
345 | fSessionPathText.setToolTipText(Messages.TraceControl_CreateSessionPathTooltip); |
346 | ||
347 | // layout widgets | |
5f1f22f8 BH |
348 | GridData data = new GridData(GridData.FILL_HORIZONTAL); |
349 | data.horizontalSpan = 3; | |
f3b33d40 | 350 | |
bbb3538a | 351 | fSessionNameText.setLayoutData(data); |
f3b33d40 BH |
352 | |
353 | data = new GridData(GridData.FILL_HORIZONTAL); | |
354 | data.horizontalSpan = 3; | |
bbb3538a | 355 | fSessionPathText.setLayoutData(data); |
bbb3538a | 356 | |
f3b33d40 | 357 | if (fParent.isNetworkStreamingSupported()) { |
f3b33d40 BH |
358 | createAdvancedOptionsComposite(); |
359 | } | |
360 | ||
bbb3538a BH |
361 | return fDialogComposite; |
362 | } | |
363 | ||
f3b33d40 BH |
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); | |
a30e79fe | 371 | fConfigureStreamingButton.setText(Messages.TraceControl_CreateSessionConfigureStreamingButtonText + " >>>"); //$NON-NLS-1$ |
f3b33d40 BH |
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); | |
a30e79fe BH |
380 | fSessionPathText.setEnabled(true); |
381 | fSessionPathLabel.setText(Messages.TraceControl_CreateSessionPathLabel); | |
f3b33d40 BH |
382 | disposeConfigureStreamingComposite(); |
383 | } else { | |
384 | fIsStreamedTrace = true; | |
385 | fConfigureStreamingButton.setText("<<< " + Messages.TraceControl_CreateSessionNoStreamingButtonText); //$NON-NLS-1$ | |
386 | fConfigureStreamingButton.setToolTipText(Messages.TraceControl_CreateSessionNoStreamingButtonTooltip); | |
a30e79fe BH |
387 | fSessionPathText.setEnabled(false); |
388 | fSessionPathText.setText(""); //$NON-NLS-1$ | |
389 | fSessionPathLabel.setText(""); //$NON-NLS-1$ | |
f3b33d40 BH |
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 | ||
a30e79fe BH |
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 | ||
f3b33d40 BH |
424 | fLinkDataWithControlButton = new Button(urlGroup, SWT.CHECK); |
425 | fLinkDataWithControlButton.setText(Messages.TraceControl_CreateSessionLinkButtonText); | |
426 | fLinkDataWithControlButton.setToolTipText(Messages.TraceControl_CreateSessionLinkButtonTooltip); | |
a30e79fe | 427 | data = new GridData(GridData.FILL_HORIZONTAL); |
f3b33d40 BH |
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 | ||
a30e79fe BH |
519 | fControlUrlKeyListener = new CopyModifyListener(fControlHostAddressText, fDataHostAddressText); |
520 | fControlHostAddressText.addModifyListener(fControlUrlKeyListener); | |
521 | ||
f3b33d40 BH |
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); | |
a30e79fe | 539 | fControlHostAddressText.addModifyListener(fControlUrlKeyListener); |
f3b33d40 BH |
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); | |
a30e79fe | 570 | fControlHostAddressText.removeModifyListener(fControlUrlKeyListener); |
f3b33d40 BH |
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 | ||
bbb3538a BH |
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) { | |
79c3db85 | 625 | createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$ |
bbb3538a BH |
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 | |
f3b33d40 BH |
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) { | |
bbb3538a BH |
655 | MessageDialog.openError(getShell(), |
656 | Messages.TraceControl_CreateSessionDialogTitle, | |
f3b33d40 | 657 | Messages.TraceControl_FileSubSystemError + "\n" + e); //$NON-NLS-1$ |
bbb3538a BH |
658 | return; |
659 | } | |
f3b33d40 | 660 | } |
bbb3538a BH |
661 | } |
662 | fIsDefaultPath = false; | |
663 | } | |
664 | ||
f3b33d40 BH |
665 | fNetworkUrl = null; |
666 | fControlUrl = null; | |
667 | fDataUrl = null; | |
668 | ||
669 | if (fIsStreamedTrace) { | |
a30e79fe BH |
670 | // Validate input data |
671 | fTracePath = fTracePathText.getText(); | |
672 | ||
f3b33d40 BH |
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, | |
a30e79fe | 706 | fTracePath); |
f3b33d40 BH |
707 | |
708 | fDataUrl = getUrlString(fControlProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()), | |
709 | fDataHostAddressText.getText(), | |
710 | null, | |
711 | fDataPortText.getText(), | |
a30e79fe | 712 | fTracePath); |
f3b33d40 BH |
713 | } else { |
714 | fNetworkUrl = getUrlString(fControlProtocolCombo.getItem(fDataProtocolCombo.getSelectionIndex()), | |
715 | fControlHostAddressText.getText(), | |
716 | fControlPortText.getText(), | |
717 | fDataPortText.getText(), | |
a30e79fe | 718 | fTracePath); |
f3b33d40 | 719 | } |
bbb3538a BH |
720 | } |
721 | ||
722 | // Check for invalid names | |
f3b33d40 | 723 | if (!"".equals(fSessionName) && !fSessionName.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$ //$NON-NLS-2$ |
bbb3538a BH |
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 | } | |
f3b33d40 | 737 | |
bbb3538a BH |
738 | // validation successful -> call super.okPressed() |
739 | super.okPressed(); | |
740 | } | |
f3b33d40 BH |
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 | ||
a30e79fe | 766 | private static class CopyModifyListener implements ModifyListener { |
f3b33d40 BH |
767 | private Text fSource; |
768 | private Text fDestination; | |
769 | ||
a30e79fe | 770 | public CopyModifyListener(Text source, Text destination) { |
f3b33d40 BH |
771 | fSource = source; |
772 | fDestination = destination; | |
773 | } | |
774 | ||
775 | @Override | |
a30e79fe | 776 | public void modifyText(ModifyEvent e) { |
f3b33d40 BH |
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 | ||
bbb3538a | 820 | } |