Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top