Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Eclipse EMF Model Transaction Development Guide
Previous Page Home Next Page


Package org.eclipse.emf.workspace

Definition of the API for a transactional editing domain integrated with the Eclipse Workbench's operation history.

See:
           Description

Interface Summary
IResourceUndoContextPolicy A rule determining the resources for which an IUndoableOperation should be tagged with ResourceUndoContexts.
IWorkspaceCommandStack A specialized transactional command stack that delegates the execution of commands to an IOperationHistory.
 

Class Summary
AbstractEMFOperation An abstract superclass for IUndoableOperations that modify EMF models.
AbstractResourceUndoContextPolicy The default implementation of the resource undo-context policy, suitable for clients to extend/override as required.
CompositeEMFOperation An implementation of a composite undoable operation for composition of operations which may include AbstractEMFOperations.
EMFCommandOperation An operation that wraps an EMF Command to execute it in a read/write transaction on an IOperationHistory.
EMFOperationCommand An implementation of the EMF Command API that wraps an IUndoableOperation.
ResourceUndoContext An IUndoContext that tags an EMF operation with a resource affected by it.
WorkspaceEditingDomainFactory Factory for creating transactional editing domains that delegate command execution, undo, and redo to an IOperationHistory.
 

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 TransactionalEditingDomains 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 Commands:

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

Copyright 2002, 2007 IBM Corporation and others.
All Rights Reserved.


 
 
  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire