org.eclipse.graphiti.ui.editor
Class DefaultUpdateBehavior

java.lang.Object
  extended by PlatformObject
      extended by org.eclipse.graphiti.ui.editor.DefaultUpdateBehavior

public class DefaultUpdateBehavior
extends PlatformObject

The default implementation for the IDiagramContainerUI behavior 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; use IDiagramContainerUI#createUpdateBehavior() to return the instance that shall be used.
Note that there is always a 1:1 relation with a IDiagramContainerUI.

Since:
0.9

Nested Class Summary
protected  class DefaultUpdateBehavior.DefaultUpdateAdapter
          The default implementation of the update adapter that cares about refreshing the diagram editor in case of resource changes.
 
Field Summary
private  boolean adapterActive
          Flag that indicates if the updateAdapter shall be active or not.
protected  DiagramBehavior diagramBehavior
           
private  TransactionalEditingDomain editingDomain
          The editing domain that is used throughout the DiagramBehavior is kept here and only here.
private  ElementDeleteListener elementDeleteListener
          Closes editor if model object is deleted.
private  boolean resourceChanged
          Is toggled by updateAdapter.
private  boolean resourceDeleted
          Is toggled by updateAdapter.
private  ResourceSetUpdateAdapter resourceSetUpdateAdapter
          This resource set update adapter is added to the ResourceSet of the TransactionalEditingDomain.
private  Adapter updateAdapter
          Stores the update adapter that cares about refreshing the diagram editor in case of resource changes.
private  WorkspaceSynchronizer workspaceSynchronizer
           
 
Constructor Summary
DefaultUpdateBehavior(DiagramBehavior diagramBehavior)
          Creates a new DefaultUpdateBehavior instance associated with the given DiagramBehavior.
 
Method Summary
protected  void closeContainer()
          Closes the IDiagramContainerUI (usually a diagram Editor) behind this DefaultUpdateBehavior instance.
protected  void createEditingDomain(IDiagramEditorInput input)
          Created the TransactionalEditingDomain that shall be used within the diagram editor and initializes it by delegating to initializeEditingDomain(TransactionalEditingDomain).
protected  Adapter createUpdateAdapter()
          Hook to create an updateAdapter that cares about updating the diagram editor.
protected  WorkspaceSynchronizer.Delegate createWorkspaceSynchronizerDelegate()
          Can be overridden to return a client specific implementation of a WorkspaceSynchronizer Delegate object.
 void dispose()
          Disposes this DefaultUpdateBehavior and free all resources it holds.
protected  void disposeEditingDomain()
          Cares about disposing the TransactionalEditingDomain held in this instance.
 TransactionalEditingDomain getEditingDomain()
          This returns the editing domain as required by the IEditingDomainProvider interface.
protected  IOperationHistory getOperationHistory()
          Returns the IOperationHistory for the command stack.
private  Shell getShell()
           
protected  Adapter getUpdateAdapter()
          Returns the updateAdapter of this instance or null in case the adapter has not yet been initialized.
 void handleActivate()
          Handles activation of the editor.
protected  void handleChangedResources()
          Handles what to do with changed resources on editor activation.
protected  boolean handleDirtyConflict()
          Shows a dialog that asks if conflicting changes should be discarded or not.
 void historyNotification(OperationHistoryEvent event)
          Is called by the operation history of the TransactionalEditingDomain in case the history changes.
 void init()
          Initializes listeners and adapters.
protected  void initializeEditingDomain(TransactionalEditingDomain domain)
          This sets up the editing domain for this model editor.
protected  boolean isAdapterActive()
          Returns the flag that indicates if the updateAdapter shall be active of not (adapterActive).
protected  boolean isResourceChanged()
          Returns the flag that indicates if the underlying resource of the Diagram has been changed.
protected  boolean isResourceDeleted()
          Returns the flag that indicates if the underlying resource of the Diagram has been deleted.
 void setAdapterActive(boolean active)
          Sets the flag that indicates if the updateAdapter shall be active of not (adapterActive).
 void setEditingDomain(TransactionalEditingDomain editingDomain)
           
 void setResourceChanged(boolean resourceChanged)
          Sets the flag that indicates if the underlying resource of the Diagram has been changed.
 void setResourceDeleted(boolean resourceDeleted)
          Sets the flag that indicates if the underlying resource of the Diagram has been deleted.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

diagramBehavior

protected final DiagramBehavior diagramBehavior
Since:
0.10

editingDomain

private TransactionalEditingDomain editingDomain
The editing domain that is used throughout the DiagramBehavior is kept here and only here.


elementDeleteListener

private ElementDeleteListener elementDeleteListener
Closes editor if model object is deleted.


resourceSetUpdateAdapter

private ResourceSetUpdateAdapter resourceSetUpdateAdapter
This resource set update adapter is added to the ResourceSet of the TransactionalEditingDomain. When notified, the resource set adapter adds the passed adapter (the updateAdapter instance held in DefaultUpdateBehavior) to the adapters of a newly added Resource in the ResourceSet or removes the adapter from a removed resource.

See Also:
initializeEditingDomain(TransactionalEditingDomain)

resourceDeleted

private boolean resourceDeleted
Is toggled by updateAdapter.


resourceChanged

private boolean resourceChanged
Is toggled by updateAdapter.


workspaceSynchronizer

private WorkspaceSynchronizer workspaceSynchronizer

adapterActive

private boolean adapterActive
Flag that indicates if the updateAdapter shall be active or not. It may be deactivated when mass operations (e.g. saving the diagram editor with all its resources) take place. Use the methods isAdapterActive() and setAdapterActive(boolean) to access this field.


