Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 157378 Details for
Bug 183055
[DataBinding] New Editing and Constraints API
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Remove all methods in *Editing that shadows *Constraints methods, experiment with changes in snippets
clipboard.txt (text/plain), 131.08 KB, created by
Matthew Hall
on 2010-01-27 02:11:41 EST
(
hide
)
Description:
Remove all methods in *Editing that shadows *Constraints methods, experiment with changes in snippets
Filename:
MIME Type:
Creator:
Matthew Hall
Created:
2010-01-27 02:11:41 EST
Size:
131.08 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.core.databinding >Index: src/org/eclipse/core/databinding/editing/BigDecimalEditing.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/editing/BigDecimalEditing.java >diff -N src/org/eclipse/core/databinding/editing/BigDecimalEditing.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/editing/BigDecimalEditing.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,197 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ovidio Mallo and others. >+ * All rights reserved. This program and the accompanying materials >+ * are 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: >+ * Ovidio Mallo - initial API and implementation (bug 183055) >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.editing; >+ >+import java.math.BigDecimal; >+ >+import org.eclipse.core.databinding.conversion.NumberToStringConverter; >+import org.eclipse.core.databinding.conversion.StringToNumberConverter; >+import org.eclipse.core.databinding.validation.constraint.BigDecimalConstraints; >+import org.eclipse.core.databinding.validation.constraint.Constraints; >+import org.eclipse.core.databinding.validation.constraint.StringConstraints; >+import org.eclipse.core.internal.databinding.validation.AbstractStringToNumberValidator; >+import org.eclipse.core.internal.databinding.validation.StringToBigDecimalValidator; >+ >+import com.ibm.icu.text.NumberFormat; >+ >+/** >+ * @noextend This class is not intended to be subclassed by clients. >+ * @since 1.3 >+ */ >+public class BigDecimalEditing extends Editing { >+ >+ private final NumberFormat displayFormat; >+ >+ /** >+ * Creates a new editing object for <code>BigDecimal</code>s. >+ * >+ * @param format >+ * The BigDecimal format defining the validations and conversions >+ * used for editing. >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to a BigDecimal. >+ * >+ * @noreference This constructor is not intended to be referenced by >+ * clients. >+ */ >+ protected BigDecimalEditing(NumberFormat format, String parseErrorMessage) { >+ this.displayFormat = format; >+ >+ final StringToNumberConverter targetConverter = StringToNumberConverter >+ .toBigDecimal(format); >+ final NumberToStringConverter modelConverter = NumberToStringConverter >+ .fromBigDecimal(format); >+ >+ final AbstractStringToNumberValidator targetValidator = new StringToBigDecimalValidator( >+ targetConverter); >+ if (parseErrorMessage != null) { >+ targetValidator.setParseErrorMessage(parseErrorMessage); >+ } >+ >+ setTargetConverter(targetConverter); >+ setModelConverter(modelConverter); >+ addTargetValidator(targetValidator); >+ } >+ >+ /** >+ * Creates a new editing object for {@link BigDecimal}s which defaults the >+ * validations and conversions used for editing based on the platform's >+ * locale. Uses the default validation messages. >+ * >+ * @return The new editing object using the default validations and >+ * conversions for editing. >+ * >+ * @see NumberFormat#getNumberInstance() >+ */ >+ public static BigDecimalEditing withDefaults() { >+ return withDefaults(null); >+ } >+ >+ /** >+ * Creates a new editing object for {@link BigDecimal}s which defaults the >+ * validations and conversions used for editing based on the platform's >+ * locale. Uses the specified custom validation message. >+ * >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to a BigDecimal. >+ * @return The new editing object using the default validations and >+ * conversions for editing. >+ * >+ * @see NumberFormat#getNumberInstance() >+ */ >+ public static BigDecimalEditing withDefaults(String parseErrorMessage) { >+ return new BigDecimalEditing(NumberFormat.getNumberInstance(), >+ parseErrorMessage); >+ } >+ >+ /** >+ * Creates a new editing object for {@link BigDecimal}s whose validations >+ * and conversions used for editing are based on the given BigDecimal >+ * format. Uses the default validation messages. >+ * >+ * @param format >+ * The BigDecimal format defining the validations and conversions >+ * used for editing. >+ * @return The new editing object configured by the given BigDecimal format. >+ */ >+ public static BigDecimalEditing forFormat(NumberFormat format) { >+ return forFormat(format, null); >+ } >+ >+ /** >+ * Creates a new editing object for {@link BigDecimal}s whose validations >+ * and conversions used for editing are based on the given BigDecimal >+ * format. Uses the specified custom validation message. >+ * >+ * @param format >+ * The BigDecimal format defining the validations and conversions >+ * used for editing. >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to a BigDecimal. >+ * @return The new editing object configured by the given BigDecimal format. >+ */ >+ public static BigDecimalEditing forFormat(NumberFormat format, >+ String parseErrorMessage) { >+ return new BigDecimalEditing(format, parseErrorMessage); >+ } >+ >+ /** >+ * Returns the target constraints to apply. >+ * >+ * <p> >+ * This method provides a typesafe access to the {@link StringConstraints >+ * string target constraints} of this editing object and is equivalent to >+ * {@code (StringConstraints) targetConstraints()}. >+ * </p> >+ * >+ * @return The target constraints to apply. >+ * >+ * @see #targetConstraints() >+ * @see StringConstraints >+ */ >+ public StringConstraints targetStringConstraints() { >+ return (StringConstraints) targetConstraints(); >+ } >+ >+ /** >+ * Returns the model constraints to apply. >+ * >+ * <p> >+ * This method provides a typesafe access to the >+ * {@link BigDecimalConstraints BigDecimal model constraints} of this >+ * editing object and is equivalent to {@code (BigDecimalConstraints) >+ * modelConstraints()}. >+ * </p> >+ * >+ * @return The model constraints to apply. >+ * >+ * @see #modelConstraints() >+ * @see BigDecimalConstraints >+ */ >+ public BigDecimalConstraints modelBigDecimalConstraints() { >+ return (BigDecimalConstraints) modelConstraints(); >+ } >+ >+ /** >+ * Returns the before-set model constraints to apply. >+ * >+ * <p> >+ * This method provides a typesafe access to the >+ * {@link BigDecimalConstraints BigDecimal before-set model constraints} of >+ * this editing object and is equivalent to {@code (BigDecimalConstraints) >+ * beforeSetModelConstraints()}. >+ * </p> >+ * >+ * @return The before-set model constraints to apply. >+ * >+ * @see #beforeSetModelConstraints() >+ * @see BigDecimalConstraints >+ */ >+ public BigDecimalConstraints beforeSetModelBigDecimalConstraints() { >+ return (BigDecimalConstraints) beforeSetModelConstraints(); >+ } >+ >+ protected Constraints createTargetConstraints() { >+ return new StringConstraints(); >+ } >+ >+ protected Constraints createModelConstraints() { >+ return new BigDecimalConstraints().bigDecimalFormat(displayFormat); >+ } >+ >+ protected Constraints createBeforeSetModelConstraints() { >+ return new BigDecimalConstraints().bigDecimalFormat(displayFormat); >+ } >+} >Index: src/org/eclipse/core/databinding/editing/StringEditing.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/editing/StringEditing.java >diff -N src/org/eclipse/core/databinding/editing/StringEditing.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/editing/StringEditing.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,172 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ovidio Mallo and others. >+ * All rights reserved. This program and the accompanying materials >+ * are 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: >+ * Ovidio Mallo - initial API and implementation (bug 183055) >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.editing; >+ >+import org.eclipse.core.databinding.conversion.IConverter; >+import org.eclipse.core.databinding.validation.constraint.Constraints; >+import org.eclipse.core.databinding.validation.constraint.StringConstraints; >+import org.eclipse.core.internal.databinding.conversion.StringStripConverter; >+import org.eclipse.core.internal.databinding.conversion.StringTrimConverter; >+ >+/** >+ * @noextend This class is not intended to be subclassed by clients. >+ * @since 1.3 >+ */ >+public class StringEditing extends Editing { >+ >+ /** >+ * Creates a new editing object for booleans. >+ * >+ * @param targetConverter >+ * The {@link #setTargetConverter(IConverter) target converter} >+ * to use for editing. >+ * >+ * @noreference This constructor is not intended to be referenced by >+ * clients. >+ */ >+ protected StringEditing(IConverter targetConverter) { >+ setTargetConverter(targetConverter); >+ } >+ >+ /** >+ * Creates a new editing object for strings which performs no validation or >+ * conversion. >+ * >+ * @return The new editing object which performs no validation or >+ * conversion. >+ */ >+ public static StringEditing withDefaults() { >+ return new StringEditing(null); >+ } >+ >+ /** >+ * Creates a new editing object which strips whitespace from both ends of >+ * the input string. >+ * >+ * @return The new editing object which strips whitespace from both ends of >+ * the input string. >+ * >+ * @see Character#isWhitespace(char) >+ */ >+ public static StringEditing stripped() { >+ return new StringEditing(new StringStripConverter(false)); >+ } >+ >+ /** >+ * Creates a new editing object which strips whitespace from both ends of >+ * the input string. In case stripping the input string results in an empty >+ * string, the input string will be converted to <code>null</code>. >+ * >+ * @return The new editing object which strips whitespace from both ends of >+ * the input string. Resulting empty strings are converted to >+ * <code>null</code>. >+ * >+ * @see Character#isWhitespace(char) >+ */ >+ public static StringEditing strippedToNull() { >+ return new StringEditing(new StringStripConverter(true)); >+ } >+ >+ /** >+ * Creates a new editing object which {@link String#trim()}s the input >+ * string. >+ * >+ * @return The new editing object which trims whitespace from both ends of >+ * the input string. >+ * >+ * @see String#trim() >+ */ >+ public static StringEditing trimmed() { >+ return new StringEditing(new StringTrimConverter(false)); >+ } >+ >+ /** >+ * Creates a new editing object which {@link String#trim()}s the input >+ * string. In case trimming the input string results in an empty string, the >+ * input string will be converted to <code>null</code>. >+ * >+ * @return The new editing object which trims whitespace from both ends of >+ * the input string. Resulting empty strings are converted to >+ * <code>null</code>. >+ * >+ * @see String#trim() >+ */ >+ public static StringEditing trimmedToNull() { >+ return new StringEditing(new StringTrimConverter(true)); >+ } >+ >+ /** >+ * Returns the target constraints to apply. >+ * >+ * <p> >+ * This method provides a typesafe access to the {@link StringConstraints >+ * string target constraints} of this editing object and is equivalent to >+ * {@code (StringConstraints) targetConstraints()}. >+ * </p> >+ * >+ * @return The target constraints to apply. >+ * >+ * @see #targetConstraints() >+ * @see StringConstraints >+ */ >+ public StringConstraints targetStringConstraints() { >+ return (StringConstraints) targetConstraints(); >+ } >+ >+ /** >+ * Returns the model constraints to apply. >+ * >+ * <p> >+ * This method provides a typesafe access to the {@link StringConstraints >+ * string model constraints} of this editing object and is equivalent to >+ * {@code (StringConstraints) modelConstraints()}. >+ * </p> >+ * >+ * @return The model constraints to apply. >+ * >+ * @see #modelConstraints() >+ * @see StringConstraints >+ */ >+ public StringConstraints modelStringConstraints() { >+ return (StringConstraints) modelConstraints(); >+ } >+ >+ /** >+ * Returns the before-set model constraints to apply. >+ * >+ * <p> >+ * This method provides a typesafe access to the {@link StringConstraints >+ * string before-set model constraints} of this editing object and is >+ * equivalent to {@code (StringConstraints) beforeSetModelConstraints()}. >+ * </p> >+ * >+ * @return The before-set model constraints to apply. >+ * >+ * @see #beforeSetModelConstraints() >+ * @see StringConstraints >+ */ >+ public StringConstraints beforeSetModelStringConstraints() { >+ return (StringConstraints) beforeSetModelConstraints(); >+ } >+ >+ protected Constraints createTargetConstraints() { >+ return new StringConstraints(); >+ } >+ >+ protected Constraints createModelConstraints() { >+ return new StringConstraints(); >+ } >+ >+ protected Constraints createBeforeSetModelConstraints() { >+ return new StringConstraints(); >+ } >+} >Index: src/org/eclipse/core/databinding/editing/Editing.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/editing/Editing.java >diff -N src/org/eclipse/core/databinding/editing/Editing.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/editing/Editing.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,1009 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ovidio Mallo and others. >+ * All rights reserved. This program and the accompanying materials >+ * are 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: >+ * Ovidio Mallo - initial API and implementation (bug 183055) >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.editing; >+ >+import org.eclipse.core.databinding.Binding; >+import org.eclipse.core.databinding.DataBindingContext; >+import org.eclipse.core.databinding.UpdateListStrategy; >+import org.eclipse.core.databinding.UpdateSetStrategy; >+import org.eclipse.core.databinding.UpdateValueStrategy; >+import org.eclipse.core.databinding.conversion.IConverter; >+import org.eclipse.core.databinding.observable.list.IObservableList; >+import org.eclipse.core.databinding.observable.set.IObservableSet; >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.databinding.validation.IValidator; >+import org.eclipse.core.databinding.validation.constraint.Constraints; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.MultiStatus; >+ >+/** >+ * @since 1.3 >+ */ >+public class Editing { >+ >+ private Constraints targetConstraints; >+ >+ private Constraints modelConstraints; >+ >+ private Constraints beforeSetModelConstraints; >+ >+ private IConverter targetConverter; >+ >+ private IConverter modelConverter; >+ >+ /** >+ * Default constructor which creates an unconfigured editing instance. >+ */ >+ protected Editing() { >+ // empty editing instance >+ } >+ >+ /** >+ * Creates an unconfigured editing instance. >+ * >+ * @return A new, unconfigured editing instance. >+ */ >+ public static Editing create() { >+ return new Editing(); >+ } >+ >+ /** >+ * Creates an editing instance with the given target-to-model and >+ * model-to-target converters. >+ * >+ * @param t2mConverter >+ * The target-to-model converter to set. May be <code>null</code> >+ * . >+ * @param m2tConverter >+ * The model-to-target converter to set. May be <code>null</code> >+ * . >+ * @return A new editing instance with the given target-to-model and >+ * model-to-target converters. >+ */ >+ public static Editing withConverters(IConverter t2mConverter, >+ IConverter m2tConverter) { >+ Editing editing = new Editing(); >+ editing.setTargetConverter(t2mConverter); >+ editing.setModelConverter(m2tConverter); >+ return editing; >+ } >+ >+ /** >+ * Returns the target constraints to apply. >+ * >+ * @return The target constraints to apply. >+ * >+ * @see #createTargetConstraints() >+ */ >+ public final Constraints targetConstraints() { >+ if (targetConstraints == null) { >+ targetConstraints = createTargetConstraints(); >+ } >+ return targetConstraints; >+ } >+ >+ /** >+ * Returns the model constraints to apply. >+ * >+ * @return The model constraints to apply. >+ * >+ * @see #createModelConstraints() >+ */ >+ public final Constraints modelConstraints() { >+ if (modelConstraints == null) { >+ modelConstraints = createModelConstraints(); >+ } >+ return modelConstraints; >+ } >+ >+ /** >+ * Returns the before-set model constraints to apply. >+ * >+ * @return The before-set model constraints to apply. >+ * >+ * @see #createBeforeSetModelConstraints() >+ */ >+ public final Constraints beforeSetModelConstraints() { >+ if (beforeSetModelConstraints == null) { >+ beforeSetModelConstraints = createBeforeSetModelConstraints(); >+ } >+ return beforeSetModelConstraints; >+ } >+ >+ /** >+ * Creates the target constraints to apply. >+ * >+ * <p> >+ * The constraints object created by this method will be exposed as the >+ * {@link #targetConstraints()} of this editing object. By default, this >+ * method returns a plain {@link Constraints} object. >+ * </p> >+ * >+ * <p> >+ * This method will be called lazily the first time the target constraints >+ * are accessed. Subclasses may overwrite this method in order to create a >+ * custom constraints object which will then be typically exposed in the >+ * subclass as API in order to allow for a typesafe access. >+ * </p> >+ * >+ * @return The target constraints to apply. >+ * >+ * @see #targetConstraints() >+ */ >+ protected Constraints createTargetConstraints() { >+ return new Constraints(); >+ } >+ >+ /** >+ * Creates the model constraints to apply. >+ * >+ * <p> >+ * The constraints object created by this method will be exposed as the >+ * {@link #modelConstraints()} of this editing object. By default, this >+ * method returns a plain {@link Constraints} object. >+ * </p> >+ * >+ * <p> >+ * This method will be called lazily the first time the model constraints >+ * are accessed. Subclasses may overwrite this method in order to create a >+ * custom constraints object which will then be typically exposed in the >+ * subclass as API in order to allow for a typesafe access. >+ * </p> >+ * >+ * @return The model constraints to apply. >+ * >+ * @see #modelConstraints() >+ */ >+ protected Constraints createModelConstraints() { >+ return new Constraints(); >+ } >+ >+ /** >+ * Creates the before-set model constraints to apply. >+ * >+ * <p> >+ * The constraints object created by this method will be exposed as the >+ * {@link #beforeSetModelConstraints()} of this editing object. By default, >+ * this method returns a plain {@link Constraints} object. >+ * </p> >+ * >+ * <p> >+ * This method will be called lazily the first time the before-set model >+ * constraints are accessed. Subclasses may overwrite this method in order >+ * to create a custom constraints object which will then be typically >+ * exposed in the subclass as API in order to allow for a typesafe access. >+ * </p> >+ * >+ * @return The before-set model constraints to apply. >+ * >+ * @see #beforeSetModelConstraints() >+ */ >+ protected Constraints createBeforeSetModelConstraints() { >+ return new Constraints(); >+ } >+ >+ /** >+ * Convenience method which {@link Constraints#addValidator(IValidator) >+ * adds} the given validator to the set of {@link #targetConstraints()}. >+ * >+ * @param validator >+ * The validator to add to the target constraints. >+ * @return This editing instance for method chaining. >+ * >+ * @see Constraints#addValidator(IValidator) >+ * @see #targetConstraints() >+ */ >+ public final Editing addTargetValidator(IValidator validator) { >+ targetConstraints().addValidator(validator); >+ return this; >+ } >+ >+ /** >+ * Convenience method which {@link Constraints#addValidator(IValidator) >+ * adds} the given validator to the set of {@link #modelConstraints()}. >+ * >+ * @param validator >+ * The validator to add to the model constraints. >+ * @return This editing instance for method chaining. >+ * >+ * @see Constraints#addValidator(IValidator) >+ * @see #modelConstraints() >+ */ >+ public final Editing addModelValidator(IValidator validator) { >+ modelConstraints().addValidator(validator); >+ return this; >+ } >+ >+ /** >+ * Convenience method which {@link Constraints#addValidator(IValidator) >+ * adds} the given validator to the set of >+ * {@link #beforeSetModelConstraints()}. >+ * >+ * @param validator >+ * The validator to add to the before-set model constraints. >+ * @return This editing instance for method chaining. >+ * >+ * @see Constraints#addValidator(IValidator) >+ * @see #beforeSetModelConstraints >+ */ >+ public final Editing addBeforeSetModelValidator(IValidator validator) { >+ beforeSetModelConstraints().addValidator(validator); >+ return this; >+ } >+ >+ /** >+ * Sets the target-to-model converter for this editing instance. >+ * >+ * @param converter >+ * The target-to-model converter to set. >+ */ >+ protected final void setTargetConverter(IConverter converter) { >+ this.targetConverter = converter; >+ } >+ >+ /** >+ * Sets the model-to-target converter for this editing instance. >+ * >+ * @param converter >+ * The model-to-target converter to set. >+ */ >+ protected final void setModelConverter(IConverter converter) { >+ this.modelConverter = converter; >+ } >+ >+ /** >+ * Creates a new target-to-model {@link UpdateValueStrategy} with a default >+ * update policy configured by the current state of this editing object. >+ * >+ * @return A new target-to-model {@link UpdateValueStrategy} configured by >+ * the current state of this editing object. >+ * >+ * @see UpdateValueStrategy#UpdateValueStrategy() >+ * @see #adaptT2MValueStrategy(UpdateValueStrategy) >+ */ >+ public final UpdateValueStrategy createT2MValueStrategy() { >+ return adaptT2MValueStrategy(new UpdateValueStrategy()); >+ } >+ >+ /** >+ * Creates a new target-to-model {@link UpdateValueStrategy} with the given >+ * update policy configured by the current state of this editing object. >+ * >+ * @param updatePolicy >+ * The update policy to use. >+ * @return A new target-to-model {@link UpdateValueStrategy} configured by >+ * the current state of this editing object. >+ * >+ * @see UpdateValueStrategy#UpdateValueStrategy(int) >+ * @see #adaptT2MValueStrategy(UpdateValueStrategy) >+ */ >+ public final UpdateValueStrategy createT2MValueStrategy(int updatePolicy) { >+ return adaptT2MValueStrategy(new UpdateValueStrategy(updatePolicy)); >+ } >+ >+ /** >+ * Creates a new model-to-target {@link UpdateValueStrategy} with a default >+ * update policy configured by the current state of this editing object. >+ * >+ * @return A new model-to-target {@link UpdateValueStrategy} configured by >+ * the current state of this editing object. >+ * >+ * @see UpdateValueStrategy#UpdateValueStrategy() >+ * @see #adaptM2TValueStrategy(UpdateValueStrategy) >+ */ >+ public final UpdateValueStrategy createM2TValueStrategy() { >+ return adaptM2TValueStrategy(new UpdateValueStrategy()); >+ } >+ >+ /** >+ * Creates a new model-to-target {@link UpdateValueStrategy} with the given >+ * update policy configured by the current state of this editing object. >+ * >+ * @param updatePolicy >+ * The update policy to use. >+ * @return A new model-to-target {@link UpdateValueStrategy} configured by >+ * the current state of this editing object. >+ * >+ * @see UpdateValueStrategy#UpdateValueStrategy(int) >+ * @see #adaptM2TValueStrategy(UpdateValueStrategy) >+ */ >+ public final UpdateValueStrategy createM2TValueStrategy(int updatePolicy) { >+ return adaptM2TValueStrategy(new UpdateValueStrategy(updatePolicy)); >+ } >+ >+ /** >+ * Creates a new target-to-model {@link UpdateListStrategy} with a default >+ * update policy configured by the current state of this editing object. >+ * >+ * @return A new target-to-model {@link UpdateListStrategy} configured by >+ * the current state of this editing object. >+ * >+ * @see UpdateListStrategy#UpdateListStrategy() >+ * @see #adaptT2MListStrategy(UpdateListStrategy) >+ */ >+ public final UpdateListStrategy createT2MListStrategy() { >+ return adaptT2MListStrategy(new UpdateListStrategy()); >+ } >+ >+ /** >+ * Creates a new target-to-model {@link UpdateListStrategy} with the given >+ * update policy configured by the current state of this editing object. >+ * >+ * @param updatePolicy >+ * The update policy to use. >+ * @return A new target-to-model {@link UpdateListStrategy} configured by >+ * the current state of this editing object. >+ * >+ * @see UpdateListStrategy#UpdateListStrategy(int) >+ * @see #adaptT2MListStrategy(UpdateListStrategy) >+ */ >+ public final UpdateListStrategy createT2MListStrategy(int updatePolicy) { >+ return adaptT2MListStrategy(new UpdateListStrategy(updatePolicy)); >+ } >+ >+ /** >+ * Creates a new model-to-target {@link UpdateListStrategy} with a default >+ * update policy configured by the current state of this editing object. >+ * >+ * @return A new model-to-target {@link UpdateListStrategy} configured by >+ * the current state of this editing object. >+ * >+ * @see UpdateListStrategy#UpdateListStrategy() >+ * @see #adaptM2TListStrategy(UpdateListStrategy) >+ */ >+ public final UpdateListStrategy createM2TListStrategy() { >+ return adaptM2TListStrategy(new UpdateListStrategy()); >+ } >+ >+ /** >+ * Creates a new model-to-target {@link UpdateListStrategy} with the given >+ * update policy configured by the current state of this editing object. >+ * >+ * @param updatePolicy >+ * The update policy to use. >+ * @return A new model-to-target {@link UpdateListStrategy} configured by >+ * the current state of this editing object. >+ * >+ * @see UpdateListStrategy#UpdateListStrategy(int) >+ * @see #adaptM2TListStrategy(UpdateListStrategy) >+ */ >+ public final UpdateListStrategy createM2TListStrategy(int updatePolicy) { >+ return adaptM2TListStrategy(new UpdateListStrategy(updatePolicy)); >+ } >+ >+ /** >+ * Creates a new target-to-model {@link UpdateSetStrategy} with a default >+ * update policy configured by the current state of this editing object. >+ * >+ * @return A new target-to-model {@link UpdateSetStrategy} configured by the >+ * current state of this editing object. >+ * >+ * @see UpdateListStrategy#UpdateListStrategy() >+ * @see #adaptT2MSetStrategy(UpdateSetStrategy) >+ */ >+ public final UpdateSetStrategy createT2MSetStrategy() { >+ return adaptT2MSetStrategy(new UpdateSetStrategy()); >+ } >+ >+ /** >+ * Creates a new target-to-model {@link UpdateListStrategy} with the given >+ * update policy configured by the current state of this editing object. >+ * >+ * @param updatePolicy >+ * The update policy to use. >+ * @return A new target-to-model {@link UpdateListStrategy} configured by >+ * the current state of this editing object. >+ * >+ * @see UpdateSetStrategy#UpdateSetStrategy(int) >+ * @see #adaptT2MSetStrategy(UpdateSetStrategy) >+ */ >+ public final UpdateSetStrategy createT2MSetStrategy(int updatePolicy) { >+ return adaptT2MSetStrategy(new UpdateSetStrategy(updatePolicy)); >+ } >+ >+ /** >+ * Creates a new model-to-target {@link UpdateSetStrategy} with a default >+ * update policy configured by the current state of this editing object. >+ * >+ * @return A new model-to-target {@link UpdateSetStrategy} configured by the >+ * current state of this editing object. >+ * >+ * @see UpdateSetStrategy#UpdateSetStrategy() >+ * @see #adaptM2TSetStrategy(UpdateSetStrategy) >+ */ >+ public final UpdateSetStrategy createM2TSetStrategy() { >+ return adaptM2TSetStrategy(new UpdateSetStrategy()); >+ } >+ >+ /** >+ * Creates a new model-to-target {@link UpdateSetStrategy} with the given >+ * update policy configured by the current state of this editing object. >+ * >+ * @param updatePolicy >+ * The update policy to use. >+ * @return A new model-to-target {@link UpdateSetStrategy} configured by the >+ * current state of this editing object. >+ * >+ * @see UpdateSetStrategy#UpdateSetStrategy(int) >+ * @see #adaptM2TSetStrategy(UpdateSetStrategy) >+ */ >+ public final UpdateSetStrategy createM2TSetStrategy(int updatePolicy) { >+ return adaptM2TSetStrategy(new UpdateSetStrategy(updatePolicy)); >+ } >+ >+ /** >+ * Configures an existing target-to-model {@link UpdateValueStrategy} with >+ * the current state of this editing object. >+ * >+ * <p> >+ * The configuration is done as follows: >+ * <ul> >+ * <li> >+ * The {@link Constraints#createValidator() validator} of the >+ * {@link #targetConstraints() target constraints} is set as the >+ * {@link UpdateValueStrategy#setAfterGetValidator(IValidator) after-get >+ * validator} of the update strategy.</li> >+ * <li>The {@link #setTargetConverter(IConverter) target converter} is set >+ * as the {@link UpdateValueStrategy#setConverter(IConverter) converter} of >+ * the update strategy.</li> >+ * <li> >+ * The {@link Constraints#createValidator() validator} of the >+ * {@link #modelConstraints() model constraints} is set as the >+ * {@link UpdateValueStrategy#setAfterConvertValidator(IValidator) >+ * after-convert validator} of the update strategy.</li> >+ * <li>The {@link Constraints#createValidator() validator} of the >+ * {@link #beforeSetModelConstraints() before-set model constraints} is set >+ * as the {@link UpdateValueStrategy#setBeforeSetValidator(IValidator) >+ * before-set validator} of the update strategy.</li> >+ * </ul> >+ * </p> >+ * >+ * @param updateStrategy >+ * The {@link UpdateValueStrategy} to configure. >+ * @return The passed-in, configured target-to-model >+ * {@link UpdateValueStrategy}. >+ * >+ * @see UpdateValueStrategy#setAfterGetValidator(IValidator) >+ * @see UpdateValueStrategy#setConverter(IConverter) >+ * @see UpdateValueStrategy#setAfterConvertValidator(IValidator) >+ * @see UpdateValueStrategy#setBeforeSetValidator(IValidator) >+ */ >+ public final UpdateValueStrategy adaptT2MValueStrategy( >+ UpdateValueStrategy updateStrategy) { >+ updateStrategy.setAfterGetValidator(createValidator(targetConstraints)); >+ updateStrategy.setConverter(targetConverter); >+ updateStrategy >+ .setAfterConvertValidator(createValidator(modelConstraints)); >+ updateStrategy >+ .setBeforeSetValidator(createValidator(beforeSetModelConstraints)); >+ return updateStrategy; >+ } >+ >+ /** >+ * Configures an existing model-to-target {@link UpdateValueStrategy} with >+ * the current state of this editing object by setting the >+ * {@link #setModelConverter(IConverter) model converter} as the >+ * {@link UpdateValueStrategy#setConverter(IConverter) converter} of the >+ * update strategy. >+ * >+ * @param updateStrategy >+ * The {@link UpdateValueStrategy} to configure. >+ * @return The passed-in, configured model-to-target >+ * {@link UpdateValueStrategy}. >+ * >+ * @see UpdateValueStrategy#setConverter(IConverter) >+ */ >+ public final UpdateValueStrategy adaptM2TValueStrategy( >+ UpdateValueStrategy updateStrategy) { >+ updateStrategy.setConverter(modelConverter); >+ return updateStrategy; >+ } >+ >+ /** >+ * Configures an existing target-to-model {@link UpdateListStrategy} with >+ * the current state of this editing object by setting the >+ * {@link #setTargetConverter(IConverter) target converter} as the >+ * {@link UpdateListStrategy#setConverter(IConverter) converter} of the >+ * update strategy. >+ * >+ * @param updateStrategy >+ * The {@link UpdateListStrategy} to configure. >+ * @return The passed-in, configured target-to-model >+ * {@link UpdateListStrategy}. >+ * >+ * @see UpdateListStrategy#setConverter(IConverter) >+ */ >+ public final UpdateListStrategy adaptT2MListStrategy( >+ UpdateListStrategy updateStrategy) { >+ updateStrategy.setConverter(targetConverter); >+ return updateStrategy; >+ } >+ >+ /** >+ * Configures an existing model-to-target {@link UpdateListStrategy} with >+ * the current state of this editing object by setting the >+ * {@link #setModelConverter(IConverter) model converter} as the >+ * {@link UpdateListStrategy#setConverter(IConverter) converter} of the >+ * update strategy. >+ * >+ * @param updateStrategy >+ * The {@link UpdateListStrategy} to configure. >+ * @return The passed-in, configured model-to-target >+ * {@link UpdateListStrategy}. >+ * >+ * @see UpdateListStrategy#setConverter(IConverter) >+ */ >+ public final UpdateListStrategy adaptM2TListStrategy( >+ UpdateListStrategy updateStrategy) { >+ updateStrategy.setConverter(modelConverter); >+ return updateStrategy; >+ } >+ >+ /** >+ * Configures an existing target-to-model {@link UpdateListStrategy} with >+ * the current state of this editing object by setting the >+ * {@link #setTargetConverter(IConverter) target converter} as the >+ * {@link UpdateSetStrategy#setConverter(IConverter) converter} of the >+ * update strategy. >+ * >+ * @param updateStrategy >+ * The {@link UpdateSetStrategy} to configure. >+ * @return The passed-in, configured target-to-model >+ * {@link UpdateSetStrategy}. >+ * >+ * @see UpdateSetStrategy#setConverter(IConverter) >+ */ >+ public final UpdateSetStrategy adaptT2MSetStrategy( >+ UpdateSetStrategy updateStrategy) { >+ updateStrategy.setConverter(targetConverter); >+ return updateStrategy; >+ } >+ >+ /** >+ * Configures an existing model-to-target {@link UpdateSetStrategy} with the >+ * current state of this editing object by setting the >+ * {@link #setModelConverter(IConverter) model converter} as the >+ * {@link UpdateSetStrategy#setConverter(IConverter) converter} of the >+ * update strategy. >+ * >+ * @param updateStrategy >+ * The {@link UpdateSetStrategy} to configure. >+ * @return The passed-in, configured model-to-target >+ * {@link UpdateSetStrategy}. >+ * >+ * @see UpdateSetStrategy#setConverter(IConverter) >+ */ >+ public final UpdateSetStrategy adaptM2TSetStrategy( >+ UpdateSetStrategy updateStrategy) { >+ updateStrategy.setConverter(modelConverter); >+ return updateStrategy; >+ } >+ >+ /** >+ * Converts a target value to a model value by performing the following >+ * steps: >+ * <ul> >+ * <li> >+ * Applying all the {@link #targetConstraints() target constraints} to the >+ * given target value.</li> >+ * <li> >+ * {@link #setTargetConverter(IConverter) Converting} the target value to >+ * the model value.</li> >+ * <li> >+ * Applying all the {@link #modelConstraints() model constraints} to the >+ * converted model value.</li> >+ * <li> >+ * Applying all the {@link #beforeSetModelConstraints() before-set model >+ * constraints} to the converted model value.</li> >+ * </ul> >+ * >+ * <p> >+ * The conversion process will be aborted by returning <code>null</code> >+ * whenever any of the applied validators produces a {@link IStatus >+ * validation status} having {@link IStatus#getSeverity() severity} >+ * <code>IStatus.ERROR</code> or <code>IStatus.CANCEL</code>. During the >+ * conversion process, any validation status whose severity is different >+ * from <code>IStatus.OK</code> will be {@link MultiStatus#merge(IStatus) >+ * aggregated} on the given <code>validationStatus</code>. >+ * </p> >+ * >+ * @param targetValue >+ * The target value to be converted to a model value. >+ * @param validationStatus >+ * Aggregate validation status to which to add the validations >+ * produced during the conversion process. May be >+ * <code>null</code>. >+ * @return The converted model value or <code>null</code> in case the >+ * conversion has been aborted due to a validation error. >+ */ >+ public final Object convertToModel(Object targetValue, >+ MultiStatus validationStatus) { >+ if (!applyConstraints(targetConstraints, targetValue, validationStatus)) { >+ return null; >+ } >+ >+ Object modelValue = (targetConverter != null) ? targetConverter >+ .convert(targetValue) : targetValue; >+ >+ if (!applyConstraints(modelConstraints, modelValue, validationStatus)) { >+ return null; >+ } >+ >+ if (!applyConstraints(beforeSetModelConstraints, modelValue, >+ validationStatus)) { >+ return null; >+ } >+ >+ return modelValue; >+ } >+ >+ /** >+ * {@link #setModelConverter(IConverter) Converts} a model value to a target >+ * value. >+ * >+ * @param modelValue >+ * The model value to be converted to a target value. >+ * @return The converted target value. >+ */ >+ public final Object convertToTarget(Object modelValue) { >+ return (modelConverter != null) ? modelConverter.convert(modelValue) >+ : modelValue; >+ } >+ >+ /** >+ * Creates a binding between a target and model observable value on the >+ * given binding context by creating new update strategies which will be >+ * both configured with the state of this editing object before passing them >+ * to the binding. >+ * >+ * <p> >+ * The target-to-model and model-to-target update strategies for the binding >+ * will be created by the methods {@link #createT2MValueStrategy()} and >+ * {@link #createM2TValueStrategy()}, respectively. >+ * </p> >+ * >+ * @param dbc >+ * The binding context on which to create the value binding. >+ * @param targetObservableValue >+ * The target observable value of the binding. >+ * @param modelObservableValue >+ * The model observable value of the binding. >+ * @return The new value binding. >+ * >+ * @see #createT2MValueStrategy() >+ * @see #createM2TValueStrategy() >+ * @see DataBindingContext#bindValue(IObservableValue, IObservableValue, >+ * UpdateValueStrategy, UpdateValueStrategy) >+ */ >+ public final Binding bindValue(DataBindingContext dbc, >+ IObservableValue targetObservableValue, >+ IObservableValue modelObservableValue) { >+ return dbc.bindValue(targetObservableValue, modelObservableValue, >+ createT2MValueStrategy(), createM2TValueStrategy()); >+ } >+ >+ /** >+ * Creates a binding between a target and model observable value on the >+ * given binding context by creating new update strategies with the provided >+ * update policies which will be both configured with the state of this >+ * editing object before passing them to the binding. >+ * >+ * @param dbc >+ * The binding context on which to create the value binding. >+ * @param targetObservableValue >+ * The target observable value of the binding. >+ * @param modelObservableValue >+ * The model observable value of the binding. >+ * @param t2mUpdatePolicy >+ * The update policy for the target-to-model >+ * {@link UpdateValueStrategy} which is >+ * {@link #createT2MValueStrategy(int) created} and passed to the >+ * new binding. >+ * @param m2tUpdatePolicy >+ * The update policy for the model-to-target >+ * {@link UpdateValueStrategy} which is >+ * {@link #createM2TValueStrategy(int) created} and passed to the >+ * new binding. >+ * @return The new value binding. >+ * >+ * @see #createT2MValueStrategy(int) >+ * @see #createM2TValueStrategy(int) >+ * @see DataBindingContext#bindValue(IObservableValue, IObservableValue, >+ * UpdateValueStrategy, UpdateValueStrategy) >+ */ >+ public final Binding bindValue(DataBindingContext dbc, >+ IObservableValue targetObservableValue, >+ IObservableValue modelObservableValue, int t2mUpdatePolicy, >+ int m2tUpdatePolicy) { >+ return dbc.bindValue(targetObservableValue, modelObservableValue, >+ createT2MValueStrategy(t2mUpdatePolicy), >+ createM2TValueStrategy(m2tUpdatePolicy)); >+ } >+ >+ /** >+ * Creates a binding between a target and model observable value on the >+ * given binding context by using the provided update strategies which will >+ * be both configured with the state of this editing object before passing >+ * them to the binding. >+ * >+ * @param dbc >+ * The binding context on which to create the value binding. >+ * @param targetObservableValue >+ * The target observable value of the binding. >+ * @param modelObservableValue >+ * The model observable value of the binding. >+ * @param t2mUpdateStrategy >+ * The target-to-model {@link UpdateValueStrategy} of the binding >+ * to be {@link #adaptT2MValueStrategy(UpdateValueStrategy) >+ * configured} with the state of this editing object before >+ * passing it to the binding. >+ * @param m2tUpdateStrategy >+ * The model-to-target {@link UpdateValueStrategy} of the binding >+ * to be {@link #adaptM2TValueStrategy(UpdateValueStrategy) >+ * configured} with the state of this editing object before >+ * passing it to the binding. >+ * @return The new value binding. >+ * >+ * @see #adaptT2MValueStrategy(UpdateValueStrategy) >+ * @see #adaptM2TValueStrategy(UpdateValueStrategy) >+ * @see DataBindingContext#bindValue(IObservableValue, IObservableValue, >+ * UpdateValueStrategy, UpdateValueStrategy) >+ */ >+ public final Binding bindValue(DataBindingContext dbc, >+ IObservableValue targetObservableValue, >+ IObservableValue modelObservableValue, >+ UpdateValueStrategy t2mUpdateStrategy, >+ UpdateValueStrategy m2tUpdateStrategy) { >+ return dbc.bindValue(targetObservableValue, modelObservableValue, >+ adaptT2MValueStrategy(t2mUpdateStrategy), >+ adaptM2TValueStrategy(m2tUpdateStrategy)); >+ } >+ >+ /** >+ * Creates a binding between a target and model observable list on the given >+ * binding context by creating new update strategies which will be both >+ * configured with the state of this editing object before passing them to >+ * the binding. >+ * >+ * <p> >+ * The target-to-model and model-to-target update strategies for the binding >+ * will be created by the methods {@link #createT2MListStrategy()} and >+ * {@link #createM2TListStrategy()}, respectively. >+ * </p> >+ * >+ * @param dbc >+ * The binding context on which to create the list binding. >+ * @param targetObservableList >+ * The target observable list of the binding. >+ * @param modelObservableList >+ * The model observable list of the binding. >+ * @return The new list binding. >+ * >+ * @see #createT2MListStrategy() >+ * @see #createM2TListStrategy() >+ * @see DataBindingContext#bindList(IObservableList, IObservableList, >+ * UpdateListStrategy, UpdateListStrategy) >+ */ >+ public final Binding bindList(DataBindingContext dbc, >+ IObservableList targetObservableList, >+ IObservableList modelObservableList) { >+ return dbc.bindList(targetObservableList, modelObservableList, >+ createT2MListStrategy(), createM2TListStrategy()); >+ } >+ >+ /** >+ * Creates a binding between a target and model observable list on the given >+ * binding context by creating new update strategies with the provided >+ * update policies which will be both configured with the state of this >+ * editing object before passing them to the binding. >+ * >+ * @param dbc >+ * The binding context on which to create the list binding. >+ * @param targetObservableList >+ * The target observable list of the binding. >+ * @param modelObservableList >+ * The model observable list of the binding. >+ * @param t2mUpdatePolicy >+ * The update policy for the target-to-model >+ * {@link UpdateListStrategy} which is >+ * {@link #createT2MListStrategy(int) created} and passed to the >+ * new binding. >+ * @param m2tUpdatePolicy >+ * The update policy for the model-to-target >+ * {@link UpdateListStrategy} which is >+ * {@link #createM2TListStrategy(int) created} and passed to the >+ * new binding. >+ * @return The new list binding. >+ * >+ * @see #createT2MListStrategy(int) >+ * @see #createM2TListStrategy(int) >+ * @see DataBindingContext#bindList(IObservableList, IObservableList, >+ * UpdateListStrategy, UpdateListStrategy) >+ */ >+ public final Binding bindList(DataBindingContext dbc, >+ IObservableList targetObservableList, >+ IObservableList modelObservableList, int t2mUpdatePolicy, >+ int m2tUpdatePolicy) { >+ return dbc.bindList(targetObservableList, modelObservableList, >+ createT2MListStrategy(t2mUpdatePolicy), >+ createM2TListStrategy(m2tUpdatePolicy)); >+ } >+ >+ /** >+ * Creates a binding between a target and model observable list on the given >+ * binding context by using the provided update strategies which will be >+ * both configured with the state of this editing object before passing them >+ * to the binding. >+ * >+ * @param dbc >+ * The binding context on which to create the list binding. >+ * @param targetObservableList >+ * The target observable list of the binding. >+ * @param modelObservableList >+ * The model observable list of the binding. >+ * @param t2mUpdateStrategy >+ * The target-to-model {@link UpdateListStrategy} of the binding >+ * to be {@link #adaptT2MListStrategy(UpdateListStrategy) >+ * configured} with the state of this editing object before >+ * passing it to the binding. >+ * @param m2tUpdateStrategy >+ * The model-to-target {@link UpdateListStrategy} of the binding >+ * to be {@link #adaptM2TListStrategy(UpdateListStrategy) >+ * configured} with the state of this editing object before >+ * passing it to the binding. >+ * @return The new list binding. >+ * >+ * @see #adaptT2MListStrategy(UpdateListStrategy) >+ * @see #adaptM2TListStrategy(UpdateListStrategy) >+ * @see DataBindingContext#bindList(IObservableList, IObservableList, >+ * UpdateListStrategy, UpdateListStrategy) >+ */ >+ public final Binding bindList(DataBindingContext dbc, >+ IObservableList targetObservableList, >+ IObservableList modelObservableList, >+ UpdateListStrategy t2mUpdateStrategy, >+ UpdateListStrategy m2tUpdateStrategy) { >+ return dbc.bindList(targetObservableList, modelObservableList, >+ adaptT2MListStrategy(t2mUpdateStrategy), >+ adaptM2TListStrategy(m2tUpdateStrategy)); >+ } >+ >+ /** >+ * Creates a binding between a target and model observable set on the given >+ * binding context by creating new update strategies which will be both >+ * configured with the state of this editing object before passing them to >+ * the binding. >+ * >+ * <p> >+ * The target-to-model and model-to-target update strategies for the binding >+ * will be created by the methods {@link #createT2MSetStrategy()} and >+ * {@link #createM2TSetStrategy()}, respectively. >+ * </p> >+ * >+ * @param dbc >+ * The binding context on which to create the set binding. >+ * @param targetObservableSet >+ * The target observable set of the binding. >+ * @param modelObservableSet >+ * The model observable set of the binding. >+ * @return The new set binding. >+ * >+ * @see #createT2MSetStrategy() >+ * @see #createM2TSetStrategy() >+ * @see DataBindingContext#bindSet(IObservableSet, IObservableSet, >+ * UpdateSetStrategy, UpdateSetStrategy) >+ */ >+ public final Binding bindSet(DataBindingContext dbc, >+ IObservableSet targetObservableSet, >+ IObservableSet modelObservableSet) { >+ return dbc.bindSet(targetObservableSet, modelObservableSet, >+ createT2MSetStrategy(), createM2TSetStrategy()); >+ } >+ >+ /** >+ * Creates a binding between a target and model observable set on the given >+ * binding context by creating new update strategies with the provided >+ * update policies which will be both configured with the state of this >+ * editing object before passing them to the binding. >+ * >+ * @param dbc >+ * The binding context on which to create the set binding. >+ * @param targetObservableSet >+ * The target observable set of the binding. >+ * @param modelObservableSet >+ * The model observable set of the binding. >+ * @param t2mUpdatePolicy >+ * The update policy for the target-to-model >+ * {@link UpdateSetStrategy} which is >+ * {@link #createT2MSetStrategy(int) created} and passed to the >+ * new binding. >+ * @param m2tUpdatePolicy >+ * The update policy for the model-to-target >+ * {@link UpdateSetStrategy} which is >+ * {@link #createM2TSetStrategy(int) created} and passed to the >+ * new binding. >+ * @return The new set binding. >+ * >+ * @see #createT2MSetStrategy(int) >+ * @see #createM2TSetStrategy(int) >+ * @see DataBindingContext#bindSet(IObservableSet, IObservableSet, >+ * UpdateSetStrategy, UpdateSetStrategy) >+ */ >+ public final Binding bindSet(DataBindingContext dbc, >+ IObservableSet targetObservableSet, >+ IObservableSet modelObservableSet, int t2mUpdatePolicy, >+ int m2tUpdatePolicy) { >+ return dbc.bindSet(targetObservableSet, modelObservableSet, >+ createT2MSetStrategy(t2mUpdatePolicy), >+ createM2TSetStrategy(m2tUpdatePolicy)); >+ } >+ >+ /** >+ * Creates a binding between a target and model observable set on the given >+ * binding context by using the provided update strategies which will be >+ * both configured with the state of this editing object before passing them >+ * to the binding. >+ * >+ * @param dbc >+ * The binding context on which to create the set binding. >+ * @param targetObservableSet >+ * The target observable set of the binding. >+ * @param modelObservableSet >+ * The model observable set of the binding. >+ * @param t2mUpdateStrategy >+ * The target-to-model {@link UpdateSetStrategy} of the binding >+ * to be {@link #adaptT2MSetStrategy(UpdateSetStrategy) >+ * configured} with the state of this editing object before >+ * passing it to the binding. >+ * @param m2tUpdateStrategy >+ * The model-to-target {@link UpdateSetStrategy} of the binding >+ * to be {@link #adaptM2TSetStrategy(UpdateSetStrategy) >+ * configured} with the state of this editing object before >+ * passing it to the binding. >+ * @return The new set binding. >+ * >+ * @see #adaptT2MSetStrategy(UpdateSetStrategy) >+ * @see #adaptM2TSetStrategy(UpdateSetStrategy) >+ * @see DataBindingContext#bindSet(IObservableSet, IObservableSet, >+ * UpdateSetStrategy, UpdateSetStrategy) >+ */ >+ public final Binding bindSet(DataBindingContext dbc, >+ IObservableSet targetObservableSet, >+ IObservableSet modelObservableSet, >+ UpdateSetStrategy t2mUpdateStrategy, >+ UpdateSetStrategy m2tUpdateStrategy) { >+ return dbc.bindSet(targetObservableSet, modelObservableSet, >+ adaptT2MSetStrategy(t2mUpdateStrategy), >+ adaptM2TSetStrategy(m2tUpdateStrategy)); >+ } >+ >+ private static IValidator createValidator(Constraints constraints) { >+ return constraints != null ? constraints.createValidator() : null; >+ } >+ >+ private static boolean applyConstraints(Constraints constraints, >+ Object value, MultiStatus aggregateStatus) { >+ IValidator validator = createValidator(constraints); >+ if (validator != null) { >+ IStatus validationStatus = validator.validate(value); >+ if (aggregateStatus != null && !validationStatus.isOK()) { >+ aggregateStatus.merge(validationStatus); >+ } >+ return isValid(validationStatus); >+ } >+ return true; >+ } >+ >+ private static boolean isValid(IStatus status) { >+ return status.isOK() || status.matches(IStatus.INFO | IStatus.WARNING); >+ } >+} >Index: src/org/eclipse/core/databinding/editing/BigIntegerEditing.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/editing/BigIntegerEditing.java >diff -N src/org/eclipse/core/databinding/editing/BigIntegerEditing.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/editing/BigIntegerEditing.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,197 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ovidio Mallo and others. >+ * All rights reserved. This program and the accompanying materials >+ * are 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: >+ * Ovidio Mallo - initial API and implementation (bug 183055) >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.editing; >+ >+import java.math.BigInteger; >+ >+import org.eclipse.core.databinding.conversion.NumberToStringConverter; >+import org.eclipse.core.databinding.conversion.StringToNumberConverter; >+import org.eclipse.core.databinding.validation.constraint.BigIntegerConstraints; >+import org.eclipse.core.databinding.validation.constraint.Constraints; >+import org.eclipse.core.databinding.validation.constraint.StringConstraints; >+import org.eclipse.core.internal.databinding.validation.AbstractStringToNumberValidator; >+import org.eclipse.core.internal.databinding.validation.StringToBigIntegerValidator; >+ >+import com.ibm.icu.text.NumberFormat; >+ >+/** >+ * @noextend This class is not intended to be subclassed by clients. >+ * @since 1.3 >+ */ >+public class BigIntegerEditing extends Editing { >+ >+ private final NumberFormat displayFormat; >+ >+ /** >+ * Creates a new editing object for <code>BigInteger</code>s. >+ * >+ * @param format >+ * The BigInteger format defining the validations and conversions >+ * used for editing. >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to a BigInteger. >+ * >+ * @noreference This constructor is not intended to be referenced by >+ * clients. >+ */ >+ protected BigIntegerEditing(NumberFormat format, String parseErrorMessage) { >+ this.displayFormat = format; >+ >+ final StringToNumberConverter targetConverter = StringToNumberConverter >+ .toBigInteger(format); >+ final NumberToStringConverter modelConverter = NumberToStringConverter >+ .fromBigInteger(format); >+ >+ final AbstractStringToNumberValidator targetValidator = new StringToBigIntegerValidator( >+ targetConverter); >+ if (parseErrorMessage != null) { >+ targetValidator.setParseErrorMessage(parseErrorMessage); >+ } >+ >+ setTargetConverter(targetConverter); >+ setModelConverter(modelConverter); >+ addTargetValidator(targetValidator); >+ } >+ >+ /** >+ * Creates a new editing object for {@link BigInteger}s which defaults the >+ * validations and conversions used for editing based on the platform's >+ * locale. Uses the default validation messages. >+ * >+ * @return The new editing object using the default validations and >+ * conversions for editing. >+ * >+ * @see NumberFormat#getIntegerInstance() >+ */ >+ public static BigIntegerEditing withDefaults() { >+ return withDefaults(null); >+ } >+ >+ /** >+ * Creates a new editing object for {@link BigInteger}s which defaults the >+ * validations and conversions used for editing based on the platform's >+ * locale. Uses the specified custom validation message. >+ * >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to a BigInteger. >+ * @return The new editing object using the default validations and >+ * conversions for editing. >+ * >+ * @see NumberFormat#getIntegerInstance() >+ */ >+ public static BigIntegerEditing withDefaults(String parseErrorMessage) { >+ return new BigIntegerEditing(NumberFormat.getIntegerInstance(), >+ parseErrorMessage); >+ } >+ >+ /** >+ * Creates a new editing object for {@link BigInteger}s whose validations >+ * and conversions used for editing are based on the given BigInteger >+ * format. Uses the default validation messages. >+ * >+ * @param format >+ * The BigInteger format defining the validations and conversions >+ * used for editing. >+ * @return The new editing object configured by the given BigInteger format. >+ */ >+ public static BigIntegerEditing forFormat(NumberFormat format) { >+ return forFormat(format, null); >+ } >+ >+ /** >+ * Creates a new editing object for {@link BigInteger}s whose validations >+ * and conversions used for editing are based on the given BigInteger >+ * format. Uses the specified custom validation message. >+ * >+ * @param format >+ * The BigInteger format defining the validations and conversions >+ * used for editing. >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to a BigInteger. >+ * @return The new editing object configured by the given BigInteger format. >+ */ >+ public static BigIntegerEditing forFormat(NumberFormat format, >+ String parseErrorMessage) { >+ return new BigIntegerEditing(format, parseErrorMessage); >+ } >+ >+ /** >+ * Returns the target constraints to apply. >+ * >+ * <p> >+ * This method provides a typesafe access to the {@link StringConstraints >+ * string target constraints} of this editing object and is equivalent to >+ * {@code (StringConstraints) targetConstraints()}. >+ * </p> >+ * >+ * @return The target constraints to apply. >+ * >+ * @see #targetConstraints() >+ * @see StringConstraints >+ */ >+ public StringConstraints targetStringConstraints() { >+ return (StringConstraints) targetConstraints(); >+ } >+ >+ /** >+ * Returns the model constraints to apply. >+ * >+ * <p> >+ * This method provides a typesafe access to the >+ * {@link BigIntegerConstraints BigInteger model constraints} of this >+ * editing object and is equivalent to {@code (BigIntegerConstraints) >+ * modelConstraints()}. >+ * </p> >+ * >+ * @return The model constraints to apply. >+ * >+ * @see #modelConstraints() >+ * @see BigIntegerConstraints >+ */ >+ public BigIntegerConstraints modelBigIntegerConstraints() { >+ return (BigIntegerConstraints) modelConstraints(); >+ } >+ >+ /** >+ * Returns the before-set model constraints to apply. >+ * >+ * <p> >+ * This method provides a typesafe access to the >+ * {@link BigIntegerConstraints BigInteger before-set model constraints} of >+ * this editing object and is equivalent to {@code (BigIntegerConstraints) >+ * beforeSetModelConstraints()}. >+ * </p> >+ * >+ * @return The before-set model constraints to apply. >+ * >+ * @see #beforeSetModelConstraints() >+ * @see BigIntegerConstraints >+ */ >+ public BigIntegerConstraints beforeSetModelBigIntegerConstraints() { >+ return (BigIntegerConstraints) beforeSetModelConstraints(); >+ } >+ >+ protected Constraints createTargetConstraints() { >+ return new StringConstraints(); >+ } >+ >+ protected Constraints createModelConstraints() { >+ return new BigIntegerConstraints().bigIntegerFormat(displayFormat); >+ } >+ >+ protected Constraints createBeforeSetModelConstraints() { >+ return new BigIntegerConstraints().bigIntegerFormat(displayFormat); >+ } >+} >Index: src/org/eclipse/core/databinding/editing/CharacterEditing.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/editing/CharacterEditing.java >diff -N src/org/eclipse/core/databinding/editing/CharacterEditing.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/editing/CharacterEditing.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,145 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ovidio Mallo and others. >+ * All rights reserved. This program and the accompanying materials >+ * are 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: >+ * Ovidio Mallo - initial API and implementation (bug 183055) >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.editing; >+ >+import org.eclipse.core.databinding.validation.constraint.CharacterConstraints; >+import org.eclipse.core.databinding.validation.constraint.Constraints; >+import org.eclipse.core.databinding.validation.constraint.StringConstraints; >+import org.eclipse.core.internal.databinding.conversion.CharacterToStringConverter; >+import org.eclipse.core.internal.databinding.conversion.StringToCharacterConverter; >+import org.eclipse.core.internal.databinding.validation.StringToCharacterValidator; >+ >+/** >+ * @noextend This class is not intended to be subclassed by clients. >+ * @since 1.3 >+ */ >+public class CharacterEditing extends Editing { >+ >+ /** >+ * Creates a new editing object for booleans. >+ * >+ * @param parseErrorMessage >+ * The validation message issued in case the input string is not >+ * a valid character. >+ * >+ * @noreference This constructor is not intended to be referenced by >+ * clients. >+ */ >+ protected CharacterEditing(String parseErrorMessage) { >+ StringToCharacterConverter targetConverter = new StringToCharacterConverter( >+ false); >+ CharacterToStringConverter modelConverter = CharacterToStringConverter >+ .fromCharacter(false); >+ >+ StringToCharacterValidator targetValidator = new StringToCharacterValidator( >+ targetConverter); >+ if (parseErrorMessage != null) { >+ targetValidator.setParseErrorMessage(parseErrorMessage); >+ } >+ >+ setTargetConverter(targetConverter); >+ setModelConverter(modelConverter); >+ addTargetValidator(targetValidator); >+ } >+ >+ /** >+ * Creates a new editing object which uses the default validations and >+ * conversions for the editing of characters. >+ * >+ * @return The new editing object for the default editing of characters. >+ */ >+ public static CharacterEditing withDefaults() { >+ return withDefaults(null); >+ } >+ >+ /** >+ * Creates a new editing object which uses the default validations and >+ * conversions for the editing of characters. Uses the specified custom >+ * validation message. >+ * >+ * @param parseErrorMessage >+ * The validation message issued in case the input string is not >+ * a valid character. >+ * @return The new editing object for the default editing of characters. >+ */ >+ public static CharacterEditing withDefaults(String parseErrorMessage) { >+ return new CharacterEditing(parseErrorMessage); >+ } >+ >+ /** >+ * Returns the target constraints to apply. >+ * >+ * <p> >+ * This method provides a typesafe access to the {@link StringConstraints >+ * string target constraints} of this editing object and is equivalent to >+ * {@code (StringConstraints) targetConstraints()}. >+ * </p> >+ * >+ * @return The target constraints to apply. >+ * >+ * @see #targetConstraints() >+ * @see StringConstraints >+ */ >+ public StringConstraints targetStringConstraints() { >+ return (StringConstraints) targetConstraints(); >+ } >+ >+ /** >+ * Returns the model constraints to apply. >+ * >+ * <p> >+ * This method provides a typesafe access to the >+ * {@link CharacterConstraints character model constraints} of this editing >+ * object and is equivalent to {@code (CharacterConstraints) >+ * modelConstraints()}. >+ * </p> >+ * >+ * @return The model constraints to apply. >+ * >+ * @see #modelConstraints() >+ * @see CharacterConstraints >+ */ >+ public CharacterConstraints modelCharacterConstraints() { >+ return (CharacterConstraints) modelConstraints(); >+ } >+ >+ /** >+ * Returns the before-set model constraints to apply. >+ * >+ * <p> >+ * This method provides a typesafe access to the >+ * {@link CharacterConstraints character before-set model constraints} of >+ * this editing object and is equivalent to {@code (CharacterConstraints) >+ * beforeSetModelConstraints()}. >+ * </p> >+ * >+ * @return The before-set model constraints to apply. >+ * >+ * @see #beforeSetModelConstraints() >+ * @see CharacterConstraints >+ */ >+ public CharacterConstraints beforeSetModelCharacterConstraints() { >+ return (CharacterConstraints) beforeSetModelConstraints(); >+ } >+ >+ protected Constraints createTargetConstraints() { >+ return new StringConstraints(); >+ } >+ >+ protected Constraints createModelConstraints() { >+ return new CharacterConstraints(); >+ } >+ >+ protected Constraints createBeforeSetModelConstraints() { >+ return new CharacterConstraints(); >+ } >+} >Index: src/org/eclipse/core/databinding/editing/BooleanEditing.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/editing/BooleanEditing.java >diff -N src/org/eclipse/core/databinding/editing/BooleanEditing.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/editing/BooleanEditing.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,204 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ovidio Mallo and others. >+ * All rights reserved. This program and the accompanying materials >+ * are 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: >+ * Ovidio Mallo - initial API and implementation (bug 183055) >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.editing; >+ >+import org.eclipse.core.databinding.validation.constraint.BooleanConstraints; >+import org.eclipse.core.databinding.validation.constraint.Constraints; >+import org.eclipse.core.databinding.validation.constraint.StringConstraints; >+import org.eclipse.core.internal.databinding.conversion.BooleanToStringConverter; >+import org.eclipse.core.internal.databinding.conversion.StringToBooleanConverter; >+import org.eclipse.core.internal.databinding.validation.StringToBooleanValidator; >+ >+/** >+ * @noextend This class is not intended to be subclassed by clients. >+ * @since 1.3 >+ */ >+public class BooleanEditing extends Editing { >+ >+ /** >+ * Creates a new editing object for booleans. >+ * >+ * @param trueValues >+ * The set of strings representing a <code>true</code> value. >+ * @param falseValues >+ * The set of strings representing a <code>false</code> value. >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to a boolean. >+ * >+ * @noreference This constructor is not intended to be referenced by >+ * clients. >+ */ >+ protected BooleanEditing(String[] trueValues, String[] falseValues, >+ String parseErrorMessage) { >+ StringToBooleanConverter targetConverter = new StringToBooleanConverter(); >+ BooleanToStringConverter modelConverter = new BooleanToStringConverter( >+ Boolean.class); >+ >+ StringToBooleanValidator targetValidator = new StringToBooleanValidator(); >+ if (parseErrorMessage != null) { >+ targetValidator.setParseErrorMessage(parseErrorMessage); >+ } >+ >+ if (trueValues != null && falseValues != null) { >+ targetValidator.setSourceStrings(trueValues, falseValues); >+ targetConverter.setSourceStrings(trueValues, falseValues); >+ modelConverter.setTargetStrings(trueValues[0], falseValues[0]); >+ } >+ >+ setTargetConverter(targetConverter); >+ setModelConverter(modelConverter); >+ addTargetValidator(targetValidator); >+ } >+ >+ /** >+ * Creates a new editing object which uses the default set of string >+ * representations for boolean values for parsing and displaying. >+ * >+ * @return The new editing object for the default set of string >+ * representations for boolean values. >+ */ >+ public static BooleanEditing withDefaults() { >+ return withDefaults(null); >+ } >+ >+ /** >+ * Creates a new editing object which uses the default set of string >+ * representations for boolean values for parsing and displaying. Uses the >+ * specified custom validation message. >+ * >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to a boolean. >+ * @return The new editing object for the default set of string >+ * representations for boolean values. >+ */ >+ public static BooleanEditing withDefaults(String parseErrorMessage) { >+ return new BooleanEditing(null, null, parseErrorMessage); >+ } >+ >+ /** >+ * Creates a new editing object which uses the given set of string >+ * representations for boolean values for parsing and displaying. >+ * >+ * <p> >+ * For parsing, the given string values will be considered valid >+ * representations of {@code true} and {@code false}, respectively. For >+ * displaying, the first element of the respective array will be used for >+ * representing the corresponding boolean value. >+ * </p> >+ * >+ * @param trueValues >+ * The set of strings representing a <code>true</code> value. >+ * @param falseValues >+ * The set of strings representing a <code>false</code> value. >+ * @return The new editing object for the given set of string >+ * representations for boolean values. >+ */ >+ public static BooleanEditing forStringValues(String[] trueValues, >+ String[] falseValues) { >+ return forStringValues(trueValues, falseValues, null); >+ } >+ >+ /** >+ * Creates a new editing object which uses the given set of string >+ * representations for boolean values for parsing and displaying. Uses the >+ * specified custom validation message. >+ * >+ * <p> >+ * For parsing, the given string values will be considered valid >+ * representations of {@code true} and {@code false}, respectively. For >+ * displaying, the first element of the respective array will be used for >+ * representing the corresponding boolean value. >+ * </p> >+ * >+ * @param trueValues >+ * The set of strings representing a <code>true</code> value. >+ * @param falseValues >+ * The set of strings representing a <code>false</code> value. >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to a boolean. >+ * @return The new editing object for the given set of string >+ * representations for boolean values. >+ */ >+ public static BooleanEditing forStringValues(String[] trueValues, >+ String[] falseValues, String parseErrorMessage) { >+ return new BooleanEditing(trueValues, falseValues, parseErrorMessage); >+ } >+ >+ /** >+ * Returns the target constraints to apply. >+ * >+ * <p> >+ * This method provides a typesafe access to the {@link StringConstraints >+ * string target constraints} of this editing object and is equivalent to >+ * {@code (StringConstraints) targetConstraints()}. >+ * </p> >+ * >+ * @return The target constraints to apply. >+ * >+ * @see #targetConstraints() >+ * @see StringConstraints >+ */ >+ public StringConstraints targetStringConstraints() { >+ return (StringConstraints) targetConstraints(); >+ } >+ >+ /** >+ * Returns the model constraints to apply. >+ * >+ * <p> >+ * This method provides a typesafe access to the {@link BooleanConstraints >+ * bool model constraints} of this editing object and is equivalent to >+ * {@code (BooleanConstraints) modelConstraints()}. >+ * </p> >+ * >+ * @return The model constraints to apply. >+ * >+ * @see #modelConstraints() >+ * @see BooleanConstraints >+ */ >+ public BooleanConstraints modelBooleanConstraints() { >+ return (BooleanConstraints) modelConstraints(); >+ } >+ >+ /** >+ * Returns the before-set model constraints to apply. >+ * >+ * <p> >+ * This method provides a typesafe access to the {@link BooleanConstraints >+ * bool before-set model constraints} of this editing object and is >+ * equivalent to {@code (BooleanConstraints) beforeSetModelConstraints()}. >+ * </p> >+ * >+ * @return The before-set model constraints to apply. >+ * >+ * @see #beforeSetModelConstraints() >+ * @see BooleanConstraints >+ */ >+ public BooleanConstraints beforeSetModelBooleanConstraints() { >+ return (BooleanConstraints) beforeSetModelConstraints(); >+ } >+ >+ protected Constraints createTargetConstraints() { >+ return new StringConstraints(); >+ } >+ >+ protected Constraints createModelConstraints() { >+ return new BooleanConstraints(); >+ } >+ >+ protected Constraints createBeforeSetModelConstraints() { >+ return new BooleanConstraints(); >+ } >+} >Index: src/org/eclipse/core/databinding/editing/IntegerEditing.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/editing/IntegerEditing.java >diff -N src/org/eclipse/core/databinding/editing/IntegerEditing.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/editing/IntegerEditing.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,463 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ovidio Mallo and others. >+ * All rights reserved. This program and the accompanying materials >+ * are 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: >+ * Ovidio Mallo - initial API and implementation (bug 183055) >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.editing; >+ >+import org.eclipse.core.databinding.conversion.NumberToStringConverter; >+import org.eclipse.core.databinding.conversion.StringToNumberConverter; >+import org.eclipse.core.databinding.validation.constraint.Constraints; >+import org.eclipse.core.databinding.validation.constraint.IntegerConstraints; >+import org.eclipse.core.databinding.validation.constraint.StringConstraints; >+import org.eclipse.core.internal.databinding.validation.AbstractStringToNumberValidator; >+import org.eclipse.core.internal.databinding.validation.StringToByteValidator; >+import org.eclipse.core.internal.databinding.validation.StringToIntegerValidator; >+import org.eclipse.core.internal.databinding.validation.StringToLongValidator; >+import org.eclipse.core.internal.databinding.validation.StringToShortValidator; >+ >+import com.ibm.icu.text.NumberFormat; >+ >+/** >+ * @noextend This class is not intended to be subclassed by clients. >+ * @since 1.3 >+ */ >+public class IntegerEditing extends Editing { >+ >+ private final NumberFormat displayFormat; >+ >+ /** >+ * Creates a new editing object for integer numbers. >+ * >+ * @param format >+ * The integer format defining the validations and conversions >+ * used for editing. >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to an integer. >+ * @param outOfRangeMessage >+ * The validation message issued in case the input string >+ * represents an integer whose value is out of range. >+ * @param integerType >+ * The specific integer type for which to set up an editing >+ * instance. >+ * >+ * @noreference This constructor is not intended to be referenced by >+ * clients. >+ */ >+ protected IntegerEditing(NumberFormat format, String parseErrorMessage, >+ String outOfRangeMessage, Class integerType) { >+ this.displayFormat = format; >+ >+ final StringToNumberConverter targetConverter; >+ final NumberToStringConverter modelConverter; >+ final AbstractStringToNumberValidator targetValidator; >+ if (Long.class.equals(integerType)) { >+ targetConverter = StringToNumberConverter.toLong(format, false); >+ modelConverter = NumberToStringConverter.fromLong(format, false); >+ targetValidator = new StringToLongValidator(targetConverter); >+ } else if (Integer.class.equals(integerType)) { >+ targetConverter = StringToNumberConverter.toInteger(format, false); >+ modelConverter = NumberToStringConverter.fromInteger(format, false); >+ targetValidator = new StringToIntegerValidator(targetConverter); >+ } else if (Short.class.equals(integerType)) { >+ targetConverter = StringToNumberConverter.toShort(format, false); >+ modelConverter = NumberToStringConverter.fromShort(format, false); >+ targetValidator = new StringToShortValidator(targetConverter); >+ } else if (Byte.class.equals(integerType)) { >+ targetConverter = StringToNumberConverter.toByte(format, false); >+ modelConverter = NumberToStringConverter.fromByte(format, false); >+ targetValidator = new StringToByteValidator(targetConverter); >+ } else { >+ throw new IllegalArgumentException( >+ "Unsupported integer type: " + integerType); //$NON-NLS-1$ >+ } >+ >+ if (parseErrorMessage != null) { >+ targetValidator.setParseErrorMessage(parseErrorMessage); >+ } >+ if (outOfRangeMessage != null) { >+ targetValidator.setOutOfRangeMessage(outOfRangeMessage); >+ } >+ >+ setTargetConverter(targetConverter); >+ setModelConverter(modelConverter); >+ addTargetValidator(targetValidator); >+ } >+ >+ /** >+ * Creates a new editing object for {@link Long}s which defaults the >+ * validations and conversions used for editing based on the platform's >+ * locale. Uses the default validation messages. >+ * >+ * @return The new editing object using the default validations and >+ * conversions for editing. >+ * >+ * @see NumberFormat#getIntegerInstance() >+ */ >+ public static IntegerEditing withLongDefaults() { >+ return withLongDefaults(null, null); >+ } >+ >+ /** >+ * Creates a new editing object for {@link Long}s which defaults the >+ * validations and conversions used for editing based on the platform's >+ * locale. Uses the specified custom validation messages. >+ * >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to an integer. >+ * @param outOfRangeMessage >+ * The validation message issued in case the input string >+ * represents an integer whose value is out of range. Can be >+ * parameterized by the <code>Long.MIN_VALUE</code> and >+ * <code>Long.MAX_VALUE</code> values. >+ * @return The new editing object using the default validations and >+ * conversions for editing. >+ * >+ * @see NumberFormat#getIntegerInstance() >+ */ >+ public static IntegerEditing withLongDefaults(String parseErrorMessage, >+ String outOfRangeMessage) { >+ return new IntegerEditing(NumberFormat.getIntegerInstance(), >+ parseErrorMessage, outOfRangeMessage, Long.class); >+ } >+ >+ /** >+ * Creates a new editing object for {@link Long}s whose validations and >+ * conversions used for editing are based on the given integer format. Uses >+ * the default validation messages. >+ * >+ * @param format >+ * The integer format defining the validations and conversions >+ * used for editing. >+ * @return The new editing object configured by the given integer format. >+ */ >+ public static IntegerEditing forLongFormat(NumberFormat format) { >+ return forLongFormat(format, null, null); >+ } >+ >+ /** >+ * Creates a new editing object for {@link Long}s whose validations and >+ * conversions used for editing are based on the given integer format. Uses >+ * the specified custom validation messages. >+ * >+ * @param format >+ * The integer format defining the validations and conversions >+ * used for editing. >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to an integer. >+ * @param outOfRangeMessage >+ * The validation message issued in case the input string >+ * represents an integer whose value is out of range. Can be >+ * parameterized by the <code>Long.MIN_VALUE</code> and >+ * <code>Long.MAX_VALUE</code> values. >+ * @return The new editing object configured by the given integer format. >+ */ >+ public static IntegerEditing forLongFormat(NumberFormat format, >+ String parseErrorMessage, String outOfRangeMessage) { >+ return new IntegerEditing(format, parseErrorMessage, outOfRangeMessage, >+ Long.class); >+ } >+ >+ /** >+ * Creates a new editing object for {@link Integer}s which defaults the >+ * validations and conversions used for editing based on the platform's >+ * locale. Uses the default validation messages. >+ * >+ * @return The new editing object using the default validations and >+ * conversions for editing. >+ * >+ * @see NumberFormat#getIntegerInstance() >+ */ >+ public static IntegerEditing withIntegerDefaults() { >+ return withIntegerDefaults(null, null); >+ } >+ >+ /** >+ * Creates a new editing object for {@link Integer}s which defaults the >+ * validations and conversions used for editing based on the platform's >+ * locale. Uses the specified custom validation messages. >+ * >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to an integer. >+ * @param outOfRangeMessage >+ * The validation message issued in case the input string >+ * represents an integer whose value is out of range. Can be >+ * parameterized by the <code>Integer.MIN_VALUE</code> and >+ * <code>Integer.MAX_VALUE</code> values. >+ * @return The new editing object using the default validations and >+ * conversions for editing. >+ * >+ * @see NumberFormat#getIntegerInstance() >+ */ >+ public static IntegerEditing withIntegerDefaults(String parseErrorMessage, >+ String outOfRangeMessage) { >+ return new IntegerEditing(NumberFormat.getIntegerInstance(), >+ parseErrorMessage, outOfRangeMessage, Integer.class); >+ } >+ >+ /** >+ * Creates a new editing object for {@link Integer}s whose validations and >+ * conversions used for editing are based on the given integer format. Uses >+ * the default validation messages. >+ * >+ * @param format >+ * The integer format defining the validations and conversions >+ * used for editing. >+ * @return The new editing object configured by the given integer format. >+ */ >+ public static IntegerEditing forIntegerFormat(NumberFormat format) { >+ return forIntegerFormat(format, null, null); >+ } >+ >+ /** >+ * Creates a new editing object for {@link Integer}s whose validations and >+ * conversions used for editing are based on the given integer format. Uses >+ * the specified custom validation messages. >+ * >+ * @param format >+ * The integer format defining the validations and conversions >+ * used for editing. >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to an integer. >+ * @param outOfRangeMessage >+ * The validation message issued in case the input string >+ * represents an integer whose value is out of range. Can be >+ * parameterized by the <code>Integer.MIN_VALUE</code> and >+ * <code>Integer.MAX_VALUE</code> values. >+ * @return The new editing object configured by the given integer format. >+ */ >+ public static IntegerEditing forIntegerFormat(NumberFormat format, >+ String parseErrorMessage, String outOfRangeMessage) { >+ return new IntegerEditing(format, parseErrorMessage, outOfRangeMessage, >+ Integer.class); >+ } >+ >+ /** >+ * Creates a new editing object for {@link Short}s which defaults the >+ * validations and conversions used for editing based on the platform's >+ * locale. Uses the default validation messages. >+ * >+ * @return The new editing object using the default validations and >+ * conversions for editing. >+ * >+ * @see NumberFormat#getIntegerInstance() >+ */ >+ public static IntegerEditing withShortDefaults() { >+ return withShortDefaults(null, null); >+ } >+ >+ /** >+ * Creates a new editing object for {@link Short}s which defaults the >+ * validations and conversions used for editing based on the platform's >+ * locale. Uses the specified custom validation messages. >+ * >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to an integer. >+ * @param outOfRangeMessage >+ * The validation message issued in case the input string >+ * represents an integer whose value is out of range. Can be >+ * parameterized by the <code>Short.MIN_VALUE</code> and >+ * <code>Short.MAX_VALUE</code> values. >+ * @return The new editing object using the default validations and >+ * conversions for editing. >+ * >+ * @see NumberFormat#getIntegerInstance() >+ */ >+ public static IntegerEditing withShortDefaults(String parseErrorMessage, >+ String outOfRangeMessage) { >+ return new IntegerEditing(NumberFormat.getIntegerInstance(), >+ parseErrorMessage, outOfRangeMessage, Short.class); >+ } >+ >+ /** >+ * Creates a new editing object for {@link Short}s whose validations and >+ * conversions used for editing are based on the given integer format. Uses >+ * the default validation messages. >+ * >+ * @param format >+ * The integer format defining the validations and conversions >+ * used for editing. >+ * @return The new editing object configured by the given integer format. >+ */ >+ public static IntegerEditing forShortFormat(NumberFormat format) { >+ return forShortFormat(format, null, null); >+ } >+ >+ /** >+ * Creates a new editing object for {@link Short}s whose validations and >+ * conversions used for editing are based on the given integer format. Uses >+ * the specified custom validation messages. >+ * >+ * @param format >+ * The integer format defining the validations and conversions >+ * used for editing. >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to an integer. >+ * @param outOfRangeMessage >+ * The validation message issued in case the input string >+ * represents an integer whose value is out of range. Can be >+ * parameterized by the <code>Short.MIN_VALUE</code> and >+ * <code>Short.MAX_VALUE</code> values. >+ * @return The new editing object configured by the given integer format. >+ */ >+ public static IntegerEditing forShortFormat(NumberFormat format, >+ String parseErrorMessage, String outOfRangeMessage) { >+ return new IntegerEditing(format, parseErrorMessage, outOfRangeMessage, >+ Short.class); >+ } >+ >+ /** >+ * Creates a new editing object for {@link Byte}s which defaults the >+ * validations and conversions used for editing based on the platform's >+ * locale. Uses the default validation messages. >+ * >+ * @return The new editing object using the default validations and >+ * conversions for editing. >+ * >+ * @see NumberFormat#getIntegerInstance() >+ */ >+ public static IntegerEditing withByteDefaults() { >+ return withByteDefaults(null, null); >+ } >+ >+ /** >+ * Creates a new editing object for {@link Byte}s which defaults the >+ * validations and conversions used for editing based on the platform's >+ * locale. Uses the specified custom validation messages. >+ * >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to an integer. >+ * @param outOfRangeMessage >+ * The validation message issued in case the input string >+ * represents an integer whose value is out of range. Can be >+ * parameterized by the <code>Byte.MIN_VALUE</code> and >+ * <code>Byte.MAX_VALUE</code> values. >+ * @return The new editing object using the default validations and >+ * conversions for editing. >+ * >+ * @see NumberFormat#getIntegerInstance() >+ */ >+ public static IntegerEditing withByteDefaults(String parseErrorMessage, >+ String outOfRangeMessage) { >+ return new IntegerEditing(NumberFormat.getIntegerInstance(), >+ parseErrorMessage, outOfRangeMessage, Byte.class); >+ } >+ >+ /** >+ * Creates a new editing object for {@link Byte}s whose validations and >+ * conversions used for editing are based on the given integer format. Uses >+ * the default validation messages. >+ * >+ * @param format >+ * The integer format defining the validations and conversions >+ * used for editing. >+ * @return The new editing object configured by the given integer format. >+ */ >+ public static IntegerEditing forByteFormat(NumberFormat format) { >+ return forByteFormat(format, null, null); >+ } >+ >+ /** >+ * Creates a new editing object for {@link Byte}s whose validations and >+ * conversions used for editing are based on the given integer format. Uses >+ * the specified custom validation messages. >+ * >+ * @param format >+ * The integer format defining the validations and conversions >+ * used for editing. >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to an integer. >+ * @param outOfRangeMessage >+ * The validation message issued in case the input string >+ * represents an integer whose value is out of range. Can be >+ * parameterized by the <code>Byte.MIN_VALUE</code> and >+ * <code>Byte.MAX_VALUE</code> values. >+ * @return The new editing object configured by the given integer format. >+ */ >+ public static IntegerEditing forByteFormat(NumberFormat format, >+ String parseErrorMessage, String outOfRangeMessage) { >+ return new IntegerEditing(format, parseErrorMessage, outOfRangeMessage, >+ Byte.class); >+ } >+ >+ /** >+ * Returns the target constraints to apply. >+ * >+ * <p> >+ * This method provides a typesafe access to the {@link StringConstraints >+ * string target constraints} of this editing object and is equivalent to >+ * {@code (StringConstraints) targetConstraints()}. >+ * </p> >+ * >+ * @return The target constraints to apply. >+ * >+ * @see #targetConstraints() >+ * @see StringConstraints >+ */ >+ public StringConstraints targetStringConstraints() { >+ return (StringConstraints) targetConstraints(); >+ } >+ >+ /** >+ * Returns the model constraints to apply. >+ * >+ * <p> >+ * This method provides a typesafe access to the {@link IntegerConstraints >+ * integer model constraints} of this editing object and is equivalent to >+ * {@code (IntegerConstraints) modelConstraints()}. >+ * </p> >+ * >+ * @return The model constraints to apply. >+ * >+ * @see #modelConstraints() >+ * @see IntegerConstraints >+ */ >+ public IntegerConstraints modelIntegerConstraints() { >+ return (IntegerConstraints) modelConstraints(); >+ } >+ >+ /** >+ * Returns the before-set model constraints to apply. >+ * >+ * <p> >+ * This method provides a typesafe access to the {@link IntegerConstraints >+ * integer before-set model constraints} of this editing object and is >+ * equivalent to {@code (IntegerConstraints) beforeSetModelConstraints()}. >+ * </p> >+ * >+ * @return The before-set model constraints to apply. >+ * >+ * @see #beforeSetModelConstraints() >+ * @see IntegerConstraints >+ */ >+ public IntegerConstraints beforeSetModelIntegerConstraints() { >+ return (IntegerConstraints) beforeSetModelConstraints(); >+ } >+ >+ protected Constraints createTargetConstraints() { >+ return new StringConstraints(); >+ } >+ >+ protected Constraints createModelConstraints() { >+ return new IntegerConstraints().integerFormat(displayFormat); >+ } >+ >+ protected Constraints createBeforeSetModelConstraints() { >+ return new IntegerConstraints().integerFormat(displayFormat); >+ } >+} >Index: src/org/eclipse/core/databinding/editing/DateEditing.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/editing/DateEditing.java >diff -N src/org/eclipse/core/databinding/editing/DateEditing.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/editing/DateEditing.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,196 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ovidio Mallo and others. >+ * All rights reserved. This program and the accompanying materials >+ * are 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: >+ * Ovidio Mallo - initial API and implementation (bug 183055) >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.editing; >+ >+import org.eclipse.core.databinding.validation.constraint.Constraints; >+import org.eclipse.core.databinding.validation.constraint.DateConstraints; >+import org.eclipse.core.databinding.validation.constraint.StringConstraints; >+import org.eclipse.core.internal.databinding.conversion.DateToStringConverter; >+import org.eclipse.core.internal.databinding.conversion.StringToDateConverter; >+import org.eclipse.core.internal.databinding.validation.StringToDateValidator; >+ >+import com.ibm.icu.text.DateFormat; >+ >+/** >+ * @noextend This class is not intended to be subclassed by clients. >+ * @since 1.3 >+ */ >+public class DateEditing extends Editing { >+ >+ private final DateFormat displayFormat; >+ >+ /** >+ * Creates a new editing object for <code>Date</code>s. >+ * >+ * @param inputFormats >+ * The date formats supported for reading in dates. >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to a date. >+ * @param displayFormat >+ * The date format for displaying dates. >+ * >+ * @noreference This constructor is not intended to be referenced by >+ * clients. >+ */ >+ protected DateEditing(DateFormat[] inputFormats, String parseErrorMessage, >+ DateFormat displayFormat) { >+ this.displayFormat = displayFormat; >+ >+ StringToDateConverter targetConverter = new StringToDateConverter(); >+ if (inputFormats != null) { >+ targetConverter.setFormatters(inputFormats); >+ } >+ >+ DateToStringConverter modelConverter = new DateToStringConverter(); >+ if (displayFormat != null) { >+ modelConverter.setFormatters(new DateFormat[] { displayFormat }); >+ } >+ >+ StringToDateValidator targetValidator = new StringToDateValidator( >+ targetConverter); >+ if (parseErrorMessage != null) { >+ targetValidator.setParseErrorMessage(parseErrorMessage); >+ } >+ >+ setTargetConverter(targetConverter); >+ setModelConverter(modelConverter); >+ addTargetValidator(targetValidator); >+ } >+ >+ /** >+ * Creates a new editing object which defaults the validations and >+ * conversions used for editing. Uses the default validation message. >+ * >+ * @return The new editing object using the default validations and >+ * conversions for editing. >+ */ >+ public static DateEditing withDefaults() { >+ return withDefaults(null); >+ } >+ >+ /** >+ * Creates a new editing object which defaults the validations and >+ * conversions used for editing. Uses the specified custom validation >+ * message. >+ * >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to a date. >+ * @return The new editing object using the default validations and >+ * conversions for editing. >+ */ >+ public static DateEditing withDefaults(String parseErrorMessage) { >+ return new DateEditing(null, parseErrorMessage, null); >+ } >+ >+ /** >+ * Creates a new editing object which supports all the given date input >+ * formats and which uses the specified format for displaying a date. Uses >+ * the default validation message. >+ * >+ * @param inputFormats >+ * The date formats supported for reading in dates. >+ * @param displayFormat >+ * The date format for displaying dates. >+ * @return The new editing object configured by the given date formats. >+ */ >+ public static DateEditing forFormats(DateFormat[] inputFormats, >+ DateFormat displayFormat) { >+ return new DateEditing(inputFormats, null, displayFormat); >+ } >+ >+ /** >+ * Creates a new editing object which supports all the given date input >+ * formats and which uses the specified format for displaying a date. Uses >+ * the specified custom validation message. >+ * >+ * @param inputFormats >+ * The date formats supported for reading in dates. >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to a date. >+ * @param displayFormat >+ * The date format for displaying dates. >+ * @return The new editing object configured by the given date formats. >+ */ >+ public static DateEditing forFormats(DateFormat[] inputFormats, >+ String parseErrorMessage, DateFormat displayFormat) { >+ return new DateEditing(inputFormats, parseErrorMessage, displayFormat); >+ } >+ >+ /** >+ * Returns the target constraints to apply. >+ * >+ * <p> >+ * This method provides a typesafe access to the {@link StringConstraints >+ * string target constraints} of this editing object and is equivalent to >+ * {@code (StringConstraints) targetConstraints()}. >+ * </p> >+ * >+ * @return The target constraints to apply. >+ * >+ * @see #targetConstraints() >+ * @see StringConstraints >+ */ >+ public StringConstraints targetStringConstraints() { >+ return (StringConstraints) targetConstraints(); >+ } >+ >+ /** >+ * Returns the model constraints to apply. >+ * >+ * <p> >+ * This method provides a typesafe access to the {@link DateConstraints date >+ * model constraints} of this editing object and is equivalent to {@code >+ * (DateConstraints) modelConstraints()}. >+ * </p> >+ * >+ * @return The model constraints to apply. >+ * >+ * @see #modelConstraints() >+ * @see DateConstraints >+ */ >+ public DateConstraints modelDateConstraints() { >+ return (DateConstraints) modelConstraints(); >+ } >+ >+ /** >+ * Returns the before-set model constraints to apply. >+ * >+ * <p> >+ * This method provides a typesafe access to the {@link DateConstraints date >+ * before-set model constraints} of this editing object and is equivalent to >+ * {@code (DateConstraints) beforeSetModelConstraints()}. >+ * </p> >+ * >+ * @return The before-set model constraints to apply. >+ * >+ * @see #beforeSetModelConstraints() >+ * @see DateConstraints >+ */ >+ public DateConstraints beforeSetModelDateConstraints() { >+ return (DateConstraints) beforeSetModelConstraints(); >+ } >+ >+ protected Constraints createTargetConstraints() { >+ return new StringConstraints(); >+ } >+ >+ protected Constraints createModelConstraints() { >+ return new DateConstraints().dateFormat(displayFormat); >+ } >+ >+ protected Constraints createBeforeSetModelConstraints() { >+ return new DateConstraints().dateFormat(displayFormat); >+ } >+} >Index: src/org/eclipse/core/databinding/editing/DecimalEditing.java >=================================================================== >RCS file: src/org/eclipse/core/databinding/editing/DecimalEditing.java >diff -N src/org/eclipse/core/databinding/editing/DecimalEditing.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/databinding/editing/DecimalEditing.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,301 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Ovidio Mallo and others. >+ * All rights reserved. This program and the accompanying materials >+ * are 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: >+ * Ovidio Mallo - initial API and implementation (bug 183055) >+ ******************************************************************************/ >+ >+package org.eclipse.core.databinding.editing; >+ >+import org.eclipse.core.databinding.conversion.NumberToStringConverter; >+import org.eclipse.core.databinding.conversion.StringToNumberConverter; >+import org.eclipse.core.databinding.validation.constraint.Constraints; >+import org.eclipse.core.databinding.validation.constraint.DecimalConstraints; >+import org.eclipse.core.databinding.validation.constraint.StringConstraints; >+import org.eclipse.core.internal.databinding.validation.AbstractStringToNumberValidator; >+import org.eclipse.core.internal.databinding.validation.StringToDoubleValidator; >+import org.eclipse.core.internal.databinding.validation.StringToFloatValidator; >+ >+import com.ibm.icu.text.NumberFormat; >+ >+/** >+ * @noextend This class is not intended to be subclassed by clients. >+ * @since 1.3 >+ */ >+public class DecimalEditing extends Editing { >+ >+ private final NumberFormat displayFormat; >+ >+ /** >+ * Creates a new editing object for decimal numbers. >+ * >+ * @param format >+ * The number format defining the validations and conversions >+ * used for editing. >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to a double. >+ * @param outOfRangeMessage >+ * The validation message issued in case the input string >+ * represents a double whose value is out of range. >+ * @param decimalType >+ * The specific decimal type for which to set up an editing >+ * instance. >+ * >+ * @noreference This constructor is not intended to be referenced by >+ * clients. >+ */ >+ protected DecimalEditing(NumberFormat format, String parseErrorMessage, >+ String outOfRangeMessage, Class decimalType) { >+ this.displayFormat = format; >+ >+ final StringToNumberConverter targetConverter; >+ final NumberToStringConverter modelConverter; >+ final AbstractStringToNumberValidator targetValidator; >+ if (Double.class.equals(decimalType)) { >+ targetConverter = StringToNumberConverter.toDouble(format, false); >+ modelConverter = NumberToStringConverter.fromDouble(format, false); >+ targetValidator = new StringToDoubleValidator(targetConverter); >+ } else if (Float.class.equals(decimalType)) { >+ targetConverter = StringToNumberConverter.toFloat(format, false); >+ modelConverter = NumberToStringConverter.fromFloat(format, false); >+ targetValidator = new StringToFloatValidator(targetConverter); >+ } else { >+ throw new IllegalArgumentException( >+ "Unsupported decimal type: " + decimalType); //$NON-NLS-1$ >+ } >+ >+ if (parseErrorMessage != null) { >+ targetValidator.setParseErrorMessage(parseErrorMessage); >+ } >+ if (outOfRangeMessage != null) { >+ targetValidator.setOutOfRangeMessage(outOfRangeMessage); >+ } >+ >+ setTargetConverter(targetConverter); >+ setModelConverter(modelConverter); >+ addTargetValidator(targetValidator); >+ } >+ >+ /** >+ * Creates a new editing object for {@link Double}s which defaults the >+ * validations and conversions used for editing based on the platform's >+ * locale. Uses the default validation messages. >+ * >+ * @return The new editing object using the default validations and >+ * conversions for editing. >+ * >+ * @see NumberFormat#getNumberInstance() >+ */ >+ public static DecimalEditing withDoubleDefaults() { >+ return withDoubleDefaults(null, null); >+ } >+ >+ /** >+ * Creates a new editing object for {@link Double}s which defaults the >+ * validations and conversions used for editing based on the platform's >+ * locale. Uses the specified custom validation messages. >+ * >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to a double. >+ * @param outOfRangeMessage >+ * The validation message issued in case the input string >+ * represents a double whose value is out of range. Can be >+ * parameterized by the <code>-Double.MAX_VALUE</code> and >+ * <code>+Double.MAX_VALUE</code> values. >+ * @return The new editing object using the default validations and >+ * conversions for editing. >+ * >+ * @see NumberFormat#getNumberInstance() >+ */ >+ public static DecimalEditing withDoubleDefaults(String parseErrorMessage, >+ String outOfRangeMessage) { >+ return new DecimalEditing(NumberFormat.getNumberInstance(), >+ parseErrorMessage, outOfRangeMessage, Double.class); >+ } >+ >+ /** >+ * Creates a new editing object for {@link Double}s whose validations and >+ * conversions used for editing are based on the given number format. Uses >+ * the default validation messages. >+ * >+ * @param format >+ * The number format defining the validations and conversions >+ * used for editing. >+ * @return The new editing object configured by the given number format. >+ */ >+ public static DecimalEditing forDoubleFormat(NumberFormat format) { >+ return forDoubleFormat(format, null, null); >+ } >+ >+ /** >+ * Creates a new editing object for {@link Double}s whose validations and >+ * conversions used for editing are based on the given number format. Uses >+ * the specified custom validation messages. >+ * >+ * @param format >+ * The number format defining the validations and conversions >+ * used for editing. >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to a double. >+ * @param outOfRangeMessage >+ * The validation message issued in case the input string >+ * represents a double whose value is out of range. Can be >+ * parameterized by the <code>-Double.MAX_VALUE</code> and >+ * <code>+Double.MAX_VALUE</code> values. >+ * @return The new editing object configured by the given number format. >+ */ >+ public static DecimalEditing forDoubleFormat(NumberFormat format, >+ String parseErrorMessage, String outOfRangeMessage) { >+ return new DecimalEditing(format, parseErrorMessage, outOfRangeMessage, >+ Double.class); >+ } >+ >+ /** >+ * Creates a new editing object for {@link Float}s which defaults the >+ * validations and conversions used for editing based on the platform's >+ * locale. Uses the default validation messages. >+ * >+ * @return The new editing object using the default validations and >+ * conversions for editing. >+ * >+ * @see NumberFormat#getNumberInstance() >+ */ >+ public static DecimalEditing withFloatDefaults() { >+ return withFloatDefaults(null, null); >+ } >+ >+ /** >+ * Creates a new editing object for {@link Float}s which defaults the >+ * validations and conversions used for editing based on the platform's >+ * locale. Uses the specified custom validation messages. >+ * >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to a double. >+ * @param outOfRangeMessage >+ * The validation message issued in case the input string >+ * represents a float whose value is out of range. Can be >+ * parameterized by the <code>-Float.MAX_VALUE</code> and >+ * <code>+Float.MAX_VALUE</code> values. >+ * @return The new editing object using the default validations and >+ * conversions for editing. >+ * >+ * @see NumberFormat#getNumberInstance() >+ */ >+ public static DecimalEditing withFloatDefaults(String parseErrorMessage, >+ String outOfRangeMessage) { >+ return new DecimalEditing(NumberFormat.getNumberInstance(), >+ parseErrorMessage, outOfRangeMessage, Float.class); >+ } >+ >+ /** >+ * Creates a new editing object for {@link Float}s whose validations and >+ * conversions used for editing are based on the given number format. Uses >+ * the default validation messages. >+ * >+ * @param format >+ * The number format defining the validations and conversions >+ * used for editing. >+ * @return The new editing object configured by the given number format. >+ */ >+ public static DecimalEditing forFloatFormat(NumberFormat format) { >+ return forFloatFormat(format, null, null); >+ } >+ >+ /** >+ * Creates a new editing object for {@link Float}s whose validations and >+ * conversions used for editing are based on the given number format. Uses >+ * the specified custom validation messages. >+ * >+ * @param format >+ * The number format defining the validations and conversions >+ * used for editing. >+ * @param parseErrorMessage >+ * The validation message issued in case the input string cannot >+ * be parsed to a float. >+ * @param outOfRangeMessage >+ * The validation message issued in case the input string >+ * represents a float whose value is out of range. Can be >+ * parameterized by the <code>-Float.MAX_VALUE</code> and >+ * <code>+Float.MAX_VALUE</code> values. >+ * @return The new editing object configured by the given number format. >+ */ >+ public static DecimalEditing forFloatFormat(NumberFormat format, >+ String parseErrorMessage, String outOfRangeMessage) { >+ return new DecimalEditing(format, parseErrorMessage, outOfRangeMessage, >+ Float.class); >+ } >+ >+ /** >+ * Returns the target constraints to apply. >+ * >+ * <p> >+ * This method provides a typesafe access to the {@link StringConstraints >+ * string target constraints} of this editing object and is equivalent to >+ * {@code (StringConstraints) targetConstraints()}. >+ * </p> >+ * >+ * @return The target constraints to apply. >+ * >+ * @see #targetConstraints() >+ * @see StringConstraints >+ */ >+ public StringConstraints targetStringConstraints() { >+ return (StringConstraints) targetConstraints(); >+ } >+ >+ /** >+ * Returns the model constraints to apply. >+ * >+ * <p> >+ * This method provides a typesafe access to the {@link DecimalConstraints >+ * decimal model constraints} of this editing object and is equivalent to >+ * {@code (DecimalConstraints) modelConstraints()}. >+ * </p> >+ * >+ * @return The model constraints to apply. >+ * >+ * @see #modelConstraints() >+ * @see DecimalConstraints >+ */ >+ public DecimalConstraints modelDecimalConstraints() { >+ return (DecimalConstraints) modelConstraints(); >+ } >+ >+ /** >+ * Returns the before-set model constraints to apply. >+ * >+ * <p> >+ * This method provides a typesafe access to the {@link DecimalConstraints >+ * decimal before-set model constraints} of this editing object and is >+ * equivalent to {@code (DecimalConstraints) beforeSetModelConstraints()}. >+ * </p> >+ * >+ * @return The before-set model constraints to apply. >+ * >+ * @see #beforeSetModelConstraints() >+ * @see DecimalConstraints >+ */ >+ public DecimalConstraints beforeSetModelDecimalConstraints() { >+ return (DecimalConstraints) beforeSetModelConstraints(); >+ } >+ >+ protected Constraints createTargetConstraints() { >+ return new StringConstraints(); >+ } >+ >+ protected Constraints createModelConstraints() { >+ return new DecimalConstraints().decimalFormat(displayFormat); >+ } >+ >+ protected Constraints createBeforeSetModelConstraints() { >+ return new DecimalConstraints().decimalFormat(displayFormat); >+ } >+} >#P org.eclipse.jface.examples.databinding >Index: src/org/eclipse/jface/examples/databinding/snippets/Snippet035Editing.java >=================================================================== >RCS file: src/org/eclipse/jface/examples/databinding/snippets/Snippet035Editing.java >diff -N src/org/eclipse/jface/examples/databinding/snippets/Snippet035Editing.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/examples/databinding/snippets/Snippet035Editing.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,294 @@ >+/******************************************************************************* >+ * Copyright (c) 2006, 2009 Ovidio Mallo and others. >+ * All rights reserved. This program and the accompanying materials >+ * are 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: >+ * Ovidio Mallo - initial API and implementation (bug 183055) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.examples.databinding.snippets; >+ >+import java.util.Calendar; >+import java.util.Date; >+ >+import org.eclipse.core.databinding.Binding; >+import org.eclipse.core.databinding.DataBindingContext; >+import org.eclipse.core.databinding.editing.BooleanEditing; >+import org.eclipse.core.databinding.editing.DateEditing; >+import org.eclipse.core.databinding.editing.DecimalEditing; >+import org.eclipse.core.databinding.editing.Editing; >+import org.eclipse.core.databinding.editing.IntegerEditing; >+import org.eclipse.core.databinding.editing.StringEditing; >+import org.eclipse.core.databinding.observable.Realm; >+import org.eclipse.core.databinding.observable.list.WritableList; >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.databinding.observable.value.WritableValue; >+import org.eclipse.core.databinding.validation.IValidator; >+import org.eclipse.core.databinding.validation.ValidationStatus; >+import org.eclipse.core.databinding.validation.constraint.Constraints; >+import org.eclipse.core.databinding.validation.constraint.IntegerConstraints; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.jface.databinding.swt.ISWTObservableValue; >+import org.eclipse.jface.databinding.swt.SWTObservables; >+import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; >+import org.eclipse.jface.examples.databinding.util.EditingFactory; >+import org.eclipse.jface.internal.databinding.provisional.fieldassist.ControlDecorationSupport; >+import org.eclipse.jface.layout.GridDataFactory; >+import org.eclipse.jface.layout.GridLayoutFactory; >+import org.eclipse.jface.viewers.LabelProvider; >+import org.eclipse.jface.viewers.ListViewer; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.FocusAdapter; >+import org.eclipse.swt.events.FocusEvent; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Group; >+import org.eclipse.swt.widgets.Label; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.swt.widgets.Text; >+ >+import com.ibm.icu.text.MessageFormat; >+ >+public class Snippet035Editing { >+ >+ private DataBindingContext dbc; >+ >+ public static void main(String[] args) { >+ Display display = new Display(); >+ >+ Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { >+ public void run() { >+ Shell shell = new Snippet035Editing().createShell(); >+ Display display = Display.getCurrent(); >+ while (!shell.isDisposed()) { >+ if (!display.readAndDispatch()) { >+ display.sleep(); >+ } >+ } >+ } >+ }); >+ } >+ >+ private Shell createShell() { >+ Display display = Display.getCurrent(); >+ Shell shell = new Shell(display); >+ shell.setText("Editing"); >+ shell.setLayout(new GridLayout(1, false)); >+ >+ dbc = new DataBindingContext(); >+ >+ createValueSection(shell); >+ createListSection(shell); >+ >+ shell.pack(); >+ shell.open(); >+ >+ return shell; >+ } >+ >+ private void createValueSection(Composite parent) { >+ Group section = createSectionGroup(parent, "Value bindings", false); >+ >+ // Edit an e-mail address. >+ Text emailText = createTextField(section, "E-Mail*"); >+ StringEditing emailEditing = EditingFactory.forEmailString(); >+ emailEditing.modelStringConstraints().required(); >+ bindTextField(emailText, new WritableValue(), emailEditing); >+ >+ // Edit a required, positive short using the default validation message. >+ Text positiveText = createTextField(section, "Positive short*"); >+ IntegerEditing positiveEditing = EditingFactory.forShort(); >+ positiveEditing.modelIntegerConstraints().required().positive(); >+ bindTextField(positiveText, new WritableValue(), positiveEditing); >+ >+ // Edit a required double with a maximum of five significant and two >+ // fractional digits. >+ Text doubleText = createTextField(section, "Price [$]*"); >+ DecimalEditing doubleEditing = EditingFactory.forDouble(); >+ doubleEditing.modelDecimalConstraints().required().maxPrecision(5) >+ .maxScale(2); >+ bindTextField(doubleText, new WritableValue(), doubleEditing); >+ >+ // Edit an integer within the range [1, 100] using the default >+ // validation message. >+ Text rangeText = createTextField(section, "Value in [1, 100]"); >+ IntegerEditing rangeEditing = EditingFactory.forInteger(); >+ rangeEditing.modelIntegerConstraints().range(1, 100); >+ bindTextField(rangeText, new WritableValue(0, null), rangeEditing); >+ >+ // Edit a percentage value which must lie within [0, 100] using a custom >+ // validation message which indicates that the value actually represents >+ // a percentage value. Note that the constraint message must be >+ // specified >+ // before the actual constraint. >+ Text percentText = createTextField(section, "Percentage [%]"); >+ IntegerEditing percentEditing = EditingFactory.forInteger(); >+ percentEditing.modelIntegerConstraints().rangeMessage( >+ "Please specify a percentage value within [{0}, {1}].").range( >+ 0, 100); >+ bindTextField(percentText, new WritableValue(-1, null), percentEditing); >+ >+ // Edit a hex integer within the range [0x00, 0xff]. The range >+ // validation >+ // message will display the range boundaries in hex format as well. >+ Text hexText = createTextField(section, "Hex value in [0x00, 0xff]"); >+ IntegerEditing hexEditing = EditingFactory.forHexInteger(2); >+ hexEditing.modelIntegerConstraints().range(0x00, 0xff); >+ bindTextField(hexText, new WritableValue(0, null), hexEditing); >+ >+ // Edit a boolean value. >+ Text boolText = createTextField(section, "Boolean value"); >+ BooleanEditing boolEditing = EditingFactory.forBoolean(); >+ bindTextField(boolText, new WritableValue(true, null), boolEditing); >+ >+ // Edit a value within [1, 10] or [20, 30]. >+ Text rangesText = createTextField(section, >+ "Value in [1, 10] or [20, 30]"); >+ Editing rangesEditing = EditingFactory.forInteger().addModelValidator( >+ new RangesValidator(1, 10, 20, 30)); >+ bindTextField(rangesText, new WritableValue(), rangesEditing); >+ } >+ >+ private void createListSection(Composite parent) { >+ Group section = createSectionGroup(parent, "List bindings", true); >+ >+ // Our date should be >= 01.01.1990. >+ Calendar year1990Calendar = Calendar.getInstance(); >+ year1990Calendar.clear(); >+ year1990Calendar.set(1990, 0, 1); >+ Date year1990 = year1990Calendar.getTime(); >+ >+ // Edit a date supporting the default input/display patterns. >+ Text dateText = createTextField(section, "Date"); >+ DateEditing dateEditing = EditingFactory.forDate(); >+ dateEditing.modelDateConstraints().afterEqual(year1990); >+ final WritableValue dateObservable = new WritableValue(); >+ final Binding dateBinding = bindTextField(dateText, dateObservable, >+ dateEditing); >+ >+ // Create a list to which the dates are added when the user hits ENTER. >+ new Label(section, SWT.LEFT); >+ ListViewer dateListViewer = new ListViewer(section); >+ GridDataFactory.fillDefaults().grab(true, true).hint(150, 200).applyTo( >+ dateListViewer.getList()); >+ >+ dateListViewer.setContentProvider(new ObservableListContentProvider()); >+ dateListViewer.setLabelProvider(new LabelProvider()); >+ >+ // We use the same DateEditing object as for the text field above to >+ // create a list binding which maps the entered dates to their string >+ // representation which is then set as input on the ListViewer. >+ final WritableList targetDateList = new WritableList(); >+ final WritableList modelDateList = new WritableList(); >+ dateEditing.bindList(dbc, targetDateList, modelDateList); >+ >+ // Set the list containing the string representation of the dates as >+ // input. >+ dateListViewer.setInput(targetDateList); >+ >+ // Add the current date in the text field when the user hits ENTER. >+ dateText.addSelectionListener(new SelectionAdapter() { >+ public void widgetDefaultSelected(SelectionEvent e) { >+ IStatus dateValidationStatus = (IStatus) dateBinding >+ .getValidationStatus().getValue(); >+ Date date = (Date) dateObservable.getValue(); >+ if (dateValidationStatus.isOK() && date != null) { >+ modelDateList.add(date); >+ } >+ } >+ }); >+ } >+ >+ private Binding bindTextField(Text text, IObservableValue modelValue, >+ Editing editing) { >+ // Create the binding using the editing object. >+ ISWTObservableValue textObservable = SWTObservables.observeText(text, >+ SWT.Modify); >+ Binding binding = editing.bindValue(dbc, textObservable, modelValue); >+ >+ // Decorate the control with the validation status. >+ ControlDecorationSupport.create(binding, SWT.TOP); >+ >+ // Re-format when the text field looses the focus in order to always >+ // display the model in the default format in case multiple input >+ // formats >+ // are supported. >+ formatOnFocusOut(text, binding); >+ >+ return binding; >+ } >+ >+ private static void formatOnFocusOut(final Control control, >+ final Binding binding) { >+ control.addFocusListener(new FocusAdapter() { >+ public void focusLost(FocusEvent e) { >+ IStatus dateValidationStatus = (IStatus) binding >+ .getValidationStatus().getValue(); >+ if (dateValidationStatus.isOK()) { >+ binding.updateModelToTarget(); >+ } >+ } >+ }); >+ } >+ >+ private static Group createSectionGroup(Composite parent, String groupText, >+ boolean grabVertical) { >+ Group section = new Group(parent, SWT.SHADOW_ETCHED_IN); >+ section.setText(groupText); >+ GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(false) >+ .margins(5, 5).spacing(15, 5).applyTo(section); >+ GridDataFactory.fillDefaults().grab(true, grabVertical) >+ .applyTo(section); >+ return section; >+ } >+ >+ private static Text createTextField(Composite parent, String labelText) { >+ Label label = new Label(parent, SWT.LEFT); >+ label.setText(labelText); >+ GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo( >+ label); >+ >+ final Text text = new Text(parent, SWT.BORDER); >+ GridDataFactory.fillDefaults().grab(true, false).hint(150, SWT.DEFAULT) >+ .applyTo(text); >+ >+ // Select the text when gaining focus. >+ text.addFocusListener(new FocusAdapter() { >+ public void focusGained(FocusEvent e) { >+ text.selectAll(); >+ } >+ }); >+ >+ return text; >+ } >+ >+ private static final class RangesValidator implements IValidator { >+ >+ private final String validationMessage; >+ >+ private final IValidator validator; >+ >+ public RangesValidator(int min1, int max1, int min2, int max2) { >+ this.validationMessage = MessageFormat.format( >+ "The value must lie within [{0}, {1}] or [{2}, {3}].", >+ new Object[] { min1, max1, min2, max2 }); >+ this.validator = new IntegerConstraints().range(min1, max1).range( >+ min2, max2).aggregationPolicy( >+ Constraints.AGGREGATION_MIN_SEVERITY).createValidator(); >+ } >+ >+ public IStatus validate(Object value) { >+ if (!validator.validate(value).isOK()) { >+ return ValidationStatus.error(validationMessage); >+ } >+ return ValidationStatus.ok(); >+ } >+ } >+} >Index: src/org/eclipse/jface/examples/databinding/snippets/Snippet036EditingTable.java >=================================================================== >RCS file: src/org/eclipse/jface/examples/databinding/snippets/Snippet036EditingTable.java >diff -N src/org/eclipse/jface/examples/databinding/snippets/Snippet036EditingTable.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/examples/databinding/snippets/Snippet036EditingTable.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,280 @@ >+/******************************************************************************* >+ * Copyright (c) 2006, 2009 Ovidio Mallo and others. >+ * All rights reserved. This program and the accompanying materials >+ * are 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: >+ * Ovidio Mallo - initial API and implementation (bug 183055) >+ ******************************************************************************/ >+ >+package org.eclipse.jface.examples.databinding.snippets; >+ >+import java.util.Date; >+ >+import org.eclipse.core.databinding.Binding; >+import org.eclipse.core.databinding.DataBindingContext; >+import org.eclipse.core.databinding.beans.BeansObservables; >+import org.eclipse.core.databinding.editing.DateEditing; >+import org.eclipse.core.databinding.editing.Editing; >+import org.eclipse.core.databinding.editing.IntegerEditing; >+import org.eclipse.core.databinding.editing.StringEditing; >+import org.eclipse.core.databinding.observable.Realm; >+import org.eclipse.core.databinding.observable.list.WritableList; >+import org.eclipse.core.databinding.observable.map.IObservableMap; >+import org.eclipse.core.databinding.observable.set.IObservableSet; >+import org.eclipse.core.databinding.observable.value.IObservableValue; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.jface.databinding.swt.ISWTObservableValue; >+import org.eclipse.jface.databinding.swt.SWTObservables; >+import org.eclipse.jface.databinding.viewers.ObservableListContentProvider; >+import org.eclipse.jface.databinding.viewers.ViewersObservables; >+import org.eclipse.jface.examples.databinding.ModelObject; >+import org.eclipse.jface.examples.databinding.util.EditingFactory; >+import org.eclipse.jface.examples.databinding.util.ObservableMapEditingCellLabelProvider; >+import org.eclipse.jface.examples.databinding.util.ObservableMapEditingSupport; >+import org.eclipse.jface.internal.databinding.provisional.fieldassist.ControlDecorationSupport; >+import org.eclipse.jface.layout.GridDataFactory; >+import org.eclipse.jface.layout.GridLayoutFactory; >+import org.eclipse.jface.viewers.StructuredSelection; >+import org.eclipse.jface.viewers.TableViewer; >+import org.eclipse.jface.viewers.TableViewerColumn; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.FocusAdapter; >+import org.eclipse.swt.events.FocusEvent; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Group; >+import org.eclipse.swt.widgets.Label; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.swt.widgets.Text; >+ >+public class Snippet036EditingTable { >+ >+ private final StringEditing nameEditing; >+ >+ private final IntegerEditing ageEditing; >+ >+ private final DateEditing bdayEditing; >+ >+ public Snippet036EditingTable() { >+ nameEditing = EditingFactory.forString(); >+ nameEditing.modelStringConstraints().required(); >+ >+ ageEditing = EditingFactory.forInteger(); >+ ageEditing.modelIntegerConstraints().required().nonNegative(); >+ >+ bdayEditing = EditingFactory.forDate(); >+ bdayEditing.modelDateConstraints().before(new Date()); >+ } >+ >+ private DataBindingContext dbc; >+ >+ private TableViewer tableViewer; >+ >+ public static void main(String[] args) { >+ Display display = new Display(); >+ >+ Realm.runWithDefault(SWTObservables.getRealm(display), new Runnable() { >+ public void run() { >+ Shell shell = new Snippet036EditingTable().createShell(); >+ Display display = Display.getCurrent(); >+ while (!shell.isDisposed()) { >+ if (!display.readAndDispatch()) { >+ display.sleep(); >+ } >+ } >+ } >+ }); >+ } >+ >+ private Shell createShell() { >+ Display display = Display.getCurrent(); >+ Shell shell = new Shell(display); >+ shell.setText("Editing"); >+ shell.setLayout(new GridLayout(2, false)); >+ >+ dbc = new DataBindingContext(); >+ >+ createTableSection(shell); >+ createFieldSection(shell); >+ >+ shell.pack(); >+ shell.open(); >+ >+ return shell; >+ } >+ >+ private void createTableSection(Composite parent) { >+ Group section = createSectionGroup(parent, 1); >+ >+ tableViewer = new TableViewer(section, SWT.SINGLE | SWT.H_SCROLL >+ | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION); >+ GridDataFactory.fillDefaults().grab(true, true).hint(350, 250).applyTo( >+ tableViewer.getTable()); >+ tableViewer.getTable().setHeaderVisible(true); >+ tableViewer.getTable().setLinesVisible(true); >+ >+ ObservableListContentProvider contentProvider = new ObservableListContentProvider(); >+ tableViewer.setContentProvider(contentProvider); >+ IObservableSet contentElements = contentProvider.getKnownElements(); >+ >+ IObservableMap nameMap = BeansObservables.observeMap(contentElements, >+ "name"); >+ createColumn("Name*", 150, nameMap, nameEditing); >+ >+ IObservableMap ageMap = BeansObservables.observeMap(contentElements, >+ "age"); >+ createColumn("Age*", 50, ageMap, ageEditing); >+ >+ IObservableMap bdayMap = BeansObservables.observeMap(contentElements, >+ "birthday"); >+ createColumn("Birthday", 80, bdayMap, bdayEditing); >+ >+ WritableList people = new WritableList(); >+ people.add(new Person("John Doe", 27)); >+ people.add(new Person("Steve Northover", 33)); >+ people.add(new Person("Grant Gayed", 54)); >+ people.add(new Person("Veronika Irvine", 25)); >+ people.add(new Person("Mike Wilson", 44)); >+ people.add(new Person("Christophe Cornu", 37)); >+ people.add(new Person("Lynne Kues", 65)); >+ people.add(new Person("Silenio Quarti", 15)); >+ >+ tableViewer.setInput(people); >+ >+ tableViewer.setSelection(new StructuredSelection(people.get(0))); >+ } >+ >+ private TableViewerColumn createColumn(String text, int width, >+ IObservableMap attributeMap, Editing modelEditing) { >+ TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE); >+ column.getColumn().setText(text); >+ column.getColumn().setWidth(width); >+ column.setLabelProvider(new ObservableMapEditingCellLabelProvider( >+ attributeMap, modelEditing)); >+ column.setEditingSupport(new ObservableMapEditingSupport(tableViewer, >+ attributeMap, modelEditing)); >+ return column; >+ } >+ >+ private void createFieldSection(Composite parent) { >+ final Group section = createSectionGroup(parent, 2); >+ >+ final IObservableValue personObservable = ViewersObservables >+ .observeSingleSelection(tableViewer); >+ >+ Text nameText = createTextField(section, "Name*"); >+ IObservableValue nameObservable = BeansObservables.observeDetailValue( >+ personObservable, "name", null); >+ bindTextField(nameText, nameObservable, nameEditing); >+ >+ Text ageText = createTextField(section, "Age*"); >+ IObservableValue ageObservable = BeansObservables.observeDetailValue( >+ personObservable, "age", null); >+ bindTextField(ageText, ageObservable, ageEditing); >+ >+ Text bdayText = createTextField(section, "Birthday"); >+ IObservableValue bdayObservable = BeansObservables.observeDetailValue( >+ personObservable, "birthday", null); >+ bindTextField(bdayText, bdayObservable, bdayEditing); >+ } >+ >+ private Binding bindTextField(Text text, IObservableValue modelValue, >+ Editing editing) { >+ // Create the binding using the editing object. >+ ISWTObservableValue textObservable = SWTObservables.observeText(text, >+ SWT.Modify); >+ Binding binding = editing.bindValue(dbc, textObservable, modelValue); >+ >+ // Decorate the control with the validation status. >+ ControlDecorationSupport.create(binding, SWT.TOP); >+ >+ formatOnFocusOut(text, binding); >+ >+ return binding; >+ } >+ >+ private static void formatOnFocusOut(final Control control, >+ final Binding binding) { >+ control.addFocusListener(new FocusAdapter() { >+ public void focusLost(FocusEvent e) { >+ IStatus dateValidationStatus = (IStatus) binding >+ .getValidationStatus().getValue(); >+ if (dateValidationStatus.isOK()) { >+ binding.updateModelToTarget(); >+ } >+ } >+ }); >+ } >+ >+ private Group createSectionGroup(Composite parent, int numColumns) { >+ Group section = new Group(parent, SWT.SHADOW_ETCHED_IN); >+ GridLayoutFactory.fillDefaults().numColumns(numColumns).equalWidth( >+ false).margins(5, 5).spacing(15, 5).applyTo(section); >+ GridDataFactory.fillDefaults().grab(true, true).applyTo(section); >+ return section; >+ } >+ >+ private static Text createTextField(Composite parent, String labelText) { >+ Label label = new Label(parent, SWT.LEFT); >+ label.setText(labelText); >+ GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo( >+ label); >+ >+ final Text text = new Text(parent, SWT.BORDER); >+ GridDataFactory.fillDefaults().grab(true, false).hint(200, SWT.DEFAULT) >+ .applyTo(text); >+ >+ // Select the text when gaining focus. >+ text.addFocusListener(new FocusAdapter() { >+ public void focusGained(FocusEvent e) { >+ text.selectAll(); >+ } >+ }); >+ >+ return text; >+ } >+ >+ public static final class Person extends ModelObject { >+ >+ private String name; >+ >+ private int age; >+ >+ private Date birthday; >+ >+ public Person(String name, int age) { >+ this.name = name; >+ this.age = age; >+ } >+ >+ public String getName() { >+ return name; >+ } >+ >+ public void setName(String name) { >+ firePropertyChange("name", this.name, this.name = name); >+ } >+ >+ public int getAge() { >+ return age; >+ } >+ >+ public void setAge(int age) { >+ firePropertyChange("age", this.age, this.age = age); >+ } >+ >+ public Date getBirthday() { >+ return birthday; >+ } >+ >+ public void setBirthday(Date birthday) { >+ firePropertyChange("birthday", this.birthday, >+ this.birthday = birthday); >+ } >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 183055
:
139097
|
142074
|
145997
|
146005
|
146551
|
147262
|
149314
|
149326
|
151361
|
152082
|
153890
|
156294
|
156446
|
157017
|
157180
| 157378 |
157469
|
160440
|
160542
|
179211
|
179212