Project: UFace
Revision: 2264
Author: kenneth.westelinck
Date: 17 Aug 2008 06:00:00
Changes:Javadoc
Files:modified: /trunk/org.ufacekit.ui/src/org/ufacekit/ui/decoration/UIStatusDecorator.java (
try)
modified: /trunk/org.ufacekit.core.databinding.common/src/org/ufacekit/core/databinding/common/validation/ValidatorSource.java (
try)
modified: /trunk/org.ufacekit.ui/src/org/ufacekit/ui/UIFormInterceptor.java (
try)
modified: /trunk/org.ufacekit.ui/src/org/ufacekit/ui/UIForm.java (
try)
modified: /trunk/org.ufacekit.ui/src/org/ufacekit/ui/interceptors/StatusDecoratingInterceptor.java (
try)
modified: /trunk/org.ufacekit.ui/src/org/ufacekit/ui/interceptors/CompositeUIFormInterceptor.java (
try)
modified: /trunk/org.ufacekit.ui/src/org/ufacekit/ui/controls/UIFormControl.java (
try)
Diff:
| ... | ...@@ -18,6 +18,15 @@ |
| 18 | 18 | import org.ufacekit.ui.controls.internal.InternalUIDecorator; |
| 19 | 19 | import org.ufacekit.ui.databinding.internal.StatusObservableValue; |
| 20 | 20 | |
| 21 | /** |
| 22 | * Used to facilitate the binding between a control's validation status and the |
| 23 | * {@link UIDecorator}. If the input of the control is invalid, |
| 24 | * {@link UIDecorator#show()} and {@link UIDecorator#show(Object)} will be |
| 25 | * called. If the input becomes valid, {@link UIDecorator#hide()} will be |
| 26 | * called. |
| 27 | * |
| 28 | * @since 1.0 |
| 29 | */ |
| 21 | 30 | public abstract class UIStatusDecorator implements InternalUIDecorator { |
| 22 | 31 | private Binding binding; |
| 23 | 32 | |
| ... | ...@@ -35,6 +44,14 @@ |
| 35 | 44 | } |
| 36 | 45 | } |
| 37 | 46 | |
| 47 | /** |
| 48 | * Create the {@link IObservableValue} that can be used to bind with the |
| 49 | * validation status of a control. |
| 50 | * |
| 51 | * @param decorator |
| 52 | * @return the {@link IObservableValue} |
| 53 | * @since 1.0 |
| 54 | */ |
| 38 | 55 | protected IObservableValue createTarget(final UIDecorator decorator) { |
| 39 | 56 | return new StatusObservableValue() { |
| 40 | 57 | protected void handleStatus(IStatus status) { |
| ... | ...@@ -26,6 +26,9 @@ |
| 26 | 26 | * on the destination at the end of the synchronization process.</li> |
| 27 | 27 | * </ul> |
| 28 | 28 | * |
| 29 | * This class serves as a registry for references to these 3 kinds of |
| 30 | * validators. |
| 31 | * |
| 29 | 32 | * @version 1.0 |
| 30 | 33 | * @since 1.0 |
| 31 | 34 | */ |
| ... | ...@@ -13,6 +13,28 @@ |
| 13 | 13 | import org.eclipse.core.databinding.DataBindingContext; |
| 14 | 14 | import org.ufacekit.ui.controls.internal.InternalUIFormControl; |
| 15 | 15 | |
| 16 | /** |
| 17 | * This interceptor is used by the {@link UIForm} to be able to manipulate the |
| 18 | * creation of controls. A typical example of this is adding additional |
| 19 | * decorations on the control that can be used to indicate if the control |
| 20 | * contains mandatory info or not. |
| 21 | * |
| 22 | * @see UIForm#setAfterBindInterceptor(UIFormInterceptor) |
| 23 | * @see UIForm#setBeforeBindInterceptor(UIFormInterceptor) |
| 24 | * |
| 25 | * @since 1.0 |
| 26 | */ |
| 16 | 27 | public interface UIFormInterceptor { |
| 28 | /** |
| 29 | * Called by the {@link UIForm} right before and right after the control is |
| 30 | * bound to the model. |
| 31 | * |
| 32 | * @param databindingContext |
| 33 | * The context that was used to bind the |
| 34 | * {@link InternalUIFormControl} to the model. |
| 35 | * @param control |
| 36 | * The UI component bound to the model that is being intercepted. |
| 37 | * @since 1.0 |
| 38 | */ |
| 17 | 39 | void processControl(DataBindingContext databindingContext, InternalUIFormControl control); |
| 18 | 40 | } |
| ... | ...@@ -129,7 +129,8 @@ |
| 129 | 129 | |
| 130 | 130 | /** |
| 131 | 131 | * @param beforeBindInterceptor |
| 132 | | * the beforeBindInterceptor to set |
| 132 | * This interceptor will be called _befor_ the model is being |
| 133 | * bound to the control. |
| 133 | 134 | */ |
| 134 | 135 | public void setBeforeBindInterceptor(UIFormInterceptor beforeBindInterceptor) { |
| 135 | 136 | this.beforeBindInterceptor = beforeBindInterceptor; |
| ... | ...@@ -137,7 +138,8 @@ |
| 137 | 138 | |
| 138 | 139 | /** |
| 139 | 140 | * @param afterBindInterceptor |
| 140 | | * the afterBindInterceptor to set |
| 141 | * This interceptor will be called _after_ the model has been |
| 142 | * bound to the control. |
| 141 | 143 | */ |
| 142 | 144 | public void setAfterBindInterceptor(UIFormInterceptor afterBindInterceptor) { |
| 143 | 145 | this.afterBindInterceptor = afterBindInterceptor; |
| ... | ...@@ -145,12 +147,13 @@ |
| 145 | 147 | |
| 146 | 148 | /** |
| 147 | 149 | * @param updateStrategyFactory |
| 148 | | * the factory that will create update strategies for our bindings |
| 150 | * the factory that will create update strategies for our |
| 151 | * bindings |
| 149 | 152 | */ |
| 150 | 153 | public void setUpdateStrategyFactory(UIUpdateStrategyFactory updateStrategyFactory) { |
| 151 | 154 | this.updateStrategyFactory = updateStrategyFactory; |
| 152 | 155 | } |
| 153 | | |
| 156 | |
| 154 | 157 | /** |
| 155 | 158 | * @return the factory that will create update strategies for our bindings |
| 156 | 159 | */ |
| ... | ...@@ -13,23 +13,39 @@ |
| 13 | 13 | import org.eclipse.core.databinding.DataBindingContext; |
| 14 | 14 | import org.eclipse.core.databinding.observable.value.IObservableValue; |
| 15 | 15 | import org.ufacekit.ui.UIDecorator; |
| 16 | import org.ufacekit.ui.UIFactory; |
| 16 | 17 | import org.ufacekit.ui.UIFormInterceptor; |
| 17 | 18 | import org.ufacekit.ui.controls.UIComposite; |
| 18 | 19 | import org.ufacekit.ui.controls.internal.InternalUIDecorator; |
| 19 | 20 | import org.ufacekit.ui.controls.internal.InternalUIFormControl; |
| 20 | 21 | |
| 22 | /** |
| 23 | * This interceptor will put a decoration on a control that will indicate if the |
| 24 | * input was valid or not. |
| 25 | * |
| 26 | * @since 1.0 |
| 27 | */ |
| 21 | 28 | public class StatusDecoratingInterceptor implements UIFormInterceptor { |
| 22 | 29 | private UIComposite parent; |
| 23 | 30 | |
| 31 | /** |
| 32 | * Create the interceptor. |
| 33 | * |
| 34 | * @param parent |
| 35 | * The parent cannot be null and is used to get a hold on its |
| 36 | * {@link UIFactory} (see {@link UIComposite#getFactory()}). |
| 37 | * @since 1.0 |
| 38 | */ |
| 24 | 39 | public StatusDecoratingInterceptor(UIComposite parent) { |
| 25 | 40 | this.parent = parent; |
| 26 | 41 | } |
| 27 | 42 | |
| 28 | 43 | public void processControl(DataBindingContext databindingContext, InternalUIFormControl control) { |
| 29 | | //Assert.isLegal(control instanceof UIInputField); |
| 44 | // Assert.isLegal(control instanceof UIInputField); |
| 30 | 45 | IObservableValue value = control.getValidationStatus(); |
| 31 | | if( value != null ) { |
| 32 | | InternalUIDecorator decorator = (InternalUIDecorator) parent.getFactory().newStatusDecorator(control, new UIDecorator.DecoratorInfo(UIDecorator.DecoratorInfo.TOP_LEFT)); |
| 46 | if (value != null) { |
| 47 | InternalUIDecorator decorator = (InternalUIDecorator) parent.getFactory().newStatusDecorator(control, |
| 48 | new UIDecorator.DecoratorInfo(UIDecorator.DecoratorInfo.TOP_LEFT)); |
| 33 | 49 | decorator.internalBind(databindingContext, value); |
| 34 | 50 | } |
| 35 | 51 | } |
| ... | ...@@ -19,6 +19,11 @@ |
| 19 | 19 | import org.ufacekit.ui.UIFormInterceptor; |
| 20 | 20 | import org.ufacekit.ui.controls.internal.InternalUIFormControl; |
| 21 | 21 | |
| 22 | /** |
| 23 | * Composite version of an {@link UIFormInterceptor}. |
| 24 | * |
| 25 | * @since 1.0 |
| 26 | */ |
| 22 | 27 | public class CompositeUIFormInterceptor implements UIFormInterceptor { |
| 23 | 28 | private List interceptors = new ArrayList(); |
| 24 | 29 | |
| ... | ...@@ -29,16 +34,33 @@ |
| 29 | 34 | } |
| 30 | 35 | } |
| 31 | 36 | |
| 37 | /** |
| 38 | * Add a child interceptor to this composite. |
| 39 | * |
| 40 | * @param interceptor |
| 41 | * @since 1.0 |
| 42 | */ |
| 32 | 43 | public void registerInterceptor(UIFormInterceptor interceptor) { |
| 33 | 44 | Assert.isNotNull(interceptor); |
| 34 | 45 | interceptors.add(interceptor); |
| 35 | 46 | } |
| 36 | 47 | |
| 48 | /** |
| 49 | * Remove the specified child interceptor from this composite. |
| 50 | * |
| 51 | * @param interceptor |
| 52 | * @since 1.0 |
| 53 | */ |
| 37 | 54 | public void unregisterInterceptor(UIFormInterceptor interceptor) { |
| 38 | 55 | Assert.isNotNull(interceptor); |
| 39 | 56 | interceptors.remove(interceptor); |
| 40 | 57 | } |
| 41 | 58 | |
| 59 | /** |
| 60 | * Clear all child interceptors from this composite. |
| 61 | * |
| 62 | * @since 1.0 |
| 63 | */ |
| 42 | 64 | public void clear() { |
| 43 | 65 | interceptors.clear(); |
| 44 | 66 | } |
| ... | ...@@ -79,11 +79,26 @@ |
| 79 | 79 | return false; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | /** |
| 83 | * Set a {@link ValidatorSource} that holds references to the validators |
| 84 | * being used to validate the user's input. |
| 85 | * |
| 86 | * @param validatorSource |
| 87 | * @return this |
| 88 | * @since 1.0 |
| 89 | */ |
| 82 | 90 | public BindingInfo registerValidatorSource(ValidatorSource validatorSource) { |
| 83 | 91 | this.validatorSource = validatorSource; |
| 84 | 92 | return this; |
| 85 | 93 | } |
| 86 | 94 | |
| 95 | /** |
| 96 | * Get the {@link ValidatorSource} that holds references to the |
| 97 | * validators being used to validate the user's input. |
| 98 | * |
| 99 | * @return the validator source |
| 100 | * @since 1.0 |
| 101 | */ |
| 87 | 102 | public ValidatorSource getValidatorSource() { |
| 88 | 103 | return validatorSource; |
| 89 | 104 | } |
To list