在 RCP 应用程序中,我想创建一个 Common Navigator Framework View ,仅从本地文件系统上的资源开始。
我已经在一个包含 org.eclipse.ui.ide 插件的项目中完成了这一任务。但是,这会创建一个过于复杂且不适合此应用程序的 UI。 (例如,它添加了大约 20 个首选项面板,其中一些与构建和版本控制相关。)
所以现在我尝试在没有 ~.ide 插件的情况下完成此操作 - 并且没有依赖于它的 org.eclipse.ui.navigator.resources 插件。
在 RCP 应用程序中,我已成功使用下面的代码在具有 ~navigator.viewer 扩展名的插件中创建了一个新的工作区项目(我认为),如下所示。但 CNF View 中什么也没有出现。
问题:
- 由于我排除了 org.eclipse.ui.navigator.resources 插件,我是否需要定义自己的内容提供程序?
- 是org.eclipse.ui.navigator.resources插件中的ResourceExtensionContentProvider类,用于实现内容绑定(bind)org.eclipse.ui.navigator.resourceContent ?
plugin.xml 摘录
<extension
point="org.eclipse.ui.navigator.viewer">
<viewerActionBinding
viewerId="com.mycompany.app.gen.workspace">
<includes>
<actionExtension pattern="org.eclipse.ui.navigator.resources.*" />
</includes>
</viewerActionBinding>
<viewerContentBinding
viewerId="com.dnastar.app.gen.workspace">
<includes>
<contentExtension pattern="org.eclipse.ui.navigator.resourceContent" />
<contentExtension pattern="org.eclipse.ui.navigator.resources.filters.*"/>
<contentExtension pattern="org.eclipse.ui.navigator.resources.linkHelper"/>
<contentExtension pattern="org.eclipse.ui.navigator.resources.workingSets"/>
</includes>
</viewerContentBinding>
</extension>
用于创建新项目的代码(为了完整性而包含在内):
Path path = new Path( sPath );
File filePath = new File( sPath );
String fileBaseName = filePath.getName();
String projectName = fileBaseName; // For now
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProjectDescription projDescr = workspace.newProjectDescription( projectName );
projDescr.setLocation( path );
IWorkspaceRoot root = workspace.getRoot();
IProject project = root.getProject( projectName );
try {
project.create( projDescr, null );
if ( ! project.isOpen() ) {
project.open( null );
}
} catch (CoreException e) {
MessageDialog.openError( Display.getCurrent().getActiveShell(),
"New Project Error", "Could not create new project." + "\n[" + e + "]");
}
最佳答案
您需要扩展它,然后重写 getInitialInput() 方法,而不是使用 CommonNavigator 类。还有返回IWorkspaceRoot
关于java - Eclipse RCP : Does CNF without IDE plug-in require custom ContentProvider?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5654420/