How to handle right mouse click on the specific Event in SmartGWT Calendar?

巧了我就是萌 提交于 2020-01-25 12:42:36

问题


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?


回答1:


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.




回答2:


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/




回答3:


@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.




回答4:


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



来源:https://stackoverflow.com/questions/5597172/how-to-handle-right-mouse-click-on-the-specific-event-in-smartgwt-calendar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!