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

Bug 276435

Summary: [Gallery] Gallery.remove(GalleryItem item) doesn't succeed to remove an item GalleryItem from a group GalleryItem.
Product: z_Archived Reporter: Vincent Monfort <nobelius>
Component: NebulaAssignee: Nicolas Richeton <nicolas.richeton>
Status: CLOSED FIXED QA Contact:
Severity: major    
Priority: P1 Keywords: plan
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
mylyn/context/zip none

Description Vincent Monfort CLA 2009-05-15 03:42:37 EDT
Build ID: M20080221-1800

Steps To Reproduce:
Case 1:
1.Create one Gallery with one GalleryItem "group" and one GalleryItem "item" which has "group" as parent.
2. Use Gallery.remove("item")
3. The GalleryItem "group" is removed because it remove the GalleryItem with index==0 of Gallery.

Case 2:
1.Create one Gallery with one GalleryItem "group" and two GalleryItem "item1" and "item2" which have both "group" as parent.
2. Use Gallery.remove("item2")
3. The Exception :
"java.lang.ArrayIndexOutOfBoundsException: 1
	at org.eclipse.nebula.widgets.gallery.Gallery._remove(Gallery.java:2141)
	at org.eclipse.nebula.widgets.gallery.Gallery.remove(Gallery.java:2128)
	at org.eclipse.nebula.widgets.gallery.Gallery.remove(Gallery.java:2136)"

will be thrown because Gallery try to remove the GalleryItem group with index==1 which doesn't exists.
Indeed the good index in the group was found ("1") but it try to remove a group and not the item.

More information:
I did a correction for my personnal purpose which resolve the problem described. It is based on the mechanism to find the good index : Gallery.indexof(GalleryItem).

Corrected method:

"public void remove(GalleryItem item) {
	int index = indexOf(item);

	if (item.getParentItem() == null){
		this.remove(index);
	}else{
		this._remove(item.getParentItem(), index);
		//To update the view otherwise it's not done
                updateStructuralValues(null, false);
		updateScrollBarsProperties();
		}
}
"
Comment 1 Nicolas Richeton CLA 2009-05-15 04:06:55 EDT
Fixed in CVS > 20090515
Added unit test
Thanks
Comment 2 Nicolas Richeton CLA 2009-05-15 04:06:57 EDT
Created attachment 135940 [details]
mylyn/context/zip
Comment 3 Nicolas Richeton CLA 2009-05-15 04:07:54 EDT
Fixed
Comment 4 Nicolas Richeton CLA 2009-06-17 06:43:50 EDT
Closing this bug