开发者

Create nodes programmatically in Eclipse GMF

开发者 https://www.devze.com 2023-03-31 01:26 出处:网络
I\'m developing an editor to design user Interfaces based on eclipse GMF. Up to now I have developed an editor with a palette. The user can drag and drop UI elements from palle开发者_如何学编程t and

I'm developing an editor to design user Interfaces based on eclipse GMF.

Up to now I have developed an editor with a palette. The user can drag and drop UI elements from palle开发者_如何学编程t and design the UI on canvas. I need to implement the facility to group these UI elements.

EX: User first design the UI by dragging and dropping elements to the canvas.Then he select a set of UI elements (say a label and text box) and press "group" button. It will automatically put the elements within a dashed line rectangle.

I'm planning to develop a plugin that can get info about selected ui elements, delete them, create a group element (dashed line rectangular) in canvas and insert deleted elements to it.

But I don't know where to start.

So, I want to know how to create/delete nodes programmatically in GMF.

If you know the relevant codes, please share them and please point me to some useful resources.


When dragging something from the palette, the following command gets created in gmf. You have to specify the element type and ask an edit part for the appropriate command for the element.

CreateUnspecifiedTypeRequest request = new
    CreateUnspecifiedTypeRequest(
        Collections.singletonList(EcoreElementTypes.EClass_1001),
        diagramEditPart.getDiagramPreferencesHint());

Command command = diagramEditPart.getCommand(request);
command.execute();

Object newObject = request.getNewObject(); // these are the newly created objects


Adding additional elements when dragging something from the palette is also possible by using e.g. the deferred commands. Those commands are created when the palette element request is created but as the final position and view is not yet know (only on drop time). The corresponding view is resolved later.

an existing command class which uses this mechanism is: DeferredCreateConnectionViewAndElementCommand or DeferredSetValueCommand

To use this classes you have to find the right place in your request creation process where the View(s) is created via CreateViewRequest. This request has the information needed (request.getNewObject()) which gets a View as soon as the object from the palette is dropped somewhere.

See this example for more info: http://wiki.eclipse.org/GMF_Tutorial_Part_3

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号