Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Creating Nodes Programmatically but not showing
Creating Nodes Programmatically but not showing [message #196414] Wed, 09 July 2008 22:06 Go to next message
Reto Hirt is currently offline Reto HirtFriend
Messages: 1
Registered: July 2009
Junior Member
Hi everyone,

I'm stuck with GMF (Eclipse 3.4) at a certain point and just hope that
somebody could help me with.
I'm using the context-menu on my gmf-diagram to call an action, which
should add some nodes on top-level programmatically. I tried to follow
docs and especially articles on this newsgroup, and I think I'm doing
everything the right (and recommended) way, see code below.
The thing is, no errors occur, but no elements and views appear on the
diagram or in the files, and I don't see any log- or error-output.

public void run(IAction action) {

EObject myNewEObject = ... // getting it from an xml-doc
CompoundCommand cc = new CompoundCommand("Create for imported
content");

// Determine the ElementType
IElementType type = ElementTypeRegistry.getInstance().getElementType(
myNewEObject);

// Creating the CreateElementRequestAdapter from the type above
CreateElementRequestAdapter elementReqAdapter = new
CreateElementRequestAdapter(new CreateElementRequest(type));

// Creating the View and Element Descriptor
ViewAndElementDescriptor viewDescriptor = new ViewAndElementDescriptor(
elementReqAdapter, XXXDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);

// Creating the element and view request
CreateViewAndElementRequest elementRequest = new
CreateViewAndElementRequest(viewDescriptor);

// Creating the command
Command createElementCmd = diagramEditPart.getCommand(elementRequest);

// Adding the command to the compound command
cc.add(createElementCmd);

// And finally running the commands
diagramEditPart.getDiagramEditDomain().getDiagramCommandStac k()
.execute(cc);
}

I have to add, that I am a newbie to EMF/GMF, so I am a little confused
about editing-domains, resources and so on, so may be, I just write the
new nodes into a model which should not be there? No idea. Or do I really
have to save the model and diagrams first?

Regards
Reto
Re: Creating Nodes Programmatically but not showing [message #202528 is a reply to message #196414] Tue, 19 August 2008 17:51 Go to previous message
Tobias Emitslöf is currently offline Tobias EmitslöfFriend
Messages: 9
Registered: July 2009
Junior Member
Reto Hirt wrote:
> Hi everyone,
>
> I'm stuck with GMF (Eclipse 3.4) at a certain point and just hope that
> somebody could help me with.
> I'm using the context-menu on my gmf-diagram to call an action, which
> should add some nodes on top-level programmatically. I tried to follow
> docs and especially articles on this newsgroup, and I think I'm doing
> everything the right (and recommended) way, see code below. The thing
> is, no errors occur, but no elements and views appear on the diagram or
> in the files, and I don't see any log- or error-output.
>
> public void run(IAction action) {
>
> EObject myNewEObject = ... // getting it from an xml-doc
> CompoundCommand cc = new CompoundCommand("Create for imported content");
> // Determine the ElementType
> IElementType type = ElementTypeRegistry.getInstance().getElementType(
> myNewEObject);
> // Creating the CreateElementRequestAdapter from the type above
> CreateElementRequestAdapter elementReqAdapter = new
> CreateElementRequestAdapter(new CreateElementRequest(type));
>
> // Creating the View and Element Descriptor
> ViewAndElementDescriptor viewDescriptor = new ViewAndElementDescriptor(
> elementReqAdapter, XXXDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
>
> // Creating the element and view request
> CreateViewAndElementRequest elementRequest = new
> CreateViewAndElementRequest(viewDescriptor);
>
> // Creating the command
> Command createElementCmd = diagramEditPart.getCommand(elementRequest);
>
> // Adding the command to the compound command
> cc.add(createElementCmd);
>
> // And finally running the commands
> diagramEditPart.getDiagramEditDomain().getDiagramCommandStac k()
> .execute(cc);
> }
>
> I have to add, that I am a newbie to EMF/GMF, so I am a little confused
> about editing-domains, resources and so on, so may be, I just write the
> new nodes into a model which should not be there? No idea. Or do I
> really have to save the model and diagrams first?
>
> Regards
> Reto
>
>
>

Hi Reto

You could try this example:

http://wiki.eclipse.org/GMF_Tutorial_Part_3#Custom_Actions

run method:

CompoundCommand cc = new CompoundCommand("Some string");

CreateViewRequest xxxRequest =
CreateViewRequestFactory.getCreateShapeRequest(your_elementt ype,
selectedElement.getDiagramPreferenceHint());

Point p = selectedElement.getFigure().getBounds().getTopRight().getCop y();

....

the full source code is available via cvs.

http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.gmf/exa mples/org.eclipse.gmf.examples.mindmap.diagram.custom/src/or g/eclipse/gmf/examples/mindmap/diagram/part/?root=Modeling_P roject

/ Tobias Emitslöf
Previous Topic:same filename for model and diagram
Next Topic:How to remove Arrange All Action from Context Menu?.
Goto Forum:
  


Current Time: Thu Apr 18 00:56:26 GMT 2024

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

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

Back to the top