Eclipse Plugin: how to get the path to the currently selected project

前端 未结 3 2028
迷失自我
迷失自我 2020-12-31 08:17

I am writing an Eclipse plugin that will display a menu item in the context menu for a Java Project. I have written the plugin.xml as follows:



        
3条回答
  •  一个人的身影
    2020-12-31 08:29

    This should get you closer (if not solve it completely for you ;))

        IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (window != null)
        {
            IStructuredSelection selection = (IStructuredSelection) window.getSelectionService().getSelection();
            Object firstElement = selection.getFirstElement();
            if (firstElement instanceof IAdaptable)
            {
                IProject project = (IProject)((IAdaptable)firstElement).getAdapter(IProject.class);
                IPath path = project.getFullPath();
                System.out.println(path);
            }
        }
    

提交回复
热议问题