Eclipse: How to CLOSE a console View?
I'm opening a console using this code:
MessageConsole console=new MessageConsole("Console", null);
ConsolePlugin.getDefault().get开发者_如何学CConsoleManager().addConsoles(new IConsole[]{console});
ConsolePlugin.getDefault().getConsoleManager().showConsoleView(console);
My question is: How can i CLOSE the console View??
The problem: I was expecting a ConsolePlugin.getDefault().getConsoleManager().closeConsoleView(...), that does not exist. Inspecting further, i found:
void org.eclipse.ui.console.IConsoleManager.removeConsoles(IConsole[] consoles)
Removes the given consoles from the console manager. If the consoles are being displayed in any console views, the associated pages will be removed and disposed.
Well, this is not true. This is the exact code present in http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fui%2Fconsole%2Factions%2FCloseConsoleAction.html, but it does NOT close the console view! (to be exact, in this doc it only says: Removes a console from the console manager)
Thanks.
Do you really need to close the whole console view or just your console?
If you need to close the whole view this is another story because it can be shown on multiple perspectives. As explained in this other question, you need to find all instances of the view and hide each one, and then the view will be disposed completely. This discussion thread even gives some code to do that.
If you need to close only the console page and not the whole view, the removeConsoles method should do it as you pointed out, and indeed it won't close the view, this is not a bug. This svn commit description may help you implement a close button on your own console. It's rather simple to make such change:
- Add a new IConsolePageParticipant just like the one here
- Modify your plugin.xml to register your new class as shown here
精彩评论