Create nodes programmatically in Eclipse GMF

I am developing an editor for developing user interfaces based on Eclipse GMF.

So far I have developed an editor with a palette. The user can drag and drop user interface elements from the pallet and create a user interface on the canvas. I need to implement a tool to group these user interface elements.

Example: a user first creates a user interface by dragging items onto the canvas. Then he selects a set of user interface elements (for example, a label and a text field) and presses the "group" button. This will automatically place the elements in a dashed line rectangle.

I plan to develop a plugin that can receive information about selected user interface elements, delete them, create a group element (dashed line rectangular) on the canvas and insert deleted elements into 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 show me some useful resources.

+4
source share
2 answers

When you drag something from the palette to gmf, the following command is created. You must specify the type of element and specify the editing part for the corresponding 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 
+1
source

Adding additional elements while dragging something from the palette is also possible using, for example, pending commands. These commands are created when a palette element request is created, but since the end position and view are not yet known (only when dropped out). Appropriate submission is permitted later.

existing class of commands that uses this mechanism: DeferredCreateConnectionViewAndElementCommand or DeferredSetValueCommand

To use these classes, you must find the right place in the process of creating the request, where View (s) is created through CreateViewRequest. This request has the necessary information (request.getNewObject ()), which receives the view as soon as an object from the palette falls somewhere.

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

+1
source

Source: https://habr.com/ru/post/1369348/


All Articles