3

I have developed an eclipse plugin in xtext and I need to write some messages in console. To do that, I have seen this site http://wiki.eclipse.org/FAQ_How_do_I_write_to_the_console_from_a_plug-in%3F and then I have implemented this code:

private static MessageConsole findConsole(String name) {

    if (ConsolePlugin.getDefault() == null)
        return null;
    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())) {
            conMan.showConsoleView(existing[i]);
            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;
}

public MessageConsoleStream getMessageStream() {
    MessageConsole myConsole = findConsole("console");
    if (myConsole != null) {

        IWorkbench wb = PlatformUI.getWorkbench();
        IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
        IWorkbenchPage page = win.getActivePage();
        String id = IConsoleConstants.ID_CONSOLE_VIEW;
        IConsoleView view;
        try {

            view = (IConsoleView) page.showView(id);
            view.display(myConsole);

            return myConsole.newMessageStream();
        } catch (PartInitException e) {
            e.printStackTrace();
        }
    }
    return null;
}

I have added org.eclipse.ui.console to plugin.xml > dependencies > required plugins.

When I want to print some message: MessageConsoleStream out = getMessageStream(); out.println(...);

And it is working. But I need a "terminate button" in my console and it seems that this code isn't enough. How can I do that? Thanks.

4

1 回答 1

1

这与控制台完全无关。您想创建一个viewContribution,它只是将一个按钮添加到现有视图的工具栏区域。在 stackoverflow 上也有一个例子。或者您可能想查阅关于该主题的 Eclipse 帮助

于 2013-04-23T17:56:42.203 回答