子菜单中的操作 上下文菜单 Java JFace SWT Eclipse
我在开发 Eclipse 插件时遇到了一个小问题。
有一个与花名册相比的视图。那里有一个用户列表。我的问题是,我想添加一个上下文菜单。
这个想法是右键单击用户,然后应该弹出菜单。到目前为止一切都很好...但问题是我不想要一个菜单。我希望在该上下文菜单中有一个“设置状态”条目,当鼠标悬停在该条目上时,菜单应该扩展以显示“离开”“忙碌”“不可见”等内容...
有人可以帮助我实现这一目标吗?
我已经实现了相应的操作并向MenuManager添加了内容。
public SessionViewContextMenu(ViewPart sessionView, TableViewer viewer,
final Action action) {
MenuManager manager = new MenuManager("#PopupMenu");
manager.setRemoveAllWhenShown(true);
manager.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
manager.add(action);
}
});
相应的操作如下所示:
public Action(...) {
super(provider, "Bla Bla");
// some fancy picture
setImageDescriptor(...);
// setId(ACTION_ID);
setToolTipText("Bla Bla");
update();
}
一切正常(至少上下文菜单显示该条目)。现在,当用户将鼠标悬停在相应操作上/选择相应操作时,我想扩展菜单。所以菜单应该扩展并显示更多的可能性......
非常感谢有关如何创建递归上下文菜单的任何帮助!
希望您理解这个问题,并且不要犹豫向dor询问澄清!
I'm having a slight problem with an Eclipse Plug-In in development.
There is a view which is comparabe to a roster. There is a list of users in there. My problem is, that I'd like to add an context menu.
The idea is to perform a right-click on a user and the menu should pop up. So far so good... but the problem is that I don't want a single menu. I'd like to have an entry "set status" to that context menu and when one hovers over this entry the menu should be extended to show stuff like "away" "busy" "invisible" and so on...
Could anyone help me out to achieve this?
I have already implemented the corresponding action and made the addition to the MenuManager.
public SessionViewContextMenu(ViewPart sessionView, TableViewer viewer,
final Action action) {
MenuManager manager = new MenuManager("#PopupMenu");
manager.setRemoveAllWhenShown(true);
manager.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
manager.add(action);
}
});
The correspodning action looks like this:
public Action(...) {
super(provider, "Bla Bla");
// some fancy picture
setImageDescriptor(...);
// setId(ACTION_ID);
setToolTipText("Bla Bla");
update();
}
Everything is working fine (at least the context menu shows the entry). Now I'd like to extend the menu when one hovers over / selects the corresponding action. So the menu should extend and show some more possibilites here...
Any help on how to create a recursive context menu is highly appreciated!
Hope, you understand the problem and don't hesitate to ask dor clarification!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需创建一个子菜单并将操作添加到该子菜单即可。
这是一个可以澄清用法的快速片段:
希望有帮助!
放在一起:
Just create a sub-menu and add the actions to this sub-menu.
Here is a quick snippet which should clarify the usage:
Hope that helps!
Put together: