Package org.eclipse.graphiti.ui.editor
Class DefaultUpdateBehavior
- java.lang.Object
-
- org.eclipse.core.runtime.PlatformObject
-
- org.eclipse.graphiti.ui.editor.DefaultUpdateBehavior
-
- All Implemented Interfaces:
org.eclipse.core.commands.operations.IOperationHistoryListener,org.eclipse.core.runtime.IAdaptable,org.eclipse.emf.edit.domain.IEditingDomainProvider
public class DefaultUpdateBehavior extends org.eclipse.core.runtime.PlatformObject implements org.eclipse.emf.edit.domain.IEditingDomainProvider, org.eclipse.core.commands.operations.IOperationHistoryListenerThe default implementation for theIDiagramContainerUIbehavior extension that controls update behavior of the editor and defines the EMF adapters that watch over model object modifications. Clients may subclass to change the behavior; useIDiagramContainerUI#createUpdateBehavior()to return the instance that shall be used.
Note that there is always a 1:1 relation with aIDiagramContainerUI.- Since:
- 0.9
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classDefaultUpdateBehavior.DefaultUpdateAdapterThe default implementation of the update adapter that cares about refreshing the diagram editor in case of resource changes.
-
Field Summary
Fields Modifier and Type Field Description protected DiagramBehaviordiagramBehavior
-
Constructor Summary
Constructors Constructor Description DefaultUpdateBehavior(DiagramBehavior diagramBehavior)Creates a newDefaultUpdateBehaviorinstance associated with the givenDiagramBehavior.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcloseContainer()Closes theIDiagramContainerUI(usually a diagram Editor) behind thisDefaultUpdateBehaviorinstance.protected voidcreateEditingDomain(IDiagramEditorInput input)Created theTransactionalEditingDomainthat shall be used within the diagram editor and initializes it by delegating toinitializeEditingDomain(TransactionalEditingDomain).protected org.eclipse.emf.common.notify.AdaptercreateUpdateAdapter()Hook to create anupdateAdapterthat cares about updating the diagram editor.protected org.eclipse.emf.workspace.util.WorkspaceSynchronizer.DelegatecreateWorkspaceSynchronizerDelegate()Can be overridden to return a client specific implementation of aWorkspaceSynchronizerWorkspaceSynchronizer.Delegateobject.voiddispose()Disposes thisDefaultUpdateBehaviorand free all resources it holds.protected voiddisposeEditingDomain()Cares about disposing theTransactionalEditingDomainheld in this instance.org.eclipse.emf.transaction.TransactionalEditingDomaingetEditingDomain()This returns the editing domain as required by theIEditingDomainProviderinterface.protected org.eclipse.core.commands.operations.IOperationHistorygetOperationHistory()Returns theIOperationHistoryfor the command stack.protected org.eclipse.emf.common.notify.AdaptergetUpdateAdapter()Returns theupdateAdapterof this instance ornullin case the adapter has not yet been initialized.voidhandleActivate()Handles activation of the editor.protected voidhandleChangedResources()Handles what to do with changed resources on editor activation.protected booleanhandleDirtyConflict()Shows a dialog that asks if conflicting changes should be discarded or not.voidhistoryNotification(org.eclipse.core.commands.operations.OperationHistoryEvent event)Is called by the operation history of theTransactionalEditingDomainin case the history changes.voidinit()Initializes listeners and adapters.protected voidinitializeEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain domain)This sets up the editing domain for this model editor.protected booleanisAdapterActive()Returns the flag that indicates if theupdateAdaptershall be active of not (adapterActive).protected booleanisResourceChanged()Returns the flag that indicates if the underlying resource of theDiagramhas been changed.protected booleanisResourceDeleted()Returns the flag that indicates if the underlying resource of theDiagramhas been deleted.voidsetAdapterActive(boolean active)Sets the flag that indicates if theupdateAdaptershall be active of not (adapterActive).voidsetEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain editingDomain)voidsetResourceChanged(boolean resourceChanged)Sets the flag that indicates if the underlying resource of theDiagramhas been changed.voidsetResourceDeleted(boolean resourceDeleted)Sets the flag that indicates if the underlying resource of theDiagramhas been deleted.
-
-
-
Field Detail
-
diagramBehavior
protected final DiagramBehavior diagramBehavior
- Since:
- 0.10
-
-
Constructor Detail
-
DefaultUpdateBehavior
public DefaultUpdateBehavior(DiagramBehavior diagramBehavior)
Creates a newDefaultUpdateBehaviorinstance associated with the givenDiagramBehavior.- Parameters:
diagramEditor- the part this model editor works on- Since:
- 0.10
-
-
Method Detail
-
isResourceDeleted
protected boolean isResourceDeleted()
Returns the flag that indicates if the underlying resource of theDiagramhas been deleted. Note that this flag will only be updated in case theupdateAdapteris enabled, seeadapterActive,isAdapterActive()andsetAdapterActive(boolean). If this flag is set the editor will close on receiving the next event.- Returns:
truein case the resource has been deleted,falseotherwise
-
setResourceDeleted
public void setResourceDeleted(boolean resourceDeleted)
Sets the flag that indicates if the underlying resource of theDiagramhas been deleted. Note that this flag should only be updated by theupdateAdapter, seeadapterActive,isAdapterActive()andsetAdapterActive(boolean).Should not be called by external clients.
- Parameters:
resourceDeleted- the value to set the flag to,trueindicates that the resource has been deleted.
-
isResourceChanged
protected boolean isResourceChanged()
Returns the flag that indicates if the underlying resource of theDiagramhas been changed. Note that this flag will only be updated in case theupdateAdapteris enabled, seeadapterActive,isAdapterActive()andsetAdapterActive(boolean).- Returns:
truein case the resource has been changed,falseotherwise
-
setResourceChanged
public void setResourceChanged(boolean resourceChanged)
Sets the flag that indicates if the underlying resource of theDiagramhas been changed. Note that this flag should only be updated by theupdateAdapter, seeadapterActive,isAdapterActive()andsetAdapterActive(boolean).Should not be called by external clients.
- Parameters:
resourceChanged- the value to set the flag to,trueindicates that the resource has been changed.
-
handleActivate
public void handleActivate()
Handles activation of the editor. In case of the underlying diagram resource being deleted (resourceDeletedistrue) the editor will be closed after a call tohandleDirtyConflict()that returnstrue. Also it will callhandleChangedResources()in case the underlying diagram resource has changed (resourceChangedistrue).
-
isAdapterActive
protected boolean isAdapterActive()
Returns the flag that indicates if theupdateAdaptershall be active of not (adapterActive). In case this method returnsfalse, theupdateAdapterwill do nothing on being called.- Returns:
truein case the adapter shall run,falseotherwise.
-
setAdapterActive
public void setAdapterActive(boolean active)
Sets the flag that indicates if theupdateAdaptershall be active of not (adapterActive).- Parameters:
active- the new value for the flag
-
handleChangedResources
protected void handleChangedResources()
Handles what to do with changed resources on editor activation.
-
handleDirtyConflict
protected boolean handleDirtyConflict()
Shows a dialog that asks if conflicting changes should be discarded or not. SeehandleActivate().- Returns:
truein case the editor shall be closed,falseotherwise
-
getEditingDomain
public org.eclipse.emf.transaction.TransactionalEditingDomain getEditingDomain()
This returns the editing domain as required by theIEditingDomainProviderinterface.- Specified by:
getEditingDomainin interfaceorg.eclipse.emf.edit.domain.IEditingDomainProvider- Returns:
- The
TransactionalEditingDomainthat is used within this editor
-
init
public void init()
Initializes listeners and adapters.
-
createUpdateAdapter
protected org.eclipse.emf.common.notify.Adapter createUpdateAdapter()
Hook to create anupdateAdapterthat cares about updating the diagram editor. The default implementation simply creates aDefaultUpdateBehavior.DefaultUpdateAdapter.- Returns:
- The newly created adapter
- Since:
- 0.11
-
getUpdateAdapter
protected org.eclipse.emf.common.notify.Adapter getUpdateAdapter()
Returns theupdateAdapterof this instance ornullin case the adapter has not yet been initialized.- Returns:
- Since:
- 0.11
-
createEditingDomain
protected void createEditingDomain(IDiagramEditorInput input)
Created theTransactionalEditingDomainthat shall be used within the diagram editor and initializes it by delegating toinitializeEditingDomain(TransactionalEditingDomain).- Parameters:
input- TheIDiagramEditorInputinstance that was used to open theIDiagramContainer.- Since:
- 0.11
-
initializeEditingDomain
protected void initializeEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain domain)
This sets up the editing domain for this model editor.- Parameters:
domain- TheTransactionalEditingDomainthat is used within this model editor
-
createWorkspaceSynchronizerDelegate
protected org.eclipse.emf.workspace.util.WorkspaceSynchronizer.Delegate createWorkspaceSynchronizerDelegate()
Can be overridden to return a client specific implementation of aWorkspaceSynchronizerWorkspaceSynchronizer.Delegateobject. Graphiti uses the returned instance to manage and react on changes done to the resources tied to the diagram outside of the diagram editor's TransactionalEditingDomain.- Returns:
- The delegate to use. The default implementation return's
Graphiti's own implementation of such a delegate that should be
sufficient for most client editors. Might return
null; in this case noWorkspaceSynchronizerwill be installed. - Since:
- 0.10
-
dispose
public void dispose()
Disposes thisDefaultUpdateBehaviorand free all resources it holds. In case you only want to omit or influence the disposal of theTransactionalEditingDomain, you can also overridedisposeEditingDomain().
-
disposeEditingDomain
protected void disposeEditingDomain()
Cares about disposing theTransactionalEditingDomainheld in this instance. Is called during thedispose()method.
-
historyNotification
public void historyNotification(org.eclipse.core.commands.operations.OperationHistoryEvent event)
Is called by the operation history of theTransactionalEditingDomainin case the history changes. Reacts on undo and redo events and updates the dirty state of the editor.- Specified by:
historyNotificationin interfaceorg.eclipse.core.commands.operations.IOperationHistoryListener- Parameters:
event- theOperationHistoryEventto react upon
-
closeContainer
protected void closeContainer()
Closes theIDiagramContainerUI(usually a diagram Editor) behind thisDefaultUpdateBehaviorinstance. Called e.g. when the diagram resource underneath the editor has been deleted.- Since:
- 0.11
-
getOperationHistory
protected org.eclipse.core.commands.operations.IOperationHistory getOperationHistory()
Returns theIOperationHistoryfor the command stack. The default implementation retrieves the command stack of the currentTransactionalEditingDomainand returns its operation history.- Returns:
- The operation history
- Since:
- 0.11
-
setEditingDomain
public void setEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain editingDomain)
- Since:
- 0.10
-
-