@Override
    public <DOC extends DocumentProperty & HasMainInterface>
    Optional<ContextMenu> createContextMenu(TreeCell<DocumentProperty> treeCell,
                                            DOC doc) {
        requireNonNulls(treeCell, doc);

        @SuppressWarnings("unchecked")
        final List<ContextMenuBuilder<DOC>> builders =
            MapStream.of(contextMenuBuilders)
                .filterKey(clazz -> clazz.isAssignableFrom(doc.getClass()))
                .values()
                .flatMap(List::stream)
                .map(builder -> (ContextMenuBuilder<DOC>) builder)
                .collect(toList());

        final ContextMenu menu = new ContextMenu();
        for (int i = 0; i < builders.size(); i++) {
            final List<MenuItem> items = builders.get(i)
                .build(treeCell, doc)
                .collect(toList());

            if (i > 0 && !items.isEmpty()) {
                menu.getItems().add(new SeparatorMenuItem());
            }

            items.forEach(menu.getItems()::add);
        }

        if (menu.getItems().isEmpty()) {
            return Optional.empty();
        } else {
            return Optional.of(menu);
        }
    }
This class is intended to be dependency injected. This constructor should
therefore not be invoked directly.
tool-parent/tool-actions/src/main/java/com/speedment/tool/actions/internal/ProjectTreeComponentImpl.java