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。
我编辑了一个问题。任何想法如何解决它? – medy75
使用HandlerUtil类的实用程序方法。第一个想法是HandlerUtil.getSelection(),你可以得到选择的ISelection表示,并且你可以得到IFile。 –
但是我正在使用AbstractHandler 'public class ViewHandler extends AbstractHandler {' ,并且HandlerUtil中没有getSelection()方法... – medy75