Create objects programmatically [message #1064159] |
Mon, 17 June 2013 17:20  |
Eclipse User |
|
|
|
Hello GMF-Forum,
so i want to create a GMF-Editor with the usual components like Palette and Canvas to enable the user to create and modify a model instance in a graphical manner. Also the editor should have a button by that the user can create several model elements in one step (instead of using drag&drop multiple times).
This is what Ive got so far to create an object programmatically:
import org.eclipse.gef.commands.Command;
import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequestFactory;
...
IWorkbenchPart activePart = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage().getActivePart();
WorkflowDiagramEditor diagramEditor = (WorkflowDiagramEditor) activePart;
DiagramEditPart diagramEditPart = diagramEditor
.getDiagramEditPart();
ComposedAppWorkflowFactory factory = ComposedAppWorkflowFactory.eINSTANCE;
Action firstAction = factory.createAction();
firstAction.setName("TEST");
CreateViewRequest actionRequest = CreateViewRequestFactory
.getCreateShapeRequest(
ComposedAppWorkflow.diagram.providers.WorkflowElementTypes.Action_2007,
PreferencesHint.USE_DEFAULTS);
ViewAndElementDescriptor descriptor = (ViewAndElementDescriptor) ((List) actionRequest
.getNewObject()).get(0);
CreateElementRequestAdapter adapter = descriptor
.getCreateElementRequestAdapter();
adapter.setNewElement(firstAction);
Command command = diagramEditPart.getCommand(actionRequest);
command.execute();
...
ComposedAppWorkflowFactory is an EFactory, Action is a CDOObject.
The code above doesn't work because the setNewElement methode got called again by command.execute(). But with a different EObject than firstAction. So i create a figure on the canvas but it is not related to firstAction.
I got inspired by this: http://wiki.eclipse.org/GMF_Tutorial_Part_3#Custom_Actions But here I dont understand how i can modifiy the related EObject by only having an IAdaptable. Also how to get form the IAdaptable to the just created figure? Eg to set the position? IAdaptable topicViewAdapter = (IAdaptable) ((List) topicRequest.getNewObject()).get(0);
Am I on the wrong track? What is the best way to archive what i have in mind?
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06345 seconds