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 113585 Details for
Bug 248700
[GalleryTreeViewer] New groups added via refresh() appear collapsed
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
Unit test for this bug
Bug248700Test.java (text/plain), 5.70 KB, created by
Nicolas Richeton
on 2008-09-26 08:41:12 EDT
(
hide
)
Description:
Unit test for this bug
Filename:
MIME Type:
Creator:
Nicolas Richeton
Created:
2008-09-26 08:41:12 EDT
Size:
5.70 KB
patch
obsolete
>package org.eclipse.nebula.widgets.gallery.tests; > >import java.util.ArrayList; >import java.util.HashMap; >import java.util.List; > >import junit.framework.TestCase; > >import org.eclipse.jface.layout.GridDataFactory; >import org.eclipse.jface.layout.GridLayoutFactory; >import org.eclipse.jface.viewers.AbstractTreeViewer; >import org.eclipse.jface.viewers.IColorProvider; >import org.eclipse.jface.viewers.IFontProvider; >import org.eclipse.jface.viewers.ITreeContentProvider; >import org.eclipse.jface.viewers.LabelProvider; >import org.eclipse.jface.viewers.TreeViewer; >import org.eclipse.jface.viewers.Viewer; >import org.eclipse.nebula.jface.galleryviewer.GalleryTreeViewer; >import org.eclipse.swt.SWT; >import org.eclipse.swt.graphics.Color; >import org.eclipse.swt.graphics.Font; >import org.eclipse.swt.graphics.FontData; >import org.eclipse.swt.graphics.Image; >import org.eclipse.swt.program.Program; >import org.eclipse.swt.widgets.Display; >import org.eclipse.swt.widgets.Shell; > >public class Bug248700Test extends TestCase { > > protected static class GalleryTestContentProvider implements > ITreeContentProvider { > // implements IStructuredContentProvider { // Use this to test > // FlatTreeContentProvider > public static final int NUM_GROUPS = 1; > public static final int NUM_ITEMS = 9; > > List groups = new ArrayList(); > HashMap itemsByGroup = new HashMap(); > > public GalleryTestContentProvider() { > for (int i = 0; i < NUM_GROUPS; i++) { > addNewGroup(); > } > } > > public Object[] getChildren(Object parentElement) { > return ((ArrayList) itemsByGroup.get(parentElement)).toArray(); > } > > public Object getParent(Object element) { > return null; > } > > public boolean hasChildren(Object element) { > return ((String) element).startsWith("Group"); > } > > public Object[] getElements(Object inputElement) { > return groups.toArray(); > } > > public void dispose() { > } > > public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { > } > > public void addNewGroup() { > List items = new ArrayList(); > for (int j = 0; j < NUM_ITEMS; j++) { > items.add("Item " + (j + 1)); > } > final String group = "Group " + (groups.size() + 1); > itemsByGroup.put(group, items); > groups.add(group); > } > } > > protected static class GalleryTestLabelProvider extends LabelProvider > implements IColorProvider, IFontProvider { > protected static Image itemImage = new Image(Display.getCurrent(), > Program.findProgram("jpg").getImageData()); > > public Image getImage(Object element) { > return itemImage; > } > > public Color getBackground(Object element) { > String label = (String) element; > if (Integer.parseInt(label.substring(label.indexOf(' ') + 1)) % 2 > 0) { > return Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW); > } else { > return null; > } > } > > public Color getForeground(Object element) { > String label = (String) element; > if (Integer.parseInt(label.substring(label.indexOf(' ') + 1)) % 2 > 0) { > return null; > } else { > return Display.getCurrent().getSystemColor(SWT.COLOR_BLUE); > } > } > > public Font getFont(Object element) { > String label = (String) element; > if (Integer.parseInt(label.substring(label.indexOf(' ') + 1)) % 2 > 0) { > return null; > } else { > FontData sysFontData = Display.getCurrent().getSystemFont() > .getFontData()[0]; > sysFontData.setStyle(SWT.BOLD | SWT.ITALIC); > return new Font(Display.getCurrent(), sysFontData); > } > } > } > > private Shell s = null; > private Display d = null; > > protected void setUp() throws Exception { > d = new Display(); > s = new Shell(d, SWT.NONE); > super.setUp(); > } > > protected void tearDown() throws Exception { > d.dispose(); > super.tearDown(); > } > > // Items class > static public class Foo { > > private String name; > private int value; > > public Foo(String message) { > this.name = message; > } > > public Foo(String name, int value) { > this.name = name; > this.value = value; > } > > public String toString() { > return name; > } > > public String getName() { > return name; > } > > public int getValue() { > return value; > } > > } > > public void testBug217988() { > Shell shell = s; > > GridLayoutFactory.fillDefaults().applyTo(shell); > > final GalleryTreeViewer viewer = new GalleryTreeViewer(shell); > GridDataFactory.fillDefaults().grab(true, true).applyTo( > viewer.getGallery()); > final GalleryTestContentProvider contentProvider = new GalleryTestContentProvider(); > viewer.setContentProvider(contentProvider); > viewer.setLabelProvider(new GalleryTestLabelProvider()); > > viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS); > viewer.setInput(new Object()); > > // Check that expand all is working > assertTrue(viewer.getGallery().getItem(0).isExpanded()); > contentProvider.addNewGroup(); > viewer.refresh(); > > // The first item should still be expanded > assertTrue(viewer.getGallery().getItem(0).isExpanded()); > > // And the new one too. > assertTrue(viewer.getGallery().getItem(1).isExpanded()); > } > > public void testBug217988Tree() { > Shell shell = s; > > GridLayoutFactory.fillDefaults().applyTo(shell); > > final TreeViewer viewer = new TreeViewer(shell); > GridDataFactory.fillDefaults().grab(true, true).applyTo( > viewer.getTree()); > final GalleryTestContentProvider contentProvider = new GalleryTestContentProvider(); > viewer.setContentProvider(contentProvider); > viewer.setLabelProvider(new GalleryTestLabelProvider()); > > viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS); > viewer.setInput(new Object()); > > // Check that expand all is working > assertTrue(viewer.getTree().getItem(0).getExpanded()); > contentProvider.addNewGroup(); > viewer.refresh(); > > // The first item should still be expanded > assertTrue(viewer.getTree().getItem(0).getExpanded()); > > // And the new one too. > assertTrue(viewer.getTree().getItem(1).getExpanded()); > } > >}
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 Raw
Actions:
View
Attachments on
bug 248700
: 113585