How to layout a diagram at initialisation? [message #649908] |
Thu, 20 January 2011 17:03  |
Eclipse User |
|
|
|
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 #652094 is a reply to message #650318] |
Wed, 02 February 2011 11:26  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.04108 seconds