diff options
author | Teemu Suo-Anttila <teemusa@vaadin.com> | 2014-12-11 14:34:05 +0200 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2014-12-11 21:21:09 +0000 |
commit | 9fc2409cb33797c536cd2e7e9ef035a5422c5e58 (patch) | |
tree | e39fa7ddfcd0a2bb6c043fed6461dafa3b672456 /server/src/com/vaadin/event | |
parent | 341126484e70bdc0f71755acd5277deada3b185c (diff) | |
download | vaadin-framework-9fc2409cb33797c536cd2e7e9ef035a5422c5e58.tar.gz vaadin-framework-9fc2409cb33797c536cd2e7e9ef035a5422c5e58.zip |
Make SelectionChangeEvent general and move it to event packacge (#13334)
Change-Id: I232bf1d021dd95dfa3e9697cef4d8e9987da3373
Diffstat (limited to 'server/src/com/vaadin/event')
-rw-r--r-- | server/src/com/vaadin/event/SelectionChangeEvent.java | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/server/src/com/vaadin/event/SelectionChangeEvent.java b/server/src/com/vaadin/event/SelectionChangeEvent.java new file mode 100644 index 0000000000..adc7b13d49 --- /dev/null +++ b/server/src/com/vaadin/event/SelectionChangeEvent.java @@ -0,0 +1,110 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.event; + +import java.io.Serializable; +import java.util.Collection; +import java.util.EventObject; +import java.util.LinkedHashSet; +import java.util.Set; + +import com.google.gwt.thirdparty.guava.common.collect.Sets; + +/** + * An event that specifies what in a selection has changed, and where the + * selection took place. + * + * @since + * @author Vaadin Ltd + */ +public class SelectionChangeEvent extends EventObject { + + private LinkedHashSet<Object> oldSelection; + private LinkedHashSet<Object> newSelection; + + public SelectionChangeEvent(Object source, Collection<Object> oldSelection, + Collection<Object> newSelection) { + super(source); + this.oldSelection = new LinkedHashSet<Object>(oldSelection); + this.newSelection = new LinkedHashSet<Object>(newSelection); + } + + /** + * A {@link Collection} of all the itemIds that became selected. + * <p> + * <em>Note:</em> this excludes all itemIds that might have been previously + * selected. + * + * @return a Collection of the itemIds that became selected + */ + public Set<Object> getAdded() { + return Sets.difference(newSelection, oldSelection); + } + + /** + * A {@link Collection} of all the itemIds that became deselected. + * <p> + * <em>Note:</em> this excludes all itemIds that might have been previously + * deselected. + * + * @return a Collection of the itemIds that became deselected + */ + public Set<Object> getRemoved() { + return Sets.difference(oldSelection, newSelection); + } + + /** + * The listener interface for receiving {@link SelectionChangeEvent + * SelectionChangeEvents}. + * + * @since + * @author Vaadin Ltd + */ + public interface SelectionChangeListener extends Serializable { + /** + * Notifies the listener that the selection state has changed. + * + * @param event + * the selection change event + */ + void selectionChange(SelectionChangeEvent event); + } + + /** + * The interface for adding and removing listeners for + * {@link SelectionChangeEvent SelectionChangeEvents}. + * + * @since + * @author Vaadin Ltd + */ + public interface SelectionChangeNotifier extends Serializable { + /** + * Registers a new selection change listener + * + * @param listener + * the listener to register + */ + void addSelectionChangeListener(SelectionChangeListener listener); + + /** + * Removes a previously registered selection change listener + * + * @param listener + * the listener to remove + */ + void removeSelectionChangeListener(SelectionChangeListener listener); + } +} |