Package org.eclipse.graphiti.ui.editor
Class DefaultPersistencyBehavior
- java.lang.Object
-
- org.eclipse.graphiti.ui.editor.DefaultPersistencyBehavior
-
public class DefaultPersistencyBehavior extends java.lang.Object
The default implementation for theDiagramBehavior
behavior extension that controls the persistence behavior of the Graphiti diagram Editor. Clients may subclass to change the behavior; useDiagramBehavior.createPersistencyBehavior()
to return the instance that shall be used.
Note that there is always a 1:1 relation with aDiagramBehavior
.- Since:
- 0.9
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
DefaultPersistencyBehavior.SaveException
protected class
DefaultPersistencyBehavior.SaveOperation
The workspace operation used to do the actual save.
-
Field Summary
Fields Modifier and Type Field Description protected DiagramBehavior
diagramBehavior
The associatedDiagramBehavior
protected org.eclipse.emf.common.command.Command
savedCommand
Used to store the command that was executed before the editor was saved.
-
Constructor Summary
Constructors Constructor Description DefaultPersistencyBehavior(DiagramBehavior diagramBehavior)
Creates a new instance ofDefaultPersistencyBehavior
that is associated with the givenDiagramBehavior
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.eclipse.jface.operation.IRunnableWithProgress
createOperation(java.util.Set<org.eclipse.emf.ecore.resource.Resource> savedResources, java.util.Map<org.eclipse.emf.ecore.resource.Resource,java.util.Map<?,?>> saveOptions)
Creates the runnable to be used to wrap the actual saving of the EMFResource
s.
To only modify the actual saving clients should rather override#save(TransactionalEditingDomain, Map)
.protected java.util.Map<org.eclipse.emf.ecore.resource.Resource,java.util.Map<?,?>>
createSaveOptions()
Returns the EMF save options to be used when saving the EMFResource
s.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.protected java.util.Set<org.eclipse.emf.ecore.resource.Resource>
save(org.eclipse.emf.transaction.TransactionalEditingDomain editingDomain, java.util.Map<org.eclipse.emf.ecore.resource.Resource,java.util.Map<?,?>> saveOptions, org.eclipse.core.runtime.IProgressMonitor monitor)
Saves all resources in the givenTransactionalEditingDomain
.void
saveDiagram(org.eclipse.core.runtime.IProgressMonitor monitor)
This method is called to save a diagram.protected void
setDiagramVersion(Diagram diagram)
Called insaveDiagram(IProgressMonitor)
to update the Graphiti diagram version before saving a diagram.protected boolean
shouldSave(org.eclipse.emf.ecore.resource.Resource resource)
Checks whether a resource should be save during the diagram save process.protected void
showSaveError(org.eclipse.core.runtime.IStatus status)
-
-
-
Field Detail
-
diagramBehavior
protected final DiagramBehavior diagramBehavior
The associatedDiagramBehavior
- Since:
- 0.10
-
savedCommand
protected org.eclipse.emf.common.command.Command savedCommand
Used to store the command that was executed before the editor was saved. By comparing with the top of the current undo stack this point in the command stack indicates if the editor is dirty.
-
-
Constructor Detail
-
DefaultPersistencyBehavior
public DefaultPersistencyBehavior(DiagramBehavior diagramBehavior)
Creates a new instance ofDefaultPersistencyBehavior
that is associated with the givenDiagramBehavior
.- Parameters:
diagramEditor
- the associatedDiagramBehavior
- 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 theTransactionalEditingDomain
and itsResourceSet
to load an EMFResource
that holds theDiagram
. It will also enable modification tracking on the diagramResource
.- Parameters:
uri
- theURI
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'sTransactionalEditingDomain
.
-
saveDiagram
public void saveDiagram(org.eclipse.core.runtime.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 theDiagramBehavior
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.19.0) to the diagram before saving it and wraps the save operation inside aIRunnableWithProgress
that cares about sending only oneResource
change event holding all modified files. Besides also all adapters are temporarily switched off (seeDiagramBehavior.disableAdapters()
).
To only modify the actual saving clients should rather override#save(TransactionalEditingDomain, Map)
.- Parameters:
monitor
- the EclipseIProgressMonitor
to use to report progress
-
isDirty
public boolean isDirty()
Returns if the editor needs to be saved or not. Is queried by theDiagramBehavior.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.
-
createSaveOptions
protected java.util.Map<org.eclipse.emf.ecore.resource.Resource,java.util.Map<?,?>> createSaveOptions()
Returns the EMF save options to be used when saving the EMFResource
s.- Returns:
- a
Map
object holding the used EMF save options.
-
createOperation
protected org.eclipse.jface.operation.IRunnableWithProgress createOperation(java.util.Set<org.eclipse.emf.ecore.resource.Resource> savedResources, java.util.Map<org.eclipse.emf.ecore.resource.Resource,java.util.Map<?,?>> saveOptions)
Creates the runnable to be used to wrap the actual saving of the EMFResource
s.
To only modify the actual saving clients should rather override#save(TransactionalEditingDomain, Map)
.- Parameters:
savedResources
- this parameter will after the operation has been performed contain all EMFResource
s that have really been saved.saveOptions
- the EMF save options to use.- Returns:
- an
IRunnableWithProgress
instance wrapping the actual save process.
-
save
protected java.util.Set<org.eclipse.emf.ecore.resource.Resource> save(org.eclipse.emf.transaction.TransactionalEditingDomain editingDomain, java.util.Map<org.eclipse.emf.ecore.resource.Resource,java.util.Map<?,?>> saveOptions, org.eclipse.core.runtime.IProgressMonitor monitor)
Saves all resources in the givenTransactionalEditingDomain
. Can be overridden to enable additional (call the super method to save the EMF resources) or other persistencies.- Parameters:
editingDomain
- theTransactionalEditingDomain
for which all resources will be savedsaveOptions
- the EMF save options used for the saving.monitor
- The progress monitor to use for reporting progress- Returns:
- a
Set
of all EMFResource
s that were actually saved. - Since:
- 0.10 The parameter monitor has been added compared to the 0.9 version of this method
-
setDiagramVersion
protected void setDiagramVersion(Diagram diagram)
Called insaveDiagram(IProgressMonitor)
to update the Graphiti diagram version before saving a diagram. Currently the diagram version is set to 0.19.0- Parameters:
diagram
- theDiagram
to update the version attribute for
-
shouldSave
protected boolean shouldSave(org.eclipse.emf.ecore.resource.Resource resource)
Checks whether a resource should be save during the diagram save process. By default, just passes the check to the editing domain.- Parameters:
resource
- theResource
to check- Returns:
- true if the resource must be saved, i.e., it's not read-only
- Since:
- 0.11
-
showSaveError
protected void showSaveError(org.eclipse.core.runtime.IStatus status)
- Since:
- 0.13
-
-