summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatti Tahvonen <matti.tahvonen@itmill.com>2009-12-01 08:07:58 +0000
committerMatti Tahvonen <matti.tahvonen@itmill.com>2009-12-01 08:07:58 +0000
commitcacb5e8d2b4191d6ec6f517fa31e7f139d3ef7c4 (patch)
tree011da87d86091e06f1797401e384dee75f607f1f /src
parent9a19625333437cfc991265af5e78a7ee7242088e (diff)
downloadvaadin-framework-cacb5e8d2b4191d6ec6f517fa31e7f139d3ef7c4.tar.gz
vaadin-framework-cacb5e8d2b4191d6ec6f517fa31e7f139d3ef7c4.zip
ItemClickListeners in Tree and Table now use the new event listener feature (with identifier)
svn changeset:10112/svn branch:6.2
Diffstat (limited to 'src')
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java8
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/VTree.java8
-rw-r--r--src/com/vaadin/ui/Table.java64
-rw-r--r--src/com/vaadin/ui/Tree.java25
4 files changed, 34 insertions, 71 deletions
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java
index e735dc67d9..61e35a28bf 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java
@@ -67,6 +67,8 @@ import com.vaadin.terminal.gwt.client.ui.VScrollTable.VScrollTableBody.VScrollTa
public class VScrollTable extends FlowPanel implements Table, ScrollHandler {
public static final String CLASSNAME = "v-table";
+ public static final String ITEM_CLICK_EVENT_ID = "itemClick";
+
private static final double CACHE_RATE_DEFAULT = 2;
/**
@@ -135,8 +137,6 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler {
/** flag to indicate that table body has changed */
private boolean isNewBody = true;
- private boolean emitClickEvents;
-
/*
* Read from the "recalcWidths" -attribute. When it is true, the table will
* recalculate the widths for columns - desirable in some cases. For #1983,
@@ -177,7 +177,6 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler {
this.client = client;
paintableId = uidl.getStringAttribute("id");
immediate = uidl.getBooleanAttribute("immediate");
- emitClickEvents = uidl.getBooleanAttribute("listenClicks");
final int newTotalRows = uidl.getIntAttribute("totalrows");
if (newTotalRows != totalRows) {
if (scrollBody != null) {
@@ -2395,7 +2394,8 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler {
}
private void handleClickEvent(Event event, Element targetTdOrTr) {
- if (emitClickEvents) {
+ if (client.hasEventListeners(VScrollTable.this,
+ ITEM_CLICK_EVENT_ID)) {
boolean doubleClick = (DOM.eventGetType(event) == Event.ONDBLCLICK);
/* This row was clicked */
diff --git a/src/com/vaadin/terminal/gwt/client/ui/VTree.java b/src/com/vaadin/terminal/gwt/client/ui/VTree.java
index 0fe4bfba31..3394821efb 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/VTree.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/VTree.java
@@ -30,6 +30,8 @@ public class VTree extends FlowPanel implements Paintable {
public static final String CLASSNAME = "v-tree";
+ public static final String ITEM_CLICK_EVENT_ID = "itemClick";
+
private Set<String> selectedIds = new HashSet<String>();
private ApplicationConnection client;
private String paintableId;
@@ -52,8 +54,6 @@ public class VTree extends FlowPanel implements Paintable {
private boolean readonly;
- private boolean emitClickEvents;
-
private boolean rendering;
public VTree() {
@@ -107,7 +107,6 @@ public class VTree extends FlowPanel implements Paintable {
disabled = uidl.getBooleanAttribute("disabled");
readonly = uidl.getBooleanAttribute("readonly");
- emitClickEvents = uidl.getBooleanAttribute("listenClicks");
isNullSelectionAllowed = uidl.getBooleanAttribute("nullselect");
@@ -219,7 +218,8 @@ public class VTree extends FlowPanel implements Paintable {
}
final int type = DOM.eventGetType(event);
final Element target = DOM.eventGetTarget(event);
- if (emitClickEvents && target == nodeCaptionSpan
+ if (client.hasEventListeners(VTree.this, ITEM_CLICK_EVENT_ID)
+ && target == nodeCaptionSpan
&& (type == Event.ONDBLCLICK || type == Event.ONMOUSEUP)) {
fireClick(event);
}
diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java
index eb669bc786..1198744519 100644
--- a/src/com/vaadin/ui/Table.java
+++ b/src/com/vaadin/ui/Table.java
@@ -319,8 +319,6 @@ public class Table extends AbstractSelect implements Action.Container,
*/
private CellStyleGenerator cellStyleGenerator = null;
- private int clickListenerCount;
-
/*
* EXPERIMENTAL feature: will tell the client to re-calculate column widths
* if set to true. Currently no setter: extend to enable.
@@ -1799,7 +1797,7 @@ public class Table extends AbstractSelect implements Action.Container,
* java.util.Map)
*/
@Override
- public void changeVariables(Object source, Map variables) {
+ public void changeVariables(Object source, Map<String, Object> variables) {
boolean clientNeedsContentRefresh = false;
@@ -1810,7 +1808,7 @@ public class Table extends AbstractSelect implements Action.Container,
if (!isSelectable() && variables.containsKey("selected")) {
// Not-selectable is a special case, AbstractSelect does not support
// TODO could be optimized.
- variables = new HashMap(variables);
+ variables = new HashMap<String, Object>(variables);
variables.remove("selected");
}
@@ -1954,24 +1952,22 @@ public class Table extends AbstractSelect implements Action.Container,
*
* @param variables
*/
- private void handleClickEvent(Map variables) {
- if (clickListenerCount > 0) {
- if (variables.containsKey("clickEvent")) {
- String key = (String) variables.get("clickedKey");
- Object itemId = itemIdMapper.get(key);
- Object propertyId = null;
- String colkey = (String) variables.get("clickedColKey");
- // click is not necessary on a property
- if (colkey != null) {
- propertyId = columnIdMap.get(colkey);
- }
- MouseEventDetails evt = MouseEventDetails
- .deSerialize((String) variables.get("clickEvent"));
- Item item = getItem(itemId);
- if (item != null) {
- fireEvent(new ItemClickEvent(this, item, itemId,
- propertyId, evt));
- }
+ private void handleClickEvent(Map<String, Object> variables) {
+ if (variables.containsKey("clickEvent")) {
+ String key = (String) variables.get("clickedKey");
+ Object itemId = itemIdMapper.get(key);
+ Object propertyId = null;
+ String colkey = (String) variables.get("clickedColKey");
+ // click is not necessary on a property
+ if (colkey != null) {
+ propertyId = columnIdMap.get(colkey);
+ }
+ MouseEventDetails evt = MouseEventDetails
+ .deSerialize((String) variables.get("clickEvent"));
+ Item item = getItem(itemId);
+ if (item != null) {
+ fireEvent(new ItemClickEvent(this, item, itemId, propertyId,
+ evt));
}
}
}
@@ -2079,10 +2075,6 @@ public class Table extends AbstractSelect implements Action.Container,
target.addAttribute("selectmode", "none");
}
- if (clickListenerCount > 0) {
- target.addAttribute("listenClicks", true);
- }
-
if (cacheRate != CACHE_RATE_DEFAULT) {
target.addAttribute("cr", cacheRate);
}
@@ -3255,25 +3247,13 @@ public class Table extends AbstractSelect implements Action.Container,
}
public void addListener(ItemClickListener listener) {
- addListener(ItemClickEvent.class, listener,
- ItemClickEvent.ITEM_CLICK_METHOD);
- clickListenerCount++;
- // repaint needed only if click listening became necessary
- if (clickListenerCount == 1) {
- requestRepaint();
- }
-
+ addListener(VScrollTable.ITEM_CLICK_EVENT_ID, ItemClickEvent.class,
+ listener, ItemClickEvent.ITEM_CLICK_METHOD);
}
public void removeListener(ItemClickListener listener) {
- removeListener(ItemClickEvent.class, listener,
- ItemClickEvent.ITEM_CLICK_METHOD);
- clickListenerCount--;
- // repaint needed only if click listening is not needed in client
- // anymore
- if (clickListenerCount == 0) {
- requestRepaint();
- }
+ removeListener(VScrollTable.ITEM_CLICK_EVENT_ID, ItemClickEvent.class,
+ listener);
}
// Identical to AbstractCompoenentContainer.setEnabled();
diff --git a/src/com/vaadin/ui/Tree.java b/src/com/vaadin/ui/Tree.java
index 825318f32b..5fa4a57c16 100644
--- a/src/com/vaadin/ui/Tree.java
+++ b/src/com/vaadin/ui/Tree.java
@@ -328,7 +328,7 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
@Override
public void changeVariables(Object source, Map variables) {
- if (clickListenerCount > 0 && variables.containsKey("clickedKey")) {
+ if (variables.containsKey("clickedKey")) {
String key = (String) variables.get("clickedKey");
Object id = itemIdMapper.get(key);
@@ -431,10 +431,6 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
target.addAttribute("nullselect", true);
}
- if (clickListenerCount > 0) {
- target.addAttribute("listenClicks", true);
- }
-
}
// Initialize variables
@@ -1008,29 +1004,16 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
}
}
- private int clickListenerCount = 0;
-
private ItemStyleGenerator itemStyleGenerator;
public void addListener(ItemClickListener listener) {
- addListener(ItemClickEvent.class, listener,
+ addListener(VTree.ITEM_CLICK_EVENT_ID, ItemClickEvent.class, listener,
ItemClickEvent.ITEM_CLICK_METHOD);
- clickListenerCount++;
- // repaint needed only if click listening became necessary
- if (clickListenerCount == 1) {
- requestRepaint();
- }
}
public void removeListener(ItemClickListener listener) {
- removeListener(ItemClickEvent.class, listener,
- ItemClickEvent.ITEM_CLICK_METHOD);
- clickListenerCount++;
- // repaint needed only if click listening is not needed in client
- // anymore
- if (clickListenerCount == 0) {
- requestRepaint();
- }
+ removeListener(VTree.ITEM_CLICK_EVENT_ID, ItemClickEvent.class,
+ listener);
}
/**