Content not displaced in TreeViewer [message #1412469] |
Tue, 26 August 2014 08:28 |
|
Hi,
I have a tree viewer and a content and label provider for the tree viewer. Most things just work. Content provider provides the content. The label provider provides text and images.
Removing an element is also working fine (calling viewer.remove(element) ).
But when I try to "insert" a new element then it ain't displayed. I insert a new element by calling
viewer.refresh(parent, true);
on the parent. The content provider is queried for the content of the parent and it is providing the content including the "inserted"/new element. So far so good. But it never queries the label provider for the element and it is not displaying it.
What am I doing wrong?
|
|
|
Re: Content not displaced in TreeViewer [message #1412595 is a reply to message #1412469] |
Tue, 26 August 2014 14:48 |
Eclipse User |
|
|
|
Works for me -- I modified the JFace Snippet002 to add a a button to add a child to a node and then call update, and it works fine (see below).
Be sure that your model objects implement equals() and hashCode().
Brian.
public Snippet002TreeViewer(Shell shell) {
final TreeViewer v = new TreeViewer(shell);
v.setLabelProvider(new LabelProvider());
v.setContentProvider(new MyContentProvider());
v.setInput(createModel());
Button b = new Button(shell, SWT.PUSH);
b.setText("Add Child");
b.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
MyModel root = (MyModel) v.getInput();
root.child.get(0).child.add(new MyModel(99999, root));
v.refresh(root, true);
}
});
}
|
|
|
Re: Content not displaced in TreeViewer [message #1413301 is a reply to message #1412595] |
Thu, 28 August 2014 08:38 |
|
Thanx for the info about hashcode() and equals(). Have forgotten about that (though I already implemented them with Eclipse generating the methods).
I forgot that I had enabled some viewer filters. And the model got modified in a background job without notifying the viewer.
Thanx for the quick post.
|
|
|
Powered by
FUDForum. Page generated in 0.02823 seconds