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 220635 Details for
Bug 388628
[Viewers] ILazyTreeContentProvider: NPE when refreshing viewer while an inner node is selected and using OwnerDrawLabelProvider
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.
Code reproducing the problem
LazyTreeViewerGetSelectionNPE.java (text/x-java), 4.09 KB, created by
Missing name
on 2012-09-02 12:38:26 EDT
(
hide
)
Description:
Code reproducing the problem
Filename:
MIME Type:
Creator:
Missing name
Created:
2012-09-02 12:38:26 EDT
Size:
4.09 KB
patch
obsolete
>package swt; > >import java.util.HashMap; >import java.util.Map; > >import org.eclipse.jface.viewers.ILazyTreeContentProvider; >import org.eclipse.jface.viewers.OwnerDrawLabelProvider; >import org.eclipse.jface.viewers.TreeViewer; >import org.eclipse.jface.viewers.Viewer; >import org.eclipse.jface.viewers.ViewerCell; >import org.eclipse.swt.SWT; >import org.eclipse.swt.events.SelectionAdapter; >import org.eclipse.swt.events.SelectionEvent; >import org.eclipse.swt.layout.FillLayout; >import org.eclipse.swt.widgets.Button; >import org.eclipse.swt.widgets.Display; >import org.eclipse.swt.widgets.Event; >import org.eclipse.swt.widgets.Shell; > >public class LazyTreeViewerGetSelectionNPE { > > private static class Element { > final String name; > final Element parent; > > Element (Element parent, String name) { > this.parent = parent; > this.name = name; > } > String getName() { > return name; > } > @Override > public String toString() { > return (parent == null ? "" : parent.toString()) + "/" + getName(); > } > @Override > public boolean equals(Object o) { > if ( ! (o instanceof Element)) return false; > Element other = (Element) o; > return other.name.equals(name) && > (other.parent == null && parent == null || > other.parent != null && other.parent.equals(parent)); > } > @Override > public int hashCode() { > return (parent == null ? 0 : parent.hashCode()) ^ > name.hashCode(); > } > } > > private static Map<Element, Integer> element2nChildren = > new HashMap<Element, Integer>(); > > private static class ContentProvider implements ILazyTreeContentProvider { > private final TreeViewer viewer; > > public ContentProvider(TreeViewer viewer) { > this.viewer = viewer; > } > public void dispose() { > } > > public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { > } > > public void updateElement(Object parent, int index) { > Element element = new Element( > (Element) parent, String.valueOf(index)); > viewer.replace(parent, index, element); > updateChildCount(element); > } > > public void updateChildCount(Object element, int currentChildCount) { > updateChildCount(element); > } > > private void updateChildCount(Object element) { > int nChildren = element2nChildren.containsKey(element) > ? element2nChildren.get(element) > : 0; > viewer.setChildCount(element, nChildren); > } > > public Object getParent(Object element) { > return ((Element)element).parent; > } > > } > > private static class ODLabelProvider extends OwnerDrawLabelProvider { > @Override > public void update(ViewerCell cell) { > cell.setText(((Element)cell.getElement()).toString()); > } > > @Override > protected void measure(Event event, Object element) { > } > > @Override > protected void paint(Event event, Object element) { > } > } > > public static void main (String [] args) { > final Display display = new Display(); > final Shell shell = new Shell(display); > > final TreeViewer viewer = new TreeViewer(shell, SWT.VIRTUAL); > viewer.setContentProvider(new ContentProvider(viewer)); > viewer.setLabelProvider(new ODLabelProvider()); > // Using a non-owner-draw LabelProvider works around the bug > //viewer.setLabelProvider(new LabelProvider()); > > viewer.setUseHashlookup(true); > > final Element root = new Element(null, "root"); > element2nChildren.put(root, 2); > element2nChildren.put(new Element(root,"1"), 1); > > viewer.setInput(root); > > Button button = new Button(shell, SWT.NONE); > button.setText("Remove second item"); > button.addSelectionListener(new SelectionAdapter() { > @Override > public void widgetSelected(SelectionEvent e) { > element2nChildren.put(root,1); > > // calling collapseAll works around this bug > //viewer.collapseAll(); > > // removing the selection programmatically doesn't help: > //viewer.setSelection(TreeSelection.EMPTY); > > viewer.refresh(root); > }; > }); > > shell.setLayout(new FillLayout()); > shell.layout(); > shell.open (); > while (!shell.isDisposed ()) { > if (!display.readAndDispatch ()) display.sleep (); > } > display.dispose (); > } > >}
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 388628
: 220635