Bug 150096 - [Viewers] Removing an object from a virtual table will NOT decrement the itemCount
Summary: [Viewers] Removing an object from a virtual table will NOT decrement the item...
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks: 154755
  Show dependency tree
 
Reported: 2006-07-09 11:11 EDT by Giovanni Quarella CLA
Modified: 2021-11-07 15:18 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Giovanni Quarella CLA 2006-07-09 11:11:46 EDT
In the doc of org.eclipse.jface.viewers.TableViewer.remove(Object element)
you read this note
"removing an object from a virtual table will decrement the itemCount"

but in the following sample code this doesn't work

System.out.println("Item Count before delete: "+ viewer.getTable().getItemCount());
				
... code to remove the item from my model

viewer.remove(obj);
viewer.refresh();
				
System.out.println("Item Count after delete: "+ viewer.getTable().getItemCount());

I've downloaded eclipse-SDK-N20060709-0010-win32.zip.
Comment 1 Giovanni Quarella CLA 2006-07-16 10:13:18 EDT
(In reply to comment #0)
> In the doc of org.eclipse.jface.viewers.TableViewer.remove(Object element)
> you read this note
> "removing an object from a virtual table will decrement the itemCount"
> but in the following sample code this doesn't work
> System.out.println("Item Count before delete: "+
> viewer.getTable().getItemCount());
> ... code to remove the item from my model
> viewer.remove(obj);
> viewer.refresh();
> System.out.println("Item Count after delete: "+
> viewer.getTable().getItemCount());
> I've downloaded eclipse-SDK-N20060709-0010-win32.zip.

Then I tried to set itemcount manually. Consider now a model with one element and the following code

... code to remove the item from my model
viewer.remove(selection.toArray());		
viewer.setItemCount(itemCount); //in this case itemcount=0
viewer.refresh();

A call to updateElement(0) is generated but element 0 has just been removed from my model so I have error.
I tried then 

... code to remove the item from my model
viewer.setItemCount(itemCount); //in this case itemcount=0
viewer.remove(selection.toArray());		
viewer.refresh();

But the setItemCount disposes the widget and the remove fails.
Then I replaced viewer.remove with viewer.getTable().remove and it works, now I deleted viewer.getTable().remove and it works the same, maybe by the viewer.refresh.
So with virtual tables is it better to don't use the viewer.remove?
Comment 2 Boris Bokowski CLA 2006-07-26 09:32:24 EDT
This is a bug (see also bug 97786 for another problem with viewer.remove()).
Comment 3 Giovanni Quarella CLA 2006-08-20 13:20:56 EDT
(In reply to comment #2)
> This is a bug (see also bug 97786 for another problem with viewer.remove()).

Now I used

... code to remove the item from my model

viewer.setItemCount(newitemCount);
viewer.refresh();

Consider a simple case: one item to remove (newitemCount=itemCount-1)
item 0 - selected
item 1
item 2

If I remove item 0, I have:
item 0 ex item 1
item 1 ex item 2 - selected

If I remove Item 0, I think that the next item should be selected. The next item is item 1, but without item 0, item 1 become item 0, so the selection shouldn't change at all.
So I manually set the desidered selection with viewer.getTable().setSelection(nextSelectedIndex), but now I submit the bug 153669.
Comment 4 Boris Bokowski CLA 2007-05-28 23:28:05 EDT
I hope we can get to this in 3.4.  In 3.3, I ended up spending so much time on the virtual tree (which is used by Debug) that I never got to look at virtual tables.
Comment 5 Boris Bokowski CLA 2008-05-02 14:56:36 EDT
Mass update - removing 3.4 target. This was one of the bugs I marked for investigation (and potential fixing) in 3.4 but I ran out of time. Please ping on the bug if fixing it would be really important for 3.4, and does not require API changes or feature work.
Comment 6 Boris Bokowski CLA 2009-11-26 09:49:37 EST
Hitesh is now responsible for watching bugs in the [Viewers] component area.
Comment 7 Eclipse Webmaster CLA 2019-09-06 16:07:09 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.
Comment 8 Eclipse Genie CLA 2021-11-07 15:18:55 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.