calendar action handler

Hi,

I prepared a contextmenu for my calendar using an actionhandler, but the actions order always change!

this is my function:

private voi prepareContextMenu() {
Action.Handler actionHandler = new Action.Handler() {
// private static final long serialVersionUID = 2122177837743583633L;

        Action apriAction = new Action("Apri");
        Action nuovoAction = new Action("Nuovo");
        Action copiaAction = new Action("Copia");
        Action incollaAction = new Action("Incolla");
        Action tagliaAction = new Action("Taglia");

        public Action[] getActions(Object target, Object sender) {
        	
            if (! (target instanceof CalendarDateRange))
                return null;
            CalendarDateRange dateRange = (CalendarDateRange) target;

            if (! (sender instanceof Calendar))
                return null;
            
            return new Action[] { apriAction, nuovoAction, copiaAction, incollaAction, tagliaAction };
        }

        public void handleAction(Action action, Object sender, Object target) {
            
            Calendar calendar = (Calendar) sender;


            if(action == apriAction)
            {
            	...
            }
            else if(action == nuovoAction)
            {
            	..

            }
            else if(action == copiaAction)
            {
            	...
            }
            else if(action == tagliaAction)
            {
            	...
            }
            else if(action == incollaAction)
            {
                   ...
            }
        }
    };
    
    cal.addActionHandler(actionHandler);

}

How can I solve the problem?

Thanks

Hi,

I quickly looked at Calendar sources and it seems to use HashMaps to build action list. That’s a bad idea :mad: Would you fill a ticket to dev.vaadin.com about the issue?

cheers,
matti

Hi Matti,

Thanks for the answer.

I looked the calendar source too and I solved the problem replacing the HashMap with a LinkedHashMap!

Regards,

Stefano

Hi,

Cool, dare to share a patch (preferably to a ticket @ dev.vaadin.com) ?

cheers,
matti

Hi,

I’ll create a ticket! :slight_smile:

cheers,

Stefano