Create a node after a drop action on the diagram [message #146927] |
Fri, 17 August 2007 05:12 |
Eclipse User |
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi.<br>
<br>
I have implemented a drag & drop from a view onto the diagram. This
works fine (I mean, I detect the drop event and dropped data).<br>
But I would like to create a node right after the drop event and I
can't make it work.<br>
<br>
The drop action is detected by the diagram edit part (named
OrchestrationEditPart in my modeller).<br>
I have installed an EditPolicy on it, which extends
DragDropEditPolicy. <br>
I have overidden the method "getDropObjectsCommand(DropObjectsRequest
request)" and created a command in it to create my node. <br>
<br>
Here is the code.<br>
<br>
@Override<br>
protected Command getDropObjectsCommand(DropObjectsRequest
request) {<br>
<b>CompositeCommand cm = new CompositeCommand("Drop
Objects Command");</b><br>
<br>
Iterator elements = request.getObjects().iterator();<br>
while (elements.hasNext()) {<br>
Object obj = elements.next();<br>
<br>
if( obj instanceof String) {<br>
System.out.println("yooohoo = " + (String) obj);<br>
<br>
/* request to create a new element and its view
*/ <br>
<b>CreateViewAndElementRequest creation = <br>
new CreateViewAndElementRequest(<br>
OrchestrationElementTypes.Service_1001, <br>
orchestrationEditPart.getDiagramPreferencesHint()<br>
);<br>
ICommand cmd = new CommandProxy(
orchestrationEditPart.getCommand( creation ));<br>
cm.add( cmd );</b><br>
}<br>
}<br>
<b>return new ICommandProxy(cm); </b><br>
}<br>
<br>
<br>
"Orchestration" is the root element in my meta-model. And "Service" is
the node I want to create (view and model). And I drop text on my
diagram.<br>
I thought that return this command would be enough. But on the drop,
the editor doesn't get dirty and nothing change.<br>
I tried to execute directly this command but I got an error (read-write
transaction in a read-only transaction). And the printing works.<br>
<br>
Does anybody know what I have forgotten or mistaken ?<br>
Is it the use of a CompositeCommand ? Do I have to use an
AbstractTransactionnalCommand and create "manually" the node ?<br>
Who should be called to get the command ? My diagram EditPart or the
node EditPart ?<br>
<br>
Any help will be appreciated.<br>
<br>
Regards,<br>
<br>
Vincent.<br>
</body>
</html>
|
|
|
Powered by
FUDForum. Page generated in 0.03866 seconds