/*
 * $RCSfile: Console.java,v $
 * $Date: 2006/01/26 14:52:19 $
 * $Revision: 1.2 $
 * $Author: andreys $
 */
 
/*
 * Copyright (c) 2002-2003 IST-2004-2006-511731 ModelWare - ModelBus.
 * All rights reserved.
 *
 * This software is published under the terms of the ModelBus Software License
 * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * A copy of ModelBus Software License is provided with this distribution in
 * doc/LICENSE.txt file.
 */
 
/*
 * Console.java Add description 
 * 
 * @author Andrey Sadovykh (LIP6)
 * @version $Revision: 1.2 $ $Date: 2006/01/26 14:52:19 $
 * @see Add references
 *
 * TODO Add description
 * TODO Add references
 */
package org.eclipse.mddi.modelbus.adapter.test.plugin;

import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IConsoleManager;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;

public class Console{
private static Console instance=null;
public static final String NAME = "ModelBus Console";
private static IConsoleManager consoleManager;
public  MessageConsole console;
private MessageConsoleStream stream;



private Console(){
  console = new MessageConsole(NAME, null);
  consoleManager.addConsoles(new IConsole[] { console });
  stream = console.newMessageStream();
}


public static Console instance(){
  if(instance == null){
      consoleManager = ConsolePlugin.getDefault().getConsoleManager();
      instance = new Console();
      instance.show();
/*      
      Display.getDefault().asyncExec(new Runnable(){
          public void run(){
              consoleManager = ConsolePlugin.getDefault().getConsoleManager();
              instance = new Console();
              instance.show();
              System.out.println("Int instance"+instance);
              }
          });
*/      
  }
 
  return instance;
}


public void show(){
  Display.getDefault().asyncExec(new Runnable(){
    public void run(){
      consoleManager.showConsoleView(console);
    }
  });
}


public void println(final String message){
  Display.getDefault().asyncExec(new Runnable(){
    public void run(){
      stream.println(message);
    }
  });
}
}
  
  