how to open multiple consoleview with different input text

偶尔善良 提交于 2019-12-25 05:15:46

问题


i want to open multiple console view with different input text on single swt button click in eclipse rcp application Can anybody tell me about this ? Thank you.


回答1:


Add org.eclipse.ui.console as dependency and after that you can create different extensions.
Some more details about the implementation you can find on this page http://www.eclipsezone.com/eclipse/forums/t66777.html.

Here a simple implementation (source):

plugin.xml

<plugin>
    <extension point="org.eclipse.ui.console.consoleFactories">
        <consoleFactory label="ConsoleX" class="console.Factory">
        </consoleFactory>
    </extension>
</plugin>

class Factory

package console;

import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IConsoleFactory;
import org.eclipse.ui.console.IConsoleManager;
import org.eclipse.ui.console.MessageConsole;

public class Factory implements IConsoleFactory {

    private static MessageConsole _console;

    public void openConsole() {
        MessageConsole console = getConsole();
        if (console != null) {
            IConsoleManager manager =
            ConsolePlugin.getDefault().getConsoleManager();
            IConsole[] existing = manager.getConsoles();
            boolean exists = false;
            for (int i = 0; i < existing.length; i++) {
                if(console == existing[i])
                    exists = true;
            }
            if(! exists)
                manager.addConsoles(new IConsole[] {console});
            manager.showConsoleView(console);
        }

    }

    public static MessageConsole getConsole() {
        if (_console == null) {
            _console = new MessageConsole("ConsoleX",null);
        }
        return _console;
    }

}

Usage

Factory.getConsole().activate();
Factory.getConsole().newOutputStream().write("Hello world.".getBytes());


来源:https://stackoverflow.com/questions/10580516/how-to-open-multiple-consoleview-with-different-input-text

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!