开发者

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

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
        }
    });

...b开发者_如何学Cut 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?


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.


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/


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