简体   繁体   中英

How to display separate console on a custom view?

I have created my custom view and put console onto it with the help of TextConsoleViewer viewer.

It appeared on my view, but it also appeared on main console view, which is also present on layout.

How to avoid this? How to put console on my view only or, may be, it is possible to hide unneeded console on console view?

The code for view part:

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();
    }

}

the code for console finder service

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;
    }
}

Don't add the console to the console manager. (If you do need a manager, you might want to implement a separate one.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM