### Eclipse Workspace Patch 1.0 #P org.eclipse.jface Index: src/org/eclipse/jface/viewers/ListViewer.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/ListViewer.java,v retrieving revision 1.14 diff -u -r1.14 ListViewer.java --- src/org/eclipse/jface/viewers/ListViewer.java 8 May 2006 20:56:56 -0000 1.14 +++ src/org/eclipse/jface/viewers/ListViewer.java 13 May 2006 18:02:13 -0000 @@ -188,5 +188,19 @@ protected void listShowSelection() { list.showSelection(); } - + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.AbstractListViewer#listGetTopIndex() + */ + protected int listGetTopIndex() { + return list.getTopIndex(); + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.viewers.AbstractListViewer#listSetTopIndex(int) + */ + protected void listSetTopIndex(int index) { + list.setTopIndex(index); + } } Index: src/org/eclipse/jface/viewers/AbstractListViewer.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jface/src/org/eclipse/jface/viewers/AbstractListViewer.java,v retrieving revision 1.13 diff -u -r1.13 AbstractListViewer.java --- src/org/eclipse/jface/viewers/AbstractListViewer.java 8 May 2006 20:56:57 -0000 1.13 +++ src/org/eclipse/jface/viewers/AbstractListViewer.java 13 May 2006 18:02:13 -0000 @@ -318,7 +318,6 @@ * Method declared on StructuredViewer. */ protected void internalRefresh(Object element) { - Control list = getControl(); if (element == null || equals(element, getRoot())) { // the parent @@ -327,7 +326,12 @@ } unmapAllElements(); List selection = getSelectionFromWidget(); - + + int topIndex = -1; + if (selection == null || selection.isEmpty()) { + topIndex = listGetTopIndex(); + } + list.setRedraw(false); listRemoveAll(); @@ -345,13 +349,39 @@ listSetItems(items); list.setRedraw(true); - setSelectionToWidget(selection, false); + + if (topIndex == -1) { + setSelectionToWidget(selection, false); + } else { + listSetTopIndex(Math.min(topIndex, children.length)); + } } else { doUpdateItem(list, element, true); } } + + /** + * Returns the index of the item currently at the top of the viewable area. + *

+ * Default implementation returns -1. + *

+ * @return index, -1 for none + */ + protected int listGetTopIndex(){ + return -1; + } /** + * Sets the index of the item to be at the top of the viewable area. + *

+ * Default implementation does nothing. + *

+ * @param index, -1 for none. index will always refer to a valid index. + */ + protected void listSetTopIndex(int index) { + } + + /** * Removes the given elements from this list viewer. * * @param elements the elements to remove