Open Perspective in new WorkbenchWindow does not set Expressions for Toolitems visibility correct [message #1591446] |
Thu, 29 January 2015 09:37  |
Eclipse User |
|
|
|
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 #1602299 is a reply to message #1600861] |
Thu, 05 February 2015 08:02  |
Eclipse User |
|
|
|
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>
|
|
|
Powered by
FUDForum. Page generated in 0.03916 seconds