1. <legend id='lXe4t'><style id='lXe4t'><dir id='lXe4t'><q id='lXe4t'></q></dir></style></legend>
  2. <i id='lXe4t'><tr id='lXe4t'><dt id='lXe4t'><q id='lXe4t'><span id='lXe4t'><b id='lXe4t'><form id='lXe4t'><ins id='lXe4t'></ins><ul id='lXe4t'></ul><sub id='lXe4t'></sub></form><legend id='lXe4t'></legend><bdo id='lXe4t'><pre id='lXe4t'><center id='lXe4t'></center></pre></bdo></b><th id='lXe4t'></th></span></q></dt></tr></i><div id='lXe4t'><tfoot id='lXe4t'></tfoot><dl id='lXe4t'><fieldset id='lXe4t'></fieldset></dl></div>
      <bdo id='lXe4t'></bdo><ul id='lXe4t'></ul>

  3. <tfoot id='lXe4t'></tfoot>

    1. <small id='lXe4t'></small><noframes id='lXe4t'>

    2. Eclipse Plugin:如何获取当前选中项目的路径

      Eclipse Plugin: how to get the path to the currently selected project(Eclipse Plugin:如何获取当前选中项目的路径)

        <tfoot id='GANrR'></tfoot>

        <small id='GANrR'></small><noframes id='GANrR'>

        • <bdo id='GANrR'></bdo><ul id='GANrR'></ul>
            <tbody id='GANrR'></tbody>

        • <i id='GANrR'><tr id='GANrR'><dt id='GANrR'><q id='GANrR'><span id='GANrR'><b id='GANrR'><form id='GANrR'><ins id='GANrR'></ins><ul id='GANrR'></ul><sub id='GANrR'></sub></form><legend id='GANrR'></legend><bdo id='GANrR'><pre id='GANrR'><center id='GANrR'></center></pre></bdo></b><th id='GANrR'></th></span></q></dt></tr></i><div id='GANrR'><tfoot id='GANrR'></tfoot><dl id='GANrR'><fieldset id='GANrR'></fieldset></dl></div>
                <legend id='GANrR'><style id='GANrR'><dir id='GANrR'><q id='GANrR'></q></dir></style></legend>
              • 本文介绍了Eclipse Plugin:如何获取当前选中项目的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在编写一个 Eclipse 插件,它将在 Java 项目的上下文菜单中显示一个菜单项.我将plugin.xml写成如下:

                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:

                <plugin>
                   <extension
                         point="org.eclipse.ui.menus">
                      <menuContribution
                            locationURI="popup:org.eclipse.jdt.ui.PackageExplorer">
                         <dynamic
                               class="uk.co.dajohnston.plugin.classpathswitcher.menu.MenuContribution"
                               id="uk.co.dajohnston.plugin.classpathSwitcher.switchMenuContribution">
                            <visibleWhen>
                               <with
                                     variable="activeMenuSelection">
                                  <iterate>
                                     <adapt
                                           type="org.eclipse.jdt.core.IJavaProject">
                                     </adapt>
                                  </iterate>
                                  <count
                                        value="1">
                                  </count>
                               </with>
                            </visibleWhen>
                         </dynamic>
                      </menuContribution>
                   </extension>
                
                </plugin>
                

                所以我现在正在尝试编写扩展 CompoundContributionItemMenuContribution 类,以便我可以创建动态菜单,并且该菜单的内容将基于Java 项目的根目录中存在的一组文件.但我一直试图从 getContributionItems 方法中获取根目录的路径.

                So I am now trying to write the MenuContribution class which extends CompoundContributionItem so that I can create a dynamic menu and the contents of this menu are going to be based on a set of files that exist in the Java Project's root directory. But I am stuck trying to get the path to the root directory from within the getContributionItems method.

                基于 plugin.xml 文件,我可以保证只有在选择了单个 Java 项目时才会调用该方法,所以我需要做的就是获取当前选择,然后获取其绝对路径.有任何想法吗?或者有更好的方法吗?

                Based on the plugin.xml file I can be guarenteed that the method will only be called if a single Java Project is selected, so all I need to do is get the current selection and then get its absolute path. Any ideas? Or is there a better way to do this?

                推荐答案

                这应该让你更接近(如果不能为你完全解决它;))

                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);
                        }
                    }
                

                这篇关于Eclipse Plugin:如何获取当前选中项目的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
              • <i id='vzX9x'><tr id='vzX9x'><dt id='vzX9x'><q id='vzX9x'><span id='vzX9x'><b id='vzX9x'><form id='vzX9x'><ins id='vzX9x'></ins><ul id='vzX9x'></ul><sub id='vzX9x'></sub></form><legend id='vzX9x'></legend><bdo id='vzX9x'><pre id='vzX9x'><center id='vzX9x'></center></pre></bdo></b><th id='vzX9x'></th></span></q></dt></tr></i><div id='vzX9x'><tfoot id='vzX9x'></tfoot><dl id='vzX9x'><fieldset id='vzX9x'></fieldset></dl></div>

                <small id='vzX9x'></small><noframes id='vzX9x'>

                    <tbody id='vzX9x'></tbody>
                    <legend id='vzX9x'><style id='vzX9x'><dir id='vzX9x'><q id='vzX9x'></q></dir></style></legend>

                      <tfoot id='vzX9x'></tfoot>
                      • <bdo id='vzX9x'></bdo><ul id='vzX9x'></ul>