Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » guidance on creating Resource set and diagram creation
guidance on creating Resource set and diagram creation [message #778814] Fri, 13 January 2012 22:10 Go to next message
Josef Pohl is currently offline Josef PohlFriend
Messages: 82
Registered: January 2012
Member
Hi there,

Well, I found out why my connections were not working yesterday. And it raised an issue that I have been wondering about, namely how to go about creating a resource set that I can add domain objects into. And as an extension how to go about extending the system with contextual features such as "save model to file". I realize that the latter has more to do with plugin-development than Graphiti, but if anyone has any pointers I would be greatly obliged. (Sorry, I am a theory guy who has been thrust into a developer role. Sad... I know. Hence why I don't know anything useful.)

So I revised my model a bit yesterday and came up with a better solution, I think.
Now I have a root element Argument, along with a Node (and Goal, Strategy, ... that inherit from it) and a Link (along with some children as well to represent the different types of references.)

What I would like to do is set Argument as the root node and be able to add in all nodes and links underneath this.

From my perusing the questions and answers there are two ways of going about this.
1. Check, when the first node is added (in Create...Feature) to the diagram, if the resource set is created and the Argument domain element has been created and linked to the diagram. If not do so.

2. Do this when the diagram is first being created.

The second sounds a bit more promising.

So I guess, here is my question, what structure(s) (infrastructure) do I need to have in place so when I implement a createDiagram function it is called whenever a new diagram is opened? And make it so the resource set can be referenced throughout the application? How do I override the default create diagram behavior?

As an extension to that, where would I implement something like SaveEMFModel()? Implementing seems straightforward enough (from the previous questions). I am just not sure of the infrastructure necessary to see that this feature is available.

Thanks, sorry for being long winded.

Joe

Re: guidance on creating Resource set and diagram creation [message #779795 is a reply to message #778814] Mon, 16 January 2012 15:21 Go to previous messageGo to next message
Matthieu Wipliez is currently offline Matthieu WipliezFriend
Messages: 26
Registered: March 2010
Junior Member
Hi Joe,

from my (limited) experience with Graphiti, you don't need to override SaveEMFModel or anything.
Normally you "link" your model with the diagram, and this way when the diagram is saved it automatically saves your model.
In my case, I have a wizard to create a new "network" (in your case that would be a new Argument from what I understand) that looks as shown on the message http://www.eclipse.org/forums/index.php/mv/msg/245609/778612/#msg_778612

As for how to access the resource set, I guess diagram.eResource().getResourceSet() should work fine.
I have found that it is not necessary to override the default behavior (in most cases the defaults work fine).

Does this answer your questions?

Cheers
Matthieu
Re: guidance on creating Resource set and diagram creation [message #779918 is a reply to message #779795] Mon, 16 January 2012 20:23 Go to previous messageGo to next message
Josef Pohl is currently offline Josef PohlFriend
Messages: 82
Registered: January 2012
Member
Hi Matthieu,
Thanks, that makes sense. You are saying that I should have a top level function that creates the link between the diagram and the "Argument". And then the default ResourceSet should be that one. Thanks for the link. I did not put that discussion into context.

I guess to back up one more step though, how does one go about creating this wizard. In the example with the tutorials there is the CreateDiagramWithAllClasses handler. Can this be extended to handle a createDiagram function that would allow me to implement the functionality described on initiation?

Thanks again for your tips!
Joe
Re: guidance on creating Resource set and diagram creation [message #780220 is a reply to message #779918] Tue, 17 January 2012 11:50 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1635
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hi Josef,

actually the CreateDiagramWithAllClassesHandler does exactly this (well it's
done in the AddAllClassesCommand it delegates to). Have a look into this to
see how it creates a diagram. How this coding is triggered is another thing:
in the tutorial it is done as a context menu entry, anotherw ay would be an
Eclipse wizard, see Eclipse extension point org.eclipse.ui.newWizards.

Michael
Re: guidance on creating Resource set and diagram creation [message #780445 is a reply to message #780220] Tue, 17 January 2012 22:56 Go to previous messageGo to next message
Josef Pohl is currently offline Josef PohlFriend
Messages: 82
Registered: January 2012
Member
Thanks Michael,

I played around with modifying the AddAllClassesCommand and CreateDiagramWithAllClassesHandler with relatively little luck. I suspect I am having one of (a multitude really) problems.

Although the context menu shows up it is not launching the diagram. I believe the issue may involve the "set-up" in getting the project container since I am trying to create a fresh diagram without any instances on it.

In digging around though I think creating the new wizard would better suit my needs. Does anyone have any guidance on creating a newWizard extension?

Thanks,
Joe
Re: guidance on creating Resource set and diagram creation [message #780599 is a reply to message #780445] Wed, 18 January 2012 18:06 Go to previous messageGo to next message
Josef Pohl is currently offline Josef PohlFriend
Messages: 82
Registered: January 2012
Member
No Message Body
Re: guidance on creating Resource set and diagram creation [message #780600 is a reply to message #780445] Wed, 18 January 2012 18:06 Go to previous messageGo to next message
Josef Pohl is currently offline Josef PohlFriend
Messages: 82
Registered: January 2012
Member
Hi there,

In the CreateDiagramWithAllClassesHandler there is an initial snippet:

		// Get the current selection
		ISelection selection = HandlerUtil.getCurrentSelection(event);
		if (!(selection instanceof IStructuredSelection)) {
			return null;
		}
				
		// Operation must be started on ECLasses node -> cancel if not
		Object first = ((IStructuredSelection) selection).getFirstElement();
		if (!(first instanceof EClassesNode)) {
			return null;
		}

		// Retrieve the project from the selected node
		EClassesNode node = (EClassesNode) first;
		IProject project = node.getProject();
		if (project == null) {
			return null;
		}


I can get the "Create Diagram" command to show up in the context menu, but as I noted above it does not do much because it fails on the second test. Mostly because, as best as I can tell, I do not have the EClassesNode container.

Is there a way to extract the "project" without looking at a particular node? For instance I can determine that, if I call the "Create Diagram" command from the "src" directory in the project explorer tree that it is an instance of ITreeSelection. Is there some derived type from this that I can use to get the project instance?

Thanks in advance,

Joe
Re: guidance on creating Resource set and diagram creation [message #780660 is a reply to message #780600] Wed, 18 January 2012 22:17 Go to previous message
Josef Pohl is currently offline Josef PohlFriend
Messages: 82
Registered: January 2012
Member
Just FYI, I solved the last problem by casting the first element of the selection to an IResource from which I was able to construct a IProject instance.

Thanks, I hope this helps someone along the way.
Joe
Previous Topic:Problem with transparancy in Styles
Next Topic:Accessibility in Graphiti
Goto Forum:
  


Current Time: Tue Nov 25 22:29:58 GMT 2014

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

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