1 /*******************************************************************************
2  * Copyright (c) 2007, 2015 Brad Reynolds 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  *     Brad Reynolds - initial API and implementation
13  *     Matthew Hall - bugs 208858, 246625
14  ******************************************************************************/
15 
16 package org.eclipse.core.internal.databinding.beans;
17 
18 import java.beans.PropertyDescriptor;
19 
20 import org.eclipse.core.databinding.beans.IBeanObservable;
21 import org.eclipse.core.databinding.observable.IObservable;
22 import org.eclipse.core.databinding.observable.IObserving;
23 import org.eclipse.core.databinding.observable.list.DecoratingObservableList;
24 import org.eclipse.core.databinding.observable.list.IObservableList;
25 
26 /**
27  * {@link IBeanObservable} decorator for an {@link IObservableList}.
28  *
29  * @param <E> the type of elements in this collection
30  *
31  * @since 3.3
32  */
33 public class BeanObservableListDecorator<E> extends DecoratingObservableList<E> implements IBeanObservable {
34 	private PropertyDescriptor propertyDescriptor;
35 
36 	/**
37 	 * @param decorated
38 	 * @param propertyDescriptor
39 	 */
BeanObservableListDecorator(IObservableList<E> decorated, PropertyDescriptor propertyDescriptor)40 	public BeanObservableListDecorator(IObservableList<E> decorated, PropertyDescriptor propertyDescriptor) {
41 		super(decorated, true);
42 		this.propertyDescriptor = propertyDescriptor;
43 	}
44 
45 	@Override
dispose()46 	public synchronized void dispose() {
47 		this.propertyDescriptor = null;
48 		super.dispose();
49 	}
50 
51 	@Override
getObserved()52 	public Object getObserved() {
53 		IObservable decorated = getDecorated();
54 		if (decorated instanceof IObserving)
55 			return ((IObserving) decorated).getObserved();
56 		return null;
57 	}
58 
59 	@Override
getPropertyDescriptor()60 	public PropertyDescriptor getPropertyDescriptor() {
61 		return propertyDescriptor;
62 	}
63 }
64