【问题标题】:How to access right-clicked file in Eclipse RCP using commands?如何使用命令访问 Eclipse RCP 中的右键单击文件?
【发布时间】:2016-03-14 13:57:13
【问题描述】:

我在我的 Eclipse RCP 应用程序的上下文菜单中实现了一个条目。该函数应该以另一种格式导出右键单击的文件。我已经实现了转换功能。

我需要的是右键文件的路径和名称。这就是我所拥有的:

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Shell shell = new Shell();
    DirectoryDialog dialog = new DirectoryDialog(shell);
    String saveToPath = dialog.open();

    String filePath = // ... how to access the clicked file?

    exportOtherFormat(filePath, saveToPath);
    return null;
}

所以基本上我想知道,如何访问右键单击的文件,特别是路径和名称。

【问题讨论】:

    标签: java path eclipse-plugin eclipse-rcp filepath


    【解决方案1】:

    在您的处理程序中获取当前选择并将其调整为 IFile

    ISelection sel = HandlerUtil.getCurrentSelection(event);
    
    if (sel instanceof IStructuredSelection)
     {
       Object selObj = ((IStructuredSelection)sel).getFirstObject();
    
       IFile file = (IFile)Platform.getAdapterManager().getAdapter(selObj, IFile.class);
    
       // TODO your code
     }
    

    【讨论】:

    • 非常感谢格雷格!你帮了我很多。
    猜你喜欢
    • 1970-01-01
    • 2020-10-04
    • 2019-07-17
    • 1970-01-01
    • 2021-07-08
    • 2021-04-12
    • 2012-12-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多