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

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

Eclipse creates a wrapper with a specific type of style that can only be provided when created. I want to remove maximization and resizing from a wrapper element created for MTrimmedWindow. If anyone has a solution for the above problem, answer.

+7
source share
3 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 visualizer. But the situation is not hopeless.

Eclipse 4 uses visualization tools to create user interface elements from an application model. These renderers can be exchanged using the Rendering Framework, and this is one of the possible ways to create a shell with a style other than the standard one.

The solution will write its own visualization tool for UIElements such as MWindow, providing the WorkbenchRendererFactory for creating a new SWT rendering for MWindows and registering a new factory with the product.

Default: WBWRenderer shell creation

WBWRenderer (desktop window rendering) is the standard visualization tool for MWTow type SWT elements.

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

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

This will cause TrimmedWindow to be maximized and modified without the ability to change this behavior after creation.

Shell creation by new renderer

To get around the above limitation, you can provide another renderer using WBWRenderer as a template. This allows you to change the code to create a shell, for example.

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

This renderer should be returned by the WorkbenchRendererFactory as the renderer used to display MWindows. In addition, the factory renderer must be added as a product property in the plugin.xml file.

These changes will cause TrimmedWindow to not be maximized or modified.

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

The best solution?

In fact, there may be a better way to create SWT shells, since WBWRenderer already uses tags to determine the behavior of MWindow: shellMaximized and shellMinimized . These tags can be set on an additional tab of the cropped window in the application model editor.

If you can set swt style tags in the same way, you can use them to set the shell style. This will be a feature request for Eclipse.

+6
source

Now this can be solved with the help of a certain key flag of the “saved state”, as described in https://bugs.eclipse.org/bugs/show_bug.cgi?id=386951 . For example, to implement the NO_TRIM window, add the key / value styleOverride / 8, where 8 is the value if you received the number

  int val = SWT.NO_TRIM; System.out.println(val); 
+1
source

In addition to col.panic answer if you want style

 SWT.CLOSE | SWT.TITLE 

your styleOverride value will be 96

 System.out.println(SWT.CLOSE | SWT.TITLE) = 96 
0
source

All Articles