Author: adietish
Date: 2010-12-28 17:28:24 -0500 (Tue, 28 Dec 2010)
New Revision: 27785
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePage.java
Log:
[JBIDE-7763] added validation to key
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePage.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePage.java 2010-12-28
22:24:18 UTC (rev 27784)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePage.java 2010-12-28
22:28:24 UTC (rev 27785)
@@ -79,6 +79,7 @@
public class NewInstancePage extends WizardPage {
private static final int IMAGE_CHECK_DELAY = 500;
+ private static final int KEY_CHECK_DELAY = 500;
private final static String NAME = "NewInstance.name"; //$NON-NLS-1$
private final static String DESCRIPTION = "NewInstance.desc"; //$NON-NLS-1$
@@ -229,15 +230,12 @@
// name
bindText(nameText, NewInstancePageModel.PROPERTY_NAME,
WizardMessages.getString(MUST_ENTER_A_NAME), dbc);
- // image
IObservableValue imageObservable = bindImage(imageText, dbc);
- // arch label
bindArchLabel(imageObservable, dbc);
bindRealmCombo(realmCombo, dbc);
bindProfileCombo(hardwareCombo, dbc);
bindProfilePages(hardwareCombo, profilePages, dbc);
- // key
- bindText(keyText, NewInstancePageModel.PROPERTY_KEYID,
WizardMessages.getString(MUST_ENTER_A_KEYNAME), dbc);
+ bindKey(keyText, dbc);
}
private void bindArchLabel(IObservableValue imageObservable, DataBindingContext dbc) {
@@ -403,6 +401,43 @@
}
}
+ private void bindKey(Text text, DataBindingContext dbc) {
+ Binding textBinding = dbc.bindValue(
+ WidgetProperties.text(SWT.Modify).observeDelayed(KEY_CHECK_DELAY, text),
+ BeanProperties.value(NewInstancePageModel.class,
NewInstancePageModel.PROPERTY_KEYID).observe(model),
+ new UpdateValueStrategy()
+ .setBeforeSetValidator(
+ new MandatoryStringValidator(WizardMessages.getString(MUST_ENTER_A_KEYNAME)))
+ .setBeforeSetValidator(
+ new KeyValidator()),
+
+ null);
+ ControlDecorationSupport.create(textBinding, SWT.LEFT | SWT.TOP);
+ }
+
+ private class KeyValidator implements IValidator {
+
+ @Override
+ public IStatus validate(Object value) {
+ if (value instanceof String
+ && ((String) value).length() > 0) {
+ if (doesKeyExist((String) value)) {
+ return ValidationStatus.ok();
+ }
+ }
+ return ValidationStatus.error(MessageFormat.format(
+ "The key is not known to cloud \"{0}\"", cloud.getName()));
+ }
+
+ private boolean doesKeyExist(String keyId) {
+ try {
+ return cloud.getKey(keyId) != null;
+ } catch (DeltaCloudException e) {
+ return false;
+ }
+ }
+ }
+
private void bindText(Text text, String property, String errorMessage,
DataBindingContext dbc) {
Binding textBinding = dbc.bindValue(
WidgetProperties.text(SWT.Modify).observe(text),
Show replies by date