Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ec514a6509c2a242853affd0c768e108d3b334e4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*******************************************************************************
 * Copyright (c) 2008 Matthew Hall 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:
 *     Matthew Hall - initial API and implementation
 *     Matthew Hall - bugs 263413, 264286
 ******************************************************************************/

package org.eclipse.jface.databinding.viewers;

import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.property.list.SimpleListProperty;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.jface.internal.databinding.viewers.ViewerObservableListDecorator;
import org.eclipse.jface.viewers.Viewer;

/**
 * Abstract list property implementation for {@link Viewer} properties. This
 * class implements some basic behavior that viewer properties are generally
 * expected to have, namely:
 * <ul>
 * <li>Calling {@link #observe(Object)} should create the observable on the
 * display realm of the viewer's control, rather than the current default realm
 * <li>All <code>observe()</code> methods should return an
 * {@link IViewerObservableList}
 * </ul>
 * 
 * @since 1.3
 */
public abstract class ViewerListProperty extends SimpleListProperty implements
		IViewerListProperty {
	public IObservableList observe(Object source) {
		if (source instanceof Viewer) {
			return observe((Viewer) source);
		}
		return super.observe(source);
	}

	public IObservableList observe(Realm realm, Object source) {
		IObservableList observable = super.observe(realm, source);
		if (source instanceof Viewer)
			observable = new ViewerObservableListDecorator(observable,
					(Viewer) source);
		return observable;
	}

	public IViewerObservableList observe(Viewer viewer) {
		return (IViewerObservableList) observe(SWTObservables.getRealm(viewer
				.getControl().getDisplay()), viewer);
	}
}

Back to the top