Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » Drag from a view, drop onto the diagram, and create a node
Drag from a view, drop onto the diagram, and create a node [message #143513] Thu, 19 July 2007 10:52 Go to next message
Eclipse UserFriend
<!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 read the messages related to drag and drop in GMF, in particular
this <a
href=" http://dev.eclipse.org/newslists/news.eclipse.technology.gmf /msg01281.html">one</a>,
but I'm still in trouble. <br>
<br>
Let me introduce what I want to do.<br>
First, I have a diagram editor, built with GMF. And then, I have a
custom view (nothing to do with GMF), defined in another plugin and
made with SWT. What I want to do is drag an element from my view and
drop it on the diagram. When I drop my element, I would like to create
a new element (model and view). <br>
<br>
There are two points: catch a drop event on the diagram, and create a
new node.<br>
<br>
For the moment, I just transfer text data. I will see later for more
complex objects.<br>
So, I created a DragSource, with a Text TypeTransfer and a DragListener
in my view. <br>
And in my diagram, I added in my *DiagramEditor file a
DropTargetListener. Here is the code:<br>
<blockquote>protected void initializeGraphicalViewer() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; super.initializeGraphicalViewer();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; getDiagramGraphicalViewer().addDropTargetListener(<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; new DiagramDropTargetListener(
getDiagramGraphicalViewer(), LocalTransfer.getInstance() ) {<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; @Override<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; protected List getObjectsBeingDropped() {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println( "Dropped !" );<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return null;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; });<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
</blockquote>
But the drop event is not detected. So, in *EditPart (the one which
corresponds to the root element of my meta-model), I installed an
EditPolicy as follows:<br>
<br>
<blockquote>installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; new DiagramDragDropEditPolicy());<br>
<br>
</blockquote>
But it's still not working. Anyone to help me please ?<br>
</body>
</html>
Re: Drag from a view, drop onto the diagram, and create a node [message #144157 is a reply to message #143513] Wed, 25 July 2007 11:30 Go to previous messageGo to next message
Eclipse UserFriend
Hello Vincent,

You have to create DropTargetListener passing correct transfer instance as
a parameter. AFAIU, you are using TextTransfer in source of you D&D and installing
listener with the LocalTransfer.getInstance() on diagram.. You should use
same TextTransfer there.

-----------------
Alex Shatalin
Re: Drag from a view, drop onto the diagram, and create a node [message #144793 is a reply to message #144157] Mon, 30 July 2007 12:21 Go to previous message
Eclipse UserFriend
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hello Alex.<br>
<br>
Thanks for your reply. It doesn't change the result, but I think you're
right. :)<br>
<br>
In fact, the use "DiagramDragDropEditPolicy" is maybe not a good thing,
since it is said that it allows the drop of semantic objects (meaning -
for me - = objects from the meta-model). I've tried to install a custom
edit policy, extending "DragDropEditPolicy" : <br>
<br>
<blockquote>public class UddiOrchestrationDragDropEditPolicy extends
DragDropEditPolicy {<br>
        private OrchestrationEditPart editPart;<br>
        <br>
        public UddiOrchestrationDragDropEditPolicy() {<br>
            super();<br>
            System.out.println(" installé ");<br>
        }<br>
<br>
        protected Command getDropCommand(ChangeBoundsRequest request) {<br>
            System.out.println("get drop command");<br>
            return null;<br>
        }<br>
        <br>
        protected Command getDropElementCommand(EObject element,
DropObjectsRequest request) {<br>
            System.out.println("get dropped element command");<br>
            return null;<br>
        }<br>
        <br>
        public Command getCommand( Request request ) {<br>
            if (RequestConstants.REQ_DROP.equals(request.getType())) {<br>
                System.out.println("send request");<br>
                return getDropCommand((ChangeBoundsRequest) request);<br>
            }<br>
            return null;<br>
        }<br>
    <br>
        protected Command getDropObjectsCommand(DropObjectsRequest
request) {<br>
            System.out.println("get drop objects command");<br>
            return null;<br>
        }<br>
}<br>
</blockquote>
But still no printing.<br>
I also tried another thing in my "initializeGraphicalViewer" method of
the *DiagramEditor. I added a "new TransferDropTargetListener" to my
viewer instead of a a "DiagramDropTargetListener". <br>
<br>
<blockquote>getDiagramGraphicalViewer().addDropTargetListener( <br>
                new TransferDropTargetListener() {<br>
                    <br>
                    public Transfer getTransfer() {<br>
                        System.out.println( "Orchestration got
transfer" );<br>
                        return TextTransfer.getInstance();<br>
                    }<br>
<br>
                    public boolean isEnabled(DropTargetEvent event) {<br>
                        System.out.println( "Orchestration is enabled"
);<br>
                        return true;<br>
                    }<br>
<br>
                    public void dragEnter(DropTargetEvent event) {<br>
                        System.out.println( "enter");<br>
                        if (event.detail == DND.DROP_DEFAULT) {<br>
                            event.detail = (event.operations &amp;
DND.DROP_COPY) != 0 ? DND.DROP_COPY : DND.DROP_NONE;<br>
                        }<br>
<br>
                        // Allow dropping text only<br>
                        for (int i = 0, n = event.dataTypes.length; i
&lt; n; i++) {<br>
                            if
(TextTransfer.getInstance().isSupportedType(event.dataTypes[ i])) {<br>
                                event.currentDataType =
event.dataTypes[i];<br>
                            }<br>
                        }<br>
                    }<br>
<br>
                    public void dragLeave(DropTargetEvent event) {<br>
                        System.out.println( "Orchestration drag leave"
);                       <br>
                    }<br>
<br>
                    public void dragOperationChanged(DropTargetEvent
event) {<br>
                        System.out.println( "Orchestration operation
changed" );<br>
                    }<br>
<br>
                    public void dragOver(DropTargetEvent event) {<br>
                        System.out.println( "Orchestration drag over"
);                      <br>
                    }<br>
<br>
                    public void drop(DropTargetEvent event) {<br>
                        if
(TextTransfer.getInstance().isSupportedType(event.currentDat aType)) {<br>
                            System.out.println("Orchestration drop");<br>
                        } else<br>
                            System.out.println("Orchestration drop
failed");<br>
                    }<br>
<br>
                    public void dropAccept(DropTargetEvent event) {<br>
                        System.out.println( "Orchestration drop
accepted" );<br>
                    }<br>
                });<br>
</blockquote>
<br>
But still nothing. I don't understand why the editor does not detect
any drop action, since I added printings everywhere. Besides, I'm
working with Linux, and the drag source calls the "dragSetData" method
only on a drop event. But with a drop on the editor, this method is not
called. I think the problem is that I don't drag and drop semantic
elements. But I don't understand why it would be a problem, since GMF
is built on top of SWT and that I didn't encounter any problem with DnD
in SWT. <br>
<br>
Any help is welcome.<br>
<br>
Regards,<br>
<br>
                 Vincent.<br>
<br>
<br>
<br>
Alex Shatalin wrote:
<blockquote cite="mid3c3172e6164fb8c99cf8ad80aa0f@news.eclipse.org"
type="cite">Hello Vincent,
<br>
<br>
You have to create DropTargetListener passing correct transfer instance
as a parameter. AFAIU, you are using TextTransfer in source of you
D&amp;D and installing listener with the LocalTransfer.getInstance() on
diagram.. You should use same TextTransfer there.
<br>
<br>
-----------------
<br>
Alex Shatalin
<br>
<br>
<br>
</blockquote>
<br>
</body>
</html>
Previous Topic:GENERATION PROBLEM
Next Topic:Access EditPart's model within a LayoutManager
Goto Forum:
  


Current Time: Fri Jun 06 01:53:37 EDT 2025

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

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

Back to the top