1 /**********************************************************************
2 * Copyright (c) 2012 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
;
14 import java
.util
.Arrays
;
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
.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
;
40 * Dialog box for connection information.
43 * @author Bernd Hufmann
45 public class NewConnectionDialog
extends Dialog
implements INewConnectionDialog
{
47 // ------------------------------------------------------------------------
49 // ------------------------------------------------------------------------
51 * The icon file for this dialog box.
53 public static final String TARGET_NEW_CONNECTION_ICON_FILE
= "icons/elcl16/target_add.gif"; //$NON-NLS-1$
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
59 * The dialog composite.
61 private Composite fDialogComposite
= null;
63 * The Group for the host combo box.
65 private Group fComboGroup
= null;
67 * The Group for the text input.
69 private Group fTextGroup
= null;
73 private CCombo fExistingHostsCombo
= null;
75 * The check box button for enabling/disabling the text input.
77 private Button fButton
= null;
79 * The text widget for the node name (alias)
81 private Text fConnectionNameText
= null;
83 * The text widget for the node address (IP or DNS name)
85 private Text fHostNameText
= null;
87 * The parent where the new node should be added.
89 private ITraceControlComponent fParent
;
91 * The node name (alias) string.
93 private String fConnectionName
= null;
95 * The node address (IP or DNS name) string.
97 private String fHostName
= null;
100 * Input list of existing RSE hosts available for selection.
102 private IHost
[] fExistingHosts
= new IHost
[0];
104 // ------------------------------------------------------------------------
106 // ------------------------------------------------------------------------
107 public NewConnectionDialog(Shell shell
) {
109 setShellStyle(SWT
.RESIZE
);
112 // ------------------------------------------------------------------------
114 // ------------------------------------------------------------------------
117 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.INewConnectionDialog#getConnectionName()
120 public String
getConnectionName() {
121 return fConnectionName
;
126 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.INewConnectionDialog#getHostName()
129 public String
getHostName() {
135 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.INewConnectionDialog#setTraceControlParent(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent)
138 public void setTraceControlParent(ITraceControlComponent parent
) {
144 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.INewConnectionDialog#setHosts(org.eclipse.rse.core.model.IHost[])
147 public void setHosts(IHost
[] hosts
) {
149 fExistingHosts
= Arrays
.copyOf(hosts
, hosts
.length
);
153 // ------------------------------------------------------------------------
155 // ------------------------------------------------------------------------
158 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
161 protected void configureShell(Shell newShell
) {
162 super.configureShell(newShell
);
163 newShell
.setText(Messages
.TraceControl_NewDialogTitle
);
164 newShell
.setImage(Activator
.getDefault().loadIcon(TARGET_NEW_CONNECTION_ICON_FILE
));
169 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
172 protected Control
createDialogArea(Composite parent
) {
175 fDialogComposite
= new Composite(parent
, SWT
.NONE
);
176 GridLayout layout
= new GridLayout(1, true);
177 fDialogComposite
.setLayout(layout
);
178 fDialogComposite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
180 // Existing connections group
181 fComboGroup
= new Group(fDialogComposite
, SWT
.SHADOW_NONE
);
182 fComboGroup
.setText(Messages
.TraceControl_NewNodeExistingConnectionGroupName
);
183 layout
= new GridLayout(2, true);
184 fComboGroup
.setLayout(layout
);
185 GridData data
= new GridData(GridData
.FILL_HORIZONTAL
);
186 fComboGroup
.setLayoutData(data
);
188 fExistingHostsCombo
= new CCombo(fComboGroup
, SWT
.READ_ONLY
);
189 fExistingHostsCombo
.setToolTipText(Messages
.TraceControl_NewNodeComboToolTip
);
190 fExistingHostsCombo
.setLayoutData(new GridData(GridData
.FILL
, GridData
.CENTER
, true, false, 2, 1));
192 String items
[] = new String
[fExistingHosts
.length
];
193 for (int i
= 0; i
< items
.length
; i
++) {
194 items
[i
] = String
.valueOf(fExistingHosts
[i
].getAliasName() + " - " + fExistingHosts
[i
].getHostName()); //$NON-NLS-1$
197 fExistingHostsCombo
.setItems(items
);
198 fExistingHostsCombo
.setEnabled(fExistingHosts
.length
> 0);
200 // Node information grop
201 fTextGroup
= new Group(fDialogComposite
, SWT
.SHADOW_NONE
);
202 layout
= new GridLayout(3, true);
203 fTextGroup
.setLayout(layout
);
204 data
= new GridData(GridData
.FILL_HORIZONTAL
);
205 fTextGroup
.setLayoutData(data
);
207 fButton
= new Button(fTextGroup
, SWT
.CHECK
);
208 fButton
.setLayoutData(new GridData(GridData
.FILL
, GridData
.CENTER
, true, false, 3, 1));
209 fButton
.setText(Messages
.TraceControl_NewNodeEditButtonName
);
210 fButton
.setEnabled(fExistingHosts
.length
> 0);
212 Label connectionNameLabel
= new Label(fTextGroup
, SWT
.RIGHT
);
213 connectionNameLabel
.setText(Messages
.TraceControl_NewNodeConnectionNameLabel
);
214 fConnectionNameText
= new Text(fTextGroup
, SWT
.NONE
);
215 fConnectionNameText
.setToolTipText(Messages
.TraceControl_NewNodeConnectionNameTooltip
);
216 fConnectionNameText
.setEnabled(fExistingHosts
.length
== 0);
218 Label hostNameLabel
= new Label(fTextGroup
, SWT
.RIGHT
);
219 hostNameLabel
.setText(Messages
.TraceControl_NewNodeHostNameLabel
);
220 fHostNameText
= new Text(fTextGroup
, SWT
.NONE
);
221 fHostNameText
.setToolTipText(Messages
.TraceControl_NewNodeHostNameTooltip
);
222 fHostNameText
.setEnabled(fExistingHosts
.length
== 0);
224 fButton
.addSelectionListener(new SelectionListener() {
226 public void widgetSelected(SelectionEvent e
) {
227 if (fButton
.getSelection()) {
228 fExistingHostsCombo
.deselectAll();
229 fExistingHostsCombo
.setEnabled(false);
230 fConnectionNameText
.setEnabled(true);
231 fHostNameText
.setEnabled(true);
233 fExistingHostsCombo
.setEnabled(true);
234 fConnectionNameText
.setEnabled(false);
235 fHostNameText
.setEnabled(false);
240 public void widgetDefaultSelected(SelectionEvent e
) {
244 fExistingHostsCombo
.addSelectionListener(new SelectionListener() {
246 public void widgetSelected(SelectionEvent e
) {
247 int index
= fExistingHostsCombo
.getSelectionIndex();
248 fConnectionNameText
.setText(fExistingHosts
[index
].getAliasName());
249 fHostNameText
.setText(fExistingHosts
[index
].getHostName());
253 public void widgetDefaultSelected(SelectionEvent e
) {
258 data
= new GridData(GridData
.FILL_HORIZONTAL
);
259 fHostNameText
.setText("666.666.666.666"); //$NON-NLS-1$
260 Point minSize
= fHostNameText
.computeSize(SWT
.DEFAULT
, SWT
.DEFAULT
, true);
261 data
.widthHint
= minSize
.x
+ 5;
262 data
.horizontalSpan
= 2;
264 fConnectionNameText
.setLayoutData(data
);
265 fHostNameText
.setLayoutData(data
);
267 fHostNameText
.setText(""); //$NON-NLS-1$
269 return fDialogComposite
;
274 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
277 protected void createButtonsForButtonBar(Composite parent
) {
278 createButton(parent
, IDialogConstants
.CANCEL_ID
, "&Cancel", true); //$NON-NLS-1$
279 createButton(parent
, IDialogConstants
.OK_ID
, "&Ok", true); //$NON-NLS-1$
284 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
287 protected void okPressed() {
288 // Validate input data
289 fConnectionName
= fConnectionNameText
.getText();
290 fHostName
= fHostNameText
.getText();
292 if (!"".equals(fHostName
)) { //$NON-NLS-1$
293 // If no node name is specified use the node address as name
294 if ("".equals(fConnectionName
)) { //$NON-NLS-1$
295 fConnectionName
= fHostName
;
297 // Check if node with name already exists in parent
298 if(fParent
.containsChild(fConnectionName
)) {
299 MessageDialog
.openError(getShell(),
300 Messages
.TraceControl_NewDialogTitle
,
301 Messages
.TraceControl_AlreadyExistsError
+ " (" + fConnectionName
+ ")"); //$NON-NLS-1$//$NON-NLS-2$
308 // validation successful -> call super.okPressed()