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