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