Showing posts with label trimbar. Show all posts
Showing posts with label trimbar. Show all posts

Monday, September 15, 2014

How to minimize a view programmatically in Eclipse e4 versions/ Adding a view to the trimbar

Below snippet can be used to minimize a view.

IViewPart part = page.showView("com.kk.views.showtasks");
if (part != null) {
 IWorkbenchPartReference myView = page.findViewReference(viewid);
MUIElement element = ((WorkbenchPage) page).getActiveElement(myView);
WorkbenchWindow activeWorkbenchWindow = (WorkbenchWindow) PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (activeWorkbenchWindow != null) {
MWindow window = activeWorkbenchWindow.getModel();
if (window != null) {
            EModelService service = window.getContext().get(EModelService.class);
if (service != null) {
element.getTags().add(IPresentationEngine.MINIMIZED);

}
}
}
}

More important thing here is,
element.getTags().add(IPresentationEngine.MINIMIZED);

When above code gets invoked, MinMaxAddon.minimize(..) will be invoked internally to minimize a view. Minimized view will be added as a toolbar item to the trimbar.

MUIElement element = ((WorkbenchPage) page).getActiveElement(myView);
Here element is PartStack element, that means all the elements(Parts) which are there in the partstack will be minimized.





How to add right trimbar/side bar in eclipse

This can be achieved through "org.eclipse.ui.menus" extension point with the locationURI as "toolbar:org.eclipse.ui.trim.vertical2"

<extension
       point="org.eclipse.ui.menus">
    <menuContribution
          allPopups="false"
          locationURI="toolbar:org.eclipse.ui.trim.vertical2">
       <toolbar
             id="myrightsidetrimbar"
             label="Eclispe rightside trimbar">
          <command
                commandId="com.kk.command.showHelp"
                icon="icons/help.gif"
                label="Help"
                style="push">
          </command>
            </toolbar>
    </menuContribution>
 </extension>


toolbar:org.eclipse.ui.trim.vertical2 -> will be for used for Right trimbar

We can find all these uri identifiers in MenuUtil.java in eclipse org.eclispe.ui.workbench plugin

 /** Top Left Trim Area */
public final static String TRIM_COMMAND1 = "toolbar:org.eclipse.ui.trim.command1"; //$NON-NLS-1$
/** Top Right Trim Area */
public final static String TRIM_COMMAND2 = "toolbar:org.eclipse.ui.trim.command2"; //$NON-NLS-1$
/** Left Vertical Trim Area */
public final static String TRIM_VERTICAL1 = "toolbar:org.eclipse.ui.trim.vertical1"; //$NON-NLS-1$
/** Right Vertical Trim Area */
public final static String TRIM_VERTICAL2 = "toolbar:org.eclipse.ui.trim.vertical2"; //$NON-NLS-1$
/** Bottom (Status) Trim Area */
public final static String TRIM_STATUS = "toolbar:org.eclipse.ui.trim.status"; //$NON-NLS-1$