|
Re: Customized Editing Domain for Diagram Editor [message #778129 is a reply to message #766019] |
Wed, 11 January 2012 12:59 |
Veit Hoffmann Messages: 20 Registered: July 2009 |
Junior Member |
|
|
Am 15.12.2011 05:42, schrieb Kunal:
> I wish to use a shared Transactional Editing Domain for Diagram Editor
> of Graphiti. The editing domain is created by external component like
> project explorer view. Now when a new diagram is opened for the first
> time, it works fine since I have overridden its init method to pass
> DiagramInput with my own editing domain.
Hi, I had the same problem too. I have an editor with several
DrillDownFeatures that open diagrams on subelements of the model. E.g. a
use case diagram that contains activity-diagrams within the use cases.
All these Editors habe to share the same EditingDomain to prevent merge
conflicts in the Buisinessmodel-Resource.
I implemented this by overwriting the DrilldownFeature like this
MyDrillDownFeature extends AbstractDrillDownFeature {
...
@Override
protected void openDiagramEditor(Diagram diagram) {
// Found a diagram to open
String diagramTypeProviderId =
GraphitiUi.getExtensionManager().getDiagramTypeProviderId(diagram.getDiagramTypeId());
GraphitiUiInternal.getWorkbenchService().openDiagramEditor(diagram,
getTransActionalEditingDomainForNewDiagram(),
diagramTypeProviderId, getDiagramEditorId(diagram), false);
// here the last parameters prevents the disposal of the editing domain
on close
}
@Override
protected TransactionalEditingDomain
getTransActionalEditingDomainForNewDiagram() {
// share the editing domain
return getDiagramEditor().getEditingDomain();
}
}
However this approach assumes that the "parent"-Editor -in the example
the use case editor- is closed last. Else you will run into the same
problem because the "parent"-Editor disposes the EditingDomain by default.
You could work around this by forcing this editor also not dispose the
editing domain.
E.g. by overwriting the setInput method of the editor like this:
@Override
protected void setInput(IEditorInput input) {
if (input instanceof DiagramEditorInput) {
super.setInput(DiagramEditorInput.createEditorInput(
diagramEditorInput.getDiagram(),
(TransactionalEditingDomain)
diagramEditorInput.getAdapter(TransactionalEditingDomain.class);
initializeEditingDomain(adapter);,
diagramEditorInput.getProviderId(), false));
}
super.setInput(input);
}
But in this case you need to handle the disposal of the EditingDomain
when the last Editor is closed by hand. E.g. with a Singleton that keeps
track of registered editors or by subclassing TransactionalEditingDomain.
If you want to keep one editing domain open the whole time while your
application is running you can also use the second approach too.
Cheers Veit
|
|
|
|
Powered by
FUDForum. Page generated in 0.03198 seconds