Author: adietish
Date: 2011-04-11 10:17:35 -0400 (Mon, 11 Apr 2011)
New Revision: 30472
Modified:
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnection.java
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPageModel.java
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnectionWizard.java
Log:
[JBIDE-8599]
Modified:
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnection.java
===================================================================
---
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnection.java 2011-04-11
14:03:00 UTC (rev 30471)
+++
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnection.java 2011-04-11
14:17:35 UTC (rev 30472)
@@ -1,7 +1,14 @@
package org.jboss.tools.internal.deltacloud.ui.wizards;
+import org.jboss.tools.deltacloud.core.DeltaCloud;
+
+/**
+ * @author Jeff Johnston
+ * @author André Dietisheim
+ */
public interface CloudConnection {
public boolean performTest();
+ public DeltaCloud getDeltaCloud();
}
Modified:
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java
===================================================================
---
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java 2011-04-11
14:03:00 UTC (rev 30471)
+++
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java 2011-04-11
14:17:35 UTC (rev 30472)
@@ -240,12 +240,19 @@
* keeping the same name when editing must be valid
*/
try {
- if (!connectionName.equals(connectionModel.getInitialName())
- /* all new names must be unique */
- && DeltaCloudManager.getDefault().findCloud(connectionName) != null) {
- return ValidationStatus
- .error(WizardMessages.getString(NAME_ALREADY_IN_USE));
+ /* all new names must be unique */
+ DeltaCloud deltaCloud = DeltaCloudManager.getDefault().findCloud(connectionName);
+ if (cloudConnection.getDeltaCloud() == null) {
+ if (deltaCloud == null) {
+ return ValidationStatus.ok();
+ }
+ } else {
+ if (cloudConnection.getDeltaCloud().equals(deltaCloud)) {
+ return ValidationStatus.ok();
+ }
}
+ return ValidationStatus
+ .error(WizardMessages.getString(NAME_ALREADY_IN_USE));
} catch (DeltaCloudException e) {
// do nothing
}
@@ -275,7 +282,11 @@
setDescription(WizardMessages.getString(DESCRIPTION));
setTitle(WizardMessages.getString(TITLE));
setImageDescriptor(SWTImagesFactory.DESC_DELTA_LARGE);
- this.connectionModel = new CloudConnectionPageModel();
+ this.connectionModel = new CloudConnectionPageModel(
+ new StringPreferenceValue(IPreferenceKeys.LAST_NAME, Activator.PLUGIN_ID).get(null),
+ new StringPreferenceValue(IPreferenceKeys.LAST_URL, Activator.PLUGIN_ID).get(null),
+ new StringPreferenceValue(IPreferenceKeys.LAST_USERNAME,
Activator.PLUGIN_ID).get(null),
+ null);
this.cloudConnection = cloudConnection;
}
@@ -289,6 +300,10 @@
public CloudConnectionPage(String pageName, String defaultName, String defaultUrl,
String defaultUsername,
String defaultPassword, Driver defaultDriver, CloudConnection cloudConnection) throws
MalformedURLException {
super(pageName);
+ defaultName = new StringPreferenceValue(IPreferenceKeys.LAST_NAME,
Activator.PLUGIN_ID).get(defaultName);
+ defaultUrl = new StringPreferenceValue(IPreferenceKeys.LAST_URL,
Activator.PLUGIN_ID).get(defaultUrl);
+ defaultUsername = new StringPreferenceValue(IPreferenceKeys.LAST_USERNAME,
Activator.PLUGIN_ID)
+ .get(defaultUsername);
this.connectionModel =
new CloudConnectionPageModel(defaultName, defaultUrl, defaultUsername,
defaultPassword, defaultDriver);
this.cloudConnection = cloudConnection;
@@ -316,19 +331,12 @@
nameLabel.setText(WizardMessages.getString(NAME_LABEL));
Text nameText = new Text(container, SWT.BORDER | SWT.SINGLE);
bindName(dbc, nameText);
- String name =
- new StringPreferenceValue(IPreferenceKeys.LAST_NAME,
Activator.PLUGIN_ID).get(nameText.getText());
-
- nameText.setText(name);
// url
Label urlLabel = new Label(container, SWT.NULL);
urlLabel.setText(WizardMessages.getString(URL_LABEL));
Point p1 = urlLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT);
Text urlText = new Text(container, SWT.BORDER | SWT.SINGLE);
- String url =
- new StringPreferenceValue(IPreferenceKeys.LAST_URL,
Activator.PLUGIN_ID).get(urlText.getText());
- connectionModel.setUrl(url);
dbc.bindValue(
WidgetProperties.text(SWT.Modify).observe(urlText),
@@ -362,10 +370,11 @@
usernameObservable,
BeanProperties.value(CloudConnectionPageModel.class,
CloudConnectionPageModel.PROPERTY_USERNAME)
.observe(connectionModel));
- String username =
- new StringPreferenceValue(IPreferenceKeys.LAST_USERNAME,
Activator.PLUGIN_ID).get(usernameText.getText());
+ String username =
+ new StringPreferenceValue(IPreferenceKeys.LAST_USERNAME,
Activator.PLUGIN_ID).get(usernameText
+ .getText());
usernameText.setText(username);
-
+
// password
Label passwordLabel = new Label(container, SWT.NULL);
passwordLabel.setText(WizardMessages.getString(PASSWORD_LABEL));
Modified:
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPageModel.java
===================================================================
---
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPageModel.java 2011-04-11
14:03:00 UTC (rev 30471)
+++
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPageModel.java 2011-04-11
14:17:35 UTC (rev 30472)
@@ -10,7 +10,7 @@
******************************************************************************/
package org.jboss.tools.internal.deltacloud.ui.wizards;
-import java.net.MalformedURLException;
+import java.net.URI;
import java.text.MessageFormat;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -37,32 +37,49 @@
public static final String INVALID_URL = "ErrorInvalidURL.text";
//$NON-NLS-1$
public static final String NONCLOUD_URL = "ErrorNonCloudURL.text";
//$NON-NLS-1$
+ private static final String HTTP_PREFIX = "http://"; //$NON-NLS-1$
+
private String name;
private String url;
private String username;
private String password;
private Driver driver;
- private String initialName;
- public CloudConnectionPageModel() {
- this("", "", "", "", Driver.UNKNOWN);
- }
-
- public CloudConnectionPageModel(String name, String url, String username, String
password) throws MalformedURLException {
+ public CloudConnectionPageModel(String name, String url, String username, String
password){
this(name, url, username, password, Driver.UNKNOWN);
}
public CloudConnectionPageModel(String name, String url, String username, String
password, Driver driver) {
this.name = name;
- this.initialName = name;
- this.url = url;
+ setUrl(prependHttp(url));
this.username = username;
this.password = password;
// this.driver = driver;
setDriverByUrl(url);
}
+ private String prependHttp(String url) {
+ if (!startsWithScheme(url)) {
+ return HTTP_PREFIX + url;
+ } else {
+ return url;
+ }
+ }
+
+ private boolean startsWithScheme(String url) {
+ if (url == null || url.length() == 0) {
+ return false;
+ } else {
+ try {
+ String scheme = URI.create(url).getScheme();
+ return scheme!=null && scheme.length() > 0;
+ } catch (IllegalArgumentException e ) {
+ return false;
+ }
+ }
+ }
+
public String getUsername() {
return username;
}
@@ -79,10 +96,6 @@
firePropertyChange(PROPERTY_PASSWORD, this.password, this.password = password);
}
- public String getInitialName() {
- return initialName;
- }
-
public String getName() {
return name;
}
Modified:
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnectionWizard.java
===================================================================
---
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnectionWizard.java 2011-04-11
14:03:00 UTC (rev 30471)
+++
branches/jbosstools-3.2.x/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewCloudConnectionWizard.java 2011-04-11
14:17:35 UTC (rev 30472)
@@ -151,4 +151,8 @@
return false;
}
}
+
+ public DeltaCloud getDeltaCloud() {
+ return initialCloud;
+ }
}