Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 447
Goutham Prasad Avatar asked Jan 08 '13 07:01

Goutham Prasad


People also ask

What is RCP programming?

The rich client platform (RCP) is a programmer tool that makes it easier to integrate independent software components, where most of the data processing occurs on the client side.

What is RCP in Java?

The Rich Client Platform (RCP) is an exciting new way to build Java applications that can compete with native applications on any platform.


2 Answers

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.

like image 181
Modus Tollens Avatar answered Sep 28 '22 16:09

Modus Tollens


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);
like image 39
col.panic Avatar answered Sep 28 '22 16:09

col.panic