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();
}
}
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);
}
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();
}
}
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);
}
Aggregations