专栏和Eclipse 中的过滤树

发布于 2024-09-07 06:03:05 字数 170 浏览 13 评论 0原文

我正在尝试创建一个包含多个列的 FilteredTree,但没有成功。如果我使用 TreeViewer ,列可以正常工作,但是当我切换到使用 FilteredTree 时,只有删除列才能使其正常工作,所以我想知道是否有一种方法可以将 FilteredTree 与列一起使用。

I'm trying to create a FilteredTree with several columns with no luck. If I use a TreeViewer the columns work fine but when I switch to using a FilteredTree I can only get it to work if I remove the columns, so I'm wondering if there is a way to use FilteredTree with columns.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

南巷近海 2024-09-14 06:03:05

您当然可以将 FilteredTree 与列查看器一起使用。例如(这也演示了使用 FilteredTree 保留 TreeColumnLayout 的使用):

final TreeColumnLayout tl = new TreeColumnLayout();

PatternFilter patternFilter = new PatternFilter();
patternFilter.setIncludeLeadingWildcard(true);
FilteredTree ft = new FilteredTree(treeViewerComposite, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | toolkit.getBorderStyle() | Window.getDefaultOrientation(), patternFilter, true) {            
   @Override
   protected Control createTreeControl(Composite parent, int style) {
       Control c = super.createTreeControl(parent, style);
       c.setLayoutData(null);
       c.getParent().setLayout(tl);
       return c;
   }        
};

viewer = ft.getViewer();
viewer.getTree().setHeaderVisible(true);

现在您可以按照通常的方式创建 TreeColumn,您的列就会出现。

You can certainly use a FilteredTree with a column viewer. For example (and this also demonstrates preserving the use of a TreeColumnLayout using a FilteredTree):

final TreeColumnLayout tl = new TreeColumnLayout();

PatternFilter patternFilter = new PatternFilter();
patternFilter.setIncludeLeadingWildcard(true);
FilteredTree ft = new FilteredTree(treeViewerComposite, SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | toolkit.getBorderStyle() | Window.getDefaultOrientation(), patternFilter, true) {            
   @Override
   protected Control createTreeControl(Composite parent, int style) {
       Control c = super.createTreeControl(parent, style);
       c.setLayoutData(null);
       c.getParent().setLayout(tl);
       return c;
   }        
};

viewer = ft.getViewer();
viewer.getTree().setHeaderVisible(true);

Now you can just create TreeColumn's the usual way and your columns will appear.

初与友歌 2024-09-14 06:03:05

您可以按照与 普通树。这是完整的设置。

PatternFilter patternFilter = new PatternFilter();
patternFilter.setIncludeLeadingWildcard(true);
filteredTree = new FilteredTree(getContainer(), SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, patternFilter, true);

TreeViewer viewer = filteredTree.getViewer();
tree = viewer.getTree();
tree.setHeaderVisible(true);

TreeColumn modelColumn = new TreeColumn(tree, SWT.LEFT);
modelColumn.setText("Model");
modelColumn.setWidth(400);

TreeViewerColumn treeViewerModelColumn = new TreeViewerColumn(viewer, modelColumn);
treeViewerModelColumn.setLabelProvider(new ColumnLabelProvider());

You can do it the same way as with a normal Tree. Here is a full setup.

PatternFilter patternFilter = new PatternFilter();
patternFilter.setIncludeLeadingWildcard(true);
filteredTree = new FilteredTree(getContainer(), SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, patternFilter, true);

TreeViewer viewer = filteredTree.getViewer();
tree = viewer.getTree();
tree.setHeaderVisible(true);

TreeColumn modelColumn = new TreeColumn(tree, SWT.LEFT);
modelColumn.setText("Model");
modelColumn.setWidth(400);

TreeViewerColumn treeViewerModelColumn = new TreeViewerColumn(viewer, modelColumn);
treeViewerModelColumn.setLabelProvider(new ColumnLabelProvider());
无妨# 2024-09-14 06:03:05

是的,有一种方法,这里概述了解决方案:
http://eclipsesource.com/blogs/2012/10 /26/filtering-tables-in-swtjface/

来自 EclipseSource 博客的图片

要点是默认的 PatternFilter 需要树叶作为 ILabelProvider。在基于列的树查看器中,树叶没有单一的文本表示。

因此,如果您使用 TreeViewerColumns 作为树列,则 PatternFilter 将为每列使用 ColumnLabelProvider。在这种情况下,您可以通过子类化 PatternFilter 并使用您自己的 isLeafMatch(..) 覆盖它来修复,

否则,当使用 TreeColumns 定义时列,TreeViewer 将需要有一个 ITableLabelProvider。除此之外,您还将对 PatternFilter 进行子类化,并再次重写方法 isLeafMatch(..)

Yes, there is a way, and the solution it is outlined here:
http://eclipsesource.com/blogs/2012/10/26/filtering-tables-in-swtjface/

image from EclipseSource blog

The point is the default PatternFilter needs tree leaves to be instance of ILabelProvider. In a column-based treeviewer there is no single text representation for the tree leaf.

So, if you are using TreeViewerColumns as tree columns, the PatternFilter will use the ColumnLabelProvider for each column. In this case you'll fix by subclassing the PatternFilter and overriding it with your own isLeafMatch(..)

Otherwise, when using TreeColumns to define columns, the TreeViewer will need to have a ITableLabelProvider. Beyond this, you'll subclass the PatternFilter and, again, override the method isLeafMatch(..)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文