3

我有一个创建新视图的插件。在我看来,我显示了有关项目中某些 Java 类的某些信息。我想让用户在我的视图中双击一个类,当他/她这样做时,我想打开该类以在编辑器中进行编辑。基本上类似于 Hierarchy View 所做的:它显示类树,当用户双击其中一个时,它会进入编辑器。如果我拥有的是类型的对象,我该怎么做IType

4

1 回答 1

0

我将根据您的要求展示一个高级实现。您必须执行以下步骤。

  • 首先,您必须分别Plugin.xml为扩展的类 viewPart以及editorPart视图和编辑器进行输入。
  • 对于层次结构视图,您必须在 ViewPart.
  • 在节点的双击监听器上,您必须打开编辑器。

要在编辑器中打开文件,请使用以下代码打开编辑器。

 if (fileToOpen.exists() && fileToOpen.isFile()) {
     String path = //Path for that to file to open;
     IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
     URI fromString = org.eclipse.core.runtime.URIUtil.fromString("file://" + path);
     try {
         IEditorPart openEditor = IDE.openEditor(page, fromString, Editor.ID, true);
         IEditorInput editorInput = openEditor.getEditorInput();
         //editorInput.
     } catch ( PartInitException e ) {
         //Put your exception handler here if you wish to.
     }
 }
于 2012-04-23T10:27:07.707 回答