Author: adietish
Date: 2010-10-26 05:06:26 -0400 (Tue, 26 Oct 2010)
New Revision: 26046
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/Url2DeltaCloudTypeConverter.java
Removed:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/UrlToCloudTypeConverter.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionModel.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/EditCloudConnection.java
Log:
[JBIDE-7402] implemented listener to url2DeltaCloudTypeConverter
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionModel.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionModel.java 2010-10-26
08:31:12 UTC (rev 26045)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionModel.java 2010-10-26
09:06:26 UTC (rev 26046)
@@ -10,7 +10,10 @@
******************************************************************************/
package org.jboss.tools.internal.deltacloud.ui.wizards;
+import java.net.MalformedURLException;
+
import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClient.DeltaCloudType;
import org.jboss.tools.internal.deltacloud.ui.common.databinding.ObservablePojo;
/**
@@ -34,14 +37,45 @@
private String password;
private DeltaCloudClient.DeltaCloudType cloudType;
+ private String initialName;
- public CloudConnectionModel(String name, String url, String username, String password)
{
+ public CloudConnectionModel() {
+ this("", "", "", "", (DeltaCloudType) null);
+ }
+
+ public CloudConnectionModel(String name, String url, String username, String password,
String cloudType) throws MalformedURLException {
+ this(name, url, username, password, getDeltaCloudType(cloudType, url));
+ }
+
+ public CloudConnectionModel(String name, String url, String username, String password)
throws MalformedURLException {
+ this(name, url, username, password, getDeltaCloudTypeFromUrl(url));
+ }
+
+ public CloudConnectionModel(String name, String url, String username, String password,
DeltaCloudType deltaCloudType) {
this.name = name;
+ this.initialName = name;
this.url = url;
this.username = username;
this.password = password;
+ this.cloudType = deltaCloudType;
}
+
+ private static DeltaCloudType getDeltaCloudTypeFromUrl(String url) throws
MalformedURLException {
+ return new DeltaCloudClient(url, "", "").getServerType();
+ }
+ private static DeltaCloudType getDeltaCloudType(String cloudType, String url) throws
MalformedURLException {
+ if (cloudType == null) {
+ return null;
+ }
+
+ try {
+ return DeltaCloudType.valueOf(cloudType);
+ } catch (IllegalArgumentException e) {
+ return getDeltaCloudTypeFromUrl(url);
+ }
+ }
+
public String getUsername() {
return username;
}
@@ -58,6 +92,10 @@
getPropertyChangeSupport().firePropertyChange(PROPERTY_PASSWORD, this.password,
this.password = password);
}
+ public String getInitialName() {
+ return initialName;
+ }
+
public String getName() {
return name;
}
@@ -67,18 +105,22 @@
}
public String getUrl() {
+ System.err.println("getting url: " + url);
return url;
}
public void setUrl(String url) {
+ System.err.println("url set to: " + url);
getPropertyChangeSupport().firePropertyChange(PROPERTY_URL, this.url, this.url = url);
}
public DeltaCloudClient.DeltaCloudType getType() {
+ System.err.println("getting cloud type: " + cloudType);
return cloudType;
}
public void setType(DeltaCloudClient.DeltaCloudType cloudType) {
+ System.err.println("cloud type set to " + cloudType);
getPropertyChangeSupport().firePropertyChange(PROPERTY_TYPE, this.cloudType,
this.cloudType = cloudType);
}
}
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-26
08:31:12 UTC (rev 26045)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java 2010-10-26
09:06:26 UTC (rev 26046)
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.jboss.tools.internal.deltacloud.ui.wizards;
+import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.core.databinding.Binding;
@@ -21,6 +22,7 @@
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.Assert;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.databinding.fieldassist.ControlDecorationSupport;
import org.eclipse.jface.databinding.swt.ISWTObservableValue;
@@ -46,6 +48,7 @@
import org.eclipse.ui.PlatformUI;
import org.jboss.tools.common.log.LogHelper;
import org.jboss.tools.deltacloud.core.DeltaCloudManager;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClient.DeltaCloudType;
import org.jboss.tools.deltacloud.ui.Activator;
import org.jboss.tools.deltacloud.ui.SWTImagesFactory;
import
org.jboss.tools.internal.deltacloud.ui.common.databinding.validator.CompositeValidator;
@@ -93,20 +96,60 @@
}
};
+ /**
+ * Displays the cloud type in the given label. Listens to ValueChangeEvents
+ * and sets the given label accordingly.
+ *
+ * @param typeLabel
+ * the label that shall display the delta cloud type
+ *
+ * @see IValueChangeListener
+ * @see DeltaCloudType
+ */
+ private class DeltaCloudTypeLabelAdapter implements IValueChangeListener {
+
+ private Label typeLabel;
+
+ public DeltaCloudTypeLabelAdapter(DeltaCloudType cloudType, Label typeLabel) {
+ this.typeLabel = typeLabel;
+ init(cloudType);
+ }
+
+ private void init(DeltaCloudType cloudType) {
+ setLabelText(cloudType);
+ }
+
+ @Override
+ public void handleValueChange(ValueChangeEvent event) {
+ Object newValue = event.diff.getNewValue();
+ Assert.isTrue(newValue instanceof DeltaCloudType);
+ setLabelText((DeltaCloudType) newValue);
+ }
+
+ private void setLabelText(DeltaCloudType cloudType) {
+ if (cloudType != null && cloudType != DeltaCloudType.UNKNOWN) {
+ typeLabel.setText(cloudType.toString());
+ } else {
+ typeLabel.setText("?"); // $NON-NLS-1$
+ }
+ }
+ }
+
public CloudConnectionPage(String pageName, CloudConnection cloudConnection) {
super(pageName);
setDescription(WizardMessages.getString(DESCRIPTION));
setTitle(WizardMessages.getString(TITLE));
setImageDescriptor(SWTImagesFactory.DESC_DELTA_LARGE);
- this.connectionModel = new CloudConnectionModel("", "",
"", "");
+ this.connectionModel = new CloudConnectionModel();
this.cloudConnection = cloudConnection;
}
public CloudConnectionPage(String pageName, String defaultName, String defaultUrl,
String defaultUsername, String defaultPassword, String defaultType,
- CloudConnection cloudConnection) {
+ CloudConnection cloudConnection) throws MalformedURLException {
super(pageName);
- this.connectionModel = new CloudConnectionModel(defaultName, defaultUrl,
defaultUsername, defaultPassword);
+ this.connectionModel = new CloudConnectionModel(defaultName, defaultUrl,
defaultUsername, defaultPassword,
+ defaultType);
this.cloudConnection = cloudConnection;
setDescription(WizardMessages.getString(DESCRIPTION));
setTitle(WizardMessages.getString(TITLE));
@@ -142,15 +185,15 @@
WidgetProperties.text(SWT.Modify).observeDelayed(CLOUDTYPE_CHECK_DELAY, urlText),
BeanProperties.value(CloudConnectionModel.class, CloudConnectionModel.PROPERTY_URL)
.observe(connectionModel),
- new UpdateValueStrategy().setAfterGetValidator(new MandatoryStringValidator(
- WizardMessages.getString(MUST_ENTER_A_URL))),
+ new UpdateValueStrategy().setAfterGetValidator(
+ new MandatoryStringValidator(WizardMessages.getString(MUST_ENTER_A_URL))),
null);
// cloud type
Label typeLabel = new Label(container, SWT.NULL);
typeLabel.setText(WizardMessages.getString(CLOUDTYPE_LABEL));
Label computedTypeLabel = new Label(container, SWT.NULL);
- Binding urlBinding = bindCloudTypeLabel(dbc, urlText, computedTypeLabel);
+ Binding urlBinding = bindCloudType(dbc, urlText, computedTypeLabel);
// username
Label usernameLabel = new Label(container, SWT.NULL);
@@ -160,8 +203,8 @@
IObservableValue usernameObservable =
WidgetProperties.text(SWT.Modify).observe(usernameText);
dbc.bindValue(
usernameObservable,
- BeanProperties.value(CloudConnectionModel.class,
CloudConnectionModel.PROPERTY_USERNAME).observe(
- connectionModel));
+ BeanProperties.value(CloudConnectionModel.class,
CloudConnectionModel.PROPERTY_USERNAME)
+ .observe(connectionModel));
// password
Label passwordLabel = new Label(container, SWT.NULL);
@@ -294,32 +337,6 @@
}
/**
- * Displays the cloud type in the given if the given binding is valid.
- *
- * @param typeLabel
- * the type label
- * @return the value change listener
- */
- private class CloudTypeAdapter implements IValueChangeListener {
-
- private Label typeLabel;
-
- public CloudTypeAdapter(Label typeLabel) {
- this.typeLabel = typeLabel;
- }
-
- @Override
- public void handleValueChange(ValueChangeEvent event) {
- IStatus status = (IStatus) event.diff.getNewValue();
- if (status.isOK()) {
- typeLabel.setText(connectionModel.getType().toString());
- } else {
- typeLabel.setText("");
- }
- }
- }
-
- /**
* Binds the given cloud type label to the given url text widget. Attaches a
* listener to the url text widget Adds a validity decorator to the url text
* widget.
@@ -333,18 +350,26 @@
* @return
* @return the binding that was created
*/
- private Binding bindCloudTypeLabel(DataBindingContext dbc, Text urlText, final Label
typeLabel) {
+ private Binding bindCloudType(DataBindingContext dbc, Text urlText, final Label
typeLabel) {
UpdateValueStrategy updateStrategy = new UpdateValueStrategy();
- updateStrategy.setConverter(new UrlToCloudTypeConverter());
+ Url2DeltaCloudTypeConverter urlToCloudTypeConverter = new
Url2DeltaCloudTypeConverter();
+ updateStrategy.setConverter(urlToCloudTypeConverter);
updateStrategy.setBeforeSetValidator(new CloudTypeValidator());
Binding binding = dbc.bindValue(
- WidgetProperties.text(SWT.Modify).observeDelayed(100, urlText),
+ WidgetProperties.text(SWT.Modify).observe(urlText),
BeanProperties.value(CloudConnectionModel.PROPERTY_TYPE).observe(connectionModel),
updateStrategy,
new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER));
- binding.getValidationStatus().addValueChangeListener(new CloudTypeAdapter(typeLabel));
+
+ // bind converter to delta cloud label
+ IObservableValue cloudTypeObservable =
urlToCloudTypeConverter.getCloudTypeObservable();
+ DeltaCloudTypeLabelAdapter cloudTypeAdapter = new DeltaCloudTypeLabelAdapter(
+ (DeltaCloudType) cloudTypeObservable.getValue(), typeLabel);
+ cloudTypeObservable.addValueChangeListener(cloudTypeAdapter);
+
ControlDecorationSupport.create(binding, SWT.LEFT | SWT.TOP);
+
return binding;
}
@@ -369,7 +394,12 @@
@Override
public IStatus validate(Object value) {
- if (nameText.getText() != null
+ /*
+ * keeping the same name when editing
+ * must be valid
+ */
+ if (!nameText.getText().equals(connectionModel.getInitialName())
+ /* all new names must be unique */
&& DeltaCloudManager.getDefault().findCloud(nameText.getText()) !=
null) {
return ValidationStatus
.error(WizardMessages.getString(NAME_ALREADY_IN_USE));
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/EditCloudConnection.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/EditCloudConnection.java 2010-10-26
08:31:12 UTC (rev 26045)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/EditCloudConnection.java 2010-10-26
09:06:26 UTC (rev 26046)
@@ -12,8 +12,11 @@
import java.net.MalformedURLException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.security.storage.ISecurePreferences;
import org.eclipse.equinox.security.storage.SecurePreferencesFactory;
+import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
@@ -40,9 +43,14 @@
@Override
public void addPages() {
String password = getPassword();
- mainPage = new CloudConnectionPage(WizardMessages.getString(MAINPAGE_NAME),
- cloud.getName(), cloud.getURL(), cloud.getUsername(), password,
- cloud.getType(), this);
+ try {
+ mainPage = new CloudConnectionPage(WizardMessages.getString(MAINPAGE_NAME),
+ cloud.getName(), cloud.getURL(), cloud.getUsername(), password,
+ cloud.getType(), this);
+ } catch (MalformedURLException e) {
+ Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR,
e.getMessage(), e);
+ ErrorDialog.openError(getShell(), "Error", "Could not open connection
wizard", status);
+ }
addPage(mainPage);
}
Copied:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/Url2DeltaCloudTypeConverter.java
(from rev 26044,
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/UrlToCloudTypeConverter.java)
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/Url2DeltaCloudTypeConverter.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/Url2DeltaCloudTypeConverter.java 2010-10-26
09:06:26 UTC (rev 26046)
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * 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.net.MalformedURLException;
+
+import org.eclipse.core.databinding.conversion.IConverter;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.databinding.observable.value.WritableValue;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClient.DeltaCloudType;
+
+/**
+ * A class that converts an url (string) to a DeltaCloudType (enum). The state
+ * of the converter may be tracked by tracking its observable value cloudType
+ * observable.
+ *
+ * @author Andre Dietisheim
+ *
+ * @see IConverter
+ * @see IObservableValue
+ * @see #getCloudTypeObservable()
+ */
+public class Url2DeltaCloudTypeConverter implements IConverter {
+
+ IObservableValue cloudTypeObservable = new WritableValue();
+
+ @Override
+ public Object getFromType() {
+ return String.class;
+ }
+
+ @Override
+ public Object getToType() {
+ return DeltaCloudClient.DeltaCloudType.class;
+ }
+
+ @Override
+ public Object convert(Object fromObject) {
+ String deltaCloudUrl = (String) fromObject;
+ DeltaCloudType cloudType = getCloudType(deltaCloudUrl);
+ cloudTypeObservable.setValue(cloudType);
+ return cloudType;
+ }
+
+ private DeltaCloudType getCloudType(String deltaCloudUrl) {
+ try {
+ return new DeltaCloudClient(deltaCloudUrl, "",
"").getServerType();
+ } catch (MalformedURLException e) {
+ return null;
+ }
+ }
+
+ public IObservableValue getCloudTypeObservable() {
+ return cloudTypeObservable;
+ }
+}
Property changes on:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/Url2DeltaCloudTypeConverter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/UrlToCloudTypeConverter.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/UrlToCloudTypeConverter.java 2010-10-26
08:31:12 UTC (rev 26045)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/UrlToCloudTypeConverter.java 2010-10-26
09:06:26 UTC (rev 26046)
@@ -1,43 +0,0 @@
-/*******************************************************************************
- * 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.net.MalformedURLException;
-
-import org.eclipse.core.databinding.conversion.IConverter;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
-
-/**
- * @author Andre Dietisheim
- */
-public class UrlToCloudTypeConverter implements IConverter {
-
- @Override
- public Object getFromType() {
- return String.class;
- }
-
- @Override
- public Object getToType() {
- return DeltaCloudClient.DeltaCloudType.class;
- }
-
- @Override
- public Object convert(Object fromObject) {
- String deltaCloudUrl = (String) fromObject;
- try {
- return new DeltaCloudClient(deltaCloudUrl, "",
"").getServerType();
- } catch (MalformedURLException e) {
- return null;
- }
- }
-
-}