private static void removeUnrelatedMenuItems(Menu menu, DBNNode node) {
        for (MenuItem item : menu.getItems()) {
            Object itemData = item.getData();
            if (itemData instanceof IContributionItem contribution) {
                String id = contribution.getId();
                if (id == null) {
                    continue;
                }
                if (id.startsWith("org.eclipse.debug") || // $NON-NLS-0$
                    id.startsWith("addFromHistoryAction")) { // $NON-NLS-0$
                    item.dispose();
                }
                if (node != null) {
                    IResource resource = node.getAdapter(IResource.class);
                    if ((resource instanceof IFolder || resource instanceof EFSNIOResource) &&
                        (id.startsWith("compareWithMenu") || // $NON-NLS-0$
                            id.startsWith("replaceWithMenu") ||
                            id.startsWith("team.main"))  // $NON-NLS-0$
                    ) {
                        item.dispose();
                    }
                }
            }
        }
    }
Find selected node for specified UI element
@param element ui element
@return node or null
plugins/org.jkiss.dbeaver.ui.navigator/src/org/jkiss/dbeaver/ui/navigator/NavigatorUtils.java