Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Reusing a diagram(Defining a diagram which can be reused in other diagrams)
Reusing a diagram [message #633060] Fri, 15 October 2010 08:51 Go to next message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
Hello,

I am still working on my project which is similar to a electronic logic editor: the user can create blocks on a diagram. Each of these blocks have a specific number and type of inputs and outputs. The user can then link an output to an input using a connector.
There's a specific type of block which is used to reduce complexity of the diagram: a container block which can be double clicked and is opened in a separate diagram.

What I would like to achieve is to be able to reuse such a container. The user would be able to save such a container block in a specific block library. Then later (on the current or another porject), he should be able to load that library which will populate the palette with the blocks that were saved in the library. Then, he should be able to create such a block on another diagram. This mean that the container will be fully recreated with its inputs, outputs and internal blocks and connectors. The graphical aspect of the block should be recerated too: the position of the blocks and ports should be saved and loaded too.

I guess that an option to do something like that would be to save the diagram in a temporary file and store that file in the "library". Then when creating such a block, all the information should be loaded from the file instead of creating an empty block.

Is it a good approach or is there a better approach ? How can I do something like that ?
Thanks for any hints.
Re: Reusing a diagram [message #634556 is a reply to message #633060] Fri, 22 October 2010 08:40 Go to previous messageGo to next message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
Isn't there any way to save/load a sub-diagram on its own ? What I mean with "sub-diagram" is the diagram that opens separately when you double-click on an item with the Open Diagram Behaviour.

It seems to me that it should be to compex to achieve something like that, but I couldn't find a way to do it.

Does anybody have even the slightest hint in which direction I can search ? I really have no clue how to do it.

Thanks.
Re: Reusing a diagram [message #635034 is a reply to message #633060] Mon, 25 October 2010 13:38 Go to previous messageGo to next message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
I've found something that could maybe be the beginning of a possible solution:

		ResourceSet resourceSet = new ResourceSetImpl();

		try {
			URI modelURI = URI.createFileURI(new File("temp.plcopeneditor")
					.getAbsolutePath());
			Resource modelResource = resourceSet.createResource(modelURI);
			modelResource.getContents().add(diagram.getElement());

			modelResource.save(null);

			URI diagramURI = URI.createFileURI(new File(
					"temp.plcopeneditor_diagram").getAbsolutePath());
			Resource diagramResource = resourceSet.createResource(diagramURI);
			diagramResource.getContents().add(diagram);

			diagramResource.save(null);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}


The previous code creates a resource pointing to the file where I want the information stored (in fact two files, one for the model and one for the diagram). However, this has some serious problems right now

I often get an IllegalStateException thrown ("Cannot modify resource set without a write transaction") with the following stack trace:
	at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.assertWriting(TransactionChangeRecorder.java:348)
	at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.appendNotification(TransactionChangeRecorder.java:302)
	at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.processObjectNotification(TransactionChangeRecorder.java:284)
	at org.eclipse.emf.transaction.impl.TransactionChangeRecorder.notifyChanged(TransactionChangeRecorder.java:240)
	at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:380)
	at org.eclipse.emf.common.notify.impl.NotificationImpl.dispatch(NotificationImpl.java:1033)
	at org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUnique(NotifyingListImpl.java:319)
	at org.eclipse.emf.common.util.AbstractEList.add(AbstractEList.java:307)
	at PLCOpenEditor.diagram.custom.ExecutionOrderView.save(ExecutionOrderView.java:167)


When this exception is thrown, the file is not saved. However, sometimes, I don't get an exception and the files are then saved properly.
But, when I switch back to the parent diagram it is asking to reload the model from the file and when the model is reloaded, my container block disappear (in fact, it is removed completely from the model). It is removed from the original file.

I think that all these problems come from the fact that when the resource is created and the model is added to the resource, it modifies the internal resource of the model. Thus, the complete model is now "used" by two different resources.

I also tried to load a container block from such a file but the same kind of problems arise.

Anyway, I'm thinking of changing my approach because I don't find a solution for all these problems. If the user wants to create a new block in a "library" he will in fact create a completely separate diagram (this will be done automatically for him).
He will then be able later to open such a library of blocks which has as a consequence to create a new drawer in the palette and populate it with the names of the blocks in the library. Once he creates such a block, the block will be filled programmatically but the user won't be able to open such a block. So, I don't need to take the graphical information into account, I can simply create a temporary model that will be loaded from the file and extract the information from the model to populate the real model on which the user is working on.
It's not a perfect solution but I have no clue how to do it in another way.
Re: Reusing a diagram [message #642344 is a reply to message #635034] Tue, 30 November 2010 21:22 Go to previous messageGo to next message
Luca Gherardi is currently offline Luca GherardiFriend
Messages: 62
Registered: November 2010
Member
Hi,

I've a similar problem.
Have you found an optimal solution?
I'd like to model my blocks in a separate editor and then drag them into another editor.

Thanks,
Luca
Re: Reusing a diagram [message #644896 is a reply to message #633060] Tue, 14 December 2010 16:33 Go to previous message
emil salageanu is currently offline emil salageanuFriend
Messages: 94
Registered: June 2010
Location: Nice, France
Member
Hi,
This is just to say I'm very interested in the topic. I think that having users create their own patterns and be able to use these patterns from the palette could be an interesting feature for many gmf applications.


Previous Topic:GMF model ported to web browser?
Next Topic:Models in the palette
Goto Forum:
  


Current Time: Thu Mar 28 20:13:05 GMT 2024

Powered by FUDForum. Page generated in 0.04022 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top