[jbosstools-commits] JBoss Tools SVN: r35553 - trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Tue Oct 11 15:35:49 EDT 2011


Author: adietish
Date: 2011-10-11 15:35:49 -0400 (Tue, 11 Oct 2011)
New Revision: 35553

Added:
   trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/StatusSeverity2BooleanConverter.java
Modified:
   trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/DataBindingUtils.java
Log:
[JBIDE-9793] corrected default behaviour of DataBindingUtils#bindEnablement (was: enabled if the severity == IStatus.ERROR; now: severity == IStatus.OK)

Modified: trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/DataBindingUtils.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/DataBindingUtils.java	2011-10-11 18:30:47 UTC (rev 35552)
+++ trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/DataBindingUtils.java	2011-10-11 19:35:49 UTC (rev 35553)
@@ -46,16 +46,16 @@
 	 */
 	public static void bindEnablementToValidationStatus(final Control control,
 			DataBindingContext dbc, Binding... bindings) {
-		bindEnablementToValidationStatus(control, IStatus.ERROR, dbc, bindings);
+		bindEnablementToValidationStatus(control, IStatus.OK, dbc, bindings);
 	}
 
-	public static void bindEnablementToValidationStatus(final Control control, int severity,
+	public static void bindEnablementToValidationStatus(final Control control, int enabledSeverityMask,
 			DataBindingContext dbc, Binding... bindings) {
 		dbc.bindValue(
 				WidgetProperties.enabled().observe(control),
 				createAggregateValidationStatus(dbc, bindings),
 				new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER),
-				new UpdateValueStrategy().setConverter(new Status2BooleanConverter(severity)));
+				new UpdateValueStrategy().setConverter(new StatusSeverity2BooleanConverter(enabledSeverityMask)));
 	}
 
 	/**

Copied: trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/StatusSeverity2BooleanConverter.java (from rev 35536, trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/Status2BooleanConverter.java)
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/StatusSeverity2BooleanConverter.java	                        (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.ui/src/org/jboss/tools/common/ui/databinding/StatusSeverity2BooleanConverter.java	2011-10-11 19:35:49 UTC (rev 35553)
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * 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.common.ui.databinding;
+
+import org.eclipse.core.databinding.conversion.Converter;
+import org.eclipse.core.runtime.IStatus;
+
+/**
+ * Converts the severity of an IStatus to a boolean on behalf of a severity
+ * mask.
+ * 
+ * @author André Dietisheim
+ * 
+ * @see IStatus
+ * @see IStatus#getSeverity()
+ * 
+ */
+public class StatusSeverity2BooleanConverter extends Converter {
+
+	private int severity;
+
+	/**
+	 * Instantiates a new converter that turns the severity of a status into a
+	 * boolean. The conversion is operated according to a severity mask that is
+	 * given at construction time. If the status that is handed over at runtime
+	 * matches the severity mask (given at construction time), then the
+	 * converter returns a <code>true</code>. It will return <code>false</code>
+	 * otherwise.
+	 * 
+	 * @param trueSeverityMask
+	 *            the severity mask that is considered as equivalent to
+	 *            <code>true</code>
+	 */
+	public StatusSeverity2BooleanConverter(int trueSeverityMask) {
+		super(IStatus.class, Boolean.class);
+		this.severity = trueSeverityMask;
+	}
+
+	/**
+	 * Compares the severity of the given IStatus to the severity mask that was
+	 * given at construction time. Returns <code>true</code> if the severity
+	 * matches the mask, <code>false</code> otherwise.
+	 * 
+	 * @see IStatus#ERROR
+	 * @see IStatus#WARNING
+	 * @see IStatus#INFO
+	 * @see IStatus#OK
+	 */
+	public Object convert(Object fromObject) {
+		if (!(fromObject instanceof IStatus)) {
+			return Boolean.FALSE;
+		}
+
+		int current = ((IStatus) fromObject).getSeverity();
+		if (current == IStatus.OK) {
+			return severity == IStatus.OK;
+		}
+		return (severity | current) == severity;
+	}
+}
\ No newline at end of file


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



More information about the jbosstools-commits mailing list