diff options
author | Artur Signell <artur@vaadin.com> | 2016-08-22 22:58:05 +0300 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2016-08-24 09:52:03 +0300 |
commit | fa2a40b38e8f06632f9b89c9acea1ed0d40c3410 (patch) | |
tree | 6dc536909086d04f88006be0c21480949047d665 /compatibility-server/src/main/java/com/vaadin/v7/event | |
parent | 33b0e33c86613eab9811da30916d55d4f5f77930 (diff) | |
download | vaadin-framework-fa2a40b38e8f06632f9b89c9acea1ed0d40c3410.tar.gz vaadin-framework-fa2a40b38e8f06632f9b89c9acea1ed0d40c3410.zip |
Move Item to compatibility package
Change-Id: I51ad45a18d2dcfbd582c7e4bdcca99300d20cee0
Diffstat (limited to 'compatibility-server/src/main/java/com/vaadin/v7/event')
-rw-r--r-- | compatibility-server/src/main/java/com/vaadin/v7/event/DataBoundTransferable.java | 80 | ||||
-rw-r--r-- | compatibility-server/src/main/java/com/vaadin/v7/event/ItemClickEvent.java | 147 |
2 files changed, 227 insertions, 0 deletions
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/event/DataBoundTransferable.java b/compatibility-server/src/main/java/com/vaadin/v7/event/DataBoundTransferable.java new file mode 100644 index 0000000000..1285fdc797 --- /dev/null +++ b/compatibility-server/src/main/java/com/vaadin/v7/event/DataBoundTransferable.java @@ -0,0 +1,80 @@ +/* + * Copyright 2000-2016 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.v7.event; + +import java.util.Map; + +import com.vaadin.event.Transferable; +import com.vaadin.event.TransferableImpl; +import com.vaadin.ui.Component; +import com.vaadin.v7.data.Container; + +/** + * Parent class for {@link Transferable} implementations that have a Vaadin + * container as a data source. The transfer is associated with an item + * (identified by its Id) and optionally also a property identifier (e.g. a + * table column identifier when transferring a single table cell). + * + * The component must implement the interface + * {@link com.vaadin.v7.data.Container.Viewer}. + * + * In most cases, receivers of data transfers should depend on this class + * instead of its concrete subclasses. + * + * @since 6.3 + */ +public abstract class DataBoundTransferable extends TransferableImpl { + + public DataBoundTransferable(Component sourceComponent, + Map<String, Object> rawVariables) { + super(sourceComponent, rawVariables); + } + + /** + * Returns the identifier of the item being transferred. + * + * @return item identifier + */ + public abstract Object getItemId(); + + /** + * Returns the optional property identifier that the transfer concerns. + * + * This can be e.g. the table column from which a drag operation originated. + * + * @return property identifier + */ + public abstract Object getPropertyId(); + + /** + * Returns the container data source from which the transfer occurs. + * + * {@link com.vaadin.v7.data.Container.Viewer#getContainerDataSource()} is used + * to obtain the underlying container of the source component. + * + * @return Container + */ + public Container getSourceContainer() { + Component sourceComponent = getSourceComponent(); + if (sourceComponent instanceof Container.Viewer) { + return ((Container.Viewer) sourceComponent) + .getContainerDataSource(); + } else { + // this should not happen + return null; + } + } +} diff --git a/compatibility-server/src/main/java/com/vaadin/v7/event/ItemClickEvent.java b/compatibility-server/src/main/java/com/vaadin/v7/event/ItemClickEvent.java new file mode 100644 index 0000000000..e5f45728a9 --- /dev/null +++ b/compatibility-server/src/main/java/com/vaadin/v7/event/ItemClickEvent.java @@ -0,0 +1,147 @@ +/* + * Copyright 2000-2016 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.v7.event; + +import java.io.Serializable; +import java.lang.reflect.Method; + +import com.vaadin.event.MouseEvents.ClickEvent; +import com.vaadin.shared.MouseEventDetails; +import com.vaadin.ui.Component; +import com.vaadin.v7.data.Item; +import com.vaadin.v7.data.Property; + +/** + * + * Click event fired by a {@link Component} implementing + * {@link com.vaadin.v7.data.Container} interface. ItemClickEvents happens on an + * {@link Item} rendered somehow on terminal. Event may also contain a specific + * {@link Property} on which the click event happened. + * + * @since 5.3 + * + */ +@SuppressWarnings("serial") +public class ItemClickEvent extends ClickEvent implements Serializable { + private Item item; + private Object itemId; + private Object propertyId; + + public ItemClickEvent(Component source, Item item, Object itemId, + Object propertyId, MouseEventDetails details) { + super(source, details); + this.item = item; + this.itemId = itemId; + this.propertyId = propertyId; + } + + /** + * Gets the item on which the click event occurred. + * + * @return item which was clicked + */ + public Item getItem() { + return item; + } + + /** + * Gets a possible identifier in source for clicked Item + * + * @return + */ + public Object getItemId() { + return itemId; + } + + /** + * Returns property on which click event occurred. Returns null if source + * cannot be resolved at property level. For example if clicked a cell in + * table, the "column id" is returned. + * + * @return a property id of clicked property or null if click didn't occur + * on any distinct property. + */ + public Object getPropertyId() { + return propertyId; + } + + public static final Method ITEM_CLICK_METHOD; + + static { + try { + ITEM_CLICK_METHOD = ItemClickListener.class.getDeclaredMethod( + "itemClick", new Class[] { ItemClickEvent.class }); + } catch (final java.lang.NoSuchMethodException e) { + // This should never happen + throw new java.lang.RuntimeException(); + } + } + + public interface ItemClickListener extends Serializable { + public void itemClick(ItemClickEvent event); + } + + /** + * The interface for adding and removing <code>ItemClickEvent</code> + * listeners. By implementing this interface a class explicitly announces + * that it will generate an <code>ItemClickEvent</code> when one of its + * items is clicked. + * <p> + * Note: The general Java convention is not to explicitly declare that a + * class generates events, but to directly define the + * <code>addListener</code> and <code>removeListener</code> methods. That + * way the caller of these methods has no real way of finding out if the + * class really will send the events, or if it just defines the methods to + * be able to implement an interface. + * </p> + * + * @since 6.5 + * @see ItemClickListener + * @see ItemClickEvent + */ + public interface ItemClickNotifier extends Serializable { + /** + * Register a listener to handle {@link ItemClickEvent}s. + * + * @param listener + * ItemClickListener to be registered + */ + public void addItemClickListener(ItemClickListener listener); + + /** + * @deprecated As of 7.0, replaced by + * {@link #addItemClickListener(ItemClickListener)} + **/ + @Deprecated + public void addListener(ItemClickListener listener); + + /** + * Removes an ItemClickListener. + * + * @param listener + * ItemClickListener to be removed + */ + public void removeItemClickListener(ItemClickListener listener); + + /** + * @deprecated As of 7.0, replaced by + * {@link #removeItemClickListener(ItemClickListener)} + **/ + @Deprecated + public void removeListener(ItemClickListener listener); + } + +} |