celllist multi select opens current page in new window?

24 views
Skip to first unread message

Aaron Weber

unread,
Jul 31, 2015, 1:41:41 PM7/31/15
to Google Web Toolkit
I would think I tested this before, but during some testing of my gwt page today I noticed that when I try to multi-select from my cellist, "something" is firing and opening a new window/tab with my current page.

My multiselect for the celllist is simple:
        // Add a selection model using the same keyProvider.
        final MultiSelectionModel<docWithId> selectionModel = new MultiSelectionModel(keyProvider);
        cellList.setSelectionModel(selectionModel);


When I try to "shift-select" or "ctrl-select" in Chrome or IE11 (on Windows 8), a new window launches!

If anyone has any ideas where to start troubleshooting this, I would appreciate it.

-AJ

Aaron Weber

unread,
Jul 31, 2015, 4:09:08 PM7/31/15
to Google Web Toolkit, aaron....@gmail.com
So..upon further review...this appears to be a general event handled by "current" browsers.  Shift-Click a link and it opens in a new tab/window.

So I guess I would like to trap the event before it gets to the DOM/window layer?  I tried adding a CellPreviewHandler and checking whether it's a shift-click, and if so, canceling the event and stopPropagation() on the NativeEvent, but this doesn't seem to have any effect.  Is there a different handler/place that I should be trapping the shift (and ctrl) click events?

Thanks,
AJ

Aaron Weber

unread,
Jul 31, 2015, 5:41:20 PM7/31/15
to Google Web Toolkit, aaron....@gmail.com
Me again...

This code seems to work (and I'm posting it here in case it helps someone else).  If anyone thinks this will cause issues somewhere else, and is kind enough to respond, I appreciate it!
        // trap the shift-click || ctrl-click launch of a new browser window.
        cellList.addCellPreviewHandler(new CellPreviewEvent.Handler()
        {
            @Override
            public void onCellPreview(final CellPreviewEvent event)
            {
                NativeEvent evt = event.getNativeEvent();

                //shift-click || ctrl-click
                if ((BrowserEvents.CLICK.equals(evt.getType())) &&
                        ((evt.getShiftKey()) || (evt.getCtrlKey())) )
                {
                    //Window.alert("Shift-Click Event");

                    event.setCanceled(true);
                    event.getNativeEvent().stopPropagation();
                    event.getNativeEvent().preventDefault();
                }
            }
        });

-AJ
Reply all
Reply to author
Forward
0 new messages