[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.gmf] Re: create and display copy of existing EObject

Hi Jevon,

the diagram updates when I press F5. Saving the diagram adds the new 
operator to the XMI file. However, all containment references are not 
included, i.e. atomic operators are contained inside the complex 
operator. Those are neither contained in the XMI file nor in the 
diagram when I double click on the complex operator.
I tried to manually put the changes in the resource:

Resource importResource = op.eResource();
Resource thisResource = 
editPart.getEditingDomain().getResourceSet().getResources().get(0);
thisResource.getContents().addAll(EcoreUtil.copyAll(importResource.getContents()));

This gives an IllegalStateException. Is it possible to create a 
SetCommand to modify a resource? The usual way doesnt work since 
Resource is not an EObject and I can't a reference to the 
EStructuralFeature "contents". Is there any other way to solve this?

Thanks for your answer.
Felix.

"Jevon Wright" <jevon@xxxxxxxxx> schrieb im Newsbeitrag 
news:ggcl31$v74$2@xxxxxxxxxxxxxxxxxxxx
> Hi Felix,
>
> Does anything change when you press F5 to refresh the diagram? Or 
> does the graphical representation correct itself when you close and 
> open the diagram?
>
> Jevon
>
> Felix Förster wrote:
>> 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.