|
|
|
Re: How to layout a diagram at initialisation? [message #652094 is a reply to message #650318] |
Wed, 02 February 2011 16:26 |
Nigel Daniels 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
|
|
|
Powered by
FUDForum. Page generated in 0.03644 seconds