Search in sources :

Example 1 with ICalendarContextMenu

use of org.eclipse.scout.rt.client.ui.action.menu.root.ICalendarContextMenu in project scout.rt by eclipse.

the class AbstractCalendar method initConfig.

protected void initConfig() {
    m_uiFacade = BEANS.get(ModelContextProxy.class).newProxy(new P_UIFacade(), ModelContext.copyCurrent());
    m_contributionHolder = new ContributionComposite(this);
    setTitle(getConfiguredTitle());
    setSelectedDate(new Date());
    setStartHour(getConfiguredStartHour());
    setEndHour(getConfiguredEndHour());
    setUseOverflowCells(getConfiguredUseOverflowCells());
    setShowDisplayModeSelection(getConfiguredShowDisplayModeSelection());
    setMarkNoonHour(getConfiguredMarkNoonHour());
    setMarkOutOfMonthDays(getConfiguredMarkOutOfMonthDays());
    // menus
    List<Class<? extends IMenu>> declaredMenus = getDeclaredMenus();
    OrderedCollection<IMenu> menus = new OrderedCollection<IMenu>();
    for (Class<? extends IMenu> menuClazz : declaredMenus) {
        IMenu menu = ConfigurationUtility.newInnerInstance(this, menuClazz);
        menus.addOrdered(menu);
    }
    List<IMenu> contributedMenus = m_contributionHolder.getContributionsByClass(IMenu.class);
    menus.addAllOrdered(contributedMenus);
    // producers
    List<Class<? extends ICalendarItemProvider>> configuredProducers = getConfiguredProducers();
    List<ICalendarItemProvider> contributedProducers = m_contributionHolder.getContributionsByClass(ICalendarItemProvider.class);
    List<ICalendarItemProvider> producerList = new ArrayList<ICalendarItemProvider>(configuredProducers.size() + contributedProducers.size());
    for (Class<? extends ICalendarItemProvider> itemProviderClazz : configuredProducers) {
        try {
            ICalendarItemProvider provider = ConfigurationUtility.newInnerInstance(this, itemProviderClazz);
            producerList.add(provider);
            // add empty space menus to the context menu
            menus.addAllOrdered(ActionUtility.getActions(provider.getMenus(), ActionUtility.createMenuFilterMenuTypes(CollectionUtility.hashSet(CalendarMenuType.EmptySpace), false)));
        } catch (Exception e) {
            BEANS.get(ExceptionHandler.class).handle(new ProcessingException("error creating instance of class '" + itemProviderClazz.getName() + "'.", e));
        }
    }
    producerList.addAll(contributedProducers);
    m_providers = producerList;
    try {
        injectMenusInternal(menus);
    } catch (Exception e) {
        LOG.error("error occured while dynamically contributing menus.", e);
    }
    new MoveActionNodesHandler<IMenu>(menus).moveModelObjects();
    ICalendarContextMenu contextMenu = new CalendarContextMenu(this, menus.getOrderedList());
    setContextMenu(contextMenu);
    // attach change listener for item updates
    for (final ICalendarItemProvider p : m_providers) {
        p.addPropertyChangeListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent e) {
                if (e.getPropertyName().equals(ICalendarItemProvider.PROP_ITEMS)) {
                    List<ICalendarItemProvider> modified = new ArrayList<ICalendarItemProvider>(1);
                    modified.add(p);
                    updateComponentsInternal(modified);
                } else if (e.getPropertyName().equals(ICalendarItemProvider.PROP_LOAD_IN_PROGRESS)) {
                    updateLoadInProgressInternal();
                }
            }
        });
    }
}
Also used : PropertyChangeListener(java.beans.PropertyChangeListener) ArrayList(java.util.ArrayList) EventListenerList(org.eclipse.scout.rt.platform.util.EventListenerList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) IMenu(org.eclipse.scout.rt.client.ui.action.menu.IMenu) PropertyChangeEvent(java.beans.PropertyChangeEvent) ContributionComposite(org.eclipse.scout.rt.shared.extension.ContributionComposite) OrderedCollection(org.eclipse.scout.rt.platform.util.collection.OrderedCollection) ICalendarItemProvider(org.eclipse.scout.rt.client.ui.basic.calendar.provider.ICalendarItemProvider) ICalendarContextMenu(org.eclipse.scout.rt.client.ui.action.menu.root.ICalendarContextMenu) Date(java.util.Date) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) CalendarContextMenu(org.eclipse.scout.rt.client.ui.action.menu.root.internal.CalendarContextMenu) ICalendarContextMenu(org.eclipse.scout.rt.client.ui.action.menu.root.ICalendarContextMenu)

Aggregations

PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 IMenu (org.eclipse.scout.rt.client.ui.action.menu.IMenu)1 ICalendarContextMenu (org.eclipse.scout.rt.client.ui.action.menu.root.ICalendarContextMenu)1 CalendarContextMenu (org.eclipse.scout.rt.client.ui.action.menu.root.internal.CalendarContextMenu)1 ICalendarItemProvider (org.eclipse.scout.rt.client.ui.basic.calendar.provider.ICalendarItemProvider)1 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)1 EventListenerList (org.eclipse.scout.rt.platform.util.EventListenerList)1 OrderedCollection (org.eclipse.scout.rt.platform.util.collection.OrderedCollection)1 ContributionComposite (org.eclipse.scout.rt.shared.extension.ContributionComposite)1