Eclipse rcp 在e4中使用PropertyTester

Eclipse rcp 在e4中使用PropertyTester,eclipse-rcp,e4,Eclipse Rcp,E4,我在从3.xEclipse迁移到Eclipse4.X时遇到了麻烦 我想保护用户界面,这样用户只能看到他们被允许看到的东西。在旧的应用程序中,我将扩展点org.eclipse.core.expressions.propertyTests与org.eclipse.ui.activities和org.eclipse.core.expressions.definitions结合使用。这里我有一个链接,可以让你更好地了解这个话题的背景 但现在我想在e4中采用同样的方式,但我无法让它们运行。永远不会调用pr

我在从3.xEclipse迁移到Eclipse4.X时遇到了麻烦

我想保护用户界面,这样用户只能看到他们被允许看到的东西。在旧的应用程序中,我将扩展点
org.eclipse.core.expressions.propertyTests
org.eclipse.ui.activities
org.eclipse.core.expressions.definitions
结合使用。这里我有一个链接,可以让你更好地了解这个话题的背景

但现在我想在e4中采用同样的方式,但我无法让它们运行。永远不会调用propertyTester中的测试方法。可以使用相同的机制来保护e4中的UI,如果可以,您能给我一些提示吗

编辑: 我的示例测试方法: plugin.xml

Application.e4xmi
表达式定义没有指定
元素来定义要测试的内容。如果没有此选项,则默认为空列表。但是,我找不到包含当前元素的变量,因此我不确定您是否可以使用这种方法

另一种方法是使用
元素来测试使用Java
System.setPropery
调用的值集。表达式定义类似于:


Java代码:

System.setProperty(“greg.music.isShowAdmin”、“true”);

(摘自我的一个e4应用程序中的工作代码)

请澄清,您指的是纯e4应用程序(使用application.e4xmi,不包括3.x兼容代码)?纯e4没有活动。是的,我希望这是一个纯e4应用程序,所以我不能再使用这种方法了。性能测试人员工作正常。向我们展示一个不起作用的实际示例。@greg-449您在哪里知道活动不能使用,哪里有好的文档?您不能使用
org.eclipse.ui.*
中的任何内容,因为它们不包括在e4中。如果您查看列出核心e4插件的
org.eclipse.e4.rcp
特性。
package e4.prototype;

import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.e4.ui.model.application.ui.MUIElement;

