org.eclipse.xtext.ui.editor
Class DirtyStateManager

java.lang.Object
  extended by org.eclipse.xtext.resource.impl.AbstractResourceDescriptionChangeEventSource
      extended by org.eclipse.xtext.ui.editor.DirtyStateManager
All Implemented Interfaces:
IExternalContentSupport.IExternalContentProvider, IResourceDescription.Event.Source, ISelectable, IDirtyStateManager

public class DirtyStateManager
extends AbstractResourceDescriptionChangeEventSource
implements IDirtyStateManager

Author:
Sebastian Zarnekow - Initial contribution and API

Nested Class Summary
protected static class DirtyStateManager.Event
           
 
Constructor Summary
DirtyStateManager()
           
 
Method Summary
 void announceDirtyStateChanged(IDirtyResource dirtyResource)
          Announce the dirty state of the given resource.
 void discardDirtyState(IDirtyResource dirtyResource)
          Mark the given dirty resource as unmanaged.
 IExternalContentSupport.IExternalContentProvider getActualContentProvider()
          Some use cases may require the latest and most up to date content - mostly in a secured, transactional context such as a rename refactoring.
 java.lang.String getContent(org.eclipse.emf.common.util.URI uri)
          Get the content that will shadow the persistent state.
 IDirtyResource getDirtyResource(org.eclipse.emf.common.util.URI uri)
           
 IResourceDescription getDirtyResourceDescription(org.eclipse.emf.common.util.URI uri)
           
 java.lang.Iterable<IEObjectDescription> getExportedObjects()
           
 java.lang.Iterable<IEObjectDescription> getExportedObjects(org.eclipse.emf.ecore.EClass type, QualifiedName name, boolean ignoreCase)
           
 java.lang.Iterable<IEObjectDescription> getExportedObjectsByObject(org.eclipse.emf.ecore.EObject object)
           
 java.lang.Iterable<IEObjectDescription> getExportedObjectsByType(org.eclipse.emf.ecore.EClass type)
           
 boolean hasContent(org.eclipse.emf.common.util.URI uri)
           
 boolean isEmpty()
          Clients may want to check the selectable to skip its processing in case it is empty.
 boolean manageDirtyState(IDirtyResource dirtyResource)
          Initially try to manage the given resource and its dirty state.
protected  void notifyListeners(IDirtyResource dirtyResource, boolean managed)
           
 
Methods inherited from class org.eclipse.xtext.resource.impl.AbstractResourceDescriptionChangeEventSource
addListener, addListeners, notifyListeners, removeListener, removeListeners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.xtext.resource.IResourceDescription.Event.Source
addListener, removeListener
 

Constructor Detail

DirtyStateManager

public DirtyStateManager()
Method Detail

announceDirtyStateChanged

public void announceDirtyStateChanged(IDirtyResource dirtyResource)
Description copied from interface: IDirtyStateManager
Announce the dirty state of the given resource. Clients should decide on their own when to call this method. The dirty state manager will not refuse any announcement due to incorrect internal state of the resource. Listeners will be notified about the changed dirty state. It is up to the implementor to decide about the actual point in time. Implementations are free to collect various announcement before actually raising an event. Events may be fired in a different thread.

Specified by:
announceDirtyStateChanged in interface IDirtyStateManager

discardDirtyState

public void discardDirtyState(IDirtyResource dirtyResource)
Description copied from interface: IDirtyStateManager
Mark the given dirty resource as unmanaged. This method may be called even if manageDirtyState has not been called before. Another dirty resource with the same URI will not become unmanaged. A call to this method will raise an event.

Specified by:
discardDirtyState in interface IDirtyStateManager
See Also:
IDirtyStateManager.announceDirtyStateChanged(IDirtyResource)

notifyListeners

protected void notifyListeners(IDirtyResource dirtyResource,
                               boolean managed)

manageDirtyState

public boolean manageDirtyState(IDirtyResource dirtyResource)
Description copied from interface: IDirtyStateManager
Initially try to manage the given resource and its dirty state. True will be returned, if the resource with the given URI was not managed before. However clients are free to call IDirtyStateManager.announceDirtyStateChanged(IDirtyResource) even if false was returned. A call to IDirtyStateManager.manageDirtyState(IDirtyResource) does not raise any events.

Specified by:
manageDirtyState in interface IDirtyStateManager
Returns:
true if this resource is the first one that has been registered for its URI

getDirtyResource

public IDirtyResource getDirtyResource(org.eclipse.emf.common.util.URI uri)

getDirtyResourceDescription

public IResourceDescription getDirtyResourceDescription(org.eclipse.emf.common.util.URI uri)
Specified by:
getDirtyResourceDescription in interface IDirtyStateManager

getContent

public java.lang.String getContent(org.eclipse.emf.common.util.URI uri)
Description copied from interface: IExternalContentSupport.IExternalContentProvider
Get the content that will shadow the persistent state.

Specified by:
getContent in interface IExternalContentSupport.IExternalContentProvider
Returns:
the actual content that should be parsed to load a resource.

getActualContentProvider

public IExternalContentSupport.IExternalContentProvider getActualContentProvider()
Description copied from interface: IExternalContentSupport.IExternalContentProvider
Some use cases may require the latest and most up to date content - mostly in a secured, transactional context such as a rename refactoring.

Specified by:
getActualContentProvider in interface IExternalContentSupport.IExternalContentProvider
Returns:
a view on the content provider that reflects always the latest state.

hasContent

public boolean hasContent(org.eclipse.emf.common.util.URI uri)
Specified by:
hasContent in interface IExternalContentSupport.IExternalContentProvider
Returns:
true if and only if external content should be used instead of the persistent one.

isEmpty

public boolean isEmpty()
Description copied from interface: ISelectable
Clients may want to check the selectable to skip its processing in case it is empty. Implementations should be fast and not require expensive precalculation. Selectable may return false if it is too expensive to compute the actual result.

Specified by:
isEmpty in interface ISelectable
Returns:
true if the selectable does not provide any descriptions.

getExportedObjects

public java.lang.Iterable<IEObjectDescription> getExportedObjects()
Specified by:
getExportedObjects in interface ISelectable
Returns:
all exported elements. May not be null.

getExportedObjects

public java.lang.Iterable<IEObjectDescription> getExportedObjects(org.eclipse.emf.ecore.EClass type,
                                                                  QualifiedName name,
                                                                  boolean ignoreCase)
Specified by:
getExportedObjects in interface ISelectable
Returns:
all elements which match the given qualified name and type. May not be null.

getExportedObjectsByObject

public java.lang.Iterable<IEObjectDescription> getExportedObjectsByObject(org.eclipse.emf.ecore.EObject object)
Specified by:
getExportedObjectsByObject in interface ISelectable
Returns:
all elements which match the given instance. May not be null.

getExportedObjectsByType

public java.lang.Iterable<IEObjectDescription> getExportedObjectsByType(org.eclipse.emf.ecore.EClass type)
Specified by:
getExportedObjectsByType in interface ISelectable
Returns:
all elements which match the given type. May not be null.