Author: adietish
Date: 2010-10-11 08:09:04 -0400 (Mon, 11 Oct 2010)
New Revision: 25710
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudType.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/META-INF/MANIFEST.MF
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/WizardMessages.properties
Log:
[JBIDE-7282] [JBIDE-7283] [JBIDE-7284] added connection test messages/decorations
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/META-INF/MANIFEST.MF 2010-10-11
10:21:15 UTC (rev 25709)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/META-INF/MANIFEST.MF 2010-10-11
12:09:04 UTC (rev 25710)
@@ -17,6 +17,7 @@
org.eclipse.core.databinding;bundle-version="1.3.100",
org.eclipse.core.databinding.observable;bundle-version="1.3.0",
org.eclipse.core.databinding.property;bundle-version="1.3.0",
- org.eclipse.core.databinding.beans;bundle-version="1.2.100"
+ org.eclipse.core.databinding.beans;bundle-version="1.2.100",
+ org.jboss.tools.common;bundle-version="3.2.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java 2010-10-11
10:21:15 UTC (rev 25709)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java 2010-10-11
12:09:04 UTC (rev 25710)
@@ -11,21 +11,23 @@
package org.jboss.tools.internal.deltacloud.ui.wizards;
import java.net.URL;
-import java.text.MessageFormat;
import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.beans.BeanProperties;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.observable.value.IValueChangeListener;
import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.databinding.fieldassist.ControlDecorationSupport;
+import org.eclipse.jface.databinding.swt.ISWTObservableValue;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.databinding.wizard.WizardPageSupport;
import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.fieldassist.ControlDecoration;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
@@ -48,6 +50,7 @@
import org.jboss.tools.deltacloud.ui.SWTImagesFactory;
import org.jboss.tools.deltacloud.ui.common.databinding.validator.CompositeValidator;
import
org.jboss.tools.deltacloud.ui.common.databinding.validator.MandatoryStringValidator;
+import org.jboss.tools.deltacloud.ui.common.swt.JFaceUtils;
public class CloudConnectionPage extends WizardPage {
@@ -70,10 +73,10 @@
private String defaultUsername = ""; //$NON-NLS-1$
private String defaultPassword = ""; //$NON-NLS-1$
private String defaultType = ""; //$NON-NLS-1$
-
+
private CloudConnectionModel connectionModel;
private CloudConnection cloudConnection;
-
+
private Listener linkListener = new Listener() {
public void handleEvent(Event event) {
@@ -82,7 +85,8 @@
URL url = new URL(urlString);
PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(url);
} catch (Exception e) {
- LogHelper.logError(Activator.getDefault(),
WizardMessages.getFormattedString(COULD_NOT_OPEN_BROWSER, urlString), e);
+ LogHelper.logError(Activator.getDefault(),
+ WizardMessages.getFormattedString(COULD_NOT_OPEN_BROWSER, urlString), e);
}
}
};
@@ -113,10 +117,6 @@
setPageComplete(false);
}
- public CloudConnectionModel getModel() {
- return connectionModel;
- }
-
@Override
public void createControl(Composite parent) {
DataBindingContext dbc = new DataBindingContext();
@@ -146,7 +146,7 @@
dbc.bindValue(
WidgetProperties.text(SWT.Modify).observeDelayed(500, urlText),
BeanProperties.value(CloudConnectionModel.class, CloudConnectionModel.PROPERTY_URL)
- .observe(connectionModel));
+ .observe(connectionModel));
// cloud type
Label typeLabel = new Label(container, SWT.NULL);
@@ -159,13 +159,13 @@
Label usernameLabel = new Label(container, SWT.NULL);
usernameLabel.setText(WizardMessages.getString(USERNAME_LABEL));
- DataBindingContext credentialsDbc = new DataBindingContext();
-
// username
Text usernameText = new Text(container, SWT.BORDER | SWT.SINGLE);
usernameText.setText(defaultUsername);
- credentialsDbc.bindValue(
- WidgetProperties.text(SWT.Modify).observe(usernameText),
+ ControlDecoration usernameDecoration = JFaceUtils.createDecoration(usernameText,
TEST_FAILURE);
+ IObservableValue usernameObservable =
WidgetProperties.text(SWT.Modify).observe(usernameText);
+ dbc.bindValue(
+ usernameObservable,
BeanProperties.value(CloudConnectionModel.class,
CloudConnectionModel.PROPERTY_USERNAME).observe(
connectionModel));
@@ -174,16 +174,24 @@
passwordLabel.setText(WizardMessages.getString(PASSWORD_LABEL));
Text passwordText = new Text(container, SWT.BORDER | SWT.PASSWORD | SWT.SINGLE);
passwordText.setText(defaultPassword);
- credentialsDbc.bindValue(
- WidgetProperties.text(SWT.Modify).observe(passwordText),
+ ControlDecoration passwordDecoration = JFaceUtils.createDecoration(passwordText,
TEST_FAILURE);
+ ISWTObservableValue passwordTextObservable =
WidgetProperties.text(SWT.Modify).observe(passwordText);
+ dbc.bindValue(
+ passwordTextObservable,
BeanProperties.value(CloudConnectionModel.class,
CloudConnectionModel.PROPERTY_PASSWORD).observe(
connectionModel));
// test button
final Button testButton = new Button(container, SWT.NULL);
testButton.setText(WizardMessages.getString(TESTBUTTON_LABEL));
testButton.setEnabled(false);
- bindTestButton(urlBinding, testButton);
+ urlBinding.getValidationStatus().addValueChangeListener(enableButtonOnUrlValidityChanges(testButton));
+ CredentialsTestAdapter credentialsTestAdapter = new
CredentialsTestAdapter(usernameDecoration,
+ passwordDecoration);
+ testButton.addSelectionListener(credentialsTestAdapter);
+ usernameObservable.addValueChangeListener(credentialsTestAdapter);
+ passwordTextObservable.addValueChangeListener(credentialsTestAdapter);
+
// ec2 user link
Link ec2userLink = new Link(container, SWT.NULL);
ec2userLink.setText(WizardMessages.getString(EC2_USER_INFO));
@@ -272,40 +280,35 @@
ec2pwLink.setLayoutData(f);
setControl(container);
- // validate();
}
- private void bindTestButton(Binding urlBinding, final Button testButton) {
- urlBinding.getValidationStatus().addValueChangeListener(new IValueChangeListener() {
+ /**
+ * Enables/Disables credentials test button on url validity changes.
+ *
+ * @param testButton
+ * the test button
+ * @return the i value change listener
+ */
+ private IValueChangeListener enableButtonOnUrlValidityChanges(final Button testButton)
{
+ return new IValueChangeListener() {
@Override
public void handleValueChange(ValueChangeEvent event) {
IStatus status = (IStatus) event.diff.getNewValue();
testButton.setEnabled(status.isOK());
}
- });
-
- testButton.addSelectionListener(new SelectionAdapter() {
-
- public void widgetSelected(SelectionEvent event) {
- boolean successful = cloudConnection.performTest();
- if (successful) {
- setMessage(WizardMessages.getString(TEST_SUCCESSFUL));
- } else {
- setErrorMessage(WizardMessages.getString(TEST_FAILURE));
- }
- }
- });
+ };
}
- private Binding bindCloudTypeLabel(DataBindingContext dbc, Text urlText, final Label
typeLabel,
- UpdateValueStrategy url2TypeStrategy) {
- Binding urlBinding = dbc.bindValue(
- WidgetProperties.text(SWT.Modify).observeDelayed(100, urlText),
- BeanProperties.value(CloudConnectionModel.PROPERTY_TYPE).observe(connectionModel),
- url2TypeStrategy,
- new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER));
- urlBinding.getValidationStatus().addValueChangeListener(new IValueChangeListener() {
+ /**
+ * Displays the cloud type in the given if the given binding is valid.
+ *
+ * @param typeLabel
+ * the type label
+ * @return the value change listener
+ */
+ private IValueChangeListener displayCloudTypeOnUrlValidityChanges(final Label typeLabel)
{
+ return new IValueChangeListener() {
@Override
public void handleValueChange(ValueChangeEvent event) {
@@ -316,7 +319,17 @@
typeLabel.setText("");
}
}
- });
+ };
+ }
+
+ private Binding bindCloudTypeLabel(DataBindingContext dbc, Text urlText, final Label
typeLabel,
+ UpdateValueStrategy url2TypeStrategy) {
+ Binding urlBinding = dbc.bindValue(
+ WidgetProperties.text(SWT.Modify).observeDelayed(100, urlText),
+ BeanProperties.value(CloudConnectionModel.PROPERTY_TYPE).observe(connectionModel),
+ url2TypeStrategy,
+ new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER));
+ urlBinding.getValidationStatus().addValueChangeListener(displayCloudTypeOnUrlValidityChanges(typeLabel));
ControlDecorationSupport.create(urlBinding, SWT.LEFT | SWT.TOP);
return urlBinding;
}
@@ -333,7 +346,8 @@
@Override
public IStatus validate(Object value) {
- if (nameText.getText() != null &&
DeltaCloudManager.getDefault().findCloud(nameText.getText()) != null) {
+ if (nameText.getText() != null
+ && DeltaCloudManager.getDefault().findCloud(nameText.getText()) !=
null) {
return ValidationStatus.error(NAME_ALREADY_IN_USE);
} else {
return ValidationStatus.ok();
@@ -343,4 +357,52 @@
null);
ControlDecorationSupport.create(nameTextBinding, SWT.LEFT | SWT.TOP);
}
+
+ public CloudConnectionModel getModel() {
+ return connectionModel;
+ }
+
+ private class CredentialsTestAdapter extends SelectionAdapter implements
IValueChangeListener {
+
+ private ControlDecoration[] controlDecorations;
+
+ public CredentialsTestAdapter(ControlDecoration... controlDecorations) {
+ this.controlDecorations = controlDecorations;
+ setDecorations(false);
+ }
+
+ public void widgetSelected(SelectionEvent event) {
+ boolean success = cloudConnection.performTest();
+ setMessage(success);
+ setDecorations(!success);
+ }
+
+ private void setMessage(boolean success) {
+ if (success) {
+ CloudConnectionPage.this.setMessage(WizardMessages.getString(TEST_SUCCESSFUL));
+ } else {
+ CloudConnectionPage.this.setErrorMessage(WizardMessages.getString(TEST_FAILURE));
+ }
+ }
+
+ private void clearMessage() {
+ CloudConnectionPage.this.setMessage(""); //$NON-NLS-1$
+ }
+
+ private void setDecorations(boolean visible) {
+ for (ControlDecoration controlDecoration : controlDecorations) {
+ if (visible) {
+ controlDecoration.show();
+ } else {
+ controlDecoration.hide();
+ }
+ }
+ }
+
+ @Override
+ public void handleValueChange(ValueChangeEvent event) {
+ setDecorations(false);
+ clearMessage();
+ }
+ }
}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudType.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudType.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudType.java 2010-10-11
12:09:04 UTC (rev 25710)
@@ -0,0 +1,131 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.internal.deltacloud.ui.wizards;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringReader;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+public class CloudType {
+
+ private static final String HTTPHEADER_KEY_ACCEPT = "Accept"; //$NON-NLS-1$
+ private static final String HTTPHEADER_VALUE_ACCEPTXML =
"application/xml;q=1.0"; //$NON-NLS-1$
+ private static final String DOCUMENT_ELEMENT_DRIVER = "driver"; //$NON-NLS-1$
+ private static final String DOCUMENT_ELEMENT_API = "api"; //$NON-NLS-1$
+ private static final String URLCONNECTION_ENCODING = "UTF-8"; //$NON-NLS-1$
+
+ public static final String UNKNOWN_TYPE_LABEL = "UnknownType.label";
//$NON-NLS-1$
+ private static final String INVALID_URL = "ErrorInvalidURL.text";
//$NON-NLS-1$
+ static final String NONCLOUD_URL = "ErrorNonCloudURL.text"; //$NON-NLS-1$
+
+ private String label = WizardMessages.getString(UNKNOWN_TYPE_LABEL);
+ private boolean isValid;
+ private String url;
+
+ public CloudType(String url) {
+ init(url);
+ }
+
+ /**
+ * Initializes this instance, sets the cloud type label and the validity. It
+ * tries to connect to the cloud instance that's supposed at the given url,
+ * requests an API response and parses the xml that's returned.
+ *
+ * @param url
+ * the cloud instance url to connect to
+ */
+ private void init(String url) {
+ this.url = url;
+ try {
+ Object o = getURLContent(url + "/api?format=xml"); //$NON-NLS-1$
+ if (o instanceof InputStream) {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ Document document = db.parse(
+ new InputSource(new StringReader(getXML((InputStream) o))));
+
+ NodeList elements = document.getElementsByTagName(DOCUMENT_ELEMENT_API);
//$NON-NLS-1$
+ if (elements.getLength() > 0) {
+ Node n = elements.item(0);
+ Node driver = n.getAttributes().getNamedItem(
+ DOCUMENT_ELEMENT_DRIVER); //$NON-NLS-1$
+ if (driver != null) {
+ isValid = true;
+ String driverValue = driver.getNodeValue();
+ label = driverValue.toUpperCase();
+ }
+ }
+ }
+ } catch (MalformedURLException e) {
+ label = WizardMessages.getString(INVALID_URL);
+ } catch (IOException e) {
+ label = WizardMessages.getString(NONCLOUD_URL);
+ } catch (ParserConfigurationException e) {
+ label = WizardMessages.getString(NONCLOUD_URL);
+ } catch (SAXException e) {
+ label = WizardMessages.getString(NONCLOUD_URL);
+ } catch (Exception e) {
+ label = WizardMessages.getString(INVALID_URL);
+ }
+ }
+
+ private String getXML(InputStream is) throws UnsupportedEncodingException, IOException
{
+ try {
+ if (is == null) {
+ return "";
+ }
+ StringBuilder sb = new StringBuilder();
+ String line = "";
+ BufferedReader reader = new BufferedReader(new InputStreamReader(is,
URLCONNECTION_ENCODING));
+ while ((line = reader.readLine()) != null) {
+ sb.append(line).append("\n"); //$NON-NLS-1$
+ }
+ return sb.toString();
+ } finally {
+ is.close();
+ }
+ }
+
+ public boolean isValid() {
+ return isValid;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ private Object getURLContent(String url) throws IOException {
+ URL u = new URL(url);
+ URLConnection connection = u.openConnection();
+ connection.setRequestProperty(HTTPHEADER_KEY_ACCEPT, HTTPHEADER_VALUE_ACCEPTXML);
//$NON-NLS-1$ $NON-NLS-2$
+ return connection.getContent();
+ }
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudType.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/WizardMessages.properties
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/WizardMessages.properties 2010-10-11
10:21:15 UTC (rev 25709)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/WizardMessages.properties 2010-10-11
12:09:04 UTC (rev 25710)
@@ -63,6 +63,7 @@
EC2PasswordLink.text=For EC2 use the <a
href="https://console.aws.amazon.com/ec2/home">Access Secret Key</a>
ErrorNameInUse.text=Error: the name chosen is already in use
+ErrorCouldNotOpenBrowser.text="Could not open url \"{0}\"in
Browser";
ErrorInvalidURL.text=URL specified is invalid
ErrorNonCloudURL.text=URL specified is not a valid Delta-cloud address
ErrorInvalidPem.text=File specified is not a valid existing key
@@ -79,7 +80,7 @@
ImageFilter.title=Image Filter
ImageFilter.name=Image Filter
-ImageFilter.label=Show all images which match the following rules (* = wildcard):
+ImageFilter.label=Show all images which match the following rules (* \= wildcard)\:
ErrorFilterEmptyRule.msg=Rules cannot be empty strings
ErrorFilterSemicolon.msg=Rules cannot contain a semi-colon character
ErrorFieldError.msg={0} {1}
@@ -87,7 +88,7 @@
InstanceFilter.desc=Specify rules to determine which Instances will appear in the
dialog.
InstanceFilter.title=Instance Filter
InstanceFilter.name=Instance Filter
-InstanceFilter.label=Show all instances which match the following rules (* = wildcard):
+InstanceFilter.label=Show all instances which match the following rules (* \= wildcard)\:
ErrorInvalidDirectory.text=Specified directory is not a valid existing directory
Directory.label=Directory