Eclipse API學習之ISelection介面

來源:互聯網
上載者:User

 

ISelection介面僅有一個方法:

isEmpty()

 

由於ISelection介面比較簡單,所以通常使用的是ISelection的子介面IStructuredSelection。

IStructuredSelection介面提供了一些方便的方法,比如擷取第一個選擇對象的的getFirstElement()

方法,擷取所有選擇對象的迭代器iterator()方法,擷取所選擇個數的size()方法,並且有把所有選擇對象轉化為List的toList()方法,和轉化為數組的toArray()方法

 

 

擴充ISelection只需要實現isEmpty()方法即可,如下即是一個實現ISelection介面的例子:

public class TabSelection implements ISelection

{

    private ChartTab chartTab;

 

    public TabSelection(ChartTab chartTab)

    {

        this.chartTab = chartTab;

    }

 

    /* (non-Javadoc)

     * @see org.eclipse.jface.viewers.ISelection#isEmpty()

     */

    public boolean isEmpty()

    {

        return chartTab == null;

    }

 

    public ChartTab getChartTab()

    {

        return chartTab;

    }

}

 

有時候在表格或者樹中,想取消選擇,即不選擇任何對象。

即通過setSelection(obj)進行設定。

這裡可能擴充一個NullSelection。NullSelection實現ISelection介面。

ISelection只有一個方法isEmpty(),只需要將isEmpty()方法返回false即可。

public class NullSelection implements ISelection{

    public NullSelection(){

 

    }

 

   public boolean isEmpty(){

       return true;

   }

}

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.