public class TestPropertyTester extends PropertyTester {
    @Override
    public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) {
        System.out.println("Start");
        if (receiver instanceof MUIElement) {
            MUIElement element = (MUIElement) receiver;

            return element.getElementId().equals(expectedValue);
        }

        return false;
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
   <extension id="product" point="org.eclipse.core.runtime.products">
      <product name="e4.prototype" application="org.eclipse.e4.ui.workbench.swt.E4Application">
         <property name="applicationCSS" value="platform:/plugin/e4.prototype/css/default.css" />
         <property name="appName" value="e4.prototype" />
      </product>
   </extension>
   <extension
       point="org.eclipse.ui.startup">
    <startup
          class="e4.prototype.E4LifeCycle">
    </startup>
 </extension>
    <extension
     point="org.eclipse.core.expressions.propertyTesters">
  <propertyTester
        class="e4.prototype/e4.prototype.TestPropertyTester"
        id="test.id"
        namespace="e4.prototype"
        properties="TestPropertyTester"
        type="org.eclipse.e4.ui.model.application.ui.MUIElement"/>
        </extension>
 <extension
       point="org.eclipse.core.expressions.definitions">
       <definition
             id="e4.prototype.part.sonderpart.isAllowed">
          <test
                forcePluginActivation="true"
                property="name.space.partId"
                value="e4.prototype.part.sonderpart">
          </test>
       </definition>
       <definition
             id="e4.prototype.saveMenu.isAllowed">
          <test
                forcePluginActivation="true"
                property="e4.prototype.TestPropertyTester">
          </test>
       </definition>
       <definition
             id="e4.prototype.sicherheitPart.isAllowed">
          <test
                forcePluginActivation="true"
                property="e4.prototype.TestPropertyTester">
          </test>
       </definition>
       <definition
             id="e4.prototype.mainmenu.isAllowed">
          <test
                forcePluginActivation="true"
                property="e4.prototype.TestPropertyTester">
          </test>
       </definition>
       <definition
             id="e4.prototype.quit.isAllowed">
          <test
                forcePluginActivation="true"
                property="e4.prototype.TestPropertyTester">
          </test>
       </definition>
 </extension>
</plugin>
<?xml version="1.0" encoding="UTF-8"?>
<application:Application xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:advanced="http://www.eclipse.org/ui/2010/UIModel/application/ui/advanced" xmlns:application="http://www.eclipse.org/ui/2010/UIModel/application" xmlns:basic="http://www.eclipse.org/ui/2010/UIModel/application/ui/basic" xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu" xmlns:ui="http://www.eclipse.org/ui/2010/UIModel/application/ui" xmi:id="_To7nkEVhEeSxjfMveZwvQg" elementId="org.eclipse.e4.ide.application" bindingContexts="_To8OqEVhEeSxjfMveZwvQg">
  <children xsi:type="basic:TrimmedWindow" xmi:id="_To8OoEVhEeSxjfMveZwvQg" label="e4.prototype" width="500" height="400">
    <children xsi:type="advanced:PerspectiveStack" xmi:id="_To8Ov0VhEeSxjfMveZwvQg">
      <children xsi:type="advanced:Perspective" xmi:id="_To8OwEVhEeSxjfMveZwvQg" elementId="id.standardperspektive" label="Standardperspektive" iconURI="platform:/plugin/e4.prototype/icons/star.png">
        <children xsi:type="basic:PartSashContainer" xmi:id="_To81sEVhEeSxjfMveZwvQg">
          <children xsi:type="basic:PartStack" xmi:id="_To81sUVhEeSxjfMveZwvQg">
            <children xsi:type="basic:Part" xmi:id="_To81skVhEeSxjfMveZwvQg" elementId="e4.prototype.part.samplepart" contributionURI="bundleclass://e4.prototype/e4.prototype.parts.SamplePart" label="Sample Part"/>
            <children xsi:type="basic:Part" xmi:id="_EVLKEJfpEeSi9rx2U_7VwA" elementId="e4.prototype.part.sicherheit" toBeRendered="false" contributionURI="bundleclass://e4.prototype/e4.prototype.parts.SicherheitPart" label="Sicherheitspart"/>
          </children>
        </children>
      </children>
      <children xsi:type="advanced:Perspective" xmi:id="_7EIEgGM6EeSQG8PUWitY6g" elementId="e4.prototype.perspective.sonderperspektive" label="Sonderperspektive" iconURI="platform:/plugin/e4.prototype/icons/icon.gif">
        <children xsi:type="basic:PartSashContainer" xmi:id="_G4C-gGM7EeSQG8PUWitY6g" elementId="e4.prototype.partsashcontainer.0">
          <children xsi:type="basic:PartStack" xmi:id="_HPiRcGM7EeSQG8PUWitY6g" elementId="e4.prototype.partstack.0">
            <children xsi:type="basic:Part" xmi:id="_HnyZYGM7EeSQG8PUWitY6g" elementId="e4.prototype.part.sonderpart" contributionURI="bundleclass://e4.prototype/e4.prototype.parts.SonderPart" label="Sonderpart"/>
          </children>
        </children>
      </children>
    </children>
    <mainMenu xmi:id="_To8OuEVhEeSxjfMveZwvQg" elementId="e4.prototype.mainmenu">
      <children xsi:type="menu:Menu" xmi:id="_To8OuUVhEeSxjfMveZwvQg" elementId="menuFile" label="File">
        <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_TVs7QJfvEeSi9rx2U_7VwA" coreExpressionId="e4.prototype.mainmenu.isAllowed"/>
        <children xsi:type="menu:HandledMenuItem" xmi:id="_To8OukVhEeSxjfMveZwvQg" elementId="open" label="Open" iconURI="platform:/plugin/e4.prototype/icons/sample.png" command="_To8Or0VhEeSxjfMveZwvQg"/>
        <children xsi:type="menu:HandledMenuItem" xmi:id="_To8Ou0VhEeSxjfMveZwvQg" elementId="save" label="Save" iconURI="platform:/plugin/e4.prototype/icons/save_edit.png" command="_To8OskVhEeSxjfMveZwvQg">
          <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_mPIjkJfoEeSi9rx2U_7VwA" coreExpressionId="e4.prototype.saveMenu.isAllowed"/>
        </children>
        <children xsi:type="menu:HandledMenuItem" xmi:id="_To8OvEVhEeSxjfMveZwvQg" elementId="e4.prototype.quit" label="Quit" command="_To8Oq0VhEeSxjfMveZwvQg">
          <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_os8loJfvEeSi9rx2U_7VwA" coreExpressionId="e4.prototype.quit.isAllowed"/>
        </children>
        <children xsi:type="menu:HandledMenuItem" xmi:id="_c4BWcGMzEeSQG8PUWitY6g" elementId="e4.prototype.handledmenuitem.wizardOverview" label="Wizard Overview" command="_gctlMGMzEeSQG8PUWitY6g">
          <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_lYatIJcbEeSasfgjZErgeg" coreExpressionId="e4.prototype.beispiel"/>
        </children>
      </children>
      <children xsi:type="menu:Menu" xmi:id="_To8OvUVhEeSxjfMveZwvQg" label="Help">
        <children xsi:type="menu:HandledMenuItem" xmi:id="_To8OvkVhEeSxjfMveZwvQg" elementId="about" label="About" command="_To8OtUVhEeSxjfMveZwvQg"/>
        <children xsi:type="menu:HandledMenuItem" xmi:id="_qBqJYGM3EeSQG8PUWitY6g" elementId="e4.prototype.handledmenuitem.help" label="Help" command="_s37L4GM3EeSQG8PUWitY6g"/>
        <children xsi:type="menu:HandledMenuItem" xmi:id="_b_f9YJZUEeSFv-fBot4czg" elementId="e4.prototype.handledmenuitem.info" label="Info" command="_gZdnQJZUEeSFv-fBot4czg"/>
      </children>
      <children xsi:type="menu:Menu" xmi:id="_PrdosJfwEeSi9rx2U_7VwA" elementId="e4.prototype.menu.misc" label="Sonstiges">
        <children xsi:type="menu:HandledMenuItem" xmi:id="_YuGt4JfwEeSi9rx2U_7VwA" elementId="e4.prototype.handledmenuitem.sichtbar" label="Sichtbar"/>
      </children>
    </mainMenu>
    <trimBars xmi:id="_To81s0VhEeSxjfMveZwvQg">
      <children xsi:type="menu:ToolBar" xmi:id="_To81tEVhEeSxjfMveZwvQg" elementId="toolbar:org.eclipse.ui.main.toolbar">
        <children xsi:type="menu:HandledToolItem" xmi:id="_To81tUVhEeSxjfMveZwvQg" iconURI="platform:/plugin/e4.prototype/icons/sample.png" command="_To8Or0VhEeSxjfMveZwvQg"/>
        <children xsi:type="menu:HandledToolItem" xmi:id="_To81tkVhEeSxjfMveZwvQg" iconURI="platform:/plugin/e4.prototype/icons/save_edit.png" command="_To8OskVhEeSxjfMveZwvQg"/>
      </children>
    </trimBars>
    <trimBars xmi:id="_LcGjEGM8EeSQG8PUWitY6g" elementId="e4.prototype.trimbar.0" side="Bottom">
      <children xsi:type="menu:ToolControl" xmi:id="_e6PzQGM7EeSQG8PUWitY6g" elementId="e4.prototype.toolcontrol.0" contributionURI="bundleclass://org.eclipse.e4.ui.workbench.perspectiveswitcher/org.eclipse.e4.ui.workbench.perspectiveswitcher.tools.PerspectiveSwitcherSwtTrim"/>
    </trimBars>
  </children>
  <handlers xmi:id="_To8OrEVhEeSxjfMveZwvQg" elementId="e4.prototype.handler.quitCommand" contributionURI="bundleclass://e4.prototype/e4.prototype.handlers.QuitHandler" command="_To8Oq0VhEeSxjfMveZwvQg"/>
  <handlers xmi:id="_To8OsEVhEeSxjfMveZwvQg" elementId="e4.prototype.handler.openCommand" contributionURI="bundleclass://e4.prototype/e4.prototype.handlers.OpenHandler" command="_To8Or0VhEeSxjfMveZwvQg"/>
  <handlers xmi:id="_To8Os0VhEeSxjfMveZwvQg" elementId="e4.prototype.handler.saveCommand" contributionURI="bundleclass://e4.prototype/e4.prototype.handlers.SaveHandler" command="_To8OskVhEeSxjfMveZwvQg"/>
  <handlers xmi:id="_To8OtkVhEeSxjfMveZwvQg" elementId="e4.prototype.handler.aboutCommand" contributionURI="bundleclass://e4.prototype/e4.prototype.handlers.AboutHandler" command="_To8OtUVhEeSxjfMveZwvQg"/>
  <handlers xmi:id="_iwUmkGMzEeSQG8PUWitY6g" elementId="e4.prototype.handler.0" contributionURI="bundleclass://e4.prototype/e4.prototype.handlers.WizardOverviewHandler" command="_gctlMGMzEeSQG8PUWitY6g"/>
  <handlers xmi:id="_usgu8GM3EeSQG8PUWitY6g" elementId="e4.prototype.handler.1" contributionURI="bundleclass://e4.prototype/e4.prototype.handlers.HelpHandler" command="_s37L4GM3EeSQG8PUWitY6g"/>
  <handlers xmi:id="_qCtZcJZUEeSFv-fBot4czg" elementId="e4.prototype.handler.info" contributionURI="bundleclass://e4.prototype/e4.prototype.handlers.InfoHandler" command="_gZdnQJZUEeSFv-fBot4czg"/>
  <bindingTables xmi:id="_To8OrUVhEeSxjfMveZwvQg" bindingContext="_To8OqEVhEeSxjfMveZwvQg">
    <bindings xmi:id="_To8OrkVhEeSxjfMveZwvQg" keySequence="M1+Q" command="_To8Oq0VhEeSxjfMveZwvQg"/>
    <bindings xmi:id="_To8OsUVhEeSxjfMveZwvQg" keySequence="M1+O" command="_To8Or0VhEeSxjfMveZwvQg"/>
    <bindings xmi:id="_To8OtEVhEeSxjfMveZwvQg" keySequence="M1+S" command="_To8OskVhEeSxjfMveZwvQg"/>
    <bindings xmi:id="_To8Ot0VhEeSxjfMveZwvQg" keySequence="M1+A" command="_To8OtUVhEeSxjfMveZwvQg"/>
  </bindingTables>
  <rootContext xmi:id="_To8OqEVhEeSxjfMveZwvQg" elementId="org.eclipse.ui.contexts.dialogAndWindow" name="In Dialog and Windows">
    <children xmi:id="_To8OqUVhEeSxjfMveZwvQg" elementId="org.eclipse.ui.contexts.window" name="In Windows"/>
    <children xmi:id="_To8OqkVhEeSxjfMveZwvQg" elementId="org.eclipse.ui.contexts.dialog" name="In Dialogs"/>
  </rootContext>
  <commands xmi:id="_To8Oq0VhEeSxjfMveZwvQg" elementId="org.eclipse.ui.file.exit" commandName="quitCommand"/>
  <commands xmi:id="_To8Or0VhEeSxjfMveZwvQg" elementId="e4.prototype.open" commandName="openCommand"/>
  <commands xmi:id="_To8OskVhEeSxjfMveZwvQg" elementId="org.eclipse.ui.file.save" commandName="saveCommand"/>
  <commands xmi:id="_To8OtUVhEeSxjfMveZwvQg" elementId="org.eclipse.ui.help.aboutAction" commandName="aboutCommand"/>
  <commands xmi:id="_gctlMGMzEeSQG8PUWitY6g" elementId="e4.prototype.command.wizardoverviewcommand" commandName="wizardOverviewCommand"/>
  <commands xmi:id="_s37L4GM3EeSQG8PUWitY6g" elementId="e4.prototype.command.helpcommand" commandName="helpCommand"/>
  <commands xmi:id="_gZdnQJZUEeSFv-fBot4czg" elementId="e4.prototype.command.infocommand" commandName="infoCommand"/>
  <addons xmi:id="_To8OoUVhEeSxjfMveZwvQg" elementId="org.eclipse.e4.core.commands.service" contributionURI="bundleclass://org.eclipse.e4.core.commands/org.eclipse.e4.core.commands.CommandServiceAddon"/>
  <addons xmi:id="_To8OokVhEeSxjfMveZwvQg" elementId="org.eclipse.e4.ui.contexts.service" contributionURI="bundleclass://org.eclipse.e4.ui.services/org.eclipse.e4.ui.services.ContextServiceAddon"/>
  <addons xmi:id="_To8Oo0VhEeSxjfMveZwvQg" elementId="org.eclipse.e4.ui.bindings.service" contributionURI="bundleclass://org.eclipse.e4.ui.bindings/org.eclipse.e4.ui.bindings.BindingServiceAddon"/>
  <addons xmi:id="_To8OpEVhEeSxjfMveZwvQg" elementId="org.eclipse.e4.ui.workbench.commands.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.CommandProcessingAddon"/>
  <addons xmi:id="_To8OpUVhEeSxjfMveZwvQg" elementId="org.eclipse.e4.ui.workbench.handler.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.HandlerProcessingAddon"/>
  <addons xmi:id="_To8OpkVhEeSxjfMveZwvQg" elementId="org.eclipse.e4.ui.workbench.contexts.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench/org.eclipse.e4.ui.internal.workbench.addons.ContextProcessingAddon"/>
  <addons xmi:id="_To8Op0VhEeSxjfMveZwvQg" elementId="org.eclipse.e4.ui.workbench.bindings.model" contributionURI="bundleclass://org.eclipse.e4.ui.workbench.swt/org.eclipse.e4.ui.workbench.swt.util.BindingProcessingAddon"/>
</application:Application>