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