| /** |
| * Copyright (c) 2011, 2015 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * 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: |
| * Florian Pirchner - Initial implementation |
| */ |
| |
| package org.eclipse.osbp.runtime.web.vaadin.databinding.properties; |
| |
| import java.util.Arrays; |
| |
| import org.eclipse.core.databinding.observable.Realm; |
| import org.eclipse.core.databinding.observable.value.IObservableValue; |
| import org.eclipse.core.databinding.property.INativePropertyListener; |
| import org.eclipse.core.databinding.property.ISimplePropertyListener; |
| import org.eclipse.core.databinding.property.value.SimpleValueProperty; |
| import org.eclipse.osbp.runtime.web.vaadin.databinding.VaadinObservables; |
| import org.eclipse.osbp.runtime.web.vaadin.databinding.component.internal.ComponentListener; |
| import org.eclipse.osbp.runtime.web.vaadin.databinding.values.IVaadinObservableValue; |
| import org.eclipse.osbp.runtime.web.vaadin.databinding.values.SimpleVaadinPropertyObservableValue; |
| import org.eclipse.osbp.runtime.web.vaadin.databinding.values.VaadinObservableValueDecorator; |
| |
| import com.vaadin.ui.Component; |
| |
| // TODO: Auto-generated Javadoc |
| /** |
| * Abstract value property implementation for {@link Component} properties. This |
| * class implements some basic behavior that widget properties are generally |
| * expected to have, namely: |
| * <ul> |
| * <li>Calling {@link #observe(Object)} should create the observable on the UI |
| * realm of the widget, rather than the current default realm |
| * <li>All <code>observe()</code> methods should return an |
| * {@link IVaadinObservableValue} |
| * </ul> |
| * This class also provides a default widget listener implementation using |
| * vaadins event concept. Subclasses may pass one or more vaadin event types |
| * (sub class of {@link Component.Event}) to the super constructor to indicate |
| * which events signal a property change. |
| */ |
| public abstract class AbstractVaadinValueProperty extends SimpleValueProperty |
| implements IVaadinValueProperty { |
| |
| /** The change events. */ |
| private Class<? extends Component.Event>[] changeEvents; |
| |
| /** The stale events. */ |
| private Class<? extends Component.Event>[] staleEvents; |
| |
| /** |
| * Constructs a ComponentValueProperty which does not listen for any vaadin |
| * events. |
| */ |
| protected AbstractVaadinValueProperty() { |
| this(new Class[0], new Class[0]); |
| } |
| |
| /** |
| * Constructs a ComponentValueProperty with the specified vaadin event type. |
| * |
| * @param changeEvent |
| * vaadin event type of the event that signifies a property |
| * change. |
| */ |
| @SuppressWarnings("unchecked") |
| protected AbstractVaadinValueProperty( |
| Class<? extends Component.Event> changeEvent) { |
| this(new Class[] { changeEvent }, new Class[0]); |
| } |
| |
| /** |
| * Constructs a ComponentValueProperty with the specified vaadin event |
| * type(s). |
| * |
| * @param changeEvents |
| * array of vaadin event constants of the events that signify a |
| * property change. |
| */ |
| @SuppressWarnings("unchecked") |
| protected AbstractVaadinValueProperty( |
| Class<? extends Component.Event>[] changeEvents) { |
| this(changeEvents, new Class[0]); |
| } |
| |
| /** |
| * Constructs a ComponentValueProperty with the specified vaadin event |
| * types. |
| * |
| * @param changeEvents |
| * array of vaadin event types of the events that signify a |
| * property change. |
| * @param staleEvents |
| * array of vaadin event types of the events that signify a |
| * property became stale. |
| */ |
| public AbstractVaadinValueProperty( |
| Class<? extends Component.Event>[] changeEvents, |
| Class<? extends Component.Event>[] staleEvents) { |
| this.changeEvents = Arrays.copyOf(changeEvents, changeEvents.length); |
| this.staleEvents = Arrays.copyOf(staleEvents, staleEvents.length); |
| |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.core.databinding.property.value.SimpleValueProperty#adaptListener(org.eclipse.core.databinding.property.ISimplePropertyListener) |
| */ |
| public INativePropertyListener adaptListener( |
| ISimplePropertyListener listener) { |
| if (changeEvents == null && staleEvents == null) { |
| return null; |
| } |
| return new ComponentListener(this, listener, changeEvents, staleEvents); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.core.databinding.property.value.ValueProperty#observe(java.lang.Object) |
| */ |
| public IVaadinObservableValue observe(Object source) { |
| if (source instanceof Component) { |
| return observe((Component) source); |
| } |
| return (IVaadinObservableValue) super.observe(source); |
| } |
| |
| /** |
| * Is used to observe the com.vaadin.data.Property#value attribute. |
| * |
| * @param realm |
| * the realm |
| * @param source |
| * the source |
| * @return the i vaadin observable value |
| */ |
| public IVaadinObservableValue observeVaadinProperty(Realm realm, |
| Object source) { |
| if (source instanceof com.vaadin.data.Property) { |
| return wrapObservable(new SimpleVaadinPropertyObservableValue( |
| realm, source, this)); |
| } |
| return wrapObservable(super.observe(realm, source)); |
| } |
| |
| /** |
| * Is used to observe the com.vaadin.data.Property#value attribute. |
| * |
| * @param source |
| * the source |
| * @return the i vaadin observable value |
| */ |
| public IVaadinObservableValue observeVaadinProperty(Object source) { |
| return observeVaadinProperty(Realm.getDefault(), source); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.core.databinding.property.value.SimpleValueProperty#observe(org.eclipse.core.databinding.observable.Realm, java.lang.Object) |
| */ |
| public IObservableValue observe(Realm realm, Object source) { |
| return wrapObservable(super.observe(realm, source)); |
| } |
| |
| /** |
| * Wrap observable. |
| * |
| * @param observable |
| * the observable |
| * @return the i vaadin observable value |
| */ |
| protected IVaadinObservableValue wrapObservable(IObservableValue observable) { |
| return new VaadinObservableValueDecorator(observable); |
| } |
| |
| /** |
| * Observe. |
| * |
| * @param widget |
| * the widget |
| * @return the i vaadin observable value |
| */ |
| public IVaadinObservableValue observe(Component widget) { |
| return (IVaadinObservableValue) observe( |
| VaadinObservables.getRealm(VaadinObservables.getUI(widget)), |
| widget); |
| } |
| |
| /** |
| * Observe delayed. |
| * |
| * @param delay |
| * the delay |
| * @param widget |
| * the widget |
| * @return the i vaadin observable value |
| */ |
| public IVaadinObservableValue observeDelayed(int delay, Component widget) { |
| throw new UnsupportedOperationException("Delayed not allowed"); |
| } |
| |
| /* (non-Javadoc) |
| * @see org.eclipse.osbp.runtime.web.vaadin.databinding.properties.IVaadinValueProperty#observeDelayed(int, java.lang.Object) |
| */ |
| @Override |
| public IVaadinObservableValue observeDelayed(int delay, Object component) { |
| throw new UnsupportedOperationException("Not implemented yet"); |
| } |
| } |