Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 355368

Summary: [Navigator & Editor Sockets] Drag and drop tree-item/element from file A to file B got problem
Product: [Automotive] Sphinx Reporter: nguyenntk Mising name <nguyenntk>
Component: CoreAssignee: Stephan Eberle <stephaneberle9>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: idydieng, quoclan, r.sezestre, stephaneberle9
Version: 0.7.0   
Target Milestone: 0.7.0   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Modified classes
none
BasicDropAdapterAssistant.java.patch idydieng: iplog+

Description nguyenntk Mising name CLA 2011-08-22 07:47:43 EDT
Build Identifier: 

1. Drag element a of file A
2. Drop it to element b of file B

Expected result:
element a is a child element of element b

Actual result:
element a is a sibling element of element b

Reproducible: Always
Comment 1 nguyenntk Mising name CLA 2011-08-22 07:58:59 EDT
Created attachment 201911 [details]
Modified classes

- Classes modified:
org.eclipse.emf.edit.command.DragAndDropCommand
org.eclipse.sphinx.emf.explorer.BasicDropAdapterAssistant:
- Edited methods to set the dragged object will become a child element, not a sibling element of the target object:
promptAndExecuteDropMove
prepareDropInsert
Comment 2 Stephan Eberle CLA 2011-08-23 02:28:50 EDT
(In reply to comment #1)
> - Classes modified:
> org.eclipse.emf.edit.command.DragAndDropCommand
> org.eclipse.sphinx.emf.explorer.BasicDropAdapterAssistant:

We cannot modify EMF code in Sphinx. Only Sphinx classes can be modified. Please revise the patch and/or submit a bug to EMF if you think that the DragAndDropCommand modification is a must to have.
Comment 3 Lan Phan CLA 2011-08-29 03:10:48 EDT
The root cause of this bug is: BasicDropAdapterAssistant doesn't use correct location.
Drag and drop, except for move, copy, link; there is another factor: location. Location is a "relative vertical location of the drag operation", and its range is from 0.0 to 1.0. Based on this location, DragAndDropCommand will understand to:
- location (<=0.2 or >=0.8):
  * do DROP_INSERT first, if not ok, do DROP_ON
- location (>0.2 and <0.8):
  * do DROP_ON first, if not ok, do DROP_INSERT

with:
* DROP_INSERT: find a parent of target element, then paste source as child of this parent --> pasted source will be a sibling element of target

* DROP_ON: paste source as child of target element --> pasted source will be a child element of target


Currently, BasicDropAdapterAssistant provides the wrong "location" to create DragAndDropCommand:
1. In validateDrop() method, it passes "0.0f" as location to create DragAndDropCommand
2. In handleDropCopy() and handleDropMove() methods, it uses "dropAdapter.getCurrentLocation()" (and this method returns integer value ranges from 1 -> 4)

Therefore, it always do DROP_INSERT first --> we'll get "pasted source is a sibling element of target" in case type of target element and its parent element is the same (for ex.: ARPackage element in Autosar)

Solution:
- Define new attribute "location=0.5f" and use this attribute for all statements to create DragAndDropCommand

Provided patch is in attachment.
Comment 4 Lan Phan CLA 2011-08-29 03:11:34 EDT
Created attachment 202299 [details]
BasicDropAdapterAssistant.java.patch
Comment 5 Stephan Eberle CLA 2011-09-01 06:23:57 EDT
(In reply to comment #3)
> Solution:
> - Define new attribute "location=0.5f" and use this attribute for all
> statements to create DragAndDropCommand
> 
> Provided patch is in attachment.

Sounds good to me. Am I right that this second patch is a replacement for the first one and removes the need to modify EMF's DragAndDropCommand? If yes then mark the first patch as obsolete, please.
Comment 6 Lan Phan CLA 2011-09-01 09:34:38 EDT
(In reply to comment #5)
> Sounds good to me. Am I right that this second patch is a replacement for the
> first one and removes the need to modify EMF's DragAndDropCommand?
Yes, it is (just apply the second patch to fix this bug, no need to modify DragAndDropCommand)

> If yes then mark the first patch as obsolete, please.
Sorry, I don't know how to mark first patch as obsolete :(, would you mind to help me?
Comment 7 Idrissa Dieng CLA 2011-09-01 09:37:53 EDT
(In reply to comment #6)
> (In reply to comment #5)
> > Sounds good to me. Am I right that this second patch is a replacement for the
> > first one and removes the need to modify EMF's DragAndDropCommand?
> Yes, it is (just apply the second patch to fix this bug, no need to modify
> DragAndDropCommand)
> 
> > If yes then mark the first patch as obsolete, please.
> Sorry, I don't know how to mark first patch as obsolete :(, would you mind to
> help me?

Click on Details of relevant patch (https://bugs.eclipse.org/bugs/attachment.cgi?id=201911&action=edit), then check "obsolete" button and submit.
Comment 8 Stephan Eberle CLA 2011-09-02 02:23:28 EDT
Fixed by applying proposed 2nd patch. Added some overriding points so as to enable clients to subclass and customize the BasicDropAdapterAssistant wrt drop location and drag and drop operations.

Thanks again for this very valuable contribution!
Comment 9 Balazs Grill CLA 2021-07-14 02:15:22 EDT
Mass-closing Resolved tickets