2012-05-25 54 views
0

在我的Eclipse插件中,我需要使用package explorer中的文件。我用鼠標右鍵單擊一個文件並選擇「查看」(我的插件名稱)。那麼,我怎樣才能在我的插件項目中達到這個文件路徑?Eclipse插件文件使用

http://i49.tinypic.com/2j29ifs.png

我有這樣的:

public class ViewHandler extends AbstractHandler { 
... 
public Object execute(ExecutionEvent event) throws ExecutionException { 
... 
... 
     URI uri = null; 
     try { 
      test(); 
      uri = URI.createURI("../models/task.cm"); 
      Resource resource = resourceSet 
        .getResource(uri, true); 
      Model model = (Model) resource.getContents().get(0); 
      ModelExtractor showModel = new ModelExtractor(model); 
      showModel.run(); 
     } catch (Exception e) { 
      System.out.print(e); 
     } 

     return null; 
    } 
} 

,我需要替換該行: uri = URI.createURI("../models/task.cm");

與到文件的相對路徑。

或者如果你有一些很好的tuto。

回答

0

在您的命令處理程序(我希望,您使用的是命令框架,而不是JFace操作),您可以檢查當前選定的元素,然後使用生成的IFile進行分析。

+0

我編輯了一個問題。任何想法如何解決它? – medy75

+0

使用HandlerUtil類的實用程序方法。第一個想法是HandlerUtil.getSelection(),你可以得到選擇的ISelection表示,並且你可以得到IFile。 –

+0

但是我正在使用AbstractHandler 'public class ViewHandler extends AbstractHandler {' ,並且HandlerUtil中沒有getSelection()方法... – medy75