| /** |
| * 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.observable.Diffs; |
| import org.eclipse.core.databinding.observable.set.SetDiff; |
| 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 SelectionNotifierSetDiffChangeListener extends NativePropertyListener |
| implements com.vaadin.event.SelectionEvent.SelectionListener { |
| |
| private Object source; |
| |
| public SelectionNotifierSetDiffChangeListener(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) { |
| SetDiff diffs = Diffs.createSetDiff(event.getAdded(), |
| event.getRemoved()); |
| fireChange(source, diffs); |
| } |
| } |