Author: adietish
Date: 2011-03-23 16:40:23 -0400 (Wed, 23 Mar 2011)
New Revision: 29981
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/ControlDecorationAdapter.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/common/swt/JFaceUtils.java
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/CloudConnectionPageModel.java
Log:
[JBIDE-8206] moved checking cloud type to background job
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2011-03-23 18:46:48
UTC (rev 29980)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2011-03-23 20:40:23
UTC (rev 29981)
@@ -1,5 +1,26 @@
+2011-03-23 André Dietisheim <André Dietisheim@adietisheim-thinkpad>
+
+ * src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPageModel.java
+ (setDriverByUrl):
+ (isKnownCloud):
+ * src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java
+ (Driver2Label):
+ (createControl):
+ (bindTestButtonEnablement):
+ (bindCloudType):
+ * src/org/jboss/tools/internal/deltacloud/ui/utils/ControlDecorationAdapter.java
(ControlDecorationAdapter):
+ [JBIDE-8206] moved checking cloud type to background job
+
2011-03-21 André Dietisheim <André Dietisheim@adietisheim-thinkpad>
+ * src/org/jboss/tools/internal/deltacloud/ui/wizards/InstanceFilterPage.java
+ (createControl):
+ (onDefaultAllPressed):
+ * src/org/jboss/tools/internal/deltacloud/ui/wizards/ImageFilterPage.java
+ (createControl):
+ (onDefaultAllPressed):
+ [JBIDE-8326] added button that resets all filters
+
2011-03-21 André Dietisheim <André Dietisheim@adietisheim-thinkpad>
* src/org/jboss/tools/deltacloud/ui/commands/CopyCVPropertySheetPageEntryHandler.java:
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/common/swt/JFaceUtils.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/common/swt/JFaceUtils.java 2011-03-23
18:46:48 UTC (rev 29980)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/common/swt/JFaceUtils.java 2011-03-23
20:40:23 UTC (rev 29981)
@@ -19,12 +19,15 @@
public class JFaceUtils {
public static ControlDecoration createDecoration(Control control, String message) {
+ return createDecoration(control, message, FieldDecorationRegistry.DEC_ERROR);
+ }
+
+ public static ControlDecoration createDecoration(Control control, String message, String
decorationId) {
ControlDecoration controlDecoration = new ControlDecoration(control, SWT.LEFT |
SWT.TOP);
controlDecoration.setDescriptionText(message);
FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault()
- .getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
+ .getFieldDecoration(decorationId);
controlDecoration.setImage(fieldDecoration.getImage());
return controlDecoration;
}
-
}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/ControlDecorationAdapter.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/ControlDecorationAdapter.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/ControlDecorationAdapter.java 2011-03-23
20:40:23 UTC (rev 29981)
@@ -0,0 +1,37 @@
+package org.jboss.tools.internal.deltacloud.ui.utils;
+
+import org.eclipse.core.databinding.observable.value.IValueChangeListener;
+import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.fieldassist.ControlDecoration;
+
+/**
+ * A listener that shows/hides given control decorations on changes in the
+ * validation status it listens to.
+ *
+ * @author André Dietisheim
+ */
+public class ControlDecorationAdapter implements IValueChangeListener {
+ private ControlDecoration decoration;
+
+ public ControlDecorationAdapter(ControlDecoration decoration, IStatus initialStatus) {
+ this.decoration = decoration;
+ setDecorationVisible(initialStatus);
+ }
+
+ @Override
+ public void handleValueChange(ValueChangeEvent event) {
+ if (event.diff.getNewValue() instanceof IStatus) {
+ IStatus status = (IStatus) event.diff.getNewValue();
+ setDecorationVisible(status);
+ }
+ }
+
+ private void setDecorationVisible(IStatus status) {
+ if (!status.isOK()) {
+ decoration.show();
+ } else {
+ decoration.hide();
+ }
+ }
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/utils/ControlDecorationAdapter.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
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 2011-03-23
18:46:48 UTC (rev 29980)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java 2011-03-23
20:40:23 UTC (rev 29981)
@@ -35,6 +35,7 @@
import org.eclipse.jface.databinding.wizard.WizardPageSupport;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.fieldassist.ControlDecoration;
+import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
@@ -67,6 +68,8 @@
import
org.jboss.tools.internal.deltacloud.ui.common.databinding.validator.MandatoryStringValidator;
import org.jboss.tools.internal.deltacloud.ui.common.swt.JFaceUtils;
import org.jboss.tools.internal.deltacloud.ui.preferences.IPreferenceKeys;
+import org.jboss.tools.internal.deltacloud.ui.utils.ControlDecorationAdapter;
+import org.jboss.tools.internal.deltacloud.ui.utils.DataBindingUtils;
import org.jboss.tools.internal.deltacloud.ui.utils.UIUtils;
/**
@@ -114,40 +117,23 @@
};
/**
- * Displays the cloud type in the given label. Listens to ValueChangeEvents
- * and sets the given label accordingly.
+ * jface databinding converter that converts Driver values to displayable
+ * text
*
- * @param typeLabel
- * the label that shall display the delta cloud type
- *
- * @see IValueChangeListener
- * @see DeltaCloudServerType
+ * @see DeltaCloudDriver
*/
- private class DeltaCloudTypeLabelAdapter implements IValueChangeListener {
+ private static class Driver2Label extends Converter {
- private Label typeLabel;
-
- public DeltaCloudTypeLabelAdapter(DeltaCloudDriver cloudType, Label typeLabel) {
- this.typeLabel = typeLabel;
- init(cloudType);
+ private Driver2Label() {
+ super(DeltaCloudDriver.class, String.class);
}
- private void init(DeltaCloudDriver cloudType) {
- setLabelText(cloudType);
- }
-
@Override
- public void handleValueChange(ValueChangeEvent event) {
- Object newValue = event.diff.getNewValue();
- setLabelText(newValue);
- }
-
- private void setLabelText(Object cloudType) {
- if (cloudType != null && !DeltaCloudDriver.UNKNOWN.equals(cloudType)) {
- typeLabel.setText(cloudType.toString());
- } else {
- typeLabel.setText("?"); // $NON-NLS-1$
+ public Object convert(Object fromObject) {
+ if (fromObject instanceof DeltaCloudDriver) {
+ return ((DeltaCloudDriver) fromObject).name();
}
+ return null;
}
}
@@ -201,7 +187,6 @@
setMessage(success);
showDecorations(!success);
}
-
});
monitor.done();
}
@@ -297,7 +282,6 @@
public CloudConnectionPage(String pageName, DeltaCloud initial, CloudConnection
connection)
throws MalformedURLException, DeltaCloudException {
-
this(pageName, initial.getName(), initial.getURL(), initial.getUsername(),
initial.getPassword(), initial.getDriver(), connection);
}
@@ -354,8 +338,16 @@
Label typeLabel = new Label(container, SWT.NULL);
typeLabel.setText(WizardMessages.getString(CLOUDTYPE_LABEL));
Label computedTypeLabel = new Label(container, SWT.NULL);
- Binding urlTypeBinding = bindCloudType(dbc, urlText, computedTypeLabel);
+ Binding typeLabelBinding = bindCloudType(dbc, urlText, computedTypeLabel);
+ // bind url text decoration to type
+ ControlDecoration decoration = JFaceUtils.createDecoration(
+ urlText, WizardMessages.getString("IllegalCloudUrl.msg"),
FieldDecorationRegistry.DEC_WARNING);
+ IObservableValue validationStatusProvider = typeLabelBinding.getValidationStatus();
+ DataBindingUtils.addValueChangeListener(
+ new ControlDecorationAdapter(decoration, (IStatus)
validationStatusProvider.getValue()),
+ typeLabelBinding.getValidationStatus(), urlText);
+
// set url from preferences
String url =
new StringPreferenceValue(IPreferenceKeys.LAST_URL,
Activator.PLUGIN_ID).get(urlText.getText());
@@ -365,7 +357,8 @@
Label usernameLabel = new Label(container, SWT.NULL);
usernameLabel.setText(WizardMessages.getString(USERNAME_LABEL));
Text usernameText = new Text(container, SWT.BORDER | SWT.SINGLE);
- UIUtils.createPreferencesProposalAdapter(usernameText,
IDeltaCloudPreferenceConstants.CLOUD_USERNAME_PROPOSAL_KEY);
+ UIUtils.createPreferencesProposalAdapter(usernameText,
+ IDeltaCloudPreferenceConstants.CLOUD_USERNAME_PROPOSAL_KEY);
IObservableValue usernameObservable =
WidgetProperties.text(SWT.Modify).observe(usernameText);
dbc.bindValue(
usernameObservable,
@@ -384,16 +377,16 @@
// test button
final Button testButton = new Button(container, SWT.NULL);
testButton.setText(WizardMessages.getString(TESTBUTTON_LABEL));
- boolean isUrlValid = ((IStatus)
urlTypeBinding.getValidationStatus().getValue()).getSeverity() == IStatus.OK;
- urlTypeBinding.getValidationStatus().addValueChangeListener(
- enableButtonOnUrlValidityChanges(testButton, isUrlValid));
+ bindTestButtonEnablement(testButton, dbc);
CredentialsTestAdapter credentialsTestAdapter = new CredentialsTestAdapter(
usernameText,
passwordText);
testButton.addSelectionListener(credentialsTestAdapter);
- usernameObservable.addValueChangeListener(credentialsTestAdapter);
- passwordTextObservable.addValueChangeListener(credentialsTestAdapter);
+ DataBindingUtils.addValueChangeListener(
+ credentialsTestAdapter, usernameObservable, usernameText);
+ DataBindingUtils.addValueChangeListener(
+ credentialsTestAdapter, passwordTextObservable, passwordText);
// ec2 user link
Link ec2userLink = new Link(container, SWT.NULL);
@@ -486,24 +479,25 @@
}
/**
- * Enables/Disables (credentials) test button on url validity changes.
+ * Enables/Disables (credentials) test button on changes in the driver
+ * property of the model.
*
* @param testButton
- * the test button
- * @param isUrlValid
- * @return the i value change listener
+ * the test button to bind
+ * @param dbc
+ * the databinding context to use
*/
- private IValueChangeListener enableButtonOnUrlValidityChanges(final Button testButton,
boolean isUrlValid) {
-
- testButton.setEnabled(isUrlValid);
- return new IValueChangeListener() {
-
- @Override
- public void handleValueChange(ValueChangeEvent event) {
- IStatus status = (IStatus) event.diff.getNewValue();
- testButton.setEnabled(status.isOK());
- }
- };
+ private void bindTestButtonEnablement(final Button testButton, DataBindingContext dbc)
{
+ dbc.bindValue(
+ WidgetProperties.enabled().observe(testButton),
+ BeanProperties.value(CloudConnectionPageModel.PROPERTY_DRIVER).observe(connectionModel),
+ new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER),
+ new UpdateValueStrategy().setConverter(new Converter(DeltaCloudDriver.class,
Boolean.class) {
+ @Override
+ public Object convert(Object fromObject) {
+ return connectionModel.isKnownCloud(fromObject);
+ }
+ }));
}
/**
@@ -520,37 +514,43 @@
* @param typeLabel
* the cloud type label to display the cloud type in
* @return
+ * @return
* @return the binding that was created
*/
private Binding bindCloudType(DataBindingContext dbc, Text urlText, final Label
typeLabel) {
- UpdateValueStrategy updateStrategy = new UpdateValueStrategy();
- Url2DriverConverter urlToCloudTypeConverter = new Url2DriverConverter();
- updateStrategy.setConverter(urlToCloudTypeConverter);
- updateStrategy.setBeforeSetValidator(new CloudDriverValidator());
- // bind url to cloud type in model
- Binding urlTypeBinding = dbc.bindValue(
- WidgetProperties.text(SWT.Modify).observeDelayed(CLOUDTYPE_CHECK_DELAY, urlText),
+ // bind driver value to driver label
+ Binding typeLabelBinding = dbc.bindValue(
+ WidgetProperties.text().observe(typeLabel),
BeanProperties.value(CloudConnectionPageModel.PROPERTY_DRIVER).observe(connectionModel),
- updateStrategy,
- new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER));
- /*
- * bind converter to delta cloud label.
- *
- * Cloud type cannot be fetched from the model since invalid url's don't
- * get propagated to the model and no type update happens in this case.
- * We could not show invalid urls in the label if we would get the type
- * in the model.
- */
- IObservableValue cloudTypeObservable =
urlToCloudTypeConverter.getCloudTypeObservable();
- Object value = cloudTypeObservable.getValue();
- Assert.isTrue(value == null || value instanceof DeltaCloudDriver);
- DeltaCloudTypeLabelAdapter cloudTypeAdapter = new
DeltaCloudTypeLabelAdapter((DeltaCloudDriver) value,
- typeLabel);
- cloudTypeObservable.addValueChangeListener(cloudTypeAdapter);
- ControlDecorationSupport.create(urlTypeBinding, SWT.LEFT | SWT.TOP);
+ new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER),
+ new UpdateValueStrategy()
+ .setConverter(new Driver2Label())
+ .setAfterGetValidator(new IValidator() {
+ @Override
+ public IStatus validate(Object value) {
+ if (connectionModel.isKnownCloud(value)) {
+ return ValidationStatus.ok();
+ } else {
+ return
ValidationStatus.warning(WizardMessages.getString("IllegalCloudUrl.msg"));
+ }
+ }
+ })
+ );
- return urlTypeBinding;
+ // set driver value when user stops typing or moves focus away
+ DataBindingUtils.addValueChangeListener(
+ new IValueChangeListener() {
+
+ @Override
+ public void handleValueChange(ValueChangeEvent event) {
+ String url = (String) event.diff.getNewValue();
+ connectionModel.setDriverByUrl(url);
+ }
+ },
+ WidgetProperties.text(SWT.Modify).observeDelayed(CLOUDTYPE_CHECK_DELAY, urlText),
+ urlText);
+ return typeLabelBinding;
}
/**
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPageModel.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPageModel.java 2011-03-23
18:46:48 UTC (rev 29980)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPageModel.java 2011-03-23
20:40:23 UTC (rev 29981)
@@ -11,14 +11,21 @@
package org.jboss.tools.internal.deltacloud.ui.wizards;
import java.net.MalformedURLException;
+import java.text.MessageFormat;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.jboss.tools.deltacloud.core.DeltaCloud;
import org.jboss.tools.deltacloud.core.DeltaCloudDriver;
-import org.jboss.tools.internal.deltacloud.core.observable.ObservablePojo;
+import org.jboss.tools.deltacloud.core.DeltaCloudException;
+import
org.jboss.tools.internal.deltacloud.ui.common.databinding.validator.ObservableUIPojo;
/**
* @author Andre Dietisheim
*/
-public class CloudConnectionPageModel extends ObservablePojo {
+public class CloudConnectionPageModel extends ObservableUIPojo {
public static final String PROPERTY_URL = "url"; //$NON-NLS-1$
public static final String PROPERTY_NAME = "name"; //$NON-NLS-1$
@@ -42,17 +49,19 @@
this("", "", "", "",
DeltaCloudDriver.UNKNOWN);
}
- public CloudConnectionPageModel(String name, String url, String username, String
password) throws MalformedURLException {
+ public CloudConnectionPageModel(String name, String url, String username, String
password)
+ throws MalformedURLException {
this(name, url, username, password, DeltaCloudDriver.UNKNOWN);
}
public CloudConnectionPageModel(String name, String url, String username, String
password, DeltaCloudDriver driver) {
this.name = name;
this.initialName = name;
- this.url = url;
+ this.url = url;
this.username = username;
this.password = password;
- this.driver = driver;
+ // this.driver = driver;
+ setDriverByUrl(url);
}
public String getUsername() {
@@ -98,4 +107,41 @@
public void setDriver(DeltaCloudDriver driver) {
firePropertyChange(PROPERTY_DRIVER, this.driver, this.driver = driver);
}
+
+ /**
+ * Sets the driver for a given cloud url. Queries the cloud at the given url
+ * and determine its driver.
+ *
+ * @param cloudUrl
+ * the url of the cloud to query
+ */
+ public void setDriverByUrl(final String url) {
+ setDriver(DeltaCloudDriver.UNKNOWN);
+ new Job(MessageFormat.format("Determining driver for cloud at url {0}", url))
{
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ DeltaCloudDriver driver = getDriverFor(url);
+ setDriver(driver);
+ return Status.OK_STATUS;
+ }
+
+ }.schedule();
+ }
+
+ private DeltaCloudDriver getDriverFor(String url) {
+ try {
+ return DeltaCloud.getServerDriver(url);
+ } catch (DeltaCloudException e) {
+ return DeltaCloudDriver.UNKNOWN;
+ }
+ }
+
+ public boolean isKnownCloud(Object value) {
+ if (value instanceof DeltaCloudDriver) {
+ DeltaCloudDriver driver = (DeltaCloudDriver) value;
+ return driver != DeltaCloudDriver.UNKNOWN;
+ }
+ return false;
+ }
}