在e4中使用PropertyTester

时间:2015-01-13 08:48:52

标签: eclipse-rcp e4

我面临着从3.X Eclipse迁移到Eclipse 4.X的麻烦。

我想保护用户界面,以便用户只能看到允许的内容。在旧应用程序中,我将扩展点org.eclipse.core.expressions.propertyTestersorg.eclipse.ui.activitiesorg.eclipse.core.expressions.definitions结合使用。在这里,我有一个链接,可以让您更好地了解该主题。http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fworkbench_advext_activities.htm

但是现在我想在e4中采用相同的方式,但我不会让它们运行。从不调用propertyTester中的test-methode。可以使用相同的机制来保护e4中的UI,如果是,你可以给我一些提示吗?

编辑:

我的示例测试方法:

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;
    }
}

的plugin.xml

<?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>

Application.e4xmi

<?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>

1 个答案:

答案 0 :(得分:0)

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

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

  <definition
        id="greg.music.admin">
     <systemTest
         property="greg.music.isShowAdmin"
         value="true"/>
  </definition>

和Java代码:

System.setProperty("greg.music.isShowAdmin", "true");

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