blob: 3690cd54f8299fcbb69927b2524af2eb56078b5a [file] [log] [blame]
/**
* 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 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Florian Pirchner - Initial implementation
*/
package org.eclipse.osbp.runtime.web.vaadin.databinding.properties;
import com.vaadin.data.Container;
import com.vaadin.data.Property;
import com.vaadin.ui.AbstractSelect;
// TODO: Auto-generated Javadoc
/**
* The Class Util.
*/
public class Util {
/**
* Returns the property datasource if available, the source as a property or
* null.
*
* @param source
* the source
* @return the property
*/
@SuppressWarnings("unchecked")
public static Property<Object> getProperty(Object source) {
Property<Object> result = null;
if (source instanceof Property.Viewer) {
result = ((Property.Viewer) source).getPropertyDataSource();
}
if (result == null && source instanceof Property<?>) {
result = (Property<Object>) source;
}
return result;
}
/**
* Returns the container datasource for the given element.
*
* @param source
* the source
* @return the container
*/
public static Container getContainer(Object source) {
// if source is AbstractSelect, then access the container by
// #getContainerDataSource
if (source instanceof Container && !(source instanceof AbstractSelect)) {
return (Container) source;
}
Container result = null;
if (source instanceof Container.Viewer) {
result = ((Container.Viewer) source).getContainerDataSource();
}
return result;
}
}