I have an Eclipse RCP application with a sort of three column layout:

The editor area is at the extreme right. Now, when you get an IPageLayout to work with, the editor area is already added in. That’s fine: we add area B to the left of the editor, and area A to the left of B, and the layout is exactly what we need.
The issue is that when you move the sash between A and B, views A and B change without resizing the editor area (good;) but when you move the other sash between B and the editor area, all three views are resized; the layout manager acts to maintain the ratio of the widths of A and B, and that’s not what we want. We want the user to be able to move each sash independently, and have it influence only the two views it touches.
It seems like the root cause of this is that the editor is in place when you get your IPageView, and therefore you have to position the IFolderLayouts relative to it. If you could position the editor relative to B, instead, then resize would do the right thing.
So my questions:
- Is there any way to tell the
IPageViewto position the editor relative to a view, instead of the other way around? - Barring that, is there any other way to influence the layout algorithm, like writing some kind of layout manager?
I know of no way to alter the layout tree of
IPageLayoutin Eclipse 3.x. In Eclipse 4.2, however, the Application Model can be changed dynamically at runtime.So, if you would consider migrating your application to Eclipse 4, this solution could be an option. To keep the original application and UI code as untouched as possible, this solution will
I started with the regular RCP Mail template of Eclipse 3 and altered the perspective to recreate the problem. This is the
Perspectiveclass I used in my test application:It basically creates the scenario you described: a three column layout where one sash effects all three parts and the other one only two.
I then proceeded to migrate the application and alter the Application Model.
Migrate the Eclipse 3 based RCP application to Eclipse 4
There are online tutorials available for this process. I found Eclipse 4.1: Run your 3.x RCP in 4.1 and Eclipse 4 and the Compatibility Layer – Tutorial to be very helpful.
I recommend including the
org.eclipse.e4.tools.emf.liveeditorand its required plug-ins in your product dependencies. With the live editor, you can take a look at the Application Model that is created by the compatibility layer.Once the application starts, thet sashes will still behave the same way. Open the live editor on your application window and take a look at your model.
You can see that the
PartSashContainerincluding the placeholder for theAViewcontains anotherPartSashContainer. Moving the sash betweenAViewand that container will update the rest of the layout tree, while moving the sash betweenBViewand the editor does not effect other parts of the layout.You could now drag the placeholder for the
AViewto the container where theBViewand the editor are located. This would instantly create the effect you desire: The sashes will only affect their direct neighbours. But these changes will only be saved in one’s own runtime workspace. Something else is needed to alter the layout structure automatically.Altering the Application Model at runtime
Since I didn’t want to touch the original code if possible, I created another plugin to make a contribution to the Application Model.
Create a Plug-In Project without an
Activatorwithout using a template.Add an
Addonclass: select New->Other->Eclipse 4->Classes->New Addon ClassAdd a
Model Fragment: select New->Other-Eclipse 4->Model->New Model Fragment. Open the createdfragment.e4xmifile and add aModel Fragment. For the Element Id, putorg.eclipse.e4.legacy.ide.application(this is the standard id of legacy applications) and for the Featurenameaddons. Add anAddonto theModel Fragment. Enter an ID and set theClass URIto your addon class.Now add your
fragment.e4xmito yourorg.eclipse.e4.workbench.modelextension point:Add your contribution plugin to the dependencies of your application product. When you start your application and look at the model with the live editor, you should see your
Addonlisted in the model.Now we can implement the
Addon. This is the code of myAddonclass:(Please note that the code above is a bit of a hack because it is only really suited for this specific problem.)
After a restart, the application should now behave in the desired way. Take a look at the Application Model to see your changes.
One thing to be aware of is that local changes are saved in the runtime workspace in the file
.metadata\.plugins\org.eclipse.e4.workbench\workbench.xmiif saving is switched on, so for recreating the unaltered model for testing this file has to be deleted.