Toggle the view of the Console in a RCP application

被刻印的时光 ゝ 提交于 2019-12-12 02:50:02

问题


I am developing a RCPP application which displays a Console. For the moment when I close the Console I cannot open it again unless I restart the application.

So I added a new menu item to show and hide the console as an extension point and created a handler for it. I can check whether the console exists but the problem is that when it closes it is actually hidden and not disposed of.

<pre> 
private Console() {
            super("", null);
            setWaterMarks(-1, -1);

            infoStream = newOutputStream();
            errorStream = newOutputStream();
            warnStream = newOutputStream();

            infoColor = new Color(DioAction.getDisplay(), new RGB(0, 0, 0));
            infoStream.setColor(infoColor);
            warnColor = new Color(DioAction.getDisplay(), new RGB(255, 128, 0));
            warnStream.setColor(warnColor);
            errorColor = new Color(DioAction.getDisplay(), new RGB(255, 0, 0));
            errorStream.setColor(errorColor);
        }
        public static Console getDefault() {
            if (instance == null) {
                instance = new Console();
                IConsoleManager manager = ConsolePlugin.getDefault().getConsoleManager();
                IConsole[] existing = manager.getConsoles();
                boolean exists = false;
                for (int i = 0; i < existing.length; i++) {
                    if (instance == existing[i])
                        exists = true;
                }
                if (!exists)
                    manager.addConsoles(new IConsole[] { instance });
                manager.showConsoleView(instance);
            }
            return instance;
        }

        public void info(String message) {
            try {
                infoStream.write(message);
                infoStream.write("\n");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
</pre>

The console is added when I call this method:

@Override
    public void postStartup() {
        super.postStartup();
        Console.getDefault().info("Hello");
    }

from the ApplicationWorkbenchAdvisor.

My question is how should I detect whether the console has been closed/hidden and show it when I select the menu item?


回答1:


See this previous answer which is an example of how to show a view.

Toggle the view of the Console in a RCP application



来源:https://stackoverflow.com/questions/9194586/toggle-the-view-of-the-console-in-a-rcp-application

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