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

            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 =
                if (events.size() == 0)
                    return new Action[] {addEvent};
                    return new Action[] {addEvent, editEvent, deleteEvent, markEventPaid, markEventUnPaid};

            public void handleAction(Action action, Object sender, Object target) {
                if (action == addEvent) {
          "Not implemented");
                            null, null);
              "Can't add on an event");*/
                } else if (action == deleteEvent) {
                    if (target instanceof CalendarEvent) {
                        CalendarEvent event = (CalendarEvent) target;
              "Not implemented");
                    } else
              "No event to delete");
                } else if(action == markEventPaid) {
          "Not implemented");
                } else if(action == editEvent) {
          "Not implemented");
                } else if(action == markEventUnPaid)
          "Not implemented");

Any help will be really apreciated :slight_smile:

Thank you in advance,

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