子菜单中的操作 上下文菜单 Java JFace SWT Eclipse

发布于 2024-09-18 22:28:32 字数 1069 浏览 2 评论 0原文

我在开发 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 技术交流群。

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

发布评论

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

评论(1

哭了丶谁疼 2024-09-25 22:28:32

只需创建一个子菜单并将操作添加到该子菜单即可。
这是一个可以澄清用法的快速片段:

            // submenu for a specific user
            MenuManager subMenu = new MenuManager("Change Status", null);

            // Actions for the sub menu
            subMenu.add(someAction);

            // add the action to the submenu
            manager.add(subMenu);

希望有帮助!

放在一起:

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

        // submenu for a specific user
        MenuManager subMenu = new MenuManager("Change Status", null);

        // Actions for the sub menu
        subMenu.add(someAction);

        // add the action to the submenu
        manager.add(subMenu);
    }
});

Just create a sub-menu and add the actions to this sub-menu.
Here is a quick snippet which should clarify the usage:

            // submenu for a specific user
            MenuManager subMenu = new MenuManager("Change Status", null);

            // Actions for the sub menu
            subMenu.add(someAction);

            // add the action to the submenu
            manager.add(subMenu);

Hope that helps!

Put together:

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

        // submenu for a specific user
        MenuManager subMenu = new MenuManager("Change Status", null);

        // Actions for the sub menu
        subMenu.add(someAction);

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