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

Bug 149799

Summary: DragEditPartsTracker NullPointerException in updateTargetRequest
Product: [Tools] GEF Reporter: Eric Kop <koperic>
Component: GEF-Legacy GEF (MVC)Assignee: Anthony Hunter <ahunter.eclipse>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P2 CC: ahunter.eclipse, hudsonr
Version: 3.2   
Target Milestone: 3.2.2 (Callisto SR2)   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
DragEditPartsTracker patch none

Description Eric Kop CLA 2006-07-06 06:13:47 EDT
I get a NullPointerException in the method updateTargetRequest, because the sourceRectangle = null. In 3.1.1 the sourceLocation was always set in the method captureSourceDimensions, but that piece of code has been removed.
Why?

In updateTargetRequest:
"if (snapToHelper != null && !getCurrentInput().isModKeyDown(MODIFIER_IGNORE_SNAP)) {
   PrecisionRectangle baseRect = sourceRectangle.getPreciseCopy();"

In captureSourceDimensions of 3.1.1 (not in 3.2):
"/* @TODO:Pratik  Remove this for 3.2 */
 if (sourceRectangle == null) {
    IFigure figure = ((GraphicalEditPart)getSourceEditPart()).getFigure();
		if (figure instanceof HandleBounds)
			sourceRectangle = new PrecisionRectangle(
					((HandleBounds)figure).getHandleBounds());
 else
   sourceRectangle = new PrecisionRectangle(figure.getBounds());
   figure.translateToAbsolute(sourceRectangle);
}"
Comment 1 Randy Hudson CLA 2006-07-06 11:39:38 EDT
Can you provide steps to reproduce the problem? Did you select both a child and its parent, and drag from the child?
Comment 2 Randy Hudson CLA 2006-07-06 11:45:03 EDT
Steps:
1) Create circuit containing an LED
2) Select both circuit and LED
3) Drag starting from LED

Possible workaround. In your editpart's getDragTracker() method, find the highest parent or ancestor editpart that is part of the viewer's selection, and forward getDragTracker() to that editpart.

EditPart walker = getParent();
EditPart highestSelected = this;
while (walker != null) {
  if (walker.getSelected() != EditPart.SELECTED_NONE)
    highestSelected = walker;
  walker = walker.getParent();
}
return new DragEditPartsTracker(highestSelected);

Please let us know if this workaround works, so we can adjust the priority as appropriate.
Comment 3 Eric Kop CLA 2006-07-08 10:49:56 EDT
(In reply to comment #2)
> Steps:
> 1) Create circuit containing an LED
> 2) Select both circuit and LED
> 3) Drag starting from LED
> Possible workaround. In your editpart's getDragTracker() method, find the
> highest parent or ancestor editpart that is part of the viewer's selection, and
> forward getDragTracker() to that editpart.
> EditPart walker = getParent();
> EditPart highestSelected = this;
> while (walker != null) {
>   if (walker.getSelected() != EditPart.SELECTED_NONE)
>     highestSelected = walker;
>   walker = walker.getParent();
> }
> return new DragEditPartsTracker(highestSelected);
> Please let us know if this workaround works, so we can adjust the priority as
> appropriate.

I need a selection for dragging (highest parent) and a selection to activate a properties page (child)
The workaround is fine, although I needed to do more than that.

Comment 4 Pratik Shah CLA 2006-07-10 11:48:52 EDT
The piece of code that was removed, I had added that originally as a fail-safe.  But then I couldn't think of a case where the selected part wouldn't be in the operation set, and marked it as to be removed, not realizing that the operation set didn't include children of selected editparts.  I think we can just add that code back again.
Comment 5 Randy Hudson CLA 2006-07-10 13:29:14 EDT
There is a place where the sourceRectangle is *sometimes* assigned. I think the best fix is to make sure it is always assigned. This makes the code easier to understand, and avoids the same code getting removed again in the future.
Comment 6 Pratik Shah CLA 2007-02-07 21:57:28 EST
I saw that GEF 3.2.2 was released yesterday.  Is it possible to re-run that build with the fix for this bug included?  Or a 3.2.2.1?

At the very least, this should be fixed in HEAD.
Comment 7 Anthony Hunter CLA 2007-02-08 10:28:23 EST
Yes, I can apply this fix to 3.2.2 and respin the final 3.2.2 build.

I have attached a patch, please confirm this is what we want just so we are all on the same page.
Comment 8 Anthony Hunter CLA 2007-02-08 10:28:54 EST
Created attachment 58561 [details]
DragEditPartsTracker patch
Comment 9 Anthony Hunter CLA 2007-02-08 13:00:35 EST
Committed to R32_Maintenance (3.2.2) and HEAD (3.3)