Author: adietish
Date: 2012-10-18 13:33:26 -0400 (Thu, 18 Oct 2012)
New Revision: 44585
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/connection/ConnectionWizardPage.java
trunk/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:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/connection/ConnectionWizardPage.java
===================================================================
---
trunk/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)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/connection/ConnectionWizardPage.java 2012-10-18
17:33:26 UTC (rev 44585)
@@ -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))
- .converting(new TrimmingStringConverter())
- .validatingAfterGet(new RequiredStringValidator("username"))
+ IObservableValue usernameObservable =
WidgetProperties.text(SWT.Modify).observe(rhLoginText);
+ ValueBindingBuilder
+ .bind(usernameObservable)
+ .converting(new TrimmingStringConverter())
.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,7 +392,38 @@
}
}
- public Connection getConnection() {
+ 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:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/connection/ConnectionWizardPageModel.java
===================================================================
---
trunk/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)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/connection/ConnectionWizardPageModel.java 2012-10-18
17:33:26 UTC (rev 44585)
@@ -20,6 +20,7 @@
import org.eclipse.osgi.util.NLS;
import org.jboss.tools.common.ui.databinding.ObservableUIPojo;
import org.jboss.tools.openshift.express.internal.core.connection.Connection;
+import org.jboss.tools.openshift.express.internal.core.connection.ConnectionUtils;
import org.jboss.tools.openshift.express.internal.core.connection.ConnectionsModel;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
import org.jboss.tools.openshift.express.internal.ui.utils.CollectionUtils;
@@ -27,6 +28,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 +63,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 +73,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;
}
@@ -114,6 +121,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());
@@ -137,8 +145,9 @@
if (this.isDefaultServer != isDefaultServer) {
firePropertyChange(PROPERTY_USE_DEFAULTSERVER,
this.isDefaultServer, this.isDefaultServer = isDefaultServer);
+ resetValid();
if (isDefaultServer) {
- setServer(editedConnection.getHost());
+ setServer(ConnectionUtils.getDefaultHostUrl());
}
resetValid();
}
@@ -235,6 +244,9 @@
} 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()));