From 84038225ac71d56d21887a338e5daa8994a76eed Mon Sep 17 00:00:00 2001 From: Anna Miroshnik Date: Mon, 8 Sep 2014 11:32:01 +0400 Subject: Tree item fails with ItemClickListener (#14388) Patch for #14388: added modifications to remove the regression on #6845 (RIGHT, MIDDLE mouse buttons listeners) Change-Id: I3ef95df68efa0a70bbe0d566ceea187505e2999a --- client/src/com/vaadin/client/ui/VTree.java | 66 +++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 19 deletions(-) (limited to 'client') diff --git a/client/src/com/vaadin/client/ui/VTree.java b/client/src/com/vaadin/client/ui/VTree.java index b12053ea04..02ad7cfb3e 100644 --- a/client/src/com/vaadin/client/ui/VTree.java +++ b/client/src/com/vaadin/client/ui/VTree.java @@ -160,6 +160,13 @@ public class VTree extends FocusElementPanel implements VHasDropHandler, private boolean selectionHasChanged = false; + /* + * to fix #14388. The cause of defect #14388: event 'clickEvent' is sent to + * server before updating of "selected" variable, but should be send after + * it + */ + private boolean sendClickEventNow = false; + /** For internal use only. May be removed or replaced in the future. */ public String[] bodyActionKeys; @@ -471,9 +478,15 @@ public class VTree extends FocusElementPanel implements VHasDropHandler, Command command = new Command() { @Override public void execute() { + /* + * we should send selection to server immediately in 2 cases: 1) + * 'immediate' property of Tree is true 2) sendClickEventNow is + * true + */ client.updateVariable(paintableId, "selected", selectedIds.toArray(new String[selectedIds.size()]), - immediate); + sendClickEventNow || immediate); + sendClickEventNow = false; selectionHasChanged = false; } }; @@ -831,26 +844,41 @@ public class VTree extends FocusElementPanel implements VHasDropHandler, // server. We do not want to send the event if there is a // selection event happening after this. In all other cases // we want to send it immediately. - boolean sendClickEventNow = true; - - if (details.getButton() == MouseButton.LEFT && immediate - && selectable) { - // Probably a selection that will cause a value change - // event to be sent - sendClickEventNow = false; - - // The exception is that user clicked on the - // currently selected row and null selection is not - // allowed == no selection event - if (isSelected() && selectedIds.size() == 1 - && !isNullSelectionAllowed) { - sendClickEventNow = true; + sendClickEventNow = true; + + if (details.getButton() == MouseButton.LEFT && selectable) { + if (immediate) { + // event to be sent + sendClickEventNow = false; + + // The exception is that user clicked on the + // currently selected row and null selection is not + // allowed == no selection event + if (isSelected() && selectedIds.size() == 1 + && !isNullSelectionAllowed) { + sendClickEventNow = true; + } } - } - client.updateVariable(paintableId, "clickedKey", key, false); - client.updateVariable(paintableId, "clickEvent", - details.toString(), sendClickEventNow); + client.updateVariable(paintableId, "clickedKey", key, + false); + + /* + * in any case event should not be send immediately here + * - send after updating of "selected" variable + */ + client.updateVariable(paintableId, "clickEvent", + details.toString(), false); + + } else { // for all another mouse buttons (RIGHT, MIDDLE) or + // if not selectable + client.updateVariable(paintableId, "clickedKey", key, + false); + + client.updateVariable(paintableId, "clickEvent", + details.toString(), sendClickEventNow); + sendClickEventNow = false; // reset it + } } }); } -- cgit v1.2.3