[Solved] MultiPageEditor with multiple Diagrams from same Resource [message #900564] |
Tue, 07 August 2012 14:47 |
|
Hi all,
I'm trying to create a MultiPageEditor such that all pages represent different views of the same underlying Resource. It seems to me that in this situation, the ResourceSet and editing domain need to be shared among all of the DiagramEditors (yes? no?)
I've gotten as far as successfully creating the additional pages (DiagramEditors) and have overridded DefaultUpdateBehavior so the ResourceSet and editing domain are shared, but I'm unable to execute any transactions in the cloned DesignEditors - I keep getting the mysterious "Cannot modify resource set without a write transaction" exception as soon as I try a diagram.setActive(true) from the cloned DiagramEditor.
At this point I'm not even worried about disposing the pages, and I expect this to be another can of worms for now I'd be happy to just get the first part working.
Thanks!
Bob
[Updated on: Wed, 08 August 2012 11:03] Report message to a moderator
|
|
|
Re: [Solved] MultiPageEditor with multiple Diagrams from same Resource [message #900742 is a reply to message #900564] |
Wed, 08 August 2012 11:20 |
|
OK, so after much gnashing of teeth, I've figured this one out: don't create new DiagramEditors for each page, just change the content in the one-and-only editor (duh!).
Here's how I did it:
1. the MultiPageEditor keeps track of the business objects for each of its pages; when a page change happens, it simply tells the editor which BO to display
2. to add a new page, the MPE creates a new business object and sends that to the DiagramEditor. The new BO can also be created by the DiagramEditor itself and the MultiPageEditor can just use a ResourceSetListener to watch for these types of events (which is what I chose to do)
Here's the code to handle the business object change. In this scenario the business object is a BPMNDiagram and has already been created and added to the domain model; we just need to either create a new Graphiti Diagram object, or select one that has already been linked with the business object:
public void setBpmnDiagram(final BPMNDiagram bpmnDiagram) {
// do we need to create a new Diagram or is this already in the Graphiti model?
Diagram oldDiagram = null;
Diagram diagram = null;
final Resource resource = getDiagramTypeProvider().getDiagram().eResource();
for (EObject o : resource.getContents()) {
if (o instanceof Diagram) {
Diagram d = (Diagram)o;
EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(d);
if (bo == bpmnDiagram) {
oldDiagram = d;
break;
}
}
}
if (oldDiagram==null) {
// create a new one
String typeId = getDiagramTypeProvider().getDiagram().getDiagramTypeId();
final Diagram newDiagram = Graphiti.getCreateService().createDiagram(typeId, bpmnDiagram.getName(), true);
final IFeatureProvider featureProvider = getDiagramTypeProvider().getFeatureProvider();
TransactionalEditingDomain domain = getEditingDomain();
domain.getCommandStack().execute(new RecordingCommand(domain) {
protected void doExecute() {
resource.getContents().add(newDiagram);
newDiagram.setActive(true);
featureProvider.link(newDiagram, bpmnDiagram);
}
});
diagram = newDiagram;
}
else {
// already there
diagram = oldDiagram;
}
// set the new Diagram in the DTP and refresh graphical viewer
getDiagramTypeProvider().init(diagram, this);
refreshContent();
// remember this for later
this.bpmnDiagram = bpmnDiagram;
}
It seems that you can call getDiagramTypeProvider().init() without any ill effects - "init" is probably just a bad choice of name for a method that just sets the Diagram and DiagramEditor in the provider
|
|
|
|
Powered by
FUDForum. Page generated in 0.03248 seconds