Source:
private void computeRepresentationContextMenu(IMenuManager menu, final Collection<DRepresentationDescriptor> selectedRepDescriptors, Collection<EObject> selectedEObjects) { if (selectedRepDescriptors == null || selectedEObjects == null) { return; } Session session = null; EObject firstEObject = null; for (DRepresentationDescriptor repDesc : selectedRepDescriptors) { firstEObject = repDesc.getTarget(); if (firstEObject != null) break; } if (firstEObject == null && !selectedEObjects.isEmpty()) { firstEObject = selectedEObjects.iterator().next(); } session = firstEObject == null ? null : SessionManager.INSTANCE.getSession(firstEObject); List<DRepresentationDescriptor> findableRepresentations = selectedRepDescriptors.stream().filter(repDesc -> new DRepresentationDescriptorQuery(repDesc).isFindableRepresentation()) .collect(Collectors.toList()); if (session != null && !findableRepresentations.isEmpty()) { addActionToMenu(menu, GROUP_OPEN, buildOpenRepresentationAction(findableRepresentations)); addActionToMenu(menu, GROUP_REORGANIZE, buildRenameRepresentationAction(findableRepresentations)); addActionToMenu(menu, GROUP_REORGANIZE, buildCopyRepresentationsAction(findableRepresentations, session)); if (session.getAllSessionResources().size() >= 1) { final Collection<Resource> targetResources = new LinkedHashSet<Resource>(session.getAllSessionResources()); final Collection<Resource> originResources = collectOriginResources(findableRepresentations); if (originResources.size() == 1) { targetResources.removeAll(originResources); } if (targetResources.size() > 0) { computeMoveMenu(menu, session, findableRepresentations, targetResources); } addActionToMenu(menu, GROUP_REORGANIZE, buildExtractRepresentationsAction(session, findableRepresentations)); } ExportRepresentationsAction actionExportImage = new ExportRepresentationsAction(session, selectedEObjects, findableRepresentations); addActionToMenu(menu, GROUP_PORT, actionExportImage); } if (!selectedRepDescriptors.isEmpty()) { addActionToMenu(menu, GROUP_EDIT, buildDeleteRepresentationAction(selectedRepDescriptors)); } }

Target:
private void computeRepresentationContextMenu(IMenuManager menu, final Collection<DRepresentationDescriptor> selectedRepDescriptors, Collection<EObject> selectedEObjects) { if (selectedRepDescriptors == null || selectedEObjects == null) { return; } Session session = null; EObject firstEObject = null; for (DRepresentationDescriptor repDesc : selectedRepDescriptors) { firstEObject = repDesc.getTarget(); if (firstEObject != null) break; } if (firstEObject == null && !selectedEObjects.isEmpty()) { firstEObject = selectedEObjects.iterator().next(); } session = firstEObject == null ? null : SessionManager.INSTANCE.getSession(firstEObject); List<DRepresentationDescriptor> reachableRepresentations = selectedRepDescriptors.stream().filter(repDesc -> new DRepresentationDescriptorQuery(repDesc).isRepresentationValid()) .collect(Collectors.toList()); if (session != null && !reachableRepresentations.isEmpty()) { addActionToMenu(menu, GROUP_OPEN, buildOpenRepresentationAction(reachableRepresentations)); addActionToMenu(menu, GROUP_REORGANIZE, buildRenameRepresentationAction(reachableRepresentations)); addActionToMenu(menu, GROUP_REORGANIZE, buildCopyRepresentationsAction(reachableRepresentations, session)); if (session.getAllSessionResources().size() >= 1) { final Collection<Resource> targetResources = new LinkedHashSet<Resource>(session.getAllSessionResources()); final Collection<Resource> originResources = collectOriginResources(reachableRepresentations); if (originResources.size() == 1) { targetResources.removeAll(originResources); } if (targetResources.size() > 0) { computeMoveMenu(menu, session, reachableRepresentations, targetResources); } addActionToMenu(menu, GROUP_REORGANIZE, buildExtractRepresentationsAction(session, reachableRepresentations)); } ExportRepresentationsAction actionExportImage = new ExportRepresentationsAction(session, selectedEObjects, reachableRepresentations); addActionToMenu(menu, GROUP_PORT, actionExportImage); } if (!selectedRepDescriptors.isEmpty()) { addActionToMenu(menu, GROUP_EDIT, buildDeleteRepresentationAction(selectedRepDescriptors)); } }