2012-05-25 45 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