Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Create PictogramLink for Diagram object itself.(This topic discusses the possibility to link Diagram objects with business objects directly.)
Create PictogramLink for Diagram object itself. [message #735558] Wed, 12 October 2011 07:59 Go to next message
Georg Hackenberg is currently offline Georg HackenbergFriend
Messages: 12
Registered: October 2011
Junior Member
Dear Graphiti community,

I have been working on a graphical editor for an EMF model for some days now. The goal is to support creating and editing models of automata (containing states and transitions). So far, adding states and transitions to the diagram works fine. Now, the states need to be contained within an automaton object. The idea was to link the diagram itself with the automaton object.

The question is where and how to do that naturally inside the Graphiti framework. For example I could imagine overwriting the method creating new diagram objects and automatically adding the automaton object so that each new diagram is linked directly. Another idea I had was to provide a utility class that retrieves the automaton object from the diagram - and creates respectively links the both if necessary. Then I could call this method where ever I need the automaton object and the automaton object is created on the fly the first time.

I would be grateful to hear some other opinions on this. Maybe there is also a built-in mechanism to support this use case.

Best regards,
Georg Hackenberg
Re: Create PictogramLink for Diagram object itself. [message #735609 is a reply to message #735558] Wed, 12 October 2011 11:28 Go to previous messageGo to next message
Hernan Gonzalez is currently offline Hernan GonzalezFriend
Messages: 188
Registered: October 2010
Location: Buenos Aires, Argentina
Senior Member
IMHO that's a perfectly reasonable (and frequent) scenario: you have a "root" domain object, linked with the diagram, and all other domain objects are added inside it. I think the normal way is to create this root object (your "automaton") when you create the diagram. Your own code will tipically have an utility method (called tipically from a creation wizard) that creates the "full" diagram -no need to overwrite any method.
Re: Create PictogramLink for Diagram object itself. [message #753662 is a reply to message #735609] Fri, 28 October 2011 09:02 Go to previous messageGo to next message
Georg Hackenberg is currently offline Georg HackenbergFriend
Messages: 12
Registered: October 2011
Junior Member
Hmm, I managed to solve the problem with the following utility method:

	public static Automaton getAutomaton(Diagram diagram)
	{
		PictogramLink link = diagram.getLink();
		
		if (link == null)
		{
			System.out.println("Creating new automaton object");
			
			EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(diagram);
			Command command;
			
			// Create the automaton object
			Automaton automaton = IfeditFactory.eINSTANCE.createAutomaton();
			
			// Add the automaton object to the diagram resource
			command = new AddCommand(editingDomain, diagram.eResource().getContents(), automaton);
			editingDomain.getCommandStack().execute(command);
			
			// Create the pictogram link object			
			link = PictogramsFactory.eINSTANCE.createPictogramLink();
			link.getBusinessObjects().add(automaton);
			
			// Set the pictogram link object for the diagram object
			command = new SetCommand(editingDomain, diagram, PictogramsPackage.eINSTANCE.getDiagram().getEStructuralFeature(PictogramsPackage.DIAGRAM__LINK), link);
			editingDomain.getCommandStack().execute(command);
		}		
		
		if (link.getBusinessObjects().size() == 1 && link.getBusinessObjects().get(0) instanceof Automaton)
		{
			// Return the automaton object
			return (Automaton) link.getBusinessObjects().get(0);
		}
		else
		{
			throw new IllegalStateException();
		}
	}


Now, anywhere I want to access the automaton I need to use this method. The automaton is created and linked on the fly if not available yet.

This seems a pretty straight forward solution, however I would be interested in the creation wizard solution. Is there an example online where I can see how to implement that?
Re: Create PictogramLink for Diagram object itself. [message #778612 is a reply to message #753662] Fri, 13 January 2012 14:09 Go to previous messageGo to next message
Matthieu Wipliez is currently offline Matthieu WipliezFriend
Messages: 30
Registered: March 2010
Member
Hi,

I know this topic is a bit old, but I just found myself in a similar situation, and ended up creating the link in my wizard (extends WizardNewFileCreationPage, this excerpt is from a method that overrides getInitialContents) to make it easier:

// create business object
Network network = DfFactory.eINSTANCE.createNetwork();
// ...

// create diagram
Diagram diagram = Graphiti.getPeCreateService().createDiagram("xdf", name, true);

// link diagram to network
PictogramLink link = PictogramsFactory.eINSTANCE.createPictogramLink();
link.getBusinessObjects().add(network);
diagram.setLink(link);


Then when I need to access the network in a feature, I just do the following:

Diagram diagram = getDiagram();
Network network = (Network) getBusinessObjectForPictogramElement(diagram);


Cheers
Matthieu
Re: Create PictogramLink for Diagram object itself. [message #779670 is a reply to message #778612] Mon, 16 January 2012 09:45 Go to previous messageGo to next message
Georg Hackenberg is currently offline Georg HackenbergFriend
Messages: 12
Registered: October 2011
Junior Member
Thanks Matthieu! That was exactly what I was looking for.
Re: Create PictogramLink for Diagram object itself. [message #1454448 is a reply to message #735558] Tue, 28 October 2014 11:58 Go to previous messageGo to next message
Simone Di Cola is currently offline Simone Di ColaFriend
Messages: 60
Registered: February 2014
Member
Hi all,
I have a two different diagrams (different even in the meta-model) that I am trying to link.
Let's pretend I want to link digram A to B. I create a BO in A, and than I add the same shape in B, but in the add context I set as BO the one created in A. First question: is this correct? If not, can you suggest a better way?
After this I link the diagram B to A by doing this:
[...]
getFeatureProvider().link(getDiagram(), objectCreatedInA);

but this result in a infinite series of error at runtime.
Any suggestions?

Thanks
Simone


Re: Create PictogramLink for Diagram object itself. [message #1457433 is a reply to message #1454448] Fri, 31 October 2014 10:11 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Simone,

the answer to the first question would be yes, but I would strongly suggest
that you separate the domain model from your graphical representation in
that case: all shapes and graphics algorithms of diagram A should go into an
EMF resource DiagramA, all shapes and graphics algorithms of diagram B in
another EMF resource DiagramB and your domain objects shopuld be stored in
yet another EMF resource Domain. Otherwise you will run into synchronization
issues in case you modify the common shape in B and have A opened in
parallel.

However, the link you are trying to set appears wrong to me. Instead of
linking the domain object to the diagram, you shopuld establish the link
between the shape representing your domain object and your domain object. In
fact there is no difference to the scenario where shape and domain object
"belong" to diagram A.

Michael
Re: Create PictogramLink for Diagram object itself. [message #1457511 is a reply to message #1457433] Fri, 31 October 2014 11:59 Go to previous messageGo to next message
Simone Di Cola is currently offline Simone Di ColaFriend
Messages: 60
Registered: February 2014
Member
Micheal,
Thanks for your answer. Can you give me an example of how I can achieve what you suggest?

Thanks
Simone
Re: Create PictogramLink for Diagram object itself. [message #1457549 is a reply to message #1457511] Fri, 31 October 2014 12:42 Go to previous message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
There is a small example of how to separate stuff into different EMF
resources linked in our FAQ, question 1 at
http://www.eclipse.org/graphiti/developers/faq.php

Hope that helps.

Michael
Previous Topic:How to use IFeature
Next Topic:Highlighting Connection of ConnectionDecorator
Goto Forum:
  


Current Time: Tue Mar 19 07:18:44 GMT 2024

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

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

Back to the top