Search in sources :

Example 1 with MenuNode

use of de.metas.ui.web.menu.MenuNode in project metasfresh-webui-api by metasfresh.

the class JSONMenuNode method ofPath.

public static final JSONMenuNode ofPath(final List<MenuNode> path, final boolean skipRootNode, final boolean includeLastNode, final MenuNodeFavoriteProvider menuNodeFavoriteProvider) {
    if (path == null || path.isEmpty()) {
        throw new AdempiereException("Empty path is not valid");
    } else if (path.size() == 1) {
        final MenuNode node = path.get(0);
        final boolean favorite = menuNodeFavoriteProvider.isFavorite(node);
        final JSONMenuNode jsonChildNode = null;
        return new JSONMenuNode(node, favorite, jsonChildNode);
    }
    int lastIndex = path.size() - 1;
    if (!includeLastNode) {
        lastIndex--;
    }
    JSONMenuNode jsonChildNode = null;
    for (int i = lastIndex; i >= 0; i--) {
        final MenuNode node = path.get(i);
        if (node.isRoot()) {
            continue;
        }
        final boolean favorite = menuNodeFavoriteProvider.isFavorite(node);
        jsonChildNode = new JSONMenuNode(node, favorite, jsonChildNode);
    }
    if (jsonChildNode == null) {
        throw new AdempiereException("Invalid path: " + path);
    }
    return jsonChildNode;
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) MenuNode(de.metas.ui.web.menu.MenuNode)

Example 2 with MenuNode

use of de.metas.ui.web.menu.MenuNode in project metasfresh-webui-api by metasfresh.

the class JSONDocumentReferencesGroupList method of.

public static // 
JSONDocumentReferencesGroupList of(// 
final Collection<DocumentReference> documentReferences, // 
final MenuTree menuTree, // 
final String othersMenuCaption, // 
final JSONOptions jsonOpts) {
    if (documentReferences.isEmpty()) {
        return EMPTY;
    }
    final Map<String, JSONDocumentReferencesGroupBuilder> groupsBuilders = new HashMap<>();
    final String othersGroupId = "_others_" + UUID.randomUUID();
    for (final DocumentReference documentReference : documentReferences) {
        final JSONDocumentReference jsonDocumentReference = JSONDocumentReference.of(documentReference, jsonOpts);
        if (jsonDocumentReference == null) {
            continue;
        }
        final MenuNode topLevelMenuGroup = menuTree.getTopLevelMenuGroupOrNull(documentReference.getWindowId());
        final String topLevelMenuGroupId = topLevelMenuGroup != null ? topLevelMenuGroup.getId() : othersGroupId;
        final JSONDocumentReferencesGroupBuilder groupBuilder = groupsBuilders.computeIfAbsent(topLevelMenuGroupId, k -> {
            final boolean isMiscGroup = topLevelMenuGroup == null;
            final String caption = topLevelMenuGroup != null ? topLevelMenuGroup.getCaption() : othersMenuCaption;
            return JSONDocumentReferencesGroup.builder().caption(caption).isMiscGroup(isMiscGroup);
        });
        groupBuilder.reference(jsonDocumentReference);
    }
    // Sort by Caption, but keep the "misc group" last
    Comparator<JSONDocumentReferencesGroup> sorting = Comparator.<JSONDocumentReferencesGroup>comparingInt(group -> group.isMiscGroup() ? 1 : 0).thenComparing(JSONDocumentReferencesGroup::getCaption);
    final List<JSONDocumentReferencesGroup> groups = groupsBuilders.values().stream().map(groupBuilder -> groupBuilder.build()).filter(group -> !group.isEmpty()).sorted(sorting).collect(ImmutableList.toImmutableList());
    return new JSONDocumentReferencesGroupList(groups);
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) MenuNode(de.metas.ui.web.menu.MenuNode) JSONDocumentReferencesGroupBuilder(de.metas.ui.web.window.datatypes.json.JSONDocumentReferencesGroup.JSONDocumentReferencesGroupBuilder) Collection(java.util.Collection) Visibility(com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility) MoreObjects(com.google.common.base.MoreObjects) HashMap(java.util.HashMap) UUID(java.util.UUID) JsonAutoDetect(com.fasterxml.jackson.annotation.JsonAutoDetect) MenuTree(de.metas.ui.web.menu.MenuTree) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator) DocumentReference(de.metas.ui.web.window.model.DocumentReference) Comparator(java.util.Comparator) HashMap(java.util.HashMap) JSONDocumentReferencesGroupBuilder(de.metas.ui.web.window.datatypes.json.JSONDocumentReferencesGroup.JSONDocumentReferencesGroupBuilder) MenuNode(de.metas.ui.web.menu.MenuNode) DocumentReference(de.metas.ui.web.window.model.DocumentReference)

Aggregations

MenuNode (de.metas.ui.web.menu.MenuNode)2 JsonAutoDetect (com.fasterxml.jackson.annotation.JsonAutoDetect)1 Visibility (com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility)1 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 MoreObjects (com.google.common.base.MoreObjects)1 ImmutableList (com.google.common.collect.ImmutableList)1 MenuTree (de.metas.ui.web.menu.MenuTree)1 JSONDocumentReferencesGroupBuilder (de.metas.ui.web.window.datatypes.json.JSONDocumentReferencesGroup.JSONDocumentReferencesGroupBuilder)1 DocumentReference (de.metas.ui.web.window.model.DocumentReference)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1