Hi everyone,
When pressing a button I would like to simply create a copy of an
existing EObject (ComplexOperator) and display the shape on the
diagram. I do the following:
//create copy of existing operator
ComplexOperator op = repository.getOperator(operatorId);
ComplexOperator newOp = (ComplexOperator) EcoreUtil.copy(op);
I currently try to change the element reference inside the newly
create node. Unfortunately this does not work well. The references are
correct but the graphical representation does not reflect the operator
copy but an empty operator instead. I do the following:
//create new shape
CreateViewRequest opRequest =
CreateViewRequestFactory.getCreateShapeRequest(SimpleElementTypes.ComplexOperator_1016,
editPart.getDiagramPreferencesHint());
Command createOpCmd = editPart.getCommand(opRequest);
editPart.getDiagramEditDomain().getDiagramCommandStack().execute(createOpCmd);
//get hold of newly created node object
IAdaptable opViewAdapter =
(IAdaptable)((List)opRequest.getNewObject()).get(0);
Map reg = editPart.getViewer().getEditPartRegistry();
EditPart elementPart = (EditPart)
reg.get(opViewAdapter.getAdapter(View.class));
Node node = (Node)elementPart.getModel();
//change element feature inside node object to newOp
EStructuralFeature f = node.eClass().getEStructuralFeature("element");
Command c = new SetCommand(editPart.getEditingDomain(), node, f,
newOp);
editPart.getEditingDomain().getCommandStack().execute(c);
As I said the internal references are correct but not reflected in the
graphical object. Can I somehow adapt the code that I create a shape
that points at my copy of the existing operator? Should I use a
different approach?
Thank you very much in advance
Best regards.
Felix Foerster.