Note that there are some explanatory texts on larger screens.

plurals
  1. POEclipse RCP - ILazyTreeContentProvider implementation is unexpectedly eager
    primarykey
    data
    text
    <p>I am developing an Eclipse RCP application, and am trying to use a <code>ILazyTreeContentProvider</code> implementation in order to show only the visible items at a certain time. </p> <p>The code:</p> <p>Inside the class extending ViewPart:</p> <pre><code>public void createPartControl(Composite parent) { viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.VIRTUAL); drillDownAdapter = new DrillDownAdapter(viewer); viewer.setContentProvider(new ViewContentProvider()); viewer.setLabelProvider(new ViewLabelProvider()); //viewer.setSorter(new NameSorter()); viewer.setInput(getViewSite()); // Create the help context id for the viewer's control PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "test.provider.lazy.viewer"); makeActions(); hookContextMenu(); hookDoubleClickAction(); contributeToActionBars(); } </code></pre> <p>Inside the ContentProvider:</p> <pre><code>@Override public void updateElement(Object parent, int index) { System.out.println(updateElementCounter++); if (parent.equals(getViewSite())) { if (index == 0) { TreeParent child = new TreeParent("Parent 1"); viewer.replace(parent, index, child); viewer.setHasChildren(child, true); } else { TreeParent child = new TreeParent("Parent 2"); viewer.replace(parent, index, child); viewer.setHasChildren(child, true); //viewer.setChildCount(child, 1); } } else { if (parent instanceof TreeParent) { TreeParent treeParent = (TreeParent) parent; if (treeParent.getName().equals("Parent 1")) { TreeObject child = new TreeObject("Leaf "+index); viewer.replace(treeParent, index, child); viewer.setHasChildren(child, false); //viewer.setChildCount(child, 0); } else { TreeObject child = new TreeObject("Special One"); viewer.replace(treeParent, index, child); viewer.setHasChildren(child, false); //viewer.setChildCount(child,0); } } } } @Override public void updateChildCount(Object element, int currentChildCount) { if (element.equals(getViewSite())) { viewer.setChildCount(getViewSite(), 2); } else if (element instanceof TreeParent) { TreeParent parent = (TreeParent) element; if (parent.getName().equals("Root")) { viewer.setChildCount(parent, 2); } else if (parent.getName().equals("Parent 1")) { viewer.setChildCount(parent, 20); } else { viewer.setChildCount(parent, 1); } } else { viewer.setChildCount(element, 0); } } </code></pre> <p>The problem is that each time I expand the children of a TreeItem, it loads all the subelements, not just the visible ones, whereas the <code>System.out.println(updateElementCounter++);</code> command prints out all 22 despite having only 7 Tree Items visible.</p> <p><img src="https://i.stack.imgur.com/QLSRf.png" alt="enter image description here"></p> <p>Shouldn't the <code>ILazyTreeContentProvider</code> only load the ones that are visible? (In this case it's 7 items) </p> <p>I must be doing something wrong...</p> <p>Anyways, any opinions are very appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload