[jbosstools-commits] JBoss Tools SVN: r43755 - trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Mon Sep 17 12:57:42 EDT 2012


Author: adietish
Date: 2012-09-17 12:57:41 -0400 (Mon, 17 Sep 2012)
New Revision: 43755

Added:
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/AlphanumericStringValidator.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/RequiredControlDecorationUpdater.java
   trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/ValidationStatusControlDecoration.java
Log:
[JBIDE-11912] implemented binding and decoration. Renamed CustomControlDecorationUpdater to RequiredControlDecorationUpdater & moved to databinding package. Extracted AlphanumerStringValidator. Extracted SSH2Home extraction from DomainWizard to util-class.

Added: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/AlphanumericStringValidator.java
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/AlphanumericStringValidator.java	                        (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/AlphanumericStringValidator.java	2012-09-17 16:57:41 UTC (rev 43755)
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.openshift.express.internal.ui.databinding;
+
+import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.core.databinding.validation.ValidationStatus;
+import org.eclipse.core.runtime.IStatus;
+import org.jboss.tools.openshift.express.internal.ui.utils.StringUtils;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class AlphanumericStringValidator implements IValidator {
+
+	private String fieldName;
+
+	public AlphanumericStringValidator(String fieldName) {
+		this.fieldName = fieldName;
+	}
+
+	@Override
+	public IStatus validate(Object value) {
+		String name = (String) value;
+		if (StringUtils.isEmpty(name)) {
+			return ValidationStatus.cancel("You have to provide a " + fieldName);
+		} else if (!StringUtils.isAlphaNumeric(name)) {
+			return ValidationStatus.cancel("You have to provide an alphanumeric " + fieldName);
+		}
+		return ValidationStatus.ok();
+	}
+
+}


Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/AlphanumericStringValidator.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Copied: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/RequiredControlDecorationUpdater.java (from rev 43743, trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/CustomControlDecorationUpdater.java)
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/RequiredControlDecorationUpdater.java	                        (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/RequiredControlDecorationUpdater.java	2012-09-17 16:57:41 UTC (rev 43755)
@@ -0,0 +1,76 @@
+/******************************************************************************* 
+ * Copyright (c) 2012 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.openshift.express.internal.ui.databinding;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.databinding.fieldassist.ControlDecorationUpdater;
+import org.eclipse.jface.fieldassist.FieldDecoration;
+import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * A custom control decoration updater that would display the "required" (*)
+ * decoration to a control if the validation status is IStatus#CANCEL
+ * 
+ * @author Xavier Coulon
+ *
+ * @see IStatus#CANCEL
+ */
+public class RequiredControlDecorationUpdater extends ControlDecorationUpdater {
+
+	private final boolean showRequiredDecorator;
+
+	/**
+	 * Default constructor: provides a 'REQUIRED' decorator when the status is
+	 * CANCEL
+	 */
+	public RequiredControlDecorationUpdater() {
+		this(true);
+	}
+
+	/**
+	 * Default constructor: provides a 'REQUIRED' decorator when the status is
+	 * CANCEL
+	 */
+	public RequiredControlDecorationUpdater(final boolean showRequiredDecorator) {
+		super();
+		this.showRequiredDecorator = showRequiredDecorator;
+	}
+
+	/**
+	 * {@inheritDoc} Overrides the standard behaviour: for CANCEL status, items
+	 * are decorated with the REQUIRED decorator, not the ERROR one.
+	 */
+	@Override
+	protected Image getImage(IStatus status) {
+		if (status == null) {
+			return null;
+		}
+		String fieldDecorationID = null;
+		switch (status.getSeverity()) {
+		case IStatus.INFO:
+			fieldDecorationID = FieldDecorationRegistry.DEC_INFORMATION;
+			break;
+		case IStatus.WARNING:
+			fieldDecorationID = FieldDecorationRegistry.DEC_WARNING;
+			break;
+		case IStatus.ERROR:
+			fieldDecorationID = FieldDecorationRegistry.DEC_ERROR;
+			break;
+		case IStatus.CANCEL:
+			fieldDecorationID = showRequiredDecorator ? FieldDecorationRegistry.DEC_REQUIRED : null;
+			break;
+		}
+
+		FieldDecoration fieldDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(fieldDecorationID);
+		return fieldDecoration == null ? null : fieldDecoration.getImage();
+	}
+}


Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/RequiredControlDecorationUpdater.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Copied: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/ValidationStatusControlDecoration.java (from rev 43743, trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/ValidationStatusControlDecoration.java)
===================================================================
--- trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/ValidationStatusControlDecoration.java	                        (rev 0)
+++ trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/ValidationStatusControlDecoration.java	2012-09-17 16:57:41 UTC (rev 43755)
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.openshift.express.internal.ui.databinding;
+
+import org.eclipse.core.databinding.ValidationStatusProvider;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.databinding.observable.value.IValueChangeListener;
+import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jface.fieldassist.ControlDecoration;
+import org.eclipse.jface.fieldassist.FieldDecoration;
+import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.widgets.Control;
+
+/**
+ * @author André Dietisheim
+ */
+public class ValidationStatusControlDecoration {
+
+	private IObservableValue validationStatus;
+
+	public ValidationStatusControlDecoration(ValidationStatusProvider provider) {
+		this.validationStatus = provider.getValidationStatus();
+	}
+
+	public void showFor(Control control, int position) {
+		ControlDecoration decoration = createDecoration(control, position);
+		IValueChangeListener validationStatusListener = onValidationStatusChanged(decoration);
+		
+		validationStatus.addValueChangeListener(validationStatusListener);
+		control.addDisposeListener(onControlDisposed(validationStatusListener));
+
+	}
+	
+	private ControlDecoration createDecoration(Control control, int position) {
+		ControlDecoration controlDecoration = new ControlDecoration(control, position);
+		FieldDecoration fieldDecoration =
+				FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR);
+		controlDecoration.setImage(fieldDecoration.getImage());
+		if (validationStatus.getValue() instanceof IStatus) {
+			showDecoration(controlDecoration, (IStatus) validationStatus.getValue());
+		}
+		return controlDecoration;
+	}
+
+	private DisposeListener onControlDisposed(final IValueChangeListener validationStatusListener) {
+		return new DisposeListener() {
+			
+			@Override
+			public void widgetDisposed(DisposeEvent e) {
+				validationStatus.removeValueChangeListener(validationStatusListener);
+			}
+		};
+	}
+
+	private IValueChangeListener onValidationStatusChanged(final ControlDecoration controlDecoration) {
+		return new IValueChangeListener() {
+
+			@Override
+			public void handleValueChange(ValueChangeEvent event) {
+				if (!(event.diff.getNewValue() instanceof IStatus)) {
+					return;
+				}
+				IStatus validationStatus = (IStatus) event.diff.getNewValue();
+				showDecoration(controlDecoration, validationStatus);
+			}
+		};
+	}
+
+	private void showDecoration(final ControlDecoration controlDecoration, IStatus validationStatus) {
+		if (validationStatus.isOK()) {
+			controlDecoration.hide();
+		} else {
+			controlDecoration.show();
+		}
+	}
+
+}


Property changes on: trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/databinding/ValidationStatusControlDecoration.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain



More information about the jbosstools-commits mailing list