【问题标题】:How to display separate console on a custom view?如何在自定义视图上显示单独的控制台?
【发布时间】:2014-01-16 16:06:11
【问题描述】:

我已经创建了我的自定义视图,并在TextConsoleViewer 查看器的帮助下将控制台放在上面。

它出现在我的视图中,但它也出现在主控制台视图中,它也出现在布局中。

如何避免这种情况?如何仅将控制台放在我的视图上,或者可能在控制台视图上隐藏不需要的控制台?

视图部分代码:

public class ChatView extends ViewPart {

    public static final String ID = "com.scisbo.eclipse.programw.ChatView";

    private ShellMod shell;

    private TextConsoleViewer textConsoleViewer;

    @Override
    public void createPartControl(Composite parent) {

        ConsoleFinderService consoleFinderService = (ConsoleFinderService) PlatformUI.getWorkbench().getService(ConsoleFinderService.class);
        MessageConsole console = consoleFinderService.findConsole("Chat");

        textConsoleViewer = new TextConsoleViewer(parent, console);

        shell = new ShellMod(
                new PrintStream(console.newMessageStream()), 
                new PrintStream(console.newMessageStream())
                );

    }

    @Override
    public void setFocus() {
        textConsoleViewer.getControl().setFocus();
    }

}

控制台查找服务的代码

public class ConsoleFinderService {

    public MessageConsole findConsole(String name) {
        ConsolePlugin plugin = ConsolePlugin.getDefault();
        IConsoleManager conMan = plugin.getConsoleManager();
        IConsole[] existing = conMan.getConsoles();
        for (int i = 0; i < existing.length; i++)
            if (name.equals(existing[i].getName()))
                return (MessageConsole) existing[i];
        // no console found, so create a new one
        MessageConsole myConsole = new MessageConsole(name, null);
        conMan.addConsoles(new IConsole[] { myConsole });
        return myConsole;
    }
}

【问题讨论】:

  • 添加屏幕截图以便更好地理解

标签: java eclipse eclipse-plugin console eclipse-rcp


【解决方案1】:

不要将控制台添加到控制台管理器。 (如果您确实需要一个经理,您可能需要实施一个单独的经理。)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-17
    • 2018-11-21
    • 2020-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-19
    相关资源
    最近更新 更多