Eclipse插件文件的使用
在我的Eclipse插件中,我需要使用来自PackageExplorer的文件。我用鼠标右键点击一个文件并选择“查看”(我的插件名)。那么,如何在我的插件项目中访问这个文件路径呢 我有这个:Eclipse插件文件的使用,eclipse,file,plugins,filepath,Eclipse,File,Plugins,Filepath,在我的Eclipse插件中,我需要使用来自PackageExplorer的文件。我用鼠标右键点击一个文件并选择“查看”(我的插件名)。那么,如何在我的插件项目中访问这个文件路径呢 我有这个: public class ViewHandler extends AbstractHandler { ... public Object execute(ExecutionEvent event) throws ExecutionException { ... ... URI ur
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。在您的命令处理程序中(我希望您使用的是命令框架,而不是JFace操作),您可以检查当前选定的元素,然后使用生成的IFile进行解析。使用HandlerUtil类的实用方法。第一个想法是HandlerUtil.getSelection(),在这里你可以得到选择的ISelection表示,从中你可以得到IFile。但是我使用的是AbstractHandler公共类ViewHandler扩展AbstractHandler{
,在你的HandlerUtil中没有getSelection()方法……事实上,我写的是getSelection()而不是getCurrentSelection()。我在写答案时没有打开Eclipse。AbstractHandler是正确的。好的,我得到了以下信息:ISelection select=HandlerUtil.getCurrentSelection(事件);
但是我不能将这个“select”重新键入IFile或IPath。如果我只键入select.toString();
it writeout[L/cz.cvut.earlgrey.classmodel/model/task.cm]
但我不希望这些[]出现在那里,也不想使用子字符串或类似的东西。请将ISelection重新键入IsStructuredSelection,然后可以在选定的元素上进行迭代(在您的情况下,可能是IFiles)。