簡體   English   中英

基於選擇的Eclipse RCP處理程序支持

[英]Eclipse RCP Handler enablement based on selection

我有點被困住了,因為資源很多,而且他們沒有為我澄清這個問題。

假設我有一個命令 ,一個處理程序 ,一個屬性測試器 ,並將這些結果作為一個酷炫的項目顯示在UI上。

現在,假設我有幾個擴展相同基數的視圖(例如BaseView )。 所有這些視圖都包含ColumnViewer (例如TableViewerTreeViewer ),它們充當選擇提供程序

  • enableWhenactiveWhen配置如何了解這些查看器中的選擇? 我無法想象如何selection + instanceOf參數工作ISelection (S)。
  • 所選對象如何傳遞到屬性測試器? test方法接收什么實例(作為receiver )?
  • 我注意到一個斷點,該處理程序的setEnabled()方法有很多遍。 那是正常的行為嗎? 可以重寫setEnabled嗎?

代碼在這里似乎與我無關。 但是無論如何,這些片段涵蓋了以下問題:

// --------------------- 1 -----------------------

  <handler
        class="com.example.ggrec.handlers.SampleHandler"
        commandId="com.example.ggrec.commands.sampleCommand">
     <enabledWhen>
        <with
              variable="selection">
           <instanceof
                 value="org.eclipse.jface.viewers.ISelection">
           </instanceof>
        </with>
     </enabledWhen>
  </handler>

// --------------------- 2 -----------------------

  <propertyTester
        class="com.example.ggrec.propertyTesters.SamplePropertyTester"
        id="com.example.ggrec.samplePropertyTester"
        namespace="com.example.ggrec.propertyTesters"
        properties="simpleTest"
        type="java.lang.Object">
  </propertyTester>

// --------------------- 3 -----------------------

/**
 * 
 * @author ggrec
 *
 */
public class SamplePropertyTester extends PropertyTester
{
    @Override
    public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue)
    {
        if (receiver instanceof ISelection) // What instance is this?
            System.out.println("RAINBOWS");

        return true;
    }
}

// --------------------- 4 -----------------------

/**
 * 
 * @author ggrec
 *
 */
public class SampleHandler extends AbstractHandler
{
    @Override
    public Object execute(final ExecutionEvent event) throws ExecutionException 
    {
        final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
        MessageDialog.openInformation(window.getShell(), "", "meh");

        return null;
    }

    @Override
    public void setEnabled(final Object evaluationContext)
    {
        super.setEnabled(evaluationContext); // Goes like crazy through here.
    }
}

每個ViewPart (和編輯器部件)都有一個由選擇服務維護並由選擇提供者設置的單獨選擇。 enabledWhenvisibleWhen使用從零件選擇服務獲得的當前活動零件的選擇。

屬性測試調用通常位於啟用表達式中的<with>塊內,該表達式建立要測試的對象。 就像是:

<with
    variable="org.eclipse.ui.selection">
   <iterate
         operator="or">
      <adapt
            type="music.resources.data.IMusicFile">
            <or>
                <test property="music.isMusicOrPlaylist"/>
                <test property="music.isVideo"/>
            </or>
       </adapt>
    </iterate>
</with>

它與當前選擇配合使用,要求選擇適應特定類型,並測試兩個屬性之一。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM