如何创建自己的 shell 来替换在 e4 RCP 的 MTrimmedWindow 中创建的 shell? [英] How to create my own shell to replace the shell created in the MTrimmedWindow in e4 RCP?

查看:26
本文介绍了如何创建自己的 shell 来替换在 e4 RCP 的 MTrimmedWindow 中创建的 shell?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法用用户定义的窗口替换 Eclipse RCP 为 MTrimmedWindow 生成的 shell?

Eclipse 创建一个具有特定样式类型的外壳,该样式只能在创建时提供.我想从为 MTrimmedWindow 创建的 shell 元素中删除最大化和调整大小.如果有人对上述问题有解决方案,请回复.

解决方案

shell的样式在创建后不能更改,shell本身在渲染器创建后不能交换.但情况并非没有希望.

Eclipse 4 使用渲染器从应用程序模型生成 UI 元素.这些渲染器可以通过使用渲染框架进行交换,这是创建与默认样式不同的外壳的一种可能方式.

解决方案将涉及为 MWindow 类型的 UIElements 编写自己的渲染器,提供 WorkbenchRendererFactory 来为 MWindows 创建新的 SWT 渲染器,并将新工厂注册到产品中.

默认:由 WBWRenderer 创建 Shell

WBWRenderer(工作台窗口渲染器)是 MWindow 类型的 SWT 元素的标准渲染器.

WBWRenderer#createWidget 中,shell 使用SWT.SHELL_TRIM 样式创建,这是SWT.CLOSE | 的便捷样式.SWT.标题 |SWT.MIN |SWT.MAX |SWT.调整大小:

wbwShell = new Shell(Display.getCurrent(), SWT.SHELL_TRIM | rtlStyle);

这将产生一个可以最大化和调整大小的 TrimmedWindow,而在创建后无法更改此行为.

新渲染器创建外壳

要解决上述限制,您可以提供不同的渲染器,使用 WBWRenderer 作为模板.这允许您更改创建 shell 的代码,例如

wbwShell = new Shell(Display.getCurrent(), SWT.CLOSE | SWT.TITLE |SWT.MIN |rtl样式);

此渲染器需要由 WorkbenchRendererFactory 返回,作为用于显示 MWindows 的渲染器.此外,渲染器工厂必须作为产品属性添加到 plugin.xml 中.

这些更改将导致 TrimmedWindow 无法最大化或调整大小.

可在此处找到如何编写和注册 WorkbenchRendererFactory 的示例..p>

更好的解决方案?

实际上,由于 WBWRenderer 已经使用标签来确定 MWindow 行为,因此可能有更好的方法来设置 SWT shell 的样式:shellMaximizedshellMinimized.这些标签可以在应用程序模型编辑器的修剪窗口的补充选项卡中设置.

如果可以以类似的方式设置 swt 样式标签,则可以使用它们来设置 shell 样式.这将是 Eclipse 的功能请求.

Is there a way to replace the shell generated by Eclipse RCP for the MTrimmedWindow by a user defined window?

Eclipse creates a shell with a particular style type, which can only be provided while creating. I want to remove maximize and resize from the shell element created for the MTrimmedWindow. If any one has a solution for the above problem please reply.

解决方案

The style for the shell cannot be changed after creation, and the shell itself cannot be exchanged after it has been created by the renderer. But the situation is not hopeless.

Eclipse 4 uses renderers to generate UI elements from the application model. These renderers can be exchanged by using the Rendering Framework, and this is one possible way to create a shell with a style different from the default.

The solution would involve writing an own renderer for UIElements of the type MWindow, providing a WorkbenchRendererFactory to create a new SWT renderer for MWindows, and registering the new factory with the product.

Default: Shell creation by WBWRenderer

WBWRenderer (workbench window renderer) is the standard renderer for SWT elements of type MWindow.

In WBWRenderer#createWidget, the shell is created with the style SWT.SHELL_TRIM, which is a convenience style for SWT.CLOSE | SWT.TITLE | SWT.MIN | SWT.MAX | SWT.RESIZE:

wbwShell = new Shell(Display.getCurrent(), SWT.SHELL_TRIM | rtlStyle);

This will result in a TrimmedWindow that can be maximized and resized, without the possibility to change this behaviour after creation.

Shell creation by new renderer

To get around the above mentioned limitation, you can provide a different renderer, using WBWRenderer as a template. This allows you to change the code for the shell creation, e.g.

wbwShell = new Shell(Display.getCurrent(), SWT.CLOSE | SWT.TITLE |
                         SWT.MIN | rtlStyle);

This renderer needs to be returned by a WorkbenchRendererFactory as the renderer used for showing MWindows. Additionally, the renderer factory has to be added as a product property in the plugin.xml.

These changes will result in a TrimmedWindow that cannot be maximized or resized.

An example of how to write and register the WorkbenchRendererFactory can be found here.

A better solution?

Actually, there could be a better way to style SWT shells since WBWRenderer already uses tags to determine MWindow behaviour: shellMaximized and shellMinimized. These tags can be set in the supplementary tab of the trimmed window in the application model editor.

If swt style tags could be set in a similar manner, they could be used to set the shell style. This would be a feature request for Eclipse.

这篇关于如何创建自己的 shell 来替换在 e4 RCP 的 MTrimmedWindow 中创建的 shell?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