|
Re: [Solved] MultiPageEditor with multiple Diagrams from same Resource [message #900742 is a reply to message #900564] |
Wed, 08 August 2012 07:20   |
Eclipse User |
|
|
|
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.25750 seconds