blob: 7d04a464c3194857b5bc0c13fae631cb5d2c9bce [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 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.model.internal;
import org.eclipse.core.databinding.observable.Diffs;
import org.eclipse.core.databinding.observable.value.ValueDiff;
import org.eclipse.core.databinding.property.IProperty;
import org.eclipse.core.databinding.property.ISimplePropertyListener;
import org.eclipse.core.databinding.property.NativePropertyListener;
import org.eclipse.osbp.runtime.web.vaadin.databinding.properties.Util;
import com.vaadin.data.Container;
import com.vaadin.data.Container.Viewer;
import com.vaadin.data.Property;
import com.vaadin.event.SelectionEvent;
/**
*/
@SuppressWarnings("serial")
public class SelectionNotifierValueChangeListener extends
NativePropertyListener implements
com.vaadin.event.SelectionEvent.SelectionListener {
private Object source;
public SelectionNotifierValueChangeListener(IProperty property,
ISimplePropertyListener listener) {
super(property, listener);
}
protected void doAddTo(Object source) {
this.source = source;
getNotifier(source).addSelectionListener(this);
}
protected SelectionEvent.SelectionNotifier getNotifier(Object source) {
Property<Object> property = Util.getProperty(source);
if (property instanceof SelectionEvent.SelectionNotifier) {
return (SelectionEvent.SelectionNotifier) property;
} else {
return (SelectionEvent.SelectionNotifier) source;
}
}
protected Container getContainer(Object source) {
Container.Viewer viewer = (Viewer) source;
Container ds = viewer.getContainerDataSource();
return ds;
}
protected void doRemoveFrom(Object source) {
getNotifier(source).removeSelectionListener(this);
}
@Override
public void select(SelectionEvent event) {
Object added = event.getAdded().stream().findFirst().orElse(null);
Object removed = event.getRemoved().stream().findFirst().orElse(null);
ValueDiff diffs = Diffs.createValueDiff(added, removed);
fireChange(source, diffs);
}
}