Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 50920 Details for
Bug 141435
[Viewers] ListViewer without a selection loses scrolled state when refreshed
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
combined patch
patch-141435.txt (text/plain), 11.17 KB, created by
Boris Bokowski
on 2006-09-26 12:19:38 EDT
(
hide
)
Description:
combined patch
Filename:
MIME Type:
Creator:
Boris Bokowski
Created:
2006-09-26 12:19:38 EDT
Size:
11.17 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jface >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.16 >diff -u -r1.16 AbstractListViewer.java >--- src/org/eclipse/jface/viewers/AbstractListViewer.java 14 Sep 2006 21:00:03 -0000 1.16 >+++ src/org/eclipse/jface/viewers/AbstractListViewer.java 26 Sep 2006 16:21:54 -0000 >@@ -9,6 +9,7 @@ > * IBM Corporation - initial API and implementation > * Chris Longfield <clongfield@internap.com> - Fix for Bug 70856 > * Tom Schindl - fix for bug 157309 >+ * Brad Reynolds - bug 141435 > *******************************************************************************/ > > package org.eclipse.jface.viewers; >@@ -349,7 +350,6 @@ > * Method declared on StructuredViewer. > */ > protected void internalRefresh(Object element) { >- > Control list = getControl(); > if (element == null || equals(element, getRoot())) { > // the parent >@@ -358,7 +358,12 @@ > } > unmapAllElements(); > List selection = getSelectionFromWidget(); >- >+ >+ int topIndex = -1; >+ if (selection == null || selection.isEmpty()) { >+ topIndex = listGetTopIndex(); >+ } >+ > list.setRedraw(false); > listRemoveAll(); > >@@ -376,13 +381,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. >+ * <p> >+ * Default implementation returns -1. >+ * </p> >+ * @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. >+ * <p> >+ * Default implementation does nothing. >+ * </p> >+ * @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 >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.15 >diff -u -r1.15 ListViewer.java >--- src/org/eclipse/jface/viewers/ListViewer.java 6 Sep 2006 18:39:27 -0000 1.15 >+++ src/org/eclipse/jface/viewers/ListViewer.java 26 Sep 2006 16:21:54 -0000 >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * Brad Reynolds - bug 141435 > *******************************************************************************/ > > package org.eclipse.jface.viewers; >@@ -188,5 +189,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); >+ } > } >#P org.eclipse.ui.tests >Index: Eclipse JFace Tests/org/eclipse/jface/tests/viewers/AllTests.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/viewers/AllTests.java,v >retrieving revision 1.36 >diff -u -r1.36 AllTests.java >--- Eclipse JFace Tests/org/eclipse/jface/tests/viewers/AllTests.java 29 Aug 2006 19:58:48 -0000 1.36 >+++ Eclipse JFace Tests/org/eclipse/jface/tests/viewers/AllTests.java 26 Sep 2006 16:21:55 -0000 >@@ -49,5 +49,6 @@ > addTestSuite(TableViewerComparatorTest.class); > addTestSuite(Bug138608Test.class); > addTestSuite(ComboViewerComparerTest.class); >+ addTestSuite(ListViewerRefreshTest.class); > } > } >Index: Eclipse JFace Tests/org/eclipse/jface/tests/viewers/ListViewerTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.tests/Eclipse JFace Tests/org/eclipse/jface/tests/viewers/ListViewerTest.java,v >retrieving revision 1.10 >diff -u -r1.10 ListViewerTest.java >--- Eclipse JFace Tests/org/eclipse/jface/tests/viewers/ListViewerTest.java 14 Sep 2006 21:00:14 -0000 1.10 >+++ Eclipse JFace Tests/org/eclipse/jface/tests/viewers/ListViewerTest.java 26 Sep 2006 16:21:55 -0000 >@@ -8,6 +8,7 @@ > * Contributors: > * IBM Corporation - initial API and implementation > * Tom Schindl - test case for bug 157309 >+ * Brad Reynolds - test case for bug 141435 > *******************************************************************************/ > package org.eclipse.jface.tests.viewers; > >@@ -103,4 +104,41 @@ > } > } > } >+ >+ /** >+ * Asserts the ability to refresh a List that contains no selection without losing vertically scrolled state. >+ * >+ * @throws Exception >+ */ >+ public void testRefreshBug141435() throws Exception { >+ fViewer = null; >+ if (fShell != null) { >+ fShell.dispose(); >+ fShell = null; >+ } >+ openBrowser(); >+ TestElement model = TestElement.createModel(1, 50); >+ fViewer.setInput(model); >+ >+ int lastIndex = model.getChildCount() - 1; >+ >+ //Scroll... >+ fViewer.reveal(model.getChildAt(lastIndex)); >+ List list = (List) fViewer.getControl(); >+ int topIndex = list.getTopIndex(); >+ >+ assertTrue("Top item should not be the first item.", topIndex != 0); >+ fViewer.refresh(); >+ assertEquals("Top index was not preserved after refresh.", topIndex, list.getTopIndex()); >+ >+ //Assert that when the previous top index after refresh is invalid no exceptions are thrown. >+ model.deleteChildren(); >+ >+ try { >+ fViewer.refresh(); >+ assertEquals(0, list.getTopIndex()); >+ } catch (Exception e) { >+ fail("Refresh failure when refreshing with an empty model."); >+ } >+ } > } >Index: Eclipse JFace Tests/org/eclipse/jface/tests/viewers/ListViewerRefreshTest.java >=================================================================== >RCS file: Eclipse JFace Tests/org/eclipse/jface/tests/viewers/ListViewerRefreshTest.java >diff -N Eclipse JFace Tests/org/eclipse/jface/tests/viewers/ListViewerRefreshTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ Eclipse JFace Tests/org/eclipse/jface/tests/viewers/ListViewerRefreshTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,151 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 Brad Reynolds. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Brad Reynolds - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.jface.tests.viewers; >+ >+import java.util.ArrayList; >+import java.util.List; >+ >+import junit.framework.TestCase; >+ >+import org.eclipse.jface.viewers.IStructuredContentProvider; >+import org.eclipse.jface.viewers.ListViewer; >+import org.eclipse.jface.viewers.StructuredSelection; >+import org.eclipse.jface.viewers.Viewer; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.layout.FillLayout; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Label; >+import org.eclipse.swt.widgets.Shell; >+ >+public class ListViewerRefreshTest extends TestCase { >+ /** >+ * Used for viewing the UI. Set to 0 if not wanting to see the UI. >+ */ >+ private static final int DELAY = 0; >+ >+ private Shell shell = null; >+ >+ private Label label = null; >+ >+ private ListViewer viewer = null; >+ >+ private ArrayList input = null; >+ >+ protected void setUp() throws Exception { >+ shell = new Shell(); >+ shell.setSize(400, 200); >+ shell.setLayout(new FillLayout()); >+ label = new Label(shell, SWT.WRAP); >+ viewer = new ListViewer(shell); >+ input = new ArrayList(); >+ >+ for (int i = 0; i < 50; i++) { >+ input.add("item " + i); //$NON-NLS-1$ >+ } >+ >+ viewer.setContentProvider(new ContentProvider()); >+ viewer.setInput(input); >+ shell.layout(); >+ shell.open(); >+ } >+ >+ /** >+ * Asserts the ability to refresh without a selection and preserve the >+ * scrolled to position. >+ * >+ * @throws Exception >+ */ >+ public void testNoSelectionRefresh() throws Exception { >+ shell.setText("Lost Scrolled Position Test"); //$NON-NLS-1$ >+ readAndDispatch(); >+ >+ run("Scrolled to position 30.", new Runnable() { //$NON-NLS-1$ >+ public void run() { >+ viewer.reveal(input.get(30)); >+ } >+ }); >+ >+ run("Refreshed viewer without a selection.", new Runnable() { //$NON-NLS-1$ >+ public void run() { >+ viewer.refresh(); >+ } >+ }); >+ >+ // BUG: The top index should not be the first item. >+ assertTrue(viewer.getList().getTopIndex() != 0); >+ } >+ >+ /** >+ * Asserts the ability to refresh with a selection and preserve the scrolled >+ * to position. >+ * >+ * @throws Exception >+ */ >+ public void testSelectionRefresh() throws Exception { >+ shell.setText("Preserved Scrolled Position Test"); //$NON-NLS-1$ >+ readAndDispatch(); >+ >+ run("Setting selection to index 30.", new Runnable() { //$NON-NLS-1$ >+ public void run() { >+ viewer.setSelection(new StructuredSelection(input >+ .get(30))); >+ } >+ }); >+ >+ run("Refreshed viewer with selection.", new Runnable() { //$NON-NLS-1$ >+ public void run() { >+ viewer.refresh(); >+ } >+ }); >+ >+ assertTrue(viewer.getList().getTopIndex() != 0); >+ } >+ >+ /** >+ * Runs the runnable and displays the description. >+ * >+ * @param description >+ * @param runnable >+ */ >+ private void run(String description, Runnable runnable) { >+ runnable.run(); >+ label.setText(description); >+ >+ readAndDispatch(); >+ } >+ >+ /** >+ * Flush UI events and {@link #DELAY delays}. >+ */ >+ private void readAndDispatch() { >+ Display display = Display.getCurrent(); >+ display.readAndDispatch(); >+ >+ try { >+ Thread.sleep(DELAY); >+ } catch (InterruptedException e) { >+ e.printStackTrace(); >+ } >+ } >+ >+ private class ContentProvider implements IStructuredContentProvider { >+ >+ public Object[] getElements(Object inputElement) { >+ return ((List) inputElement).toArray(); >+ } >+ >+ public void dispose() { >+ } >+ >+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { >+ } >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 141435
:
41233
|
41406
|
41407
| 50920