Drag and Drop and Creating Corresponding Elements [message #191736] |
Mon, 09 June 2008 13:51 |
Eclipse User |
|
|
|
Originally posted by: janiko.gmx.de
Hi,
i try to implement a drag and drop support from a navigator view to the
GMF editor.
With the help of these threads
http://dev.eclipse.org/newslists/news.eclipse.technology.gmf /msg01281.html
i already have a DropTargetlistener and a DiagramDragDropEditPolicy in the
parent EditPart rely an this thread
http://dev.eclipse.org/newslists/news.eclipse.modeling.gmf/m sg08513.html,
but it still don't work. the getObjectsBeingDropped creates the right
EObject and the getDropObjectsCommand buit a command, but there is the end
and nothing more.
Very thanks for any hint.
Best regards,
Peter
The DropTargetListener in the Editor:
getDiagramGraphicalViewer().addDropTargetListener(new
DiagramDropTargetListener(getDiagramGraphicalViewer(),
SelectionTransfer.getInstance()){
@Override
protected List getObjectsBeingDropped() {
TransferData[] data = getCurrentEvent().dataTypes;
List<EObject> eObjects = new ArrayList<EObject>();
for (int i=0; i<data.length; i++) {
if (SelectionTransfer.getInstance().isSupportedType(data[i])) {
IStructuredSelection selection =
(IStructuredSelection)SelectionTransfer.getInstance().native ToJava(data[i]);
for (Object o : selection.toList()){
if(o instanceof TreeItem && ((TreeItem)o).getData() instanceof
IEntityModuleElement){
IEntityModuleElement treeElement =
(IEntityModuleElement)((TreeItem)o).getData();
if(treeElement instanceof ClazzTreeElement){
OWLClass owlClass=OdmFactory.eINSTANCE.createOWLClass();
owlClass.setURIFromOWLEntity(((ClazzTreeElement)treeElement) .getOntologyUri());
owlClass.setTag(((ClazzTreeElement)treeElement).getLocalName ());
eObjects.add(owlClass); //FIXME Ugly (need a generic factory and
use them in the Transfer.nativToJava() method)
}
}
}
}
}
return eObjects;
}
@Override
public boolean isEnabled(DropTargetEvent event) {
super.isEnabled(event);
ISelection selection = SelectionTransfer.getInstance().getSelection();
if (selection instanceof IStructuredSelection) {
List eObjects = ((IStructuredSelection)selection).toList();
if (eObjects == null)
return false;
for (Iterator i = eObjects.iterator(); i.hasNext();) {
Object o = i.next();
if (!(o instanceof TreeItem))
return false;
}
return true;
}
return false;
}
@Override
protected void updateTargetRequest() {
((DropObjectsRequest)getTargetRequest()).setLocation(getDrop Location());
}
});
And the DiagramDragDropEditPolicy:
installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new
DiagramDragDropEditPolicy() {
public Command getDropObjectsCommand(DropObjectsRequest dropRequest) {
OWLEditPart selectedElement = (OWLEditPart) getHost();
String compartemntsSemanticHint =
OdmVisualIDRegistry.getType(OWLClassEditPart.VISUAL_ID);
OWLClassEditPart owlClassEditPart = (OWLClassEditPart)
selectedElement.getChildBySemanticHint(compartemntsSemanticH int);
IElementType type = OdmElementTypes.OWLClass_2001;
ViewAndElementDescriptor viewDescriptor = new ViewAndElementDescriptor(new
CreateElementRequestAdapter(new CreateElementRequest(type)), Node.class,
((IHintedType) type).getSemanticHint(),
selectedElement.getDiagramPreferencesHint());
CreateViewAndElementRequest req = new
CreateViewAndElementRequest(viewDescriptor);
CompoundCommand cmd = new CompoundCommand("Create 1 class");
cmd.add(owlClassEditPart.getCommand(req));
selectedElement.getDiagramEditDomain().getDiagramCommandStac k().execute(cmd);
refresh();
return cmd;
}
});
}
|
|
|
Re: Drag and Drop and Creating Corresponding Elements [message #191908 is a reply to message #191736] |
Tue, 10 June 2008 15:02 |
Eclipse User |
|
|
|
Originally posted by: janiko.gmx.de
No one have a hint?
Actually my problem is the position of the creation command in the
getDropObjectsCommand method, because this method is called a lot if times
in one drag and drop operation. On the other hand i don't know how and
were i have to execute this command.
i really hope anyone have a solution or hint.
|
|
|
Powered by
FUDForum. Page generated in 0.02724 seconds