Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Regarding DND
Regarding DND [message #215256] Thu, 15 January 2009 09:37 Go to next message
Shiva Selvadurai is currently offline Shiva SelvaduraiFriend
Messages: 25
Registered: July 2009
Location: Bangalore
Junior Member
I tried DND from a treeviewer to a graphical editor and succedded to update the diagram but not the model.

My Model looks like this
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="test"
nsURI="http://test/1.0" nsPrefix="test">
<eClassifiers xsi:type="ecore:EClass" name="E">
<eStructuralFeatures xsi:type="ecore:EReference" name="instance" lowerBound="1"
eType="#//C" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="C">
<eStructuralFeatures xsi:type="ecore:EReference" name="instance" upperBound="-1"
eType="#//C" containment="true"/>
</eClassifiers>
</ecore:EPackage>


Transfer on both sides are LocalSelectionTransfer.

I add a DropTargetListener to my graphical viewer which extends DiagramDropTargetListener.

I install a DragDropPolicy in my EditParts. The getDropObjectsCommand() contains following code :

public Command getDropObjectsCommand(DropObjectsRequest dropRequest) {
List<CreateViewRequest.ViewDescriptor) viewDescriptors = new ArrayList<CreateViewRequest.ViewDescriptors>() ;
for (Iterator it = dropRequest.getObjects().iterator(); it.hasNext();) {
String nextObj = (String)it.next();
C cObj = XXXFactorg.eINSTANCE.createC() ;
cObj.setName(nextObj) ;
EObject eObj = cObj ;
if(obj != null)
viewDescriptors.add(new CreateViewRequest.ViewDescriptor(new EObjectAdapter(cObj),Node.class, null, getDiagramPreferencesHint()) ;
}

return createCommand(dropRequest, viewDescriptors) ;
}

private Command createCommand(DropObjectsRequest dropRequest, List viewDescriptors) {
Command command = createViewsAndArrangeCommand(dropRequest, viewDescriptors);
if (command != null)
return command.chain(new ICommandProxy(new CreateCCommand(getEditingDomain(),(View) getModel(),viewDescriptors)));

return null;
}

CreateCCommand extends AbstractTransactionalCommand.

After all these when I drop a object from treeviewer to the editor I get the diagram C drawn in the diagram. But when I do getModel() from the Root
EditPart I don't see this object reflected.

When I click the newly created diagram and do getModel() in that editpart I get the object, but its eContainer is NULL.

So could anyone let me know if I'm going wrong anywhere.
How could I update my domain model with that of the diagram.

-Shiva.S
Re: Regarding DND [message #215547 is a reply to message #215256] Fri, 16 January 2009 16:14 Go to previous messageGo to next message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Shiva,

> When I click the newly created diagram and do getModel() in that
> editpart I get the object, but its eContainer is NULL.
You've created new domain element instance but in addition to it you have
to assign this element to it's parent like:

C cObj = XXXFactorg.eINSTANCE.createC() ;
cObj.setName(nextObj) ;
myEInstance.getCs().add(cObj);

-----------------
Alex Shatalin
Re: Regarding DND [message #217895 is a reply to message #215547] Mon, 09 February 2009 12:24 Go to previous messageGo to next message
Shiva Selvadurai is currently offline Shiva SelvaduraiFriend
Messages: 25
Registered: July 2009
Location: Bangalore
Junior Member
Alex,

When I do ((C)(((View)getModel).getElement())).getCs().add(cObj) I get a IllegalStateException - Cannot modify resource set without a write transaction.

Can I know why this happens and this happens only in CEditPart and not on C2EditPart and C3EditPart.

Please let me know if I'm going wrong some where.

Can I have create my own EObject and maintain the model in it.

Yours,
Shiva.S

Alex Shatalin wrote:
> Hello Shiva,
>
>> When I click the newly created diagram and do getModel() in that
>> editpart I get the object, but its eContainer is NULL.
>
> You've created new domain element instance but in addition to it you
> have to assign this element to it's parent like:
>
> C cObj = XXXFactorg.eINSTANCE.createC() ;
> cObj.setName(nextObj) ;
> myEInstance.getCs().add(cObj);
>
> -----------------
> Alex Shatalin
>
>
Re: Regarding DND [message #217935 is a reply to message #217895] Mon, 09 February 2009 12:43 Go to previous message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Shiva,

You have to perform any modifications to the underlying domain model inside
a write transaction. One of the possible ways is:
- create a subclass of AbstractTransactionalCommand performing necessary
domain model modifications in implemented "doExecuteWithResult" method.
- execute this command by calling OperationHistoryFactory.getOperationHistory().execute(...)

-----------------
Alex Shatalin
Previous Topic:Changing and saving the value of a label?
Next Topic:Creating a child of the same size as its compartment
Goto Forum:
  


Current Time: Wed Mar 03 09:24:40 GMT 2021

Powered by FUDForum. Page generated in 0.02272 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top