Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Open Perspective in new WorkbenchWindow does not set Expressions for Toolitems visibility correct
Open Perspective in new WorkbenchWindow does not set Expressions for Toolitems visibility correct [message #1591446] Thu, 29 January 2015 14:37 Go to next message
Rainer Rieder is currently offline Rainer RiederFriend
Messages: 4
Registered: January 2015
Junior Member
I am currently in the process of trying to run my Eclipse 3.8 RCP Application in compatibility mode under Eclipse 4.4.1 So far I could work around most of the quirks. The only issue left ist the visibility of Toolbar-Items in the main Toolbar linked to perspectives when the perspective is opened in a new WorkbenchWindow.

I created a TestApplication (based on the Mail-Template) to confirm the problematic behaviour.

I have two perspectives and two Core-Expression-Definitions

<extension point="org.eclipse.core.expressions.definitions">
  <definition id="onPerspective1">
     <with variable="activeWorkbenchWindow.activePerspective">
           <equals value="zzTestMailTemplate.perspective1"/>
      </with>
  </definition>


<extension point="org.eclipse.core.expressions.definitions">
  <definition id="onPerspective2">
     <with variable="activeWorkbenchWindow.activePerspective">
           <equals value="zzTestMailTemplate.perspective2"/>
      </with>
  </definition>
</extension>


The Toolbar-Contributions are linked to either of the Perspectives by setting them visible only when the spcecified definition-id is active.

<extension
     point="org.eclipse.ui.menus">
  <menuContribution
        allPopups="false"
        locationURI="toolbar:org.eclipse.ui.main.toolbar">
     <toolbar
           id="zzTestMailTemplate.toolbar1">
        <command
              commandId="zzTestMailTemplate.open"
              icon="icons/sample3.gif"
              label="Open Mailbox-View"
              style="push">
           <visibleWhen
                 checkEnabled="false">
              <reference
                    definitionId="onPerspective1">
              </reference>
           </visibleWhen>
        </command>


This works as long as the perspective is switched in the same workbench window

IWorkbench workbench = window.getWorkbench();
workbench.showPerspective(PerspectiveFactory2.ID, window, null);


But when I open the Perspective in another WorkbenchWindow the Toolbar of that window gets the Items only valid to the first perspective. If I activate a window outside of the RCP application and switch back, the first window that gets activated/the focus shows the ToolItems valid for the second perspective.

IWorkbench workbench = window.getWorkbench();
IWorkbenchPage ldPage = window.openPage(PerspectiveFactory2.ID, new WorkbenchPageInput(PerspectiveFactory2.ID));

This used to work correct running under Eclipse Platform 3.8.
And it seems that it is somehow related to context evaluation by window activation.
I would be very happy if someone could give me a hint how I could work around this problem.
Re: Open Perspective in new WorkbenchWindow does not set Expressions for Toolitems visibility correc [message #1600861 is a reply to message #1591446] Wed, 04 February 2015 14:50 Go to previous messageGo to next message
Santiago Regueiro is currently offline Santiago RegueiroFriend
Messages: 1
Registered: February 2015
Junior Member
We have just found the same problem.

This blog post shows how to fix it in Eclipse 4: https://jonathanjwright.wordpress.com/2014/07/15/eclipse-4-4-0-perspective-based-show-hide-of-tool-bar-items/

[Updated on: Wed, 04 February 2015 15:25] by Moderator

Report message to a moderator

Re: Open Perspective in new WorkbenchWindow does not set Expressions for Toolitems visibility correc [message #1602299 is a reply to message #1600861] Thu, 05 February 2015 13:02 Go to previous message
Rainer Rieder is currently offline Rainer RiederFriend
Messages: 4
Registered: January 2015
Junior Member
I modified my Test-Application (running in compatibility Mode) to use PropertyTesters and the variable "org.eclipse.e4.ui.model.application.ui.advanced.MPerspective" instead of "activeWorkbenchWindow.activePerspective" with an additional id-check.
This worked much better. Although the non active Window shows an empty toolbar.
If you switch between Windows activating one of its Workbench-Parts the correct Toolbar-Items appear while the deactivated windows shows no items.
So it seems, that the active perspective in Window B makes the Toolbar-Items in Window A invisible.
The active perspective seems to be global between the thwo windows instead of affecting only the toolbar of the window it is assigned to.
If you activate a window by it's trim bar the former window gets the toolbar-items shown and the activated window shows an empty toolbar.

Here are my code changes:

PropertyTesters:

  <extension
         point="org.eclipse.core.expressions.propertyTesters">
      <propertyTester
            class="zztestmailtemplate.Perspectice1PropertyTester"
            id="zztestmailtemplate.Perspectice1PropertyTester"
            namespace="zztestmailtemplate.Perspectice1PropertyTester"
            properties="activeperspective"
            type="java.lang.Object">
      </propertyTester>
      <propertyTester
            class="zztestmailtemplate.Perspectice2PropertyTester"
            id="zztestmailtemplate.Perspectice2PropertyTester"
            namespace="zztestmailtemplate.Perspectice2PropertyTester"
            properties="activeperspective"
            type="java.lang.Object">
      </propertyTester>
   </extension>


PropertyTester-Code:

public class Perspectice1PropertyTester extends PropertyTester {

	@Override
	public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) {

		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		if(window.equals(PlatformUI.getWorkbench().getWorkbenchWindows()[0])) {
			IPerspectiveDescriptor perspective = window.getActivePage().getPerspective();
			String perspectiveId = perspective.getId();
			String checkId = perspectiveId;
			if(receiver instanceof MPerspective) {
				MPerspective mperspective = (MPerspective) receiver;
				checkId = mperspective.getElementId();
			}
			if (checkId.startsWith((String)expectedValue)) {
				return true;
			}
		}
		return false;
	}
}


Expression-Definitions:

  <extension
         point="org.eclipse.core.expressions.definitions">
      <definition
            id="onPerspectiveDefinition1">
         <with
               variable="org.eclipse.e4.ui.model.application.ui.advanced.MPerspective">
            <test
                  forcePluginActivation="true"
                  property="zztestmailtemplate.Perspectice1PropertyTester.activeperspective"
                  value="zzTestMailTemplate.perspective1">
            </test>
         </with>
      </definition>
      <definition
            id="onPerspectiveDefinition2">
         <with
               variable="org.eclipse.e4.ui.model.application.ui.advanced.MPerspective">
            <test
                  forcePluginActivation="true"
                  property="zztestmailtemplate.Perspectice2PropertyTester.activeperspective"
                  value="zzTestMailTemplate.perspective2">
            </test>
         </with>
      </definition>
   </extension>
Previous Topic:A MWindow with isToBeRendered to true and getWidget returning null
Next Topic:Toggle Handled Menu Item initialisation and persisted state
Goto Forum:
  


Current Time: Thu Nov 23 03:58:06 GMT 2017

Powered by FUDForum. Page generated in 0.02124 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software