updateAdapter

private Adapter updateAdapter
Stores the update adapter that cares about refreshing the diagram editor in case of resource changes. May be disabled by overriding isAdapterActive() and returning false. The instance will be created in the initializeEditingDomain(TransactionalEditingDomain) method and can be exchanged with an own implementation by overriding createUpdateAdapter().

See Also:
init(), initializeEditingDomain(TransactionalEditingDomain)
Constructor Detail

DefaultUpdateBehavior

public DefaultUpdateBehavior(DiagramBehavior diagramBehavior)
Creates a new DefaultUpdateBehavior instance associated with the given DiagramBehavior.

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 the Diagram has been deleted. Note that this flag will only be updated in case the updateAdapter is enabled, see adapterActive, isAdapterActive() and setAdapterActive(boolean). If this flag is set the editor will close on receiving the next event.

Returns:
true in case the resource has been deleted, false otherwise

setResourceDeleted

public void setResourceDeleted(boolean resourceDeleted)
Sets the flag that indicates if the underlying resource of the Diagram has been deleted. Note that this flag should only be updated by the updateAdapter, see adapterActive, isAdapterActive() and setAdapterActive(boolean).

Should not be called by external clients.

Parameters:
resourceDeleted - the value to set the flag to, true indicates that the resource has been deleted.

isResourceChanged

protected boolean isResourceChanged()
Returns the flag that indicates if the underlying resource of the Diagram has been changed. Note that this flag will only be updated in case the updateAdapter is enabled, see adapterActive, isAdapterActive() and setAdapterActive(boolean).

Returns:
true in case the resource has been changed, false otherwise

setResourceChanged

public void setResourceChanged(boolean resourceChanged)
Sets the flag that indicates if the underlying resource of the Diagram has been changed. Note that this flag should only be updated by the updateAdapter, see adapterActive, isAdapterActive() and setAdapterActive(boolean).

Should not be called by external clients.

Parameters:
resourceChanged - the value to set the flag to, true indicates that the resource has been changed.

handleActivate

public void handleActivate()
Handles activation of the editor. In case of the underlying diagram resource being deleted (resourceDeleted is true) the editor will be closed after a call to handleDirtyConflict() that returns true. Also it will call handleChangedResources() in case the underlying diagram resource has changed (resourceChanged is true).


isAdapterActive

protected boolean isAdapterActive()
Returns the flag that indicates if the updateAdapter shall be active of not (adapterActive). In case this method returns false, the updateAdapter will do nothing on being called.

Returns:
true in case the adapter shall run, false otherwise.

setAdapterActive

public void setAdapterActive(boolean active)
Sets the flag that indicates if the updateAdapter shall 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. See handleActivate().

Returns:
true in case the editor shall be closed, false otherwise

getEditingDomain

public TransactionalEditingDomain getEditingDomain()
This returns the editing domain as required by the IEditingDomainProvider interface.

Returns:
The TransactionalEditingDomain that is used within this editor

init

public void init()
Initializes listeners and adapters.


createUpdateAdapter

protected Adapter createUpdateAdapter()
Hook to create an updateAdapter that cares about updating the diagram editor. The default implementation simply creates a DefaultUpdateBehavior.DefaultUpdateAdapter.

Returns:
The newly created adapter
Since:
0.11

getUpdateAdapter

protected Adapter getUpdateAdapter()
Returns the updateAdapter of this instance or null in case the adapter has not yet been initialized.

Returns:
Since:
0.11

createEditingDomain

protected void createEditingDomain(IDiagramEditorInput input)
Created the TransactionalEditingDomain that shall be used within the diagram editor and initializes it by delegating to initializeEditingDomain(TransactionalEditingDomain).

Parameters:
input - The IDiagramEditorInput instance that was used to open the IDiagramContainer.
Since:
0.11

initializeEditingDomain

protected void initializeEditingDomain(TransactionalEditingDomain domain)
This sets up the editing domain for this model editor.

Parameters:
domain - The TransactionalEditingDomain that is used within this model editor

createWorkspaceSynchronizerDelegate

protected WorkspaceSynchronizer.Delegate createWorkspaceSynchronizerDelegate()
Can be overridden to return a client specific implementation of a WorkspaceSynchronizer Delegate object. 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 no WorkspaceSynchronizer will be installed.
Since:
0.10

dispose

public void dispose()
Disposes this DefaultUpdateBehavior and free all resources it holds. In case you only want to omit or influence the disposal of the TransactionalEditingDomain, you can also override disposeEditingDomain().


disposeEditingDomain

protected void disposeEditingDomain()
Cares about disposing the TransactionalEditingDomain held in this instance. Is called during the dispose() method.


historyNotification

public void historyNotification(OperationHistoryEvent event)
Is called by the operation history of the TransactionalEditingDomain in case the history changes. Reacts on undo and redo events and updates the dirty state of the editor.

Parameters:
event - the OperationHistoryEvent to react upon

getShell

private Shell getShell()

closeContainer

protected void closeContainer()
Closes the IDiagramContainerUI (usually a diagram Editor) behind this DefaultUpdateBehavior instance. Called e.g. when the diagram resource underneath the editor has been deleted.

Since:
0.11

getOperationHistory

protected IOperationHistory getOperationHistory()
Returns the IOperationHistory for the command stack. The default implementation retrieves the command stack of the current TransactionalEditingDomain and returns its operation history.

Returns:
The operation history
Since:
0.11

setEditingDomain

public void setEditingDomain(TransactionalEditingDomain editingDomain)
Since:
0.10


Copyright (c) SAP AG 2005, 2012.