blob: 8693a6be4decf70101448d72d6782aba7aa4aec9 [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.model.internal;
import org.eclipse.core.databinding.property.INativePropertyListener;
import org.eclipse.core.databinding.property.ISimplePropertyListener;
import org.eclipse.osbp.runtime.web.vaadin.databinding.properties.AbstractVaadinValueProperty;
import org.eclipse.osbp.runtime.web.vaadin.databinding.properties.Util;
import com.vaadin.data.Property;
import com.vaadin.ui.AbstractField;
/**
*/
public class PropertyValueProperty extends AbstractVaadinValueProperty {
public PropertyValueProperty() {
}
public INativePropertyListener adaptListener(ISimplePropertyListener listener) {
return new PropertyValueChangeListener(this, listener);
}
@Override
public Object getValueType() {
return Object.class;
}
@Override
protected Object doGetValue(Object source) {
Property<?> property = Util.getProperty(source);
return property.getValue();
}
@SuppressWarnings("rawtypes")
@Override
protected void doSetValue(Object source, Object value) {
// if (source instanceof AbstractField) {
// AbstractField field = (AbstractField) source;
// if (!field.isValid()) {
// // workaround - if value is invalid, then property#setValue will
// // not change the field value. So we need to reset the value
// // internally to the datasource value
// field.discard();
// }
// }
Property<Object> property = Util.getProperty(source);
property.setValue(value);
if (source instanceof AbstractField) {
AbstractField field = (AbstractField) source;
if (field.getValue() != value) {
// workaround - if value is invalid, then property#setValue will
// not change the field value. So we need to reset the value
// internally to the datasource value
field.discard();
}
}
}
}