Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Create element in DiagramEditPart programmatically
Create element in DiagramEditPart programmatically [message #215113] Tue, 13 January 2009 11:55 Go to next message
Eclipse UserFriend
Originally posted by: Erazerx.gmx.de

Hi,

i am trying to create a element in the diagram edit part with an action.
I tried to do it just like it was written in the GMF Tips
( http://wiki.eclipse.org/GMF_Tips#Creating_New_Elements_And_C orresponding_Views).

Well, the only difference i have is that i don't want to add a element
to the main DiagramEditPart instead of a compartment. When the action
gets started, you can see that something changes in the diagram, but
only when you create some element with the toolbar manually, the
elements that were created with the action are drawn.

The code of the action is below:

DiagramEditPart parent = selectedElement;
IElementType type = Req_metamodelElementTypes.Document_1001;

ViewAndElementDescriptor viewDescriptor = new
ViewAndElementDescriptor(new CreateElementRequestAdapter(new
CreateElementRequest(type)),
Node.class,

((IHintedType)type).getSemanticHint(),

selectedElement.getDiagramPreferencesHint());

CreateViewAndElementRequest req = new
CreateViewAndElementRequest(viewDescriptor);

CompoundCommand cmd = new CompoundCommand();

cmd.add(parent.getCommand(req));

selectedElement.getDiagramEditDomain()
.getDiagramCommandStack()
.execute(cmd);

I hope someone has time to help me with this little issue.
Thx in advance, Arne :)
Re: Create element in DiagramEditPart programmatically [message #215121 is a reply to message #215113] Tue, 13 January 2009 12:45 Go to previous message
Eclipse UserFriend
Originally posted by: Erazerx.gmx.de

Just solved it, doing it like this :) :

CreateViewRequest documentReq =
CreateViewRequestFactory.getCreateShapeRequest(Req_metamodel ElementTypes.Document_1001,

selectedElement.getDiagramPreferencesHint());

org.eclipse.gef.commands.Command createDocument =
selectedElement.getCommand(documentReq);
selectedElement.getDiagramEditDomain()
.getDiagramCommandStack()
.execute(createDocument);


Arne schrieb:
> Hi,
>
> i am trying to create a element in the diagram edit part with an action.
> I tried to do it just like it was written in the GMF Tips
> ( http://wiki.eclipse.org/GMF_Tips#Creating_New_Elements_And_C orresponding_Views).
>
> Well, the only difference i have is that i don't want to add a element
> to the main DiagramEditPart instead of a compartment. When the action
> gets started, you can see that something changes in the diagram, but
> only when you create some element with the toolbar manually, the
> elements that were created with the action are drawn.
>
> The code of the action is below:
>
> DiagramEditPart parent = selectedElement;
> IElementType type = Req_metamodelElementTypes.Document_1001;
>
> ViewAndElementDescriptor viewDescriptor = new
> ViewAndElementDescriptor(new CreateElementRequestAdapter(new
> CreateElementRequest(type)),
> Node.class,
>
> ((IHintedType)type).getSemanticHint(),
>
> selectedElement.getDiagramPreferencesHint());
>
> CreateViewAndElementRequest req = new
> CreateViewAndElementRequest(viewDescriptor);
>
> CompoundCommand cmd = new CompoundCommand();
>
> cmd.add(parent.getCommand(req));
>
> selectedElement.getDiagramEditDomain()
> .getDiagramCommandStack()
> .execute(cmd);
>
> I hope someone has time to help me with this little issue.
> Thx in advance, Arne :)
Previous Topic:Doubt regarding getting values from the gmf figures
Next Topic:Book (looking for documentation) ?
Goto Forum:
  


Current Time: Thu Apr 25 01:20:18 GMT 2024

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

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

Back to the top