Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Martina Felber is currently offline Martina FelberFriend
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;
	}
}



Re: TreeViewer with ILazyTreeContentProvider [message #1764160 is a reply to message #1689738] Fri, 26 May 2017 06:28 Go to previous messageGo to next message
Gaurav Tripathi is currently offline Gaurav TripathiFriend
Messages: 41
Registered: September 2015
Member
Hi,
I am facing the same issue as whenever I do expandToLevel it calls updateElement method and it starts from root till leaf node even if they are not visible.
I have implemented ILazyTreeContentProvider for my treeViewer and given SWT.Virtual style with setHashLookup set as true.
Also sometimes I get widget disposed exception and while debugging I found out that internally there is one customElement hashmap which contains disposed treeitem. How should I resolve this ?


Please let me know if you have found any solution for this.

Thanks in advance.
Re: TreeViewer with ILazyTreeContentProvider [message #1764161 is a reply to message #1689738] Fri, 26 May 2017 06:29 Go to previous message
Gaurav Tripathi is currently offline Gaurav TripathiFriend
Messages: 41
Registered: September 2015
Member
Hi,
I am facing the same issue as whenever I do expandToLevel it calls updateElement method and it starts from root till leaf node even if they are not visible.
I have implemented ILazyTreeContentProvider for my treeViewer and given SWT.Virtual style with setHashLookup set as true.
Also sometimes I get widget disposed exception and while debugging I found out that internally there is one customElement hashmap which contains disposed treeitem. How should I resolve this ?


Please let me know if you have found any solution for this.

Thanks in advance.
Previous Topic:TreeViewer & Columns number
Next Topic:Passing data between ViewerDropAdapter and DragSourceListener
Goto Forum:
  


Current Time: Fri Nov 16 22:54:58 GMT 2018

Powered by FUDForum. Page generated in 0.02105 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top