/** {@inheritDoc} */ @Override public void fillContextMenu(IMenuManager menu) { Object selectedElement = resolveSemanticObject(getFirstSelectedElement()); if (selectedElement != null && selectedElement instanceof Diagram) { Diagram diagram = (Diagram) selectedElement; // Get the Editor IPageMngr. It should be Transactional. IPageMngr pageMngr = EditorUtils.getIPageMngr(); // Create Rename Diagram action RenameDiagramAction renameDiagramAction = new RenameDiagramAction(diagram); menu.add(renameDiagramAction); // Create Delete Diagram action OpenDiagramAction openDiagramAction = new OpenDiagramAction(pageMngr, diagram); menu.add(openDiagramAction); // Create Delete Diagram action CloseDiagramAction closeDiagramAction = new CloseDiagramAction(pageMngr, diagram); menu.add(closeDiagramAction); // Create Close all diagrams action // fjcano #287948 :: close all diagrams action CloseAllDiagramsAction closeAllDiagramsAction = new CloseAllDiagramsAction(pageMngr); menu.add(closeAllDiagramsAction); // Create Delete Diagram action DeleteDiagramAction deleteDiagramAction = new DeleteDiagramAction(pageMngr, diagram); menu.add(deleteDiagramAction); // Create Duplicate Diagram action DuplicateDiagramAction duplicateDiagramAction = new DuplicateDiagramAction(pageMngr, diagram); menu.add(duplicateDiagramAction); } }
/** {@inheritDoc} */ @Override public boolean isEnabled() { if (EditorUtils.getMultiDiagramEditor() == null) { return false; } return super.isEnabled(); }
/** * get the editing domain * * @return get the Transaction Editing Domain */ protected TransactionalEditingDomain getEditingDomain() { return EditorUtils.getTransactionalEditingDomain(); }
/** * Check if controlled sub-packages can be correctly updated : - Check if controlled package is * loaded - Change the control strategy if necessary - Report error if the controlled package is * read-only * * @param controlledPackages the controlled sub-packages (may be updated if contains proxies) * @return true if can be updated */ private boolean checkControlledPackagesUpdateable(Set<Package> controlledPackages) { boolean notLoadedPackages = false; StringBuffer notLoadedPackagesList = new StringBuffer(); boolean readOnlyPackages = false; StringBuffer readOnlyPackagesList = new StringBuffer(); // Check if controlled package is loaded for (Iterator<Package> iterator = controlledPackages.iterator(); iterator.hasNext(); ) { Package pack = iterator.next(); EditingDomain domain = EditorUtils.getTransactionalEditingDomain(); if (pack.eIsProxy()) { EObject loadedObject = domain.getResourceSet().getEObject(((InternalEObject) pack).eProxyURI(), true); if (loadedObject != null) { // pack has been reload, replace proxy; controlledPackages.remove(pack); pack = (Package) loadedObject; controlledPackages.add(pack); } } if (pack.eIsProxy()) { notLoadedPackages = true; URI uri = ((InternalEObject) pack).eProxyURI(); String uriLastSeg = uri.lastSegment(); String name = uriLastSeg.substring(0, uriLastSeg.length() - uri.fileExtension().length() - 1); String qualifName = EMFCoreUtil.getQualifiedName(pack.getOwner(), true) .concat("::") .concat(name); // $NON-NLS-1$ notLoadedPackagesList.append(String.format(ENTRY_FORMAT, qualifName)); } else { if (domain instanceof AdapterFactoryEditingDomain) { // reset read-only cache map ((AdapterFactoryEditingDomain) domain).getResourceToReadOnlyMap().clear(); } if (domain.isReadOnly(pack.eResource())) { readOnlyPackages = true; String name = EMFCoreUtil.getQualifiedName(pack, true); readOnlyPackagesList.append(String.format(ENTRY_FORMAT, name)); } } } // Report error if the controlled package is read-only if (readOnlyPackages) { String msg = NLS.bind(Messages.error_readonly, readOnlyPackagesList.toString()); NotificationBuilder notifBuild = NotificationBuilder.createErrorPopup(msg); notifBuild.setHTML(true); notifBuild.run(); return false; } // Change the control strategy if necessary if (notLoadedPackages) { String msg = NLS.bind(Messages.switch_loading_strategy, notLoadedPackagesList.toString()); final BooleanResult stategyChanged = new BooleanResult(); Runnable runStrategySwitch = new Runnable() { public void run() { StrategyChooser.setCurrentStrategy(LOAD_ALL_STRATEGY); stategyChanged.setValue(true); } }; Runnable cancel = new Runnable() { public void run() { stategyChanged.setValue(false); } }; NotificationBuilder notifBuild = NotificationBuilder.createYesNo(msg, runStrategySwitch, cancel); notifBuild.setHTML(true); notifBuild.setAsynchronous(false); notifBuild.run(); if (stategyChanged.getValue()) { // refresh set controlledPackages return checkControlledPackagesUpdateable(controlledPackages); } else { return false; } } return true; }