Java 如何在单独视图中创建新控制台

Java 如何在单独视图中创建新控制台,java,eclipse-plugin,Java,Eclipse Plugin,我使用以下代码创建了一个新的控制台 this.console = new IOConsole(name, null); IConsole[] consoles = new IConsole[1]; consoles[0] = this.console ; ConsolePlugin.getDefault().getConsoleManager() .addConsoles(consoles); IOConsoleOutputStream consoleStream

我使用以下代码创建了一个新的控制台

this.console = new IOConsole(name, null);
IConsole[] consoles = new IConsole[1];
consoles[0] = this.console ;
ConsolePlugin.getDefault().getConsoleManager()
                .addConsoles(consoles);
IOConsoleOutputStream consoleStream = this.console.newOutputStream();
consoleStream.write("Printing in console..");
public void createPartControl(Composite parent) {
  IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
    .getActivePage();
  IViewReference ref = page.findViewReference(IConsoleConstants.ID_CONSOLE_VIEW);
  IOConsole  console = createConsole(); // here create new console

  // this will ad console page to corresponding view                
        IPageBookViewPage pageBook = targetConsole.createPage(this);
        try {
            pageBook.init(new PageSite((IViewSite) ref.getView(true).getSite()));
        } catch (PartInitException e) {
            e.printStackTrace();
        }
        pageBook.createControl(parent);

}
我已经创建了3个与上面相同的新控制台

但实际上,我不想将我的新控制台页面添加到现有控制台中。 我想创建新的控制台视图,它应该显示这些控制台消息。 如何获得单独的控制台视图,而不是添加现有的控制台管理器。 因为我想分离我自己的一个控制台视图,而不是其他控制台

是否可以创建新视图并将一个控制台连接到该视图。
有人能帮我弄到这个吗。

过去两天一直在为这个问题苦苦挣扎。无论如何,我自己找到了解决办法。 仍然存在一些问题。 我想分享我得到的

我刚刚创建了一个新的视图。这个视图类应该实现IConsoleView,当然,扩展了IViewPart

在createPatrControl中,我添加了以下代码

this.console = new IOConsole(name, null);
IConsole[] consoles = new IConsole[1];
consoles[0] = this.console ;
ConsolePlugin.getDefault().getConsoleManager()
                .addConsoles(consoles);
IOConsoleOutputStream consoleStream = this.console.newOutputStream();
consoleStream.write("Printing in console..");
public void createPartControl(Composite parent) {
  IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
    .getActivePage();
  IViewReference ref = page.findViewReference(IConsoleConstants.ID_CONSOLE_VIEW);
  IOConsole  console = createConsole(); // here create new console

  // this will ad console page to corresponding view                
        IPageBookViewPage pageBook = targetConsole.createPage(this);
        try {
            pageBook.init(new PageSite((IViewSite) ref.getView(true).getSite()));
        } catch (PartInitException e) {
            e.printStackTrace();
        }
        pageBook.createControl(parent);

}
但我认为,这里遗漏了一些东西

实际上,我希望在视图类之外完成此操作。 在创建控制台之后,我希望通过编程创建新视图并添加如下内容:

// here that new view should be get and passed into createPage()
PageBookViewPage pageBook = targetConsole.createPage(IConsoleView);

在过去的两天里一直在努力解决这个问题。无论如何,我自己找到了解决办法。 仍然存在一些问题。 我想分享我得到的

我刚刚创建了一个新的视图。这个视图类应该实现IConsoleView,当然,扩展了IViewPart

在createPatrControl中,我添加了以下代码

this.console = new IOConsole(name, null);
IConsole[] consoles = new IConsole[1];
consoles[0] = this.console ;
ConsolePlugin.getDefault().getConsoleManager()
                .addConsoles(consoles);
IOConsoleOutputStream consoleStream = this.console.newOutputStream();
consoleStream.write("Printing in console..");
public void createPartControl(Composite parent) {
  IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
    .getActivePage();
  IViewReference ref = page.findViewReference(IConsoleConstants.ID_CONSOLE_VIEW);
  IOConsole  console = createConsole(); // here create new console

  // this will ad console page to corresponding view                
        IPageBookViewPage pageBook = targetConsole.createPage(this);
        try {
            pageBook.init(new PageSite((IViewSite) ref.getView(true).getSite()));
        } catch (PartInitException e) {
            e.printStackTrace();
        }
        pageBook.createControl(parent);

}
但我认为,这里遗漏了一些东西

实际上,我希望在视图类之外完成此操作。 在创建控制台之后,我希望通过编程创建新视图并添加如下内容:

// here that new view should be get and passed into createPage()
PageBookViewPage pageBook = targetConsole.createPage(IConsoleView);