Author: adietish
Date: 2012-10-18 12:53:43 -0400 (Thu, 18 Oct 2012)
New Revision: 44584
Modified:
branches/jbosstools-4.0.0.Beta1/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/connection/ConnectionWizardPage.java
branches/jbosstools-4.0.0.Beta1/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/connection/ConnectionWizardPageModel.java
Log:
[JBIDE-12898] various fixes, switching from in-binding validation to
multivalidator-validation (which does not prevent non-valid values to make it to model)
Modified:
branches/jbosstools-4.0.0.Beta1/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/connection/ConnectionWizardPage.java
===================================================================
---
branches/jbosstools-4.0.0.Beta1/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/connection/ConnectionWizardPage.java 2012-10-18
16:43:58 UTC (rev 44583)
+++
branches/jbosstools-4.0.0.Beta1/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/connection/ConnectionWizardPage.java 2012-10-18
16:53:43 UTC (rev 44584)
@@ -14,7 +14,10 @@
import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.DataBindingContext;
+import org.eclipse.core.databinding.ValidationStatusProvider;
import org.eclipse.core.databinding.beans.BeanProperties;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.list.WritableList;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.observable.value.IValueChangeListener;
import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
@@ -54,7 +57,6 @@
import org.jboss.tools.openshift.express.internal.core.connection.Connection;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
import org.jboss.tools.openshift.express.internal.ui.OpenshiftUIMessages;
-import org.jboss.tools.openshift.express.internal.ui.databinding.HostNameValidator;
import
org.jboss.tools.openshift.express.internal.ui.databinding.RequiredControlDecorationUpdater;
import
org.jboss.tools.openshift.express.internal.ui.databinding.RequiredStringValidator;
import
org.jboss.tools.openshift.express.internal.ui.databinding.TrimmingStringConverter;
@@ -243,7 +245,7 @@
Combo serversCombo = new Combo(connectionWidgets, SWT.BORDER);
Binding serverBinding = ValueBindingBuilder
.bind(WidgetProperties.text().observe(serversCombo))
- .validatingAfterGet(new HostNameValidator())
+ .validatingAfterGet(new RequiredStringValidator("server"))
.to(BeanProperties.value(ConnectionWizardPageModel.PROPERTY_SERVER).observe(pageModel))
.in(dbc);
ControlDecorationSupport
@@ -273,14 +275,17 @@
rhLoginText = new Text(connectionWidgets, SWT.BORDER);
GridDataFactory.fillDefaults()
.align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1).applyTo(rhLoginText);
- Binding usernameBinding = ValueBindingBuilder
- .bind(WidgetProperties.text(SWT.Modify).observe(rhLoginText))
+ IObservableValue usernameObservable =
WidgetProperties.text(SWT.Modify).observe(rhLoginText);
+ ValueBindingBuilder
+ .bind(usernameObservable)
.converting(new TrimmingStringConverter())
- .validatingAfterGet(new RequiredStringValidator("username"))
.to(BeanProperties.value(ConnectionWizardPageModel.PROPERTY_USERNAME).observe(pageModel))
.in(dbc);
+ ValidationStatusProvider usernameValidation = new
RequiredStringValidationProvider(usernameObservable,
+ "username");
+ dbc.addValidationStatusProvider(usernameValidation);
ControlDecorationSupport
- .create(usernameBinding, SWT.LEFT | SWT.TOP, null, new
RequiredControlDecorationUpdater());
+ .create(usernameValidation, SWT.LEFT | SWT.TOP, null, new
RequiredControlDecorationUpdater());
// password
Label passwordLabel = new Label(connectionWidgets, SWT.NONE);
@@ -290,13 +295,16 @@
passwordText = new Text(connectionWidgets, SWT.BORDER | SWT.PASSWORD);
GridDataFactory.fillDefaults()
.align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(passwordText);
- Binding passwordBinding = ValueBindingBuilder
- .bind(WidgetProperties.text(SWT.Modify).observe(passwordText))
- .validatingAfterGet(new RequiredStringValidator("password"))
+ IObservableValue passwordObservable =
WidgetProperties.text(SWT.Modify).observe(passwordText);
+ ValueBindingBuilder
+ .bind(passwordObservable)
.to(BeanProperties.value(ConnectionWizardPageModel.PROPERTY_PASSWORD).observe(pageModel))
.in(dbc);
+ ValidationStatusProvider passwordValidation =
+ new RequiredStringValidationProvider(passwordObservable,"password");
+ dbc.addValidationStatusProvider(passwordValidation);
ControlDecorationSupport
- .create(passwordBinding, SWT.LEFT | SWT.TOP, null, new
RequiredControlDecorationUpdater());
+ .create(passwordValidation, SWT.LEFT | SWT.TOP, null, new
RequiredControlDecorationUpdater());
Button rememberPasswordCheckBox = new Button(connectionWidgets, SWT.CHECK);
rememberPasswordCheckBox.setText(OpenshiftUIMessages.OpenshiftWizardSavePassword);
@@ -312,7 +320,6 @@
final CredentialsValidator credentialsValidator =
new CredentialsValidator(credentialsStatusObservable);
dbc.addValidationStatusProvider(credentialsValidator);
- ControlDecorationSupport.create(credentialsValidator, SWT.LEFT | SWT.TOP);
return connectionWidgets;
}
@@ -385,6 +392,37 @@
}
}
+ class RequiredStringValidationProvider extends MultiValidator {
+
+ private IObservableValue observableValue;
+ private String name;
+
+ public RequiredStringValidationProvider(IObservableValue value, String name) {
+ this.observableValue = value;
+ this.name = name;
+ }
+
+ @Override
+ protected IStatus validate() {
+ if (!(observableValue.getValue() instanceof String)) {
+ return ValidationStatus.cancel("You have to provide a " + name);
+ }
+ String string = (String) observableValue.getValue();
+ if (string.isEmpty()) {
+ return ValidationStatus.cancel("You have to provide a " + name);
+ }
+ return ValidationStatus.ok();
+ }
+
+ @Override
+ public IObservableList getTargets() {
+ IObservableList targets = new WritableList();
+ targets.add(observableValue);
+ return targets;
+ }
+
+ }
+
public Connection getConnection() {
return pageModel.getConnection();
}
Modified:
branches/jbosstools-4.0.0.Beta1/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/connection/ConnectionWizardPageModel.java
===================================================================
---
branches/jbosstools-4.0.0.Beta1/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/connection/ConnectionWizardPageModel.java 2012-10-18
16:43:58 UTC (rev 44583)
+++
branches/jbosstools-4.0.0.Beta1/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/connection/ConnectionWizardPageModel.java 2012-10-18
16:53:43 UTC (rev 44584)
@@ -27,6 +27,7 @@
import org.jboss.tools.openshift.express.internal.ui.wizard.IConnectionAwareModel;
import com.openshift.client.IUser;
+import com.openshift.client.InvalidCredentialsOpenShiftException;
import com.openshift.client.NotFoundOpenShiftException;
import com.openshift.client.OpenShiftException;
import com.openshift.client.OpenShiftTimeoutException;
@@ -61,7 +62,7 @@
Connection wizardModelConnection = wizardModel.getConnection();
this.selectedConnection = getSelectedConnection(wizardModelConnection);
this.isCreateNewConnection = getIsCreateNewConnection(selectedConnection);
- this.editedConnection = createConnection(wizardModelConnection);
+ this.editedConnection = createConnection(selectedConnection);
this.servers = getServers(editedConnection);
}
@@ -71,7 +72,12 @@
private Connection getSelectedConnection(Connection wizardModelConnection) {
if (wizardModelConnection == null) {
- return new NewConnectionMarker();
+ Connection recentConnection = ConnectionsModel.getDefault().getRecentConnection();
+ if (recentConnection != null) {
+ return recentConnection;
+ } else {
+ return new NewConnectionMarker();
+ }
} else {
return wizardModelConnection;
}
@@ -116,6 +122,7 @@
private void setEditedConnection(Connection connection) {
Connection oldValue = editedConnection;
this.editedConnection = connection;
+ resetValid();
firePropertyChange(PROPERTY_SERVER, oldValue.getHost(),
this.editedConnection.getHost());
firePropertyChange(PROPERTY_USERNAME, oldValue.getUsername(),
this.editedConnection.getUsername());
firePropertyChange(PROPERTY_PASSWORD, oldValue.getPassword(),
this.editedConnection.getPassword());
@@ -139,10 +146,10 @@
if (this.isDefaultServer != isDefaultServer) {
firePropertyChange(PROPERTY_USE_DEFAULTSERVER,
this.isDefaultServer, this.isDefaultServer = isDefaultServer);
+ resetValid();
if (isDefaultServer) {
- setServer(editedConnection.getHost());
+ setServer(new Connection().getHost());
}
- resetValid();
}
}
@@ -237,9 +244,12 @@
} catch (OpenShiftTimeoutException e) {
status = OpenShiftUIActivator.createErrorStatus(NLS.bind(
"Could not reach server at {0}. Connection timeouted.",
editedConnection.getHost()));
+ } catch (InvalidCredentialsOpenShiftException e) {
+ status = OpenShiftUIActivator.createErrorStatus(NLS.bind(
+ "The credentials for user {0} are not valid",
editedConnection.getUsername()));
} catch (OpenShiftException e) {
status = OpenShiftUIActivator.createErrorStatus(NLS.bind(
- "The credentials for user {0} are not valid",
editedConnection.getUsername()));
+ "Could not check user credentials: {0}", e.getMessage()));
}
}
} catch (NotFoundOpenShiftException e) {