com.vaadin.data
Class RpcDataProviderExtension.DataProviderKeyMapper

java.lang.Object
  extended by com.vaadin.data.RpcDataProviderExtension.DataProviderKeyMapper
All Implemented Interfaces:
java.io.Serializable
Enclosing class:
RpcDataProviderExtension

public class RpcDataProviderExtension.DataProviderKeyMapper
extends java.lang.Object
implements java.io.Serializable

ItemId to Key to ItemId mapper.

This class is used when transmitting information about items in container related to Grid. It introduces a consistent way of mapping ItemIds and its container to a String that can be mapped back to ItemId.

Technical note: This class also keeps tabs on which indices are being shown/selected, and is able to clean up after itself once the itemId ⇆ key mapping is not needed anymore. In other words, this doesn't leak memory.

See Also:
Serialized Form

Method Summary
 java.lang.Object getItemId(java.lang.String key)
          Gets the registered item id based on its key.
 java.util.Collection<java.lang.Object> getItemIds(java.util.Collection<java.lang.String> keys)
          Gets corresponding item ids for each of the keys in a collection.
 java.lang.String getKey(java.lang.Object itemId)
          Gets the key for a given item id.
 java.util.List<java.lang.String> getKeys(java.util.Collection<java.lang.Object> itemIds)
          Gets keys for a collection of item ids.
 boolean isPinned(java.lang.Object itemId)
          Checks whether an item id is pinned or not.
 void pin(java.lang.Object itemId)
          Pin an item id to be cached indefinitely.
 void unpin(java.lang.Object itemId)
          Unpin an item id.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getKey

public java.lang.String getKey(java.lang.Object itemId)
Gets the key for a given item id. Creates a new key mapping if no existing mapping was found for the given item id.

Parameters:
itemId - the item id to get the key for
Returns:
the key for the given item id
Since:
7.5.0

getKeys

public java.util.List<java.lang.String> getKeys(java.util.Collection<java.lang.Object> itemIds)
Gets keys for a collection of item ids.

If the itemIds are currently cached, the existing keys will be used. Otherwise new ones will be created.

Parameters:
itemIds - the item ids for which to get keys
Returns:
keys for the itemIds

getItemId

public java.lang.Object getItemId(java.lang.String key)
                           throws java.lang.IllegalStateException
Gets the registered item id based on its key.

A key is used to identify a particular row on both a server and a client. This method can be used to get the item id for the row key that the client has sent.

Parameters:
key - the row key for which to retrieve an item id
Returns:
the item id corresponding to key
Throws:
java.lang.IllegalStateException - if the key mapper does not have a record of key .

getItemIds

public java.util.Collection<java.lang.Object> getItemIds(java.util.Collection<java.lang.String> keys)
                                                  throws java.lang.IllegalStateException
Gets corresponding item ids for each of the keys in a collection.

Parameters:
keys - the keys for which to retrieve item ids
Returns:
a collection of item ids for the keys
Throws:
java.lang.IllegalStateException - if one or more of keys don't have a corresponding item id in the cache

pin

public void pin(java.lang.Object itemId)
         throws java.lang.IllegalStateException
Pin an item id to be cached indefinitely.

Normally when an itemId is not an active row, it is discarded from the cache. Pinning an item id will make sure that it is kept in the cache.

In effect, while an item id is pinned, it always has the same key.

Parameters:
itemId - the item id to pin
Throws:
java.lang.IllegalStateException - if itemId was already pinned
See Also:
unpin(Object), isPinned(Object), getItemIds(Collection)

unpin

public void unpin(java.lang.Object itemId)
           throws java.lang.IllegalStateException
Unpin an item id.

This cancels the effect of pinning an item id. If the item id is currently inactive, it will be immediately removed from the cache.

Parameters:
itemId - the item id to unpin
Throws:
java.lang.IllegalStateException - if itemId was not pinned
See Also:
pin(Object), isPinned(Object), getItemIds(Collection)

isPinned

public boolean isPinned(java.lang.Object itemId)
Checks whether an item id is pinned or not.

Parameters:
itemId - the item id to check for pin status
Returns:
true iff the item id is currently pinned


Copyright © 2000-2014 Vaadin Ltd. All Rights Reserved.