| /******************************************************************************* |
| * Copyright (c) 2008, 2009 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 194734) |
| * Matthew Hall - bugs 195222, 264307, 265561 |
| ******************************************************************************/ |
| |
| package org.eclipse.core.internal.databinding.beans; |
| |
| import java.beans.PropertyDescriptor; |
| |
| import org.eclipse.core.databinding.property.INativePropertyListener; |
| import org.eclipse.core.databinding.property.ISimplePropertyListener; |
| import org.eclipse.core.databinding.property.value.SimpleValueProperty; |
| |
| /** |
| * @since 3.3 |
| * |
| */ |
| public class PojoValueProperty extends SimpleValueProperty { |
| private final PropertyDescriptor propertyDescriptor; |
| private final Class valueType; |
| |
| /** |
| * @param propertyDescriptor |
| * @param valueType |
| */ |
| public PojoValueProperty(PropertyDescriptor propertyDescriptor, |
| Class valueType) { |
| this.propertyDescriptor = propertyDescriptor; |
| this.valueType = valueType == null ? propertyDescriptor |
| .getPropertyType() : valueType; |
| } |
| |
| public Object getValueType() { |
| return valueType; |
| } |
| |
| protected Object doGetValue(Object source) { |
| if (source == null) |
| return null; |
| return BeanPropertyHelper.readProperty(source, propertyDescriptor); |
| } |
| |
| protected void doSetValue(Object source, Object value) { |
| BeanPropertyHelper.writeProperty(source, propertyDescriptor, value); |
| } |
| |
| public INativePropertyListener adaptListener( |
| ISimplePropertyListener listener) { |
| return null; |
| } |
| |
| public String toString() { |
| String s = BeanPropertyHelper.propertyName(propertyDescriptor); |
| if (valueType != null) |
| s += "<" + BeanPropertyHelper.shortClassName(valueType) + ">"; //$NON-NLS-1$//$NON-NLS-2$ |
| return s; |
| } |
| } |