天道酬勤,学无止境

treeviewer

Jface TreeViewer add right click menu, depending on clicked node

问题 关于如何根据所选项目正确地将右键单击菜单连接到Jface TreeViewer有一个很好的线程。 我想根据以下条件显示右键菜单:右键单击是在节点上还是在“空白空间”中。 问题是如果您单击空白区域,TreeViewer 不会自动清除选择。 有什么干净的方法可以实现这一目标吗? 我目前的方法是使用以下 mouseDown 方法简单地将MouseListener连接到树: @Override public void mouseDown(MouseEvent e) { TreeItem item = treeViewer.getTree().getItem(new Point(e.x, e.y)); if (item == null) { treeViewer.getTree().deselectAll(); } } 这似乎工作得很好。 你觉得这怎么样? 回答1 final Tree tree = viewer.getTree(); final Menu menu = new Menu(tree); tree.setMenu(menu); menu.addMenuListener(new MenuAdapter() { @Override public void menuShown(MenuEvent e) { Point point = tree.toControl(Display

2022-05-09 00:05:04    分类:技术分享    java   swt   jface   treeviewer

How to expand an object in a Treeviewer?

问题 我正在尝试了解 Java 树视图。 我使用以下教程创建了一个 Treeviewer: http://www.eclipse.org/articles/Article-TreeViewer/TreeViewerArticle.htm 现在我有一个我无法解决的问题:/ 我想用另一个对象扩展书籍对象。 例如: + BookTitleX BookAuthorX etc otherobjectname etc etc etc 如何将对象添加到对象? 非常感谢你 这是代码: 内容提供商: import java.util.Iterator; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; public class ContentProvider implements ITreeContentProvider, IDeltaListener { private static Object[] EMPTY_ARRAY = new Object[0]; protected TreeViewer viewer; /* * @see IContentProvider

2022-05-08 15:57:11    分类:技术分享    java   swt   jface   expand   treeviewer

Jface TreeViewer add right click menu, depending on clicked node

There is a good thread on how to correctly hook up a right-click menu to a Jface TreeViewer depending on the selected item. I would like to show the right click menu depending on: if the right-click was on a node or into "empty space". The problem is that TreeViewer does not automatically clear the selection if you click into empty space. Is there any clean way how to achieve this? My current approach would be to simply hook up a MouseListener to the tree with the following mouseDown method: @Override public void mouseDown(MouseEvent e) { TreeItem item = treeViewer.getTree().getItem(new Point

2022-04-26 08:44:31    分类:问答    java   swt   jface   treeviewer

How to expand an object in a Treeviewer?

I am trying to understand java treeviews. I created a Treeviewer with the following tutorial: http://www.eclipse.org/articles/Article-TreeViewer/TreeViewerArticle.htm Now I have a problem that I can´t solve :/ I want to expand the book-objects with another object. For example: + BookTitleX BookAuthorX etc otherobjectname etc etc etc How can I add an object to an object ? Thank u so much This is the code: Content Provider: import java.util.Iterator; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; public

2022-04-26 08:34:32    分类:问答    java   swt   jface   expand   treeviewer

CheckboxTreeViewer: Can't expand nodes by default

I recently implemented a CheckboxTreeViewer in my own Dialog. This works fine so far except that the tree doesn't allow me to expand nodes by default. It only works when I check the checkbox, as you can see in the following images: This is by default. As you can see, it's not possible to expand the node, though it has children: After checking the check box, it works: I already tried to use setExpandPreCheckFilters , but with no success: Composite container = (Composite) super.createDialogArea(parent); tv = new CheckboxTreeViewer(container, SWT.MULTI | SWT.H_SCROLL| SWT.V_SCROLL); GridData

2022-04-17 00:10:57    分类:问答    java   checkbox   swt   jface   treeviewer

Vertical align 2 jface TreeViewers to specific element

I have two TreeViewer objects on a page (2 columns, one TreeViewer in each column), and I want to vertically align a tree when the other is scrolled or selected. import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.widgets.Tree; I think the solution should look something like treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent arg0) { TreeViewer mirrorTree = (treeViewer == treeVwrSource ? treeVwrTarget : treeVwrSource); // find position of selected element (element x) in treeViewer // set position

2022-02-14 05:04:56    分类:问答    java   swt   eclipse-rcp   jface   treeviewer

滚动 TreeViewer 树 SWT(Scrolling TreeViewer Tree SWT)

问题

2022-02-10 10:51:27    分类:技术分享    java   tree   swt   treeviewer