Creating Nodes Programmatically but not showing [message #196414] |
Wed, 09 July 2008 22:06 |
Reto Hirt 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 |
Tobias Emitslöf 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
|
|
|
Powered by
FUDForum. Page generated in 0.02591 seconds