Calendar - get right-clicked date in monthly view?

Hello All,

I use Vaddin Calendar to manage some events. What I would like to do is to have a option to add new event to calendar using right-click.

I have added a action handler containing my actions, but I ain’t got no clue - how should I get the right-clicked date. I’d like to right-click a date (e.g. Feb, 10th, 2017) and open a event window with 02/10/2017 already selected as event date.

My current code:

Action.Handler actHandler = new Action.Handler() {
            
            /**
             * 
             */
            private static final long serialVersionUID = -5909491223935135605L;
            Action addEvent = new Action("Add expense");
            Action editEvent = new Action("Edit expense");
            Action deleteEvent = new Action("Delete expense");
            Action markEventPaid = new Action("Mark as paid");
            Action markEventUnPaid = new Action("Mark as unpaid");

            @Override
            public Action[] getActions(Object target, Object sender) {
                if (! (target instanceof CalendarDateRange))
                    return null;
                CalendarDateRange dateRange = (CalendarDateRange) target;
                if (! (sender instanceof Calendar))
                    return null;
                Calendar calendar = (Calendar) sender;
                List<CalendarEvent> events =
                        calendar.getEvents(dateRange.getStart(),
                                           dateRange.getEnd());
                if (events.size() == 0)
                    return new Action[] {addEvent};
                else
                    return new Action[] {addEvent, editEvent, deleteEvent, markEventPaid, markEventUnPaid};
            }

            @Override
            public void handleAction(Action action, Object sender, Object target) {
                if (action == addEvent) {
                    Notification.show("Not implemented");
                    ExpenseDetailsWindow.open(new ExpenseEvent(),
                            null, null);
                        Notification.show("Can't add on an event");*/
                } else if (action == deleteEvent) {
                    if (target instanceof CalendarEvent) {
                        CalendarEvent event = (CalendarEvent) target;
                        calendar.removeEvent(event);
                        Notification.show("Not implemented");
                    } else
                        Notification.show("No event to delete");
                } else if(action == markEventPaid) {
                    Notification.show("Not implemented");
                } else if(action == editEvent) {
                    Notification.show("Not implemented");
                } else if(action == markEventUnPaid)
                    Notification.show("Not implemented");
                
            }
            
        };
        calendar.addActionHandler(actHandler);

Any help will be really apreciated :slight_smile:

Thank you in advance,
Tom

Ok, nevermind :wink: I’ll answer it for myself (and others who’s lookin for an answer):

The method public void handleAction(Action action, Object sender, Object target) {} returns many different objects as ‘target’, depending on what was clicked.

In my case - if I’ll click on existing event - the CalendarEvent object will be returned. If I’ll click on an empty space - Date object will be returned as ‘target’, containing current (clicked) date.

For me this code works:

if (action == addEvent) {
                    if(target instanceof Date) {
                        System.out.println(((Date) target).toString()); //clicked date
                    } else if(target instanceof CalendarEvent) {
                        //Nothing to do
                    }
}