1

ターゲットプラットフォーム3.7でRCPアプリを作成しています。menuItemを有効にするのは、特定のビューがアクティブな場合のみ有効にし、そうでない場合は無効にする必要があります。以下のplugin.xmlに示すような式で試してみましたが、menuItemは常にアクティブです。

 <extension
         point="org.eclipse.ui.commands">
      <command
            defaultHandler="pgui.handler.SaveHandler"
            id="pgui.rcp.command.save"
            name="Save">
      </command>
   </extension>
   <extension
     point="org.eclipse.ui.views">
     <view
          allowMultiple="true"
          class="pgui.view.LogView"
          id="pgui.view.LogView"
          name="logview"
          restorable="true">
     </view>
   </extension>
   <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            allPopups="false"
            locationURI="menu:org.eclipse.ui.main.menu">
         <menu
               id="fileMenu"
               label="File">
            <command
                  commandId="pgui.rcp.command.save"
                  label="Save"
                  style="push"
                  tooltip="Save the active log file.">
            </command>
         </menu>
      </menuContribution>
    </extension>
    <extension
         point="org.eclipse.ui.handlers">
      <handler
            commandId="pgui.rcp.command.save">
         <activeWhen>
            <with
                  variable="activePart">
               <instanceof
                     value="pgui.view.LogView">
               </instanceof>
            </with>
         </activeWhen>
      </handler>
   </extension>
4

1 に答える 1

3

まず、コマンドからdefaultHandlerを削除します。

次に、代わりにハンドラークラスをハンドラー拡張ポイントに追加します。

基本的に、このメカニズムでは、異なるactiveWhen式を使用して、同じコマンドに対して複数のハンドラーを定義し、異なる状況で異なるハンドラークラスによってコマンドを処理させることができます。

コマンドに対して定義されたすべてのハンドラーのすべてのactiveWhen式がfalseと評価され、コマンド自体にdefaultHandlerが定義されている場合、そのデフォルトハンドラーがコマンドに使用されます。コマンドを処理するためのデフォルトのハンドラーが常に存在するため、コマンドは基本的に常にアクティブになります。

たとえば、既存のLogViewとユニコーンでいっぱいの別のビューの両方があり、同じpgui.rcp.command.saveコマンドを使用して、いずれかのビューからのアイテムの保存を処理したい場合は、次のようになります。

<extension point="org.eclipse.ui.commands">
    <command
        id="pgui.rcp.command.save"
        name="Save">
    </command>
</extension>
:
<extension point="org.eclipse.ui.handlers">
    <handler
        class="pgui.handler.SaveLogHandler"
        commandId="pgui.rcp.command.save">

        <activeWhen>
            <with variable="activePart">
                <instanceof value="pgui.view.LogView">
                </instanceof>
            </with>
        </activeWhen>
    </handler>
</extension>
:
<extension point="org.eclipse.ui.handlers">
    <handler
        class="pgui.handler.SaveUnicornHandler"
        commandId="pgui.rcp.command.save">

        <activeWhen>
            <with variable="activePart">
                <instanceof value="pgui.view.UnicornView">
                </instanceof>
            </with>
        </activeWhen>
    </handler>
</extension>
于 2012-07-23T14:52:57.717 に答える