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