KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > internal > databinding > provisional > Binding


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  ******************************************************************************/

11
12 package org.eclipse.jface.internal.databinding.provisional;
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.List JavaDoc;
16
17 import org.eclipse.jface.internal.databinding.provisional.observable.value.IObservableValue;
18 import org.eclipse.jface.internal.databinding.provisional.validation.ValidationError;
19
20 /**
21  * The interface that represents a binding between a model and a target.
22  *
23  * This interface is not intended to be implemented by clients.
24  *
25  * @since 1.0
26  */

27 public abstract class Binding {
28
29     private List JavaDoc bindingEventListeners = new ArrayList JavaDoc();
30
31     protected final DataBindingContext context;
32
33     /**
34      * @param context
35      */

36     public Binding(DataBindingContext context) {
37         this.context = context;
38     }
39
40     /**
41      * Add a listener to the set of listeners that will be notified when an
42      * event occurs in the data flow pipeline that is managed by this Binding.
43      *
44      * @param listener
45      * The listener to add.
46      */

47     public void addBindingEventListener(IBindingListener listener) {
48         bindingEventListeners.add(listener);
49     }
50
51     /**
52      * Fires the given event to the binding event listeners, exiting early when
53      * one of the listeners flags a validation error. If no listener flags a
54      * validation error, the data binding context's binding listeners will be
55      * notified in the same manner.
56      *
57      * @param event
58      * @return the validation error, or null
59      */

60     protected ValidationError fireBindingEvent(BindingEvent event) {
61         ValidationError result = null;
62         IBindingListener[] listeners = (IBindingListener[]) bindingEventListeners
63                 .toArray(new IBindingListener[bindingEventListeners.size()]);
64         for (int i = 0; i < listeners.length; i++) {
65             IBindingListener listener = listeners[i];
66             result = listener.bindingEvent(event);
67             if (result != null)
68                 break;
69         }
70         if (result == null)
71             result = context.fireBindingEvent(event);
72         return result;
73     }
74
75     /**
76      * @return an observable value containing the current partial validation
77      * error or null
78      */

79     public abstract IObservableValue getPartialValidationError();
80
81     /**
82      * @return an observable value containing the current validation error or
83      * null
84      */

85     public abstract IObservableValue getValidationError();
86
87     /**
88      * Removes a listener from the set of listeners that will be notified when
89      * an event occurs in the data flow pipeline that is managed by this
90      * Binding.
91      *
92      * @param listener
93      * The listener to remove.
94      */

95     public void removeBindingEventListener(IBindingListener listener) {
96         bindingEventListeners.remove(listener);
97     }
98
99     /**
100      *
101      */

102     public abstract void updateModelFromTarget();
103
104     /**
105      *
106      */

107     public abstract void updateTargetFromModel();
108
109 }
110
Popular Tags