2014-12-19 82 views
3

我創建了一個查詢所選項目的插件名稱& Path。這裏是代碼:eclipse插件:檢查選定的項目是關閉還是打開

IStructuredSelection selection = (IStructuredSelection) window.getSelectionService().getSelection(); 
Object firstElement = selection.getFirstElement(); 
if (firstElement != null) { 
    if (firstElement instanceof IAdaptable) { 
     IProject project = (IProject) ((IAdaptable) firstElement).getAdapter(IProject.class); 
     IPath path = project.getFullPath(); 
     IPath location = project.getLocation(); 
    } 
} 

但是,我怎麼能檢查選定的項目是關閉還是打開?

回答

2

IProject有一個isOpen()方法。這會告訴你該項目目前是否開放。

+0

謝謝。有效。 – 2014-12-19 15:11:03

+0

但是,關閉的項目(但仍然出現在Project Explorer視圖中)和剛剛位於工作區中的項目之間是否存在任何差異?對於他們兩個我得到isOpen()== false,但我想區分這種類型的「封閉」項目。 – 2017-05-18 13:56:32

相關問題