【问题标题】:How to programmatically define the project types that the project explorer in a WizardNewFileCreationPage will display如何以编程方式定义 WizardNewFileCreationPage 中的项目浏览器将显示的项目类型
【发布时间】:2016-06-13 14:49:39
【问题描述】:

我正在开发一个实现导入文件向导的 Eclipse 插件项目,该向导专为与自定义项目类型相关的文件而设计。向导的页面之一是WizardNewFileCreationPage 页面,其中会自动显示项目资源管理器(据我所知)。此项目资源管理器显示工作区中可用的所有项目。但是,正如我所说,由于向导处理的文件对一种特定的项目类型很有用,我想限制资源管理器并仅显示该自定义类型的项目。

我知道如何选择自定义类型的项目:

  List<IProject> projectList = new LinkedList<IProject>();
  try {
     IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
     IProject[] projects = workspaceRoot.getProjects();
     for(int i = 0; i < projects.length; i++) {
        IProject project = projects[i];
        if(project.hasNature("com.example.www.myNature")) {
           projectList.add(project);
        }
     }
  }
  catch(CoreException ce) {
     ce.printStackTrace();
  }

在此链接中找到:Get a list of all java projects open in an Eclipse workspace

我假设WizardNewFileCreationPage 类在幕后包括TreeViewer 或类似的东西。无论如何,如何在此向导页面中过滤项目资源管理器的内容? 我看了以下问题:How to programmatically change the selection within package explorer,但在我的情况下,activePart 变量的类型是

org.eclipse.ui.navigator.resources.ProjectExplorer

没有getTreeViewer() 方法。它有一个createPartControl() 方法:

public void createPartControl(Composite aParent);

这对我想要的有用吗?还是使用扩展点的情况?

提前感谢您的回答。

【问题讨论】:

    标签: eclipse wizard project-explorer


    【解决方案1】:

    没有办法做到这一点。

    虽然WizardNewFileCreationPage 中显示的树看起来类似于项目资源管理器,但它并不是基于该代码。

    用于显示树的代码是org.eclipse.ui.internal.ide.misc.ContainerSelectionGroup,它本身包含在org.eclipse.ui.internal.ide.misc.ResourceAndContainerGroup 中。这些类不支持太多自定义,并且在任何情况下都无法在WizardNewFileCreationPage 之外访问。

    【讨论】:

    • 谢谢格雷格,我很害怕这个。我会再等一会儿,但我怀疑我会接受你的回答。
    猜你喜欢
    • 2020-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-21
    • 1970-01-01
    • 1970-01-01
    • 2011-01-26
    • 1970-01-01
    相关资源
    最近更新 更多