blob: 1a8e4b9ab57e39e7a0babeeb2143851a58454da1 (
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
/*******************************************************************************
* 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 (bug 247997)
******************************************************************************/
package org.eclipse.core.databinding.property.list;
import java.util.Collections;
import java.util.List;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.list.ListDiff;
import org.eclipse.core.databinding.property.INativePropertyListener;
import org.eclipse.core.databinding.property.ISimplePropertyListener;
/**
* @since 1.2
*
*/
public abstract class DelegatingListProperty extends ListProperty {
private final IListProperty nullProperty;
private final Object elementType;
protected DelegatingListProperty() {
this(null);
}
protected DelegatingListProperty(Object elementType) {
this.elementType = elementType;
this.nullProperty = new NullListProperty();
}
/**
* Returns the property to delegate to for the specified source object.
* Repeated calls to this method with the same source object returns the
* same delegate instance.
*
* @param source
* the property source (may be null)
* @return the property to delegate to for the specified source object.
*/
public final IListProperty getDelegate(Object source) {
if (source == null)
return null;
IListProperty delegate = doGetDelegate(source);
if (delegate == null)
delegate = nullProperty;
return delegate;
}
/**
* Returns the property to delegate to for the specified source object.
* Implementers must ensure that repeated calls to this method with the same
* source object returns the same delegate instance.
*
* @param source
* the property source
* @return the property to delegate to for the specified source object.
*/
protected abstract IListProperty doGetDelegate(Object source);
public Object getElementType() {
return elementType;
}
public IObservableList observe(Object source) {
return getDelegate(source).observe(source);
}
public IObservableList observe(Realm realm, Object source) {
return getDelegate(source).observe(realm, source);
}
private class NullListProperty extends SimpleListProperty {
public Object getElementType() {
return elementType;
}
protected List doGetList(Object source) {
return Collections.EMPTY_LIST;
}
protected void doSetList(Object source, List list, ListDiff diff) {
}
public INativePropertyListener adaptListener(
ISimplePropertyListener listener) {
return null;
}
protected void doAddListener(Object source,
INativePropertyListener listener) {
}
protected void doRemoveListener(Object source,
INativePropertyListener listener) {
}
}
}
|