How to handle right mouse click on the specific Ev

2019-09-03 17:12发布

I want to create a context-menu under a right click for every Event in SmartGWT Calendar or simply handle right-click on event to display a pop-up window.

calendar.addEventClickHandler(new EventClickHandler() {
        @Override
        public void onEventClick(TimetableEventClick event) {
            // TODO Auto-generated method stub
        }
    });

Code above don't let me to differ actions depending on left/right mouse was clicked. There is a handler I can add to calendar instance:

calendar.addRightMouseDownHandler(new RightMouseDownHandler() {
        @Override
        public void onRightMouseDown(RightMouseDownEvent event) {
            // TODO Auto-generated method stub
        }
    });

...but how can I get info which event was clicked exactly? No event.getId() available, neither anything similar. I suppose getX(), getY() and playing with position is not a solution?

BTW: Is handling right-clicks in GWT still a bad habit? Should I leave its functionality for a browser?

4条回答
混吃等死
2楼-- · 2019-09-03 17:28

You can pass the calendar as a parameter to the constructor of the handler. When the click is triggered, you get the selected date from the calendar

查看更多
欢心
3楼-- · 2019-09-03 17:30

I guess this is what you want:

calendar.addShowContextMenuHandler(new ShowContextMenuHandler() {
    @Override
    public void onShowContextMenu(ShowContextMenuEvent event) {
       event.cancel();
       // your code
    }
});

I don't think hadling right-click in GWT is a bad habit. If it is so, these methods would have not been defined in the API to be overridden.

查看更多
相关推荐>>
4楼-- · 2019-09-03 17:30
@UiHandler("calendar")
void onCalendarClick(ClickEvent event) {
    Date timeSelected = calendar.getActiveTime();
    int  daySelected = calendar.getActiveDay();
}

You use a general ClickEvent handler and use the functions of the calendar object getActiveTime() and/or getActiveDay() to fetch the position of the cell the pointer was hovering over. The code above is using UI Binder but will work similarly with normal JAVA GWT code.

查看更多
劫难
5楼-- · 2019-09-03 17:37

The right click functionality for calendar does not exist natively.

This article sums up GWT's deficiency in this area pretty well and a way to override it.

http://whatwouldnickdo.com/wordpress/370/gwt-right-click-context-menu/

查看更多
登录 后发表回答