1

I'm opening a console using this code:

MessageConsole console=new MessageConsole("Console", null);  
ConsolePlugin.getDefault().getConsoleManager().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.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
marcolopes
  • 9,232
  • 14
  • 54
  • 65

1 Answers1

2

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:

  1. Add a new IConsolePageParticipant just like the one here
  2. Modify your plugin.xml to register your new class as shown here
Community
  • 1
  • 1
fmjrey
  • 1,141
  • 1
  • 10
  • 16
  • Thanks for your help. I have edited my question. Please take a look (i presume this is a BUG). – marcolopes Sep 09 '11 at 05:13
  • Weird. The method I suggested above for letting the user close a console works fine in my case. Here's an example that may help also: http://code.google.com/p/expresso-plugin/source/browse/trunk/src/expresso_plugin/editors/ExpressoDocumentProvider.java?spec=svn5&r=5 – fmjrey Sep 09 '11 at 08:50
  • In your example, the console VIEW is closed, or just cleared? Made some new tests, with an action calling the removeConsoles(...) and it does not close the view. – marcolopes Sep 10 '11 at 04:45
  • I edited my answer to clearly explain that closing the whole view is another story. There's no bug in removeConsoles. – fmjrey Sep 13 '11 at 14:47
  • Great info. Very detailed. Thanks a lot. – marcolopes Sep 14 '11 at 22:28