<legend id='FwRgb'><style id='FwRgb'><dir id='FwRgb'><q id='FwRgb'></q></dir></style></legend>

    1. <tfoot id='FwRgb'></tfoot>
      <i id='FwRgb'><tr id='FwRgb'><dt id='FwRgb'><q id='FwRgb'><span id='FwRgb'><b id='FwRgb'><form id='FwRgb'><ins id='FwRgb'></ins><ul id='FwRgb'></ul><sub id='FwRgb'></sub></form><legend id='FwRgb'></legend><bdo id='FwRgb'><pre id='FwRgb'><center id='FwRgb'></center></pre></bdo></b><th id='FwRgb'></th></span></q></dt></tr></i><div id='FwRgb'><tfoot id='FwRgb'></tfoot><dl id='FwRgb'><fieldset id='FwRgb'></fieldset></dl></div>

        <bdo id='FwRgb'></bdo><ul id='FwRgb'></ul>

      <small id='FwRgb'></small><noframes id='FwRgb'>

      Eclipse RCP - ILazyTreeContentProvider 实现出人意料地渴望

      时间:2023-08-21
        <bdo id='1CujB'></bdo><ul id='1CujB'></ul>

          <tfoot id='1CujB'></tfoot>

          <small id='1CujB'></small><noframes id='1CujB'>

          <legend id='1CujB'><style id='1CujB'><dir id='1CujB'><q id='1CujB'></q></dir></style></legend>
            <tbody id='1CujB'></tbody>

            1. <i id='1CujB'><tr id='1CujB'><dt id='1CujB'><q id='1CujB'><span id='1CujB'><b id='1CujB'><form id='1CujB'><ins id='1CujB'></ins><ul id='1CujB'></ul><sub id='1CujB'></sub></form><legend id='1CujB'></legend><bdo id='1CujB'><pre id='1CujB'><center id='1CujB'></center></pre></bdo></b><th id='1CujB'></th></span></q></dt></tr></i><div id='1CujB'><tfoot id='1CujB'></tfoot><dl id='1CujB'><fieldset id='1CujB'></fieldset></dl></div>
              • 本文介绍了Eclipse RCP - ILazyTreeContentProvider 实现出人意料地渴望的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在开发一个 Eclipse RCP 应用程序,并尝试使用 ILazyTreeContentProvider 实现,以便在特定时间仅显示可见项目.

                I am developing an Eclipse RCP application, and am trying to use a ILazyTreeContentProvider implementation in order to show only the visible items at a certain time.

                代码:

                在扩展 ViewPart 的类中:

                Inside the class extending ViewPart:

                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();
                    }
                

                在 ContentProvider 内部:

                Inside the ContentProvider:

                @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);
                            }
                
                        }
                

                问题是每次我展开 TreeItem 的子元素时,它都会加载所有子元素,而不仅仅是可见的子元素,而 System.out.println(updateElementCounter++); 命令会打印出来尽管只有 7 个树项可见,但全部 22 个.

                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 System.out.println(updateElementCounter++); command prints out all 22 despite having only 7 Tree Items visible.

                ILazyTreeContentProvider 不应该只加载可见的吗?(在本例中为 7 项)

                Shouldn't the ILazyTreeContentProvider only load the ones that are visible? (In this case it's 7 items)

                我一定是做错了什么……

                I must be doing something wrong...

                无论如何,任何意见都非常感谢!

                Anyways, any opinions are very appreciated!

                推荐答案

                我已经将我的示例与 这个而且我发现只有一个不同之处:

                I have compared my example with this one And I've found only one difference that made all the difference:

                v.setUseHashlookup(true); //v is the TreeViewer
                

                该方法在其文档中的说明:

                What the method states in its doc:

                配置此结构化查看器是否使用内部哈希表加快元素和 SWT 项之间的映射.这必须是在为查看器提供输入之前调用(通过 setInput).

                Configures whether this structured viewer uses an internal hash table to speeds up the mapping between elements and SWT items. This must be called before the viewer is given an input (via setInput).

                现在内容提供者实际上很懒惰.仅绘制可见项目,而不是全部.

                Now the content provider is actually lazy. Only paints the visible items, not ALL of them.

                这篇关于Eclipse RCP - ILazyTreeContentProvider 实现出人意料地渴望的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何在 Eclipse 插件中使用 Java11(Java10)? 下一篇:Eclipse 扩展和声明式服务

                相关文章

                <tfoot id='NmBYW'></tfoot>

                <small id='NmBYW'></small><noframes id='NmBYW'>

                  <i id='NmBYW'><tr id='NmBYW'><dt id='NmBYW'><q id='NmBYW'><span id='NmBYW'><b id='NmBYW'><form id='NmBYW'><ins id='NmBYW'></ins><ul id='NmBYW'></ul><sub id='NmBYW'></sub></form><legend id='NmBYW'></legend><bdo id='NmBYW'><pre id='NmBYW'><center id='NmBYW'></center></pre></bdo></b><th id='NmBYW'></th></span></q></dt></tr></i><div id='NmBYW'><tfoot id='NmBYW'></tfoot><dl id='NmBYW'><fieldset id='NmBYW'></fieldset></dl></div>
                    • <bdo id='NmBYW'></bdo><ul id='NmBYW'></ul>
                  1. <legend id='NmBYW'><style id='NmBYW'><dir id='NmBYW'><q id='NmBYW'></q></dir></style></legend>