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;
}
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);
}
Aggregations