Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » How to layout a diagram at initialisation?
How to layout a diagram at initialisation? [message #649908] Thu, 20 January 2011 22:03 Go to next message
Nigel is currently offline NigelFriend
Messages: 7
Registered: October 2010
Junior Member
Hi,

I would like to ensure that when a diagram is created it has some
predefined nodes and an initial layout. However after that point the
layout should be up to the user.

I have customised the initializeNewDiagram() method in the inner class
OpenDigramCommand found in the OpenDiagramEditPolicy. Here I have been
able to add an instance of my model to the:

EObject diagramDomainElement

This seems to work as the elements added all appear on the diagram.
However the result is not very pretty.

At the end of the method it returns an
org.eclipse.gmf.runtime.notation.Diagram d. I then tried to do the
following:

for (Iterator it1 = d.getChildren().iterator(); it1.hasNext();)
{
Object obj = it1.next();

if (obj instanceof Node)
{
Node node = (Node) obj;

if (node.getElement() instanceof MyNodeImpl)
{
Bounds bounds = NotationFactory.eINSTANCE.createBounds();
bounds.setX(30);
bounds.setY(260);
node.setLayoutConstraint(bounds);
}
}
}

But I never get any child nodes? Investigating the Diagram in the
debugger I cannot see where the rest of the diagram is! Any advice on
what I should be doing is very welcome.

Thanks ofr any help,

regards, Nigel
Re: How to layout a diagram at initialisation? [message #650318 is a reply to message #649908] Mon, 24 January 2011 11:47 Go to previous messageGo to next message
Romain Bioteau is currently offline Romain BioteauFriend
Messages: 65
Registered: August 2009
Location: Grenoble
Member
How do you insert your elements ? using Commands ?

You can see here an example of a diagram initialization with command.

HTH
Romain


R&D Engineer at BonitaSoft
Re: How to layout a diagram at initialisation? [message #650535 is a reply to message #650318] Tue, 25 January 2011 12:59 Go to previous messageGo to next message
Nigel is currently offline NigelFriend
Messages: 7
Registered: October 2010
Junior Member
On 24/01/2011 11:47, Romain Bioteau wrote:
> How do you insert your elements ? using Commands ?
>
> You can see
> http://www.bonitasoft.org/websvn/filedetails.php?repname=Bon ita+Open+Solution&path=%2Fbonita-studio%2Ftags%2Fbonita- studio-5.3%2Fplugins%2Forg.bonitasoft.studio.application%2Fs rc%2Forg%2Fbonitasoft%2Fstudio%2Fapplication%2Factions%2FNew ProcessCommandHandler.java
> an example of a diagram initialization with command.
>
> HTH
> Romain
Hi Romain,

thanks getting back to me and for the link.

I am inserting the elements by customizing the generated
OpenDiagramEditPolicy.initialiseNewDigram() method. There I cast the
EObject diagramDomainElement to my diagram type and build the EMF model
directly. This ensures the diagram is initialised with the content I
need. I am not using commands to do this as the diagramDomainElement is
then passed to the the following command:

Diagram d = ViewService.createDiagram(diagramDomainElement,
getDiagramKind(), getPreferencesHint());

I then wanted to lay out the content, but could not find out how to
reference the items I just added to the new Diagram d.

Best regards,

Nigel
Re: How to layout a diagram at initialisation? [message #652094 is a reply to message #650318] Wed, 02 February 2011 16:26 Go to previous message
Nigel Daniels is currently offline Nigel DanielsFriend
Messages: 66
Registered: July 2009
Member
Hi Romain,

I have given my code a complete rewrite and have been using a command
approach. This works really well when I add items to the diagram and it
let's me set the items locations. However when i attempt to get the edit
part for an element with a compartment my code fails with a class cast
error : DummyEditPart cannot be cast to ContainerEditPart.

The code I have used looks like this :


private void layoutNewDiagram(Diagram diagram)
{
// Get the diagrams Edit Part then we can add things to it
Shell shell = new Shell();
DiagramEditPart diagramEP =
OffscreenEditPartFactory.getInstance().createDiagramEditPart (diagram,
shell);


// Create the node with a compartment
ViewAndElementDescriptor containerViewDescriptior = new
ViewAndElementDescriptor(
new CreateElementRequestAdapter(new
CreateElementRequest(MyElementTypes.Container_2017)),
Node.class,
((IHintedType)MyElementTypes.Container_2017).getSemanticHint (),
diagramEP.getDiagramPreferencesHint()
);
CreateViewAndElementRequest containerRequest = new
CreateViewAndElementRequest(containerViewDescriptior);
contanerRequest.setLocation(new Point(160,100));


diagramEP.getDiagramEditDomain().getDiagramCommandStack().ex ecute(diagramEP.getCommand(containerRequest));


// Now lets get the containers edit part
String containerSemanticHint =
MyVisualIDRegistry.getType(ContainerEditPart.VISUAL_ID);
String containerCompartmentSemanticHint =
MyIDRegistry.getType(ContainerContainerCompartmentEditPart.V ISUAL_ID);
ContainerEditPart contanerEP = (ContainerEditPart)
diagramEP.getChildBySemanticHint(containerSemanticHint);
ContainerContainerCompartmentEditPart contanerCompartmentEP =
(ContainerContainerCompartmentEditPart)
containerEP.getChildBySemanticHint(containerCompartmentSeman ticHint);
}


It's the second from last line that fails for me:

ContainerEditPart contanerEP = (ContainerEditPart)
diagramEP.getChildBySemanticHint(containerSemanticHint);

Using the debugger to step into the getChildBySemanticHint method it
contains the comment:

// the ep had not been created yet, create a dummy one

This is where it sets the return type, creating the problem I have. Is
there something I can do to ensure that the edit part for my container
(and I suspect it's compartment) is created when I submit my request?

Thanks for any suggestions,

Nigel

On 24/01/2011 11:47, Romain Bioteau wrote:
> How do you insert your elements ? using Commands ?
>
> You can see
> http://www.bonitasoft.org/websvn/filedetails.php?repname=Bon ita+Open+Solution&path=%2Fbonita-studio%2Ftags%2Fbonita- studio-5.3%2Fplugins%2Forg.bonitasoft.studio.application%2Fs rc%2Forg%2Fbonitasoft%2Fstudio%2Fapplication%2Factions%2FNew ProcessCommandHandler.java
> an example of a diagram initialization with command.
>
> HTH
> Romain
Previous Topic:OCL Expression Labels not automatically updating
Next Topic:Fix to fill scalable polygon node with gradient background
Goto Forum:
  


Current Time: Tue Apr 30 08:00:07 GMT 2024

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

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

Back to the top