How to create my own shell to replace the shell created in the MTrimmedWindow in e4 RCP?
Asked Answered
C

3

7

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.

Culpable answered 8/1, 2013 at 7:3 Comment(0)
P
6

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.

Poseur answered 9/1, 2013 at 2:21 Comment(2)
Thank You. Will try the above solution. I have also suggested the tag option in one of the eclipse forum posts. Once again thanks a lot.Culpable
@GouthamPrasad I just found a bug report concerning the style feature for the application window in Eclipse 4 herePoseur
J
1

This can now be solved with a specific "persisted state" key flag, as documented in https://bugs.eclipse.org/bugs/show_bug.cgi?id=386951 . For example to realize a NO_TRIM window, add the key/value styleOverride/8, where 8 is the value if you get the numeric of

    int val = SWT.NO_TRIM;
    System.out.println(val);
Junko answered 28/7, 2015 at 10:32 Comment(0)
F
0

In addition to col.panic's answer if you wanted a style of

SWT.CLOSE | SWT.TITLE

your styleOverride value would be 96

System.out.println(SWT.CLOSE | SWT.TITLE) = 96
Fairbanks answered 5/8, 2015 at 19:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.