/* * (non-Javadoc) * * @see org.eclipse.papyrus.commands.ICreationCommand#createDiagram(org.eclipse.emf.ecore.resource.Resource, org.eclipse.emf.ecore.EObject, * org.eclipse.emf.ecore.EObject, org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype, java.lang.String) */ @Override public final Diagram createDiagram( ModelSet modelSet, EObject owner, EObject element, ViewPrototype prototype, String name) { ICommand createCmd = getCreateDiagramCommand(modelSet, owner, element, prototype, name); TransactionalEditingDomain dom = modelSet.getTransactionalEditingDomain(); CompositeCommand cmd = new CompositeCommand("Create diagram"); cmd.add(createCmd); cmd.add(new OpenDiagramCommand(dom, createCmd)); try { IStatus status = CheckedOperationHistory.getInstance().execute(cmd, new NullProgressMonitor(), null); if (status.isOK()) { CommandResult result = cmd.getCommandResult(); Object returnValue = result.getReturnValue(); // CompositeCommands should always return a collection if (returnValue instanceof Collection<?>) { for (Object returnElement : (Collection<?>) returnValue) { if (returnElement instanceof Diagram) { return (Diagram) returnElement; } } } } else if (status.getSeverity() != IStatus.CANCEL) { StatusManager.getManager().handle(status, StatusManager.SHOW); } } catch (ExecutionException ex) { Activator.log.error(ex); } return null; }
public TransactionalEditingDomain createTransactionalEditingDomain(ResourceSet resourceSet) { NotifyingWorkspaceCommandStack stack = new NotifyingWorkspaceCommandStack(CheckedOperationHistory.getInstance()); stack.setResourceUndoContextPolicy(IResourceUndoContextPolicy.DEFAULT); TransactionalEditingDomain result = new PapyrusROTransactionalEditingDomain( new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE), stack, resourceSet); WorkspaceEditingDomainFactory.INSTANCE.mapResourceSet(result); return result; }