Showing posts with label eclipse e4. Show all posts
Showing posts with label eclipse e4. Show all posts

Monday, September 15, 2014

Expanding a trim view Vertically in programmatic way in Eclipse e4

Generally, If you have minimized a view, It will go and add it to the trimbar as shown on the left hand side.

If you click on tool item from the trimbar, it will show as a fast view. Means, It won't expand completely either in horizontally or vertically. But, user can do this by changing the orientation as show on the image.












To achieve this programmatically, we have to use Eclipse e4 workbench presentation engine component

For Vertically:
IPresentationEngine.ORIENTATION_VERTICAL

For Horizontal:
IPresentationEngine.ORIENTATION_HORIZONTAL


WorkbenchPartReference myView = page.findViewReference("myviewid");
MUIElement element = ((WorkbenchPage) page).getActiveElement(myView);

WorkbenchWindow activeWorkbenchWindow = (WorkbenchWindow) PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (activeWorkbenchWindow != null) {
MWindow window = activeWorkbenchWindow.getModel();
if (window != null) {
EModelService modelService = window.getContext().get(EModelService.class);
if (modelService != null) {
element.getTags().add(IPresentationEngine.ORIENTATION_VERTICAL);
}
}
}



By adding a element tag sets the behaviour for a particular element.

From Eclipse, "This tag can be applied to an element as a hint to the renderers that the element would prefer to be vertical. For an MPart this could be used both as a hint to how to show the view when it's in the trim but could also be used when picking a stack to add a newly opening part to. It could also be used for example to control where the tabs appear on an MPartStack."


How to get Eclipse EModelService from workbench ?


WorkbenchWindow activeWorkbenchWindow = (WorkbenchWindow) PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (activeWorkbenchWindow != null) {
MWindow window = activeWorkbenchWindow.getModel();
if (window != null) {
EModelService modelService = window.getContext().get(EModelService.class);

//your calls
}
}