Class EclipseConsole


  • public class EclipseConsole
    extends java.lang.Object
    Retrieve the MessageConsole of the currently running Elcipse-instance.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String CONSOLE_NAME  
      static EclipseConsole INSTANCE
      Stores the singleton instance of the Eclipse console.
      private org.eclipse.ui.console.MessageConsole msgConsole
      The MessageConsole of the currently running Eclipse-instance.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private EclipseConsole()
      The private constructor of this class.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clearConsole()
      Clears the console.
      boolean displayConsole()
      Tries to show the console inside the GUI.
      private org.eclipse.ui.IWorkbenchPage getActiveWorkbenchPage()
      Returns the currently active page for this workbench window.
      private org.eclipse.ui.console.MessageConsole getMessageConsole​(java.lang.String consoleName)
      This method searches for and returns a specific instance of the MessageConsole of the currently running Eclipse-instance by name.
      boolean writeToConsole​(java.lang.String text, boolean lineBreak)
      Displays the specified text at the console, followed by a line separator string.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • INSTANCE

        public static final EclipseConsole INSTANCE
        Stores the singleton instance of the Eclipse console.
      • msgConsole

        private org.eclipse.ui.console.MessageConsole msgConsole
        The MessageConsole of the currently running Eclipse-instance.
    • Constructor Detail

      • EclipseConsole

        private EclipseConsole()
        The private constructor of this class. This class is a singleton.
    • Method Detail

      • getMessageConsole

        private org.eclipse.ui.console.MessageConsole getMessageConsole​(java.lang.String consoleName)
        This method searches for and returns a specific instance of the MessageConsole of the currently running Eclipse-instance by name. If the console with the given name does not exist, a new console-instance will be created and returned. Please note that this code is taken from: http://wiki.eclipse.org/FAQ_How_do_I_write_to_the_console_from_a_plug-in%3F
        Parameters:
        consoleName - the name of the MessageConsole-instance that should be returned.
        Returns:
        the MessageConsole with the given name or a new instance of the MessageConsole if the instance with the given name does not exist.
      • writeToConsole

        public boolean writeToConsole​(java.lang.String text,
                                      boolean lineBreak)
        Displays the specified text at the console, followed by a line separator string.
        Parameters:
        text - message to display
        lineBreak - true if a linebreak shall be inserted after the message.
        Returns:
        true if the message was successfully displayed inside the console.
      • clearConsole

        public void clearConsole()
        Clears the console.

        Since a console may or may not support direct manipulation of its document's contents, this method should be called to clear a text console's document. The default implementation sets this console's document content to the empty string directly. Subclasses should override as required.

      • displayConsole

        public boolean displayConsole()
        Tries to show the console inside the GUI.
        Returns:
        true if the console could be displayed inside the GUI.
      • getActiveWorkbenchPage

        private org.eclipse.ui.IWorkbenchPage getActiveWorkbenchPage()
        Returns the currently active page for this workbench window.
        Returns:
        the active page, or null if none