Package org.eclipse.emf.workspace
Definition of the API for a transactional editing domain integrated with the
Eclipse Workbench's operation history.
See:
Description
Package org.eclipse.emf.workspace Description
Definition of the API for a transactional editing domain integrated with the
Eclipse Workbench's operation history.
Package Specification
Creating an Editing Domain
The following snippet illustrates the creation of a workbench editing
domain:
// can use any operation history instance
IOperationHistory myHistory = OperationHistoryFactory.getOperationHistory();
TransactionalEditingDomain domain = WorkspaceEditingDomainFactory.INSTANCE.createEditingDomain(myHistory);
ResourceSet rset = domain.getResourceSet();
// could also just let the editing domain get the default history from the history factory
TransactionalEditingDomain domain = WorkspaceEditingDomainFactory.INSTANCE.createEditingDomain();
The same editing domain registry and extension point used for sharing
TransactionalEditingDomain
s can also be used to share workbench editing
domains. Just register an editing domain ID and a factory implementation on the
org.eclipse.emf.transaction.editingDomains
extension point and
use the
TransactionalEditingDomain.Registry
to access
your domain.
Executing Operations
The normal procedure for modifying resources in a workbench editing domain is
to use undoable operations:
IUndoableOperation operation = new AbstractEMFOperation(
domain, "Create Library") {
protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info)
throws ExecutionException {
Resource res = rset.getResource(
URI.createFileURI("/tmp/my.xmi"),
true);
Library library = LibraryFactory.eINSTANCE.createLibrary();
// these modifications require a write transaction in this
// editing domain. The operation provides this transaction
res.getContents().add(library);
library.setName("Main Branch");
}
};
try {
myHistory.execute(operation, new NullProgressMonitor(), null);
} catch (ExecutionException ee) {
getLog().log(ee);
}
Of course, it is just as easy to re-use existing EMF Command
s:
IUndoableOperation operation = new EMFCommandOperation(
domain, new CreateLibraryCommand());
try {
myHistory.execute(operation, new NullProgressMonitor(), null);
} catch (ExecutionException ee) {
getLog().log(ee);
}
// alternatively, the command stack of our editing domain will automatically
// wrap the command in an operation and execute it on the operation history
domain.getCommandStack().execute(new CreateLibraryCommand());
In either case, undoing and redoing operations is as simple as the operation history API
makes it:
// undo
try {
myHistory.undo(myEditorContext, new NullProgressMonitor(), null);
} catch (ExecutionException ee) {
getLog().log(ee);
}
// redo
try {
myHistory.redo(myEditorContext, new NullProgressMonitor(), null);
} catch (ExecutionException ee) {
getLog().log(ee);
}
-
See Also:
-
WorkspaceEditingDomainFactory
,
AbstractEMFOperation
,
CompositeEMFOperation