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 / NewConnectionDialog.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 **********************************************************************/
12 package org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs;
13
14 import java.util.Arrays;
15
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.ITraceControlComponent;
22 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.IRemoteSystemProxy;
23 import org.eclipse.rse.core.model.IHost;
24 import org.eclipse.swt.SWT;
25 import org.eclipse.swt.custom.CCombo;
26 import org.eclipse.swt.events.SelectionEvent;
27 import org.eclipse.swt.events.SelectionListener;
28 import org.eclipse.swt.events.VerifyEvent;
29 import org.eclipse.swt.events.VerifyListener;
30 import org.eclipse.swt.graphics.Point;
31 import org.eclipse.swt.layout.GridData;
32 import org.eclipse.swt.layout.GridLayout;
33 import org.eclipse.swt.widgets.Button;
34 import org.eclipse.swt.widgets.Composite;
35 import org.eclipse.swt.widgets.Control;
36 import org.eclipse.swt.widgets.Group;
37 import org.eclipse.swt.widgets.Label;
38 import org.eclipse.swt.widgets.Shell;
39 import org.eclipse.swt.widgets.Text;
40
41 /**
42 * <p>
43 * Dialog box for connection information.
44 * </p>
45 *
46 * @author Bernd Hufmann
47 */
48 public class NewConnectionDialog extends Dialog implements INewConnectionDialog {
49
50 // ------------------------------------------------------------------------
51 // Constants
52 // ------------------------------------------------------------------------
53 /**
54 * The icon file for this dialog box.
55 */
56 public static final String TARGET_NEW_CONNECTION_ICON_FILE = "icons/elcl16/target_add.gif"; //$NON-NLS-1$
57
58 // ------------------------------------------------------------------------
59 // Attributes
60 // ------------------------------------------------------------------------
61 /**
62 * The dialog composite.
63 */
64 private Composite fDialogComposite = null;
65 /**
66 * The Group for the host combo box.
67 */
68 private Group fComboGroup = null;
69 /**
70 * The Group for the text input.
71 */
72 private Group fTextGroup = null;
73 /**
74 * The host combo box.
75 */
76 private CCombo fExistingHostsCombo = null;
77 /**
78 * The check box button for enabling/disabling the text input.
79 */
80 private Button fButton = null;
81 /**
82 * The text widget for the node name (alias)
83 */
84 private Text fConnectionNameText = null;
85 /**
86 * The text widget for the node address (IP or DNS name)
87 */
88 private Text fHostNameText = null;
89 /**
90 * The text widget for the IP port
91 */
92 private Text fPortText = null;
93 /**
94 * The parent where the new node should be added.
95 */
96 private ITraceControlComponent fParent;
97 /**
98 * The node name (alias) string.
99 */
100 private String fConnectionName = null;
101 /**
102 * The node address (IP or DNS name) string.
103 */
104 private String fHostName = null;
105 /**
106 * The IP port of the connection.
107 */
108 private int fPort = IRemoteSystemProxy.INVALID_PORT_NUMBER;
109 /**
110 * Input list of existing RSE hosts available for selection.
111 */
112 private IHost[] fExistingHosts = new IHost[0];
113
114 // ------------------------------------------------------------------------
115 // Constructors
116 // ------------------------------------------------------------------------
117 /**
118 * Constructor
119 *
120 * @param shell
121 * The shell
122 */
123 public NewConnectionDialog(Shell shell) {
124 super(shell);
125 setShellStyle(SWT.RESIZE);
126 }
127
128 // ------------------------------------------------------------------------
129 // Accessors
130 // ------------------------------------------------------------------------
131
132 @Override
133 public String getConnectionName() {
134 return fConnectionName;
135 }
136
137 @Override
138 public String getHostName() {
139 return fHostName;
140 }
141
142 @Override
143 public int getPort() {
144 return fPort;
145 }
146
147 @Override
148 public void setTraceControlParent(ITraceControlComponent parent) {
149 fParent = parent;
150 }
151
152 @Override
153 public void setHosts(IHost[] hosts) {
154 if (hosts != null) {
155 fExistingHosts = Arrays.copyOf(hosts, hosts.length);
156 }
157 }
158
159 @Override
160 public void setPort(int port) {
161 fPort = port;
162 }
163
164 // ------------------------------------------------------------------------
165 // Operations
166 // ------------------------------------------------------------------------
167
168 @Override
169 protected void configureShell(Shell newShell) {
170 super.configureShell(newShell);
171 newShell.setText(Messages.TraceControl_NewDialogTitle);
172 newShell.setImage(Activator.getDefault().loadIcon(TARGET_NEW_CONNECTION_ICON_FILE));
173 }
174
175 @Override
176 protected Control createDialogArea(Composite parent) {
177
178 // Main dialog panel
179 fDialogComposite = new Composite(parent, SWT.NONE);
180 GridLayout layout = new GridLayout(1, true);
181 fDialogComposite.setLayout(layout);
182 fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
183
184 // Existing connections group
185 fComboGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
186 fComboGroup.setText(Messages.TraceControl_NewNodeExistingConnectionGroupName);
187 layout = new GridLayout(2, true);
188 fComboGroup.setLayout(layout);
189 GridData data = new GridData(GridData.FILL_HORIZONTAL);
190 fComboGroup.setLayoutData(data);
191
192 fExistingHostsCombo = new CCombo(fComboGroup, SWT.READ_ONLY);
193 fExistingHostsCombo.setToolTipText(Messages.TraceControl_NewNodeComboToolTip);
194 fExistingHostsCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 2, 1));
195
196 String items[] = new String[fExistingHosts.length];
197 for (int i = 0; i < items.length; i++) {
198 items[i] = String.valueOf(fExistingHosts[i].getAliasName() + " - " + fExistingHosts[i].getHostName()); //$NON-NLS-1$
199 }
200
201 fExistingHostsCombo.setItems(items);
202 fExistingHostsCombo.setEnabled(fExistingHosts.length > 0);
203
204 // Node information grop
205 fTextGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
206 layout = new GridLayout(3, true);
207 fTextGroup.setLayout(layout);
208 data = new GridData(GridData.FILL_HORIZONTAL);
209 fTextGroup.setLayoutData(data);
210
211 fButton = new Button(fTextGroup, SWT.CHECK);
212 fButton.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 3, 1));
213 fButton.setText(Messages.TraceControl_NewNodeEditButtonName);
214 fButton.setEnabled(fExistingHosts.length > 0);
215
216 Label connectionNameLabel = new Label(fTextGroup, SWT.RIGHT);
217 connectionNameLabel.setText(Messages.TraceControl_NewNodeConnectionNameLabel);
218 fConnectionNameText = new Text(fTextGroup, SWT.NONE);
219 fConnectionNameText.setToolTipText(Messages.TraceControl_NewNodeConnectionNameTooltip);
220 fConnectionNameText.setEnabled(fExistingHosts.length == 0);
221
222 Label hostNameLabel = new Label(fTextGroup, SWT.RIGHT);
223 hostNameLabel.setText(Messages.TraceControl_NewNodeHostNameLabel);
224 fHostNameText = new Text(fTextGroup, SWT.NONE);
225 fHostNameText.setToolTipText(Messages.TraceControl_NewNodeHostNameTooltip);
226 fHostNameText.setEnabled(fExistingHosts.length == 0);
227
228 Label portLabel = new Label(fTextGroup, SWT.RIGHT);
229 portLabel.setText(Messages.TraceControl_NewNodePortLabel);
230 fPortText = new Text(fTextGroup, SWT.NONE);
231 fPortText.setToolTipText(Messages.TraceControl_NewNodePortTooltip);
232 fPortText.setEnabled(fExistingHosts.length == 0);
233 fPortText.addVerifyListener(new VerifyListener() {
234 @Override
235 public void verifyText(VerifyEvent e) {
236 // only numbers are allowed.
237 e.doit = e.text.matches("[0-9]*"); //$NON-NLS-1$
238 }
239 });
240
241 fButton.addSelectionListener(new SelectionListener() {
242 @Override
243 public void widgetSelected(SelectionEvent e) {
244 if (fButton.getSelection()) {
245 fExistingHostsCombo.deselectAll();
246 fExistingHostsCombo.setEnabled(false);
247 fConnectionNameText.setEnabled(true);
248 fHostNameText.setEnabled(true);
249 fPortText.setEnabled(true);
250 } else {
251 fExistingHostsCombo.setEnabled(true);
252 fConnectionNameText.setEnabled(false);
253 fHostNameText.setEnabled(false);
254 fPortText.setEnabled(false);
255 }
256 }
257
258 @Override
259 public void widgetDefaultSelected(SelectionEvent e) {
260 }
261 });
262
263 fExistingHostsCombo.addSelectionListener(new SelectionListener() {
264 @Override
265 public void widgetSelected(SelectionEvent e) {
266 int index = fExistingHostsCombo.getSelectionIndex();
267 fConnectionNameText.setText(fExistingHosts[index].getAliasName());
268 fHostNameText.setText(fExistingHosts[index].getHostName());
269 fPortText.setText(""); //$NON-NLS-1$
270 }
271
272 @Override
273 public void widgetDefaultSelected(SelectionEvent e) {
274 }
275 });
276
277 // layout widgets
278 data = new GridData(GridData.FILL_HORIZONTAL);
279 fHostNameText.setText("666.666.666.666"); //$NON-NLS-1$
280 Point minSize = fHostNameText.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
281 int widthHint = minSize.x + 5;
282 data.widthHint = widthHint;
283 data.horizontalSpan = 2;
284 fConnectionNameText.setLayoutData(data);
285
286 data = new GridData(GridData.FILL_HORIZONTAL);
287 data.widthHint = widthHint;
288 data.horizontalSpan = 2;
289 fHostNameText.setLayoutData(data);
290
291 data = new GridData(GridData.FILL_HORIZONTAL);
292 data.widthHint = widthHint;
293 data.horizontalSpan = 2;
294 fPortText.setLayoutData(data);
295
296 fHostNameText.setText(""); //$NON-NLS-1$
297
298 return fDialogComposite;
299 }
300
301 @Override
302 protected void createButtonsForButtonBar(Composite parent) {
303 createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$
304 createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$
305 }
306
307 @Override
308 protected void okPressed() {
309 // Validate input data
310 fConnectionName = fConnectionNameText.getText();
311 fHostName = fHostNameText.getText();
312 fPort = (fPortText.getText().length() > 0) ? Integer.parseInt(fPortText.getText()) : IRemoteSystemProxy.INVALID_PORT_NUMBER;
313
314 if (!"".equals(fHostName)) { //$NON-NLS-1$
315 // If no node name is specified use the node address as name
316 if ("".equals(fConnectionName)) { //$NON-NLS-1$
317 fConnectionName = fHostName;
318 }
319 // Check if node with name already exists in parent
320 if(fParent.containsChild(fConnectionName)) {
321 MessageDialog.openError(getShell(),
322 Messages.TraceControl_NewDialogTitle,
323 Messages.TraceControl_AlreadyExistsError + " (" + fConnectionName + ")"); //$NON-NLS-1$//$NON-NLS-2$
324 return;
325 }
326 }
327 else {
328 return;
329 }
330 // validation successful -> call super.okPressed()
331 super.okPressed();
332 }
333 }
This page took 0.037537 seconds and 5 git commands to generate.