Home » Eclipse Projects » JFace » TreeViewer with ILazyTreeContentProvider(updateElement() from ILazyTreeContentProvider gets called for expanded elements, although they are not visible)
TreeViewer with ILazyTreeContentProvider [message #1689738] |
Tue, 24 March 2015 08:07 |
Martina Felber Messages: 1 Registered: March 2015 |
Junior Member |
|
|
Hello!
I'm developing an eclipse plugin with a view and I'm facing two problems.
The View uses an TreeViewer and TreeViewerColumns, each column has it's own LabelProvider.
Here's an example of the structure of the TreeViewer.
root
Leaf
Leaf
Root
Leaf
Leaf
Leaf
Leaf
Root
....
My first problem:
I'm using a thread to call viewer.refresh() periodically. To prevent the viewer from updating every element I'm using ILazyTreeContentProvider. This works great if the root nodes are NOT expanded. But if the root nodes are expanded, the content provider updates the root nodes (not the leafs), although they are not visible.
Example:
Root not visible, update, ERROR
Leaf not visible, no update, correct
Leaf not visible, no update, correct
Root not visible, no update, correct
Root not visible, update, ERROR
Leaf not visible, no update, correct
Leaf not visible, no update, correct
----------------------------------------------------
Root visible, update, correct
Root visible, update, correct
Root visible, update, correct
Root visible, update, correct
Leaf visible, update, correct
Leaf visible, update, correct
I don't know what I'm implementing wrong. I have enabled hash lookup for the TreeViewer (viewer.setUseHashlookup(true) ) and ensured that it's called before viewer.setInput().
My second problem:
The user can edit the treeviewer columns (I'm using CheckboxCellEditor and TextCellEditor). I would like to call viewer.refresh() every second. If the user wants to edit he or she has to type in the value within a second, otherwise the selection vanishes, because of the update. I tried to check if the user edits at the moment with viewer.IsCellEditorActive() and this works, but if I don't call TreeViewer.replace or TreeViewer.setChildCount -> the whole row vanishes. I don't know how to implement this correctly. I'm able to stop updating generally while the user is editing, but I would like to prevent an update only for the edited node.
I hope I didn't miss that a similar question has already been asked and that I'm in the correct forum. Any help would be much appreciated. Many thanks in advance.
Explanation of source code:
The View displays a TreeRegisterGroup, a TreeRegisterGroup contains TreeRegisters (root nodes) and TreeRegister contain TreeFields (leafs). Every object is a TreeElement, but TreeRegisterGroup and TreeRegister are also TreeParents (can have child TreeElements) - Composite pattern.
class ViewContentProvider implements ILazyTreeContentProvider {
@Override
public void inputChanged(Viewer viewer, Object OldInput, Object NewInput) {
mRegisterGroupToDisplay = (TreeRegisterGroup) NewInput;
}
@Override
public void updateChildCount(Object element, int currentChildCount) {
int NewChildCount = 0;
if (element instanceof TreeParent) {
NewChildCount = ((TreeParent) element).GetChildrenCount();
}
viewer.setChildCount(element, NewChildCount);
}
@Override
public void updateElement(Object parent, int index) {
TreeElement[] Children = null;
TreeElement ChildAtIndex = null;
int ChildCount = 0;
if (parent instanceof TreeParent) {
Children = ((TreeParent) parent).GetChildren2();
} else if (parent instanceof TreeElement) {
viewer.setHasChildren(parent, false);
viewer.setChildCount(parent, 0);
}
if (Children != null) {
ChildCount = Children.length;
if (ChildCount > index) {
ChildAtIndex = Children[index];
viewer.replace(parent, index, ChildAtIndex);
// get childcount of child (not of parent!!!)
if (ChildAtIndex instanceof TreeParent) {
ChildCount = ((TreeParent) ChildAtIndex)
.GetChildrenCount();
viewer.setChildCount(ChildAtIndex, ChildCount);
} else {
viewer.setChildCount(ChildAtIndex, 0);
}
}
}
}
@Override
public Object getParent(Object child) {
if (child instanceof TreeElement) {
return ((TreeElement) child).GetParent();
}
return mRegisterGroupToDisplay;
}
}
|
|
| | |
Goto Forum:
Current Time: Thu Apr 25 15:07:11 GMT 2024
Powered by FUDForum. Page generated in 0.03259 seconds
|