protected HashSet<Handler> actionHandlers = null;
/** Action mapper */
- protected KeyMapper actionMapper = null;
+ protected KeyMapper<Action> actionMapper = null;
protected Component viewer;
* removed but still exist on client side
*/
if (!actions.isEmpty() || clientHasActions) {
- actionMapper = new KeyMapper();
+ actionMapper = new KeyMapper<Action>();
paintTarget.addVariable(viewer, "action", "");
paintTarget.startTag("actions");
public void handleActions(Map<String, Object> variables, Container sender) {
if (variables.containsKey("action") && actionMapper != null) {
final String key = (String) variables.get("action");
- final Action action = (Action) actionMapper.get(key);
+ final Action action = actionMapper.get(key);
final Object target = variables.get("actiontarget");
if (action != null) {
handleAction(action, sender, target);
package com.vaadin.terminal;
import java.io.Serializable;
-import java.util.Hashtable;
+import java.util.HashMap;
/**
* <code>KeyMapper</code> is the simple two-way map for generating textual keys
* @VERSION@
* @since 3.0
*/
-@SuppressWarnings("serial")
-public class KeyMapper implements Serializable {
+public class KeyMapper<V> implements Serializable {
private int lastKey = 0;
- private final Hashtable<Object, String> objectKeyMap = new Hashtable<Object, String>();
+ private final HashMap<V, String> objectKeyMap = new HashMap<V, String>();
- private final Hashtable<String, Object> keyObjectMap = new Hashtable<String, Object>();
+ private final HashMap<String, V> keyObjectMap = new HashMap<String, V>();
/**
* Gets key for an object.
* @param o
* the object.
*/
- public String key(Object o) {
+ public String key(V o) {
if (o == null) {
return "null";
* the name with the desired value.
* @return the object with the key.
*/
- public Object get(String key) {
-
+ public V get(String key) {
return keyObjectMap.get(key);
}
* @param removeobj
* the object to be removed.
*/
- public void remove(Object removeobj) {
+ public void remove(V removeobj) {
final String key = objectKeyMap.get(removeobj);
if (key != null) {
/**
* Keymapper used to map key values.
*/
- protected KeyMapper itemIdMapper = new KeyMapper();
+ protected KeyMapper<Object> itemIdMapper = new KeyMapper<Object>();
/**
* Item icons.
* Mapper between server-side component instances (tab contents) and keys
* given to the client that identify tabs.
*/
- private final KeyMapper keyMapper = new KeyMapper();
+ private final KeyMapper<Component> keyMapper = new KeyMapper<Component>();
/**
* When true, the tab selection area is not displayed to the user.
@Override
public void changeVariables(Object source, Map<String, Object> variables) {
if (variables.containsKey("selected")) {
- setSelectedTab((Component) keyMapper.get((String) variables
- .get("selected")));
+ setSelectedTab(keyMapper.get((String) variables.get("selected")));
}
if (variables.containsKey("close")) {
- final Component tab = (Component) keyMapper.get((String) variables
- .get("close"));
+ final Component tab = keyMapper
+ .get((String) variables.get("close"));
if (tab != null) {
closeHandler.onTabClose(this, tab);
}
/**
* Keymapper for column ids.
*/
- private final KeyMapper columnIdMap = new KeyMapper();
+ private final KeyMapper<Object> columnIdMap = new KeyMapper<Object>();
/**
* Holds visible column propertyIds - in order.
/**
* Action mapper.
*/
- private KeyMapper actionMapper = null;
+ private KeyMapper<Action> actionMapper = null;
/**
* Table cell editor factory.
(String) variables.get("action"), ",");
if (st.countTokens() == 2) {
final Object itemId = itemIdMapper.get(st.nextToken());
- final Action action = (Action) actionMapper.get(st.nextToken());
+ final Action action = actionMapper.get(st.nextToken());
if (action != null && (itemId == null || containsId(itemId))
&& actionHandlers != null) {
if (actionHandlers == null) {
actionHandlers = new LinkedList<Handler>();
- actionMapper = new KeyMapper();
+ actionMapper = new KeyMapper<Action>();
}
if (!actionHandlers.contains(actionHandler)) {
/**
* Action mapper.
*/
- private KeyMapper actionMapper = null;
+ private KeyMapper<Action> actionMapper = null;
/**
* Is the tree selectable on the client side.
(String) variables.get("action"), ",");
if (st.countTokens() == 2) {
final Object itemId = itemIdMapper.get(st.nextToken());
- final Action action = (Action) actionMapper.get(st.nextToken());
+ final Action action = actionMapper.get(st.nextToken());
if (action != null && (itemId == null || containsId(itemId))
&& actionHandlers != null) {
for (Handler ah : actionHandlers) {
if (actionHandlers == null) {
actionHandlers = new LinkedList<Action.Handler>();
- actionMapper = new KeyMapper();
+ actionMapper = new KeyMapper<Action>();
}
if (!actionHandlers.contains(actionHandler)) {
public class TestKeyMapper extends TestCase {
public void testAdd() {
- KeyMapper mapper = new KeyMapper();
+ KeyMapper<Object> mapper = new KeyMapper<Object>();
Object o1 = new Object();
Object o2 = new Object();
Object o3 = new Object();
}
public void testRemoveAll() {
- KeyMapper mapper = new KeyMapper();
+ KeyMapper<Object> mapper = new KeyMapper<Object>();
Object o1 = new Object();
Object o2 = new Object();
Object o3 = new Object();
}
public void testRemove() {
- KeyMapper mapper = new KeyMapper();
+ KeyMapper<Object> mapper = new KeyMapper<Object>();
Object o1 = new Object();
Object o2 = new Object();
Object o3 = new Object();
}
- private void assertSize(KeyMapper mapper, int i) {
+ private void assertSize(KeyMapper<?> mapper, int i) {
try {
Field f1 = KeyMapper.class.getDeclaredField("objectKeyMap");
Field f2 = KeyMapper.class.getDeclaredField("keyObjectMap");