1 /*******************************************************************************
2  * Copyright (c) 2009, 2015 Matthew Hall and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     Matthew Hall - initial API and implementation (bug 264286)
13  *******************************************************************************/
14 
15 package org.eclipse.jface.databinding.swt;
16 
17 import org.eclipse.core.databinding.observable.value.IObservableValue;
18 import org.eclipse.core.databinding.observable.value.IVetoableValue;
19 import org.eclipse.core.databinding.observable.value.ValueChangingEvent;
20 import org.eclipse.core.databinding.property.value.IValueProperty;
21 import org.eclipse.swt.widgets.Widget;
22 
23 /**
24  * {@link IValueProperty} for observing an SWT Widget
25  *
26  * @param <S> type of the source widget
27  * @param <T> type of the value of the property
28  *
29  * @since 1.3
30  * @noimplement This interface is not intended to be implemented by clients.
31  */
32 public interface IWidgetValueProperty<S extends Widget, T> extends IValueProperty<S, T> {
33 	/**
34 	 * Returns an {@link ISWTObservableValue} observing this value property on
35 	 * the given widget
36 	 *
37 	 * @param widget
38 	 *            the source widget
39 	 * @return an observable value observing this value property on the given
40 	 *         widget
41 	 */
42 	@Override
observe(S widget)43 	public ISWTObservableValue<T> observe(S widget);
44 
45 	/**
46 	 * Returns an {@link ISWTObservableValue} observing this value property on the
47 	 * given widget, which delays notification of value changes until at least
48 	 * <code>delay</code> milliseconds have elapsed since that last change event, or
49 	 * until a FocusOut event is received from the widget (whichever happens first).
50 	 * <p>
51 	 * This observable helps to boost performance in situations where an observable
52 	 * has computationally expensive listeners (e.g. changing filters in a viewer)
53 	 * or many dependencies (master fields with multiple detail fields). A common
54 	 * use of this observable is to delay validation of user input until the user
55 	 * stops typing in a UI field.
56 	 * <p>
57 	 * To notify about pending changes, the returned observable fires a stale event
58 	 * when the wrapped observable value fires a change event, and remains stale
59 	 * until the delay has elapsed and the value change is fired. A call to
60 	 * {@link IObservableValue#getValue} while a value change is pending will fire
61 	 * the value change immediately, short-circuiting the delay.
62 	 * <p>
63 	 * Only updates resulting from the observed widget are delayed. Calls directly
64 	 * to {@link IObservableValue#setValue} are not, and they cancel pending delayed
65 	 * values.
66 	 * <p>
67 	 * Note that this observable will not forward {@link ValueChangingEvent} events
68 	 * from a wrapped {@link IVetoableValue}.
69 	 * <p>
70 	 * This method is equivalent to
71 	 * <code>SWTObservables.observeDelayedValue(delay, observe(widget))</code>.
72 	 *
73 	 * @param delay  the delay in milliseconds.
74 	 * @param widget the source widget
75 	 * @return an observable value observing this value property on the given
76 	 *         widget, and which delays change notifications for <code>delay</code>
77 	 *         milliseconds.
78 	 */
observeDelayed(int delay, S widget)79 	public ISWTObservableValue<T> observeDelayed(int delay, S widget);
80 }
81