如何使 propertysheetpage 成为选择提供者?

发布于 2024-12-23 15:46:14 字数 1360 浏览 0 评论 0原文

我有一个贡献的命令和一个处理程序。处理程序的执行事件必须获取属性视图中实际选择的属性的值并对其进行操作,或者如果未选择属性则禁用。

我尝试过:

1)将选择提供程序设置为从属性视图中提供选择的内容。在这种情况下,只是 PropertySheetPage 的 PropertySheetViewer,但我无法将其设置为选择提供程序,因为 PropertySheetPage 的查看器是私有的并且没有 getter。

2) 重写PropertySheetPage 的createControl 方法:该方法为PropertySheetViewer 创建一个Tree 控件。可以为该树控件安装一个选择监听器,所以也许我可以让我的命令处理程序实现 SelectionListener...解决方案将类似于:

在我的编辑器中:

public Object getAdapter(@SuppressWarnings("rawtypes") Class type) {
        if (type == IPropertySheetPage.class) {
            PropertySheetPage page = new PropertySheetPage() {
                @Override
                public void createControl(Composite parent) {
                    super.createControl(parent);

                                    IHandler handler = someWayToGetMyCmdHandler();
                    ((org.eclipse.swt.widgets.Tree) getControl())
                            .addSelectionListener(handler);
                }

            };
            IPropertySheetEntry entry = new UndoablePropertySheetEntry(
                    getCommandStack());
            page.setRootEntry(entry);
            return page;
        }

    return super.getAdapter(type);
}

并且我的命令处理程序实现 SelectionListener 正如我所说...问题这种方法是我找不到一种方法来获取对我贡献的命令处理程序的引用(上面的 someWayToGetMyCmdHandler() )。

有没有人对此有任何线索,或解决该问题的任何其他可能的方法?

I've got a contributed command and a handler for it. The handler's execute event has to get the value for the property actually selected in the properties view and act on it, or to be disabled if no property selected.

I've tried:

1) Set the selection provider to something which provides selection from the property view. Something in this case is just PropertySheetViewer for my PropertySheetPage, but i can't set it as the selection provider because the PropertySheetPage's viewer is private and has no getter.

2) Overriding PropertySheetPage's createControl method: This method creates a Tree control for the PropertySheetViewer. A selection listener can be installed for that tree control, so maybe i can make my command handler implement SelectionListener... The solution would be somethin like:

In my editor:

public Object getAdapter(@SuppressWarnings("rawtypes") Class type) {
        if (type == IPropertySheetPage.class) {
            PropertySheetPage page = new PropertySheetPage() {
                @Override
                public void createControl(Composite parent) {
                    super.createControl(parent);

                                    IHandler handler = someWayToGetMyCmdHandler();
                    ((org.eclipse.swt.widgets.Tree) getControl())
                            .addSelectionListener(handler);
                }

            };
            IPropertySheetEntry entry = new UndoablePropertySheetEntry(
                    getCommandStack());
            page.setRootEntry(entry);
            return page;
        }

    return super.getAdapter(type);
}

And my command handler implementing SelectionListener as i said... The problem with this approach is that i can't find a way to get a reference to my contributed command handler (someWayToGetMyCmdHandler() above).

Has anybody got any clue on this, or any other possible approach to the problem??

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

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

发布评论

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

评论(1

留一抹残留的笑 2024-12-30 15:46:14

PropertySheetPage 您可以覆盖它以收到有关查看器中的选择更改的通知(尽管PropertySheetPage@noextend)。

第二部分(更新处理程序)比通常情况下要棘手一些。当工作台选择更改时,命令/处理程序会自动更新(您只需要实现 setEnabled(ObjectvaluationContext) AbstractHandler)。但由于 PropertySheetPage 被设计为在全局选择更改时更改其输入,因此您必须找到一些自定义方法来通知/更新您的处理程序。

据我了解,目前无法使用自定义变量扩展平台命令事件处理机制,因此您只需使用 IHandlerService 工作台。

There's handleEntrySelection(ISelection selection) method in PropertySheetPage that you could override to be notified about selection changes in the viewer (although PropertySheetPage is @noextend).

The second part (updating the handler) is a bit more tricky than it would normally be. Commands/handlers get updated automatically when workbench selection changes (you just need to implement setEnabled(Object evaluationContext) AbstractHandler). But since PropertySheetPage is designed to change its input on global selection change, then you have to find some custom way to notify/update your handler.

As I understand, it is currently not possible to extend the platform command event handling mechanism with custom variables, so you just need to directly look up your handler using IHandlerService of the workbench.

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