Search in sources :

Example 6 with AbstractTransactionalCommand

use of org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand in project statecharts by Yakindu.

the class ShadowModelValidationJob method cloneResource.

protected void cloneResource(final IProgressMonitor monitor, final Resource shadowResource) throws ExecutionException {
    final ByteArrayOutputStream bout = new ByteArrayOutputStream();
    AbstractTransactionalCommand cmd = new AbstractTransactionalCommand(TransactionUtil.getEditingDomain(resource), "", null) {

        @Override
        protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
            try {
                XMISaveImpl saver = new XMISaveImpl(new XMIHelperImpl((XMLResource) resource));
                saver.save((XMLResource) resource, bout, Collections.emptyMap());
                bout.flush();
            } catch (Throwable t) {
                return CommandResult.newErrorCommandResult(t.getMessage());
            }
            return CommandResult.newOKCommandResult();
        }
    };
    cmd.execute(monitor, null);
    try {
        shadowResource.load(new ByteArrayInputStream(bout.toByteArray()), Collections.emptyMap());
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) XMIHelperImpl(org.eclipse.emf.ecore.xmi.impl.XMIHelperImpl) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) XMISaveImpl(org.eclipse.emf.ecore.xmi.impl.XMISaveImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) AbstractTransactionalCommand(org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource)

Example 7 with AbstractTransactionalCommand

use of org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand in project statecharts by Yakindu.

the class DefaultValidationJob method relinkModel.

protected void relinkModel(final IProgressMonitor monitor, final AbstractSCTResource eResource) throws ExecutionException {
    AbstractTransactionalCommand cmd = new AbstractTransactionalCommand(TransactionUtil.getEditingDomain(eResource), "", null) {

        @Override
        protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
            eResource.linkSpecificationElements();
            return CommandResult.newOKCommandResult();
        }
    };
    cmd.execute(monitor, null);
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AbstractTransactionalCommand(org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand)

Example 8 with AbstractTransactionalCommand

use of org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand in project Palladio-Editors-Sirius by PalladioSimulator.

the class AllocationCreationWizard method finish.

@Override
protected void finish() {
    Allocation allocation = (Allocation) modelObject;
    Session session = SessionManager.INSTANCE.getSession(modelObject);
    TransactionalEditingDomain domain = session.getTransactionalEditingDomain();
    String fileString = modelURI.toPlatformString(true);
    IPath path = new Path(fileString);
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
    List<IFile> list = new ArrayList<IFile>();
    list.add(file);
    AbstractTransactionalCommand command = new AbstractTransactionalCommand(domain, "Save Allocation model.", list) {

        @Override
        protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
            allocation.setTargetResourceEnvironment_Allocation(resourceEnvironmentSelectorpage.getSelectedResourceEnvironment(session));
            allocation.setSystem_Allocation(systemSelectorPage.getSelectedSystem(session));
            return CommandResult.newOKCommandResult();
        }
    };
    try {
        OperationHistoryFactory.getOperationHistory().execute(command, new NullProgressMonitor(), null);
    } catch (ExecutionException e) {
        System.out.println("Unable to save allocation model.");
        e.printStackTrace();
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IAdaptable(org.eclipse.core.runtime.IAdaptable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) AbstractTransactionalCommand(org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) Allocation(org.palladiosimulator.pcm.allocation.Allocation) ExecutionException(org.eclipse.core.commands.ExecutionException) Session(org.eclipse.sirius.business.api.session.Session)

Example 9 with AbstractTransactionalCommand

use of org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand in project statecharts by Yakindu.

the class AbstractRefactoring method execute.

/**
 * Wraps an {@link AbstractTransactionalCommand} around the refactoring
 * logic.
 */
public void execute() {
    if (!isExecutable()) {
        return;
    }
    AbstractTransactionalCommand refactoringCommand = new AbstractTransactionalCommand(getEditingDomain(), getCommandLabel(), getAffectedFiles()) {

        @Override
        protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
            try {
                executeRefactoring();
            } catch (Exception ex) {
                return CommandResult.newErrorCommandResult(ex);
            }
            return CommandResult.newOKCommandResult();
        }

        @Override
        protected IStatus doUndo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
            if (internalDoUndo())
                return super.doUndo(monitor, info);
            return Status.CANCEL_STATUS;
        }
    };
    executeCommand(refactoringCommand);
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) AbstractTransactionalCommand(org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand) ExecutionException(org.eclipse.core.commands.ExecutionException)

Aggregations

IAdaptable (org.eclipse.core.runtime.IAdaptable)9 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)9 AbstractTransactionalCommand (org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand)9 ExecutionException (org.eclipse.core.commands.ExecutionException)7 IOException (java.io.IOException)4 IFile (org.eclipse.core.resources.IFile)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 CoreException (org.eclipse.core.runtime.CoreException)2 EObject (org.eclipse.emf.ecore.EObject)2 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2 XMLResource (org.eclipse.emf.ecore.xmi.XMLResource)2 Diagram (org.eclipse.gmf.runtime.notation.Diagram)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 LinkedList (java.util.LinkedList)1