Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » [Solved] MultiPageEditor with multiple Diagrams from same Resource
[Solved] MultiPageEditor with multiple Diagrams from same Resource [message #900564] Tue, 07 August 2012 10:47 Go to next message
Robert Brodt is currently offline Robert Brodt
Messages: 589
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

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 Sad for now I'd be happy to just get the first part working.

Thanks!
Bob

[Updated on: Wed, 08 August 2012 07: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 07:20 Go to previous messageGo to next message
Robert Brodt is currently offline Robert Brodt
Messages: 589
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

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 Wink
Re: [Solved] MultiPageEditor with multiple Diagrams from same Resource [message #900776 is a reply to message #900742] Wed, 08 August 2012 09:00 Go to previous message
Matthias Gorning is currently offline Matthias Gorning
Messages: 80
Registered: April 2010
Location: Germany
Member
In my opinion the name for the method init() is a good choice.

You can override this method to add some initialization stuff. That's simply a hook for the developer, after the instances of Diagram and DiagramEditor are available.

BR,
Matthias
Previous Topic:Updating a diagram after saving its business model to database
Next Topic:DefaultRemoveFeature.removeAllConnections() with nested shapes?
Goto Forum:
  


Current Time: Wed Aug 20 08:53:32 EDT 2014

Powered by FUDForum. Page generated in 0.01724 seconds