org.eclipse.graphiti.ui.editor

## Class DefaultPersistencyBehavior

- java.lang.Object
- - org.eclipse.graphiti.ui.editor.DefaultPersistencyBehavior

    public class DefaultPersistencyBehavior
    extends Object

The default implementation for the `DiagramBehavior` behavior extension that controls the persistence behavior of the Graphiti diagram Editor. Clients may subclass to change the behavior; use `DiagramBehavior.createPersistencyBehavior()` to return the instance that shall be used.
Note that there is always a 1:1 relation with a `DiagramBehavior`.

Since:
  0.9

### Constructor Summary

Constructors
Constructor and Description
`DefaultPersistencyBehavior(DiagramBehavior diagramBehavior)` Creates a new instance of `DefaultPersistencyBehavior` that is associated with the given `DiagramBehavior`.

### Method Summary

All Methods Instance Methods Concrete Methods
`boolean` `isDirty()` Returns if the editor needs to be saved or not.
`Diagram` `loadDiagram(org.eclipse.emf.common.util.URI uri)` This method is called to load the diagram into the editor.
`void` `saveDiagram(IProgressMonitor monitor)` This method is called to save a diagram.

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### DefaultPersistencyBehavior

    public DefaultPersistencyBehavior(DiagramBehavior diagramBehavior)

Creates a new instance of `DefaultPersistencyBehavior` that is associated with the given `DiagramBehavior`.

Parameters:
  `diagramEditor` - the associated `DiagramBehavior`
Since:
  0.10

### Method Detail

#### loadDiagram

    public Diagram loadDiagram(org.eclipse.emf.common.util.URI uri)

This method is called to load the diagram into the editor. The default implementation here will use the `TransactionalEditingDomain` and its `ResourceSet` to load an EMF `Resource` that holds the `Diagram`. It will also enable modification tracking on the diagram `Resource`.

Parameters:
  `uri` - the `URI` of the diagram to load
Returns:
  the instance of the `Diagram` as it is resolved within the editor, meaning as it is resolved within the editor's `TransactionalEditingDomain`.

#### saveDiagram

    public void saveDiagram(IProgressMonitor monitor)

This method is called to save a diagram. The default implementation here saves all changes done to any of the EMF resources loaded within the `DiagramBehavior` so that the complete state of all modified objects will be persisted in the file system.
The default implementation also sets the current version information (currently 0.14.0) to the diagram before saving it and wraps the save operation inside a `IRunnableWithProgress` that cares about sending only one `Resource` change event holding all modified files. Besides also all adapters are temporarily switched off (see `DiagramBehavior.disableAdapters()`).
To only modify the actual saving clients should rather override `#save(TransactionalEditingDomain, Map)`.

Parameters:
  `monitor` - the Eclipse `IProgressMonitor` to use to report progress

#### isDirty

    public boolean isDirty()

Returns if the editor needs to be saved or not. Is queried by the `DiagramBehavior.isDirty()` method. The default implementation checks if the top of the current undo stack is equal to the stored top command of the undo stack at the time of the last saving of the editor.

Returns:
  `true` in case the editor needs to be saved, `false` otherwise.