Mercurial > projects > dwt2
comparison org.eclipse.jface.databinding/src/org/eclipse/jface/internal/databinding/viewers/ViewerInputObservableValue.d @ 78:0a55d2d5a946
Added file for databinding
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 14 Apr 2009 11:35:29 +0200 |
parents | |
children | 6be48cf9f95c |
comparison
equal
deleted
inserted
replaced
76:f05e6e8b2f2d | 78:0a55d2d5a946 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2007 Matthew Hall 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 * Matthew Hall - initial API and implementation (bug 206839) | |
10 *******************************************************************************/ | |
11 | |
12 module org.eclipse.jface.internal.databinding.viewers.ViewerInputObservableValue; | |
13 | |
14 import java.lang.all; | |
15 | |
16 import org.eclipse.core.databinding.observable.Diffs; | |
17 import org.eclipse.core.databinding.observable.Realm; | |
18 import org.eclipse.core.databinding.observable.value.AbstractObservableValue; | |
19 import org.eclipse.jface.util.Util; | |
20 import org.eclipse.jface.viewers.Viewer; | |
21 | |
22 /** | |
23 * Observes the input of a <code>Viewer</code>. | |
24 * <p> | |
25 * This observer is blind to changes in the viewer's input unless its | |
26 * {@link #setValue(Object)} method is called directly. | |
27 * | |
28 * @since 1.2 | |
29 */ | |
30 public class ViewerInputObservableValue : AbstractObservableValue { | |
31 | |
32 private final Viewer viewer; | |
33 | |
34 /** | |
35 * Constructs a new instance associated with the provided <code>viewer</code>. | |
36 * | |
37 * @param realm | |
38 * @param viewer | |
39 */ | |
40 public this( Realm realm, Viewer viewer ) { | |
41 super( realm ); | |
42 if ( viewer is null ) { | |
43 throw new IllegalArgumentException( "The 'viewer' parameter is null." ); //$NON-NLS-1$ | |
44 } | |
45 | |
46 this.viewer = viewer; | |
47 } | |
48 | |
49 /** | |
50 * Sets the input to the provided <code>value</code>. Value change events are | |
51 * fired after input is set in the viewer. | |
52 * | |
53 * @param value object to set as input | |
54 */ | |
55 protected void doSetValue( Object value ) { | |
56 Object oldValue = doGetValue(); | |
57 viewer.setInput( value ); | |
58 if ( !Util.equals( oldValue, value ) ) { | |
59 fireValueChange( Diffs.createValueDiff( oldValue, value ) ); | |
60 } | |
61 } | |
62 | |
63 /** | |
64 * Retrieves the current input. | |
65 * | |
66 * @return the current input | |
67 */ | |
68 protected Object doGetValue() { | |
69 return viewer.getInput(); | |
70 } | |
71 | |
72 public Object getValueType() { | |
73 return null; | |
74 } | |
75 } |