Results 1 to 5 of 5

Thread: Drag & Drop Copy/Move question

  1. #1
    Sencha Premium User
    Join Date
    Nov 2008
    Location
    Vienna - Austria
    Posts
    888
    Vote Rating
    1
      0  

    Default Drag & Drop Copy/Move question

    Hi everyone.

    I am using drag and drop for reordering/copying nodes over a tree.

    I want to perform a Move operation by default, but I want to change the operation to Copy when the user presses the alt key while dragging...

    Is it possible to achieve this behaviour?
    How?

    Thanks for replying.

    Regards,
    Michel.

  2. #2
    Sencha Premium Member
    Join Date
    Sep 2007
    Posts
    13,976
    Vote Rating
    131
      0  

    Default

    extend your DragSource and override onDragDrop.
    Code:
    Operation o = e.getOperation();
    if(e.isAltKey()){
    e.setOperation(Operation.COPY);
    }
    super.onDragDrop(e);
    e.setOperation(o);
    I havent tested that good, but should work

  3. #3
    Sencha Premium User
    Join Date
    Nov 2008
    Location
    Vienna - Austria
    Posts
    888
    Vote Rating
    1
      0  

    Default

    hmm.
    Tks for the reply sven...

    But this didn't work.

    The default operation (MOVE) was applied.

    And even if this worked, I guess the icon used while dragging would also not be updated...

    Do you have any other idea?

  4. #4
    Sencha Premium User
    Join Date
    Nov 2008
    Location
    Vienna - Austria
    Posts
    888
    Vote Rating
    1
      0  

    Default

    Actually it almost worked...
    Sorry, I did not what you were telling me to do... I created a listener... instead of override the TreePanelDragSource...

    Anyway, the way you suggested actually did not move the node...
    But the copy failed in some way...

    Also, the icon while dragging was not updated as well... (as expected).
    I will try to think about something else...
    If someone knows something about this, please post it here..


    PS:
    Actually I don't care about the behaviour... this is ok for me if the new node is not created...
    Since my tree structure is defined in the server side, a Operation.NONE for me would be the best one.
    I just needed to define a different icon:
    one icon for me copy operation
    one icon for the move operation

  5. #5
    Sencha Premium User
    Join Date
    Nov 2008
    Location
    Vienna - Austria
    Posts
    888
    Vote Rating
    1
      0  

    Default

    Ok, so I figured it out how to change the icons on the event.

    You have to extend the TreeDropTarget (in my case I am using the Drop on a tree), overriding this two methods: handleAppend and handleInsert.

    Then you can change your css in the following way (for example):

    Code:
    @Override
                protected void handleAppend(DNDEvent event, TreeItem item) {
                    super.handleAppend(event, item);
                    if (event.isAltKey()) {
                        event.status.setStatus(true, "x-dd-drop-ok-add");
                    } else {
                        event.status.setStatus(true, "x-dd-drop-ok");
                    }
                }
    Hope this can be helpful for someone else as well.

    Regards,
    Michel.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •