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.