package no.kantega.publishing.api.ui;

import java.util.Collections;
import java.util.List;

/**
 *
 */
public class UIContributionAdapter implements UIContribution {

    /**
     * {@inheritDoc}
     */
    public List<MenuItem> getRootMenuItems() {
        return Collections.emptyList();
    }

    /**
     * {@inheritDoc}
     */
    public List<MenuItem> getAdminMenuItems() {
        return Collections.emptyList();
    }
}

package no.kantega.publishing.api.ui;

import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 *
 */
public class UIContributionAdapter implements UIContribution {

    private final List<MenuItem> adminMenuItems = new ArrayList<MenuItem>();

    @Autowired
    private UIServices uiServices;

    /**
     * {@inheritDoc}
     */
    public List<MenuItem> getRootMenuItems() {
        return Collections.emptyList();
    }

    /**
     * {@inheritDoc}
     */
    public List<MenuItem> getAdminMenuItems() {
        return adminMenuItems;
    }

    public void setAdminMenuLinkMap(Map<String, Object> adminMenuLinks) {
        MenuItem item = uiServices.createMenu();

        processMenuItem(item, adminMenuLinks);
        adminMenuItems.add(item);
    }

    private void processMenuItem(MenuItem item, Map<String, Object> map) {
        for(String key : map.keySet()) {
            Object dest = map.get(key);
            if(dest instanceof String) {
                item.addLink(key, (String)dest);
            } else if (dest instanceof Map) {
                MenuItem subitem = item.addChildMenuItem(key);
                processMenuItem(subitem, (Map<String, Object>) dest);
            } else {
                throw new IllegalArgumentException("Map key " +key +" maps to illegal type " + dest.getClass().getName());
            }
        }
    }
}

Add support for declaring admin menus directly in spring.xml without creating a class
Add support for declaring admin menus directly in spring.xml without creating a class

git-svn-id: 8def386c603904b39326d3fc08add479b8279298@3699 fd808399-8219-4f14-9d4c-37719d9ec93d
