diff options
author | Artur Signell <artur@vaadin.com> | 2015-01-29 07:43:39 +0000 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2015-01-29 07:43:40 +0000 |
commit | a681bf8f13163b67f55ec2d334f44f976d3eb161 (patch) | |
tree | 857a4cc6ef8910db66e256da4256c21d778b6496 /server/src/com/vaadin/event | |
parent | 336299a558e74e7366482640c650716880886275 (diff) | |
parent | e30b3136589799dc95049bcc87d4b7f7e707549e (diff) | |
download | vaadin-framework-a681bf8f13163b67f55ec2d334f44f976d3eb161.tar.gz vaadin-framework-a681bf8f13163b67f55ec2d334f44f976d3eb161.zip |
Merge "Merge branch 'origin/grid'"
Diffstat (limited to 'server/src/com/vaadin/event')
-rw-r--r-- | server/src/com/vaadin/event/SelectionEvent.java | 114 | ||||
-rw-r--r-- | server/src/com/vaadin/event/SortEvent.java | 110 |
2 files changed, 224 insertions, 0 deletions
diff --git a/server/src/com/vaadin/event/SelectionEvent.java b/server/src/com/vaadin/event/SelectionEvent.java new file mode 100644 index 0000000000..e75369e6da --- /dev/null +++ b/server/src/com/vaadin/event/SelectionEvent.java @@ -0,0 +1,114 @@ +/* + * 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.Collections; +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 7.4 + * @author Vaadin Ltd + */ +public class SelectionEvent extends EventObject { + + private LinkedHashSet<Object> oldSelection; + private LinkedHashSet<Object> newSelection; + + public SelectionEvent(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); + } + + /** + * A {@link Collection} of all the itemIds that are currently selected. + * + * @return a Collection of the itemIds that are currently selected + */ + public Set<Object> getSelected() { + return Collections.unmodifiableSet(newSelection); + } + + /** + * The listener interface for receiving {@link SelectionEvent + * SelectionEvents}. + */ + public interface SelectionListener extends Serializable { + /** + * Notifies the listener that the selection state has changed. + * + * @param event + * the selection change event + */ + void select(SelectionEvent event); + } + + /** + * The interface for adding and removing listeners for + * {@link SelectionEvent SelectionEvents}. + */ + public interface SelectionNotifier extends Serializable { + /** + * Registers a new selection listener + * + * @param listener + * the listener to register + */ + void addSelectionListener(SelectionListener listener); + + /** + * Removes a previously registered selection change listener + * + * @param listener + * the listener to remove + */ + void removeSelectionListener(SelectionListener listener); + } +} diff --git a/server/src/com/vaadin/event/SortEvent.java b/server/src/com/vaadin/event/SortEvent.java new file mode 100644 index 0000000000..f303e47781 --- /dev/null +++ b/server/src/com/vaadin/event/SortEvent.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.List; + +import com.vaadin.data.sort.SortOrder; +import com.vaadin.ui.Component; + +/** + * Event describing a change in sorting of a {@link Container}. Fired by + * {@link SortNotifier SortNotifiers}. + * + * @see SortListener + * + * @since 7.4 + * @author Vaadin Ltd + */ +public class SortEvent extends Component.Event { + + private final List<SortOrder> sortOrder; + private final boolean userOriginated; + + /** + * Creates a new sort order change event with a sort order list. + * + * @param source + * the component from which the event originates + * @param sortOrder + * the new sort order list + * @param userOriginated + * <code>true</code> if event is a result of user interaction, + * <code>false</code> if from API call + */ + public SortEvent(Component source, List<SortOrder> sortOrder, + boolean userOriginated) { + super(source); + this.sortOrder = sortOrder; + this.userOriginated = userOriginated; + } + + /** + * Gets the sort order list. + * + * @return the sort order list + */ + public List<SortOrder> getSortOrder() { + return sortOrder; + } + + /** + * Returns whether this event originated from actions done by the user. + * + * @return true if sort event originated from user interaction + */ + public boolean isUserOriginated() { + return userOriginated; + } + + /** + * Listener for sort order change events. + */ + public interface SortListener extends Serializable { + /** + * Called when the sort order has changed. + * + * @param event + * the sort order change event + */ + public void sort(SortEvent event); + } + + /** + * The interface for adding and removing listeners for {@link SortEvent + * SortEvents}. + */ + public interface SortNotifier extends Serializable { + /** + * Adds a sort order change listener that gets notified when the sort + * order changes. + * + * @param listener + * the sort order change listener to add + */ + public void addSortListener(SortListener listener); + + /** + * Removes a sort order change listener previously added using + * {@link #addSortListener(SortListener)}. + * + * @param listener + * the sort order change listener to remove + */ + public void removeSortListener(SortListener listener); + } +} |