org.eclipse.ui.console.MessageConsole Java Examples

The following examples show how to use org.eclipse.ui.console.MessageConsole. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: YangToSkelxml.java    From yang-design-studio with Eclipse Public License 1.0 6 votes vote down vote up
private static MessageConsole findConsole(String name) {//Find and return console, otherwise make one

   if (ConsolePlugin.getDefault() == null)
    	return null;
   ConsolePlugin plugin = ConsolePlugin.getDefault();
   IConsoleManager YangConsole = plugin.getConsoleManager();
   IConsole[] existing = YangConsole.getConsoles();
   for (int i = 0; i < existing.length; i++)
      if (name.equals(existing[i].getName())) {
      	YangConsole.showConsoleView(existing[i]);
      	return (MessageConsole) existing[i];
      }
   MessageConsole myConsole = new MessageConsole(name, null);
   YangConsole.addConsoles(new IConsole[] { myConsole });
   return myConsole;
}
 
Example #2
Source File: YangToUML.java    From yang-design-studio with Eclipse Public License 1.0 6 votes vote down vote up
private static MessageConsole findConsole(String name) {//Find and return console, otherwise make one

          			if (ConsolePlugin.getDefault() == null)
          				return null;
          			ConsolePlugin plugin = ConsolePlugin.getDefault();
          			IConsoleManager YangConsole = plugin.getConsoleManager();
          			IConsole[] existing = YangConsole.getConsoles();
          			for (int i = 0; i < existing.length; i++)
          				if (name.equals(existing[i].getName())) {
          					YangConsole.showConsoleView(existing[i]);
          					return (MessageConsole) existing[i];
          				}
          			MessageConsole myConsole = new MessageConsole(name, null);
          			YangConsole.addConsoles(new IConsole[] { myConsole });
          			return myConsole;
          		}
 
Example #3
Source File: YangToYin.java    From yang-design-studio with Eclipse Public License 1.0 6 votes vote down vote up
private static MessageConsole findConsole(String name) {//Find and return console, otherwise make one

            			if (ConsolePlugin.getDefault() == null)
            				return null;
            			ConsolePlugin plugin = ConsolePlugin.getDefault();
            			IConsoleManager YangConsole = plugin.getConsoleManager();
            			IConsole[] existing = YangConsole.getConsoles();
            			for (int i = 0; i < existing.length; i++)
            				if (name.equals(existing[i].getName())) {
            					YangConsole.showConsoleView(existing[i]);
            					return (MessageConsole) existing[i];
            				}
            			MessageConsole myConsole = new MessageConsole(name, null);
            			YangConsole.addConsoles(new IConsole[] { myConsole });
            			return myConsole;
            		}
 
Example #4
Source File: YangToJSTREE.java    From yang-design-studio with Eclipse Public License 1.0 6 votes vote down vote up
private static MessageConsole findConsole(String name) {//Find and return console, otherwise make one

   if (ConsolePlugin.getDefault() == null)
    	return null;
   ConsolePlugin plugin = ConsolePlugin.getDefault();
   IConsoleManager YangConsole = plugin.getConsoleManager();
   IConsole[] existing = YangConsole.getConsoles();
   for (int i = 0; i < existing.length; i++)
      if (name.equals(existing[i].getName())) {
      	YangConsole.showConsoleView(existing[i]);
      	return (MessageConsole) existing[i];
      }
   // no console found, so create a new one
   MessageConsole myConsole = new MessageConsole(name, null);
   YangConsole.addConsoles(new IConsole[] { myConsole });
   return myConsole;
}
 
Example #5
Source File: YangToXslt.java    From yang-design-studio with Eclipse Public License 1.0 6 votes vote down vote up
private static MessageConsole findConsole(String name) {//Find and return console, otherwise make one

   if (ConsolePlugin.getDefault() == null)
    	return null;
   ConsolePlugin plugin = ConsolePlugin.getDefault();
   IConsoleManager YangConsole = plugin.getConsoleManager();
   IConsole[] existing = YangConsole.getConsoles();
   for (int i = 0; i < existing.length; i++)
      if (name.equals(existing[i].getName())) {
      	YangConsole.showConsoleView(existing[i]);
      	return (MessageConsole) existing[i];
      }
   MessageConsole myConsole = new MessageConsole(name, null);
   YangConsole.addConsoles(new IConsole[] { myConsole });
   return myConsole;
}
 
Example #6
Source File: YangToXSD.java    From yang-design-studio with Eclipse Public License 1.0 6 votes vote down vote up
private static MessageConsole findConsole(String name) {//Find and return console, otherwise make one

   if (ConsolePlugin.getDefault() == null)
    	return null;
   ConsolePlugin plugin = ConsolePlugin.getDefault();
   IConsoleManager YangConsole = plugin.getConsoleManager();
   IConsole[] existing = YangConsole.getConsoles();
   for (int i = 0; i < existing.length; i++)
      if (name.equals(existing[i].getName())) {
      	YangConsole.showConsoleView(existing[i]);
      	return (MessageConsole) existing[i];
      }
   MessageConsole myConsole = new MessageConsole(name, null);
   YangConsole.addConsoles(new IConsole[] { myConsole });
   return myConsole;
}
 
Example #7
Source File: RunSelectedSequenceDiagramHandler.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Searches for a console with the name "Sequence Diagram Console" and
 * returns it if it was found. If the console was not found creates a new
 * one and returns it.
 */
private MessageConsole findConsole() {
	final String seqDiagConsoleName = "Sequence Diagram Console";
	ConsolePlugin plugin = ConsolePlugin.getDefault();
	IConsoleManager conMan = plugin.getConsoleManager();
	IConsole[] existing = conMan.getConsoles();
	Optional<IConsole> seqConsole = Stream.of(existing)
			.filter(console -> console.getName().equals(seqDiagConsoleName)).findFirst();

	if (seqConsole.isPresent()) {
		return (MessageConsole) seqConsole.get();
	} else {
		MessageConsole newSeqConsole = new MessageConsole(seqDiagConsoleName, null);
		conMan.addConsoles(new IConsole[] { newSeqConsole });
		return newSeqConsole;
	}
}
 
Example #8
Source File: TLAPMConsoleFactory.java    From tlaplus with MIT License 6 votes vote down vote up
/**
 * Finds the console with a given name.
 * 
 * @param name, name of the console
 * @return
 */
private static MessageConsole findConsole(String name)
{
    if (name == null)
    {
        throw new IllegalArgumentException("Console name must be not null");
    }
    IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager();

    IConsole[] existing = consoleManager.getConsoles();
    // try to find existing
    for (int i = 0; i < existing.length; i++)
    {
        if (name.equals(existing[i].getName()))
        {
            return (MessageConsole) existing[i];
        }
    }

    // no console found, create a new one
    MessageConsole myConsole = new MessageConsole(name, null);
    consoleManager.addConsoles(new IConsole[] { myConsole });
    return myConsole;
}
 
Example #9
Source File: ConsoleOutputStreamProvider.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public OutputStream getOutputStream(final OutputStreamType type, OutputRedirection redirect) {
	if (!PlatformUI.isWorkbenchRunning()) {
		return DEFAULT.getOutputStream(type, redirect);
	}
	final MessageConsole console = consoleSupplier.get();
	boolean silent = redirect == OutputRedirection.SUPPRESS;
	if (!silent) {
		console.activate();
	}
	ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { console });
	final MessageConsoleStream stream = console.newMessageStream();
	getDisplay().asyncExec(() -> {
		stream.setColor(toColor(type));
		showConsoleView(silent);
	});
	return stream;
}
 
Example #10
Source File: MessageConsoles.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public static IOConsoleOutputStream getConsoleOutputStream(String name, String iconPath) {
    synchronized (lock) {
        IOConsoleOutputStream outputStream = consoleOutputs.get(name);
        if (outputStream == null) {
            MessageConsole console = getConsole(name, iconPath);

            HashMap<IOConsoleOutputStream, String> themeConsoleStreamToColor = new HashMap<IOConsoleOutputStream, String>();
            outputStream = console.newOutputStream();
            themeConsoleStreamToColor.put(outputStream, "console.output");
            console.setAttribute("themeConsoleStreamToColor", themeConsoleStreamToColor);
            ConsoleColorCache.getDefault().keepConsoleColorsSynched(console);
            consoles.put(name, console);
            consoleOutputs.put(name, outputStream);
        }
        return outputStream;
    }
}
 
Example #11
Source File: YangToTree.java    From yang-design-studio with Eclipse Public License 1.0 6 votes vote down vote up
private static MessageConsole findConsole(String name) {//Find and return console, otherwise make one

          			if (ConsolePlugin.getDefault() == null)
          				return null;
          			ConsolePlugin plugin = ConsolePlugin.getDefault();
          			IConsoleManager YangConsole = plugin.getConsoleManager();
          			IConsole[] existing = YangConsole.getConsoles();
          			for (int i = 0; i < existing.length; i++)
          				if (name.equals(existing[i].getName())) {
          					YangConsole.showConsoleView(existing[i]);
          					return (MessageConsole) existing[i];
          				}
          			MessageConsole myConsole = new MessageConsole(name, null);
          			YangConsole.addConsoles(new IConsole[] { myConsole });
          			return myConsole;
          		}
 
Example #12
Source File: YangToDsdl.java    From yang-design-studio with Eclipse Public License 1.0 6 votes vote down vote up
private static MessageConsole findConsole(String name) {//Find and return console, otherwise make one

   if (ConsolePlugin.getDefault() == null)
    	return null;
   ConsolePlugin plugin = ConsolePlugin.getDefault();
   IConsoleManager YangConsole = plugin.getConsoleManager();
   IConsole[] existing = YangConsole.getConsoles();
   for (int i = 0; i < existing.length; i++)
      if (name.equals(existing[i].getName())) {
      	YangConsole.showConsoleView(existing[i]);
      	return (MessageConsole) existing[i];
      }
   // no console found, so create a new one
   MessageConsole myConsole = new MessageConsole(name, null);
   YangConsole.addConsoles(new IConsole[] { myConsole });
   return myConsole;
}
 
Example #13
Source File: ConsoleDisplayMgr.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns console associated with given name. If console with given name doesn't exists will create new one.
 */
public static XpectConsole getOrCreate(String name) {
	XpectConsole console = map.get(name);
	if (console != null) {
		return console;
	} else {
		MessageConsole lkpMessageConsole = findMessageConsole(name);
		if (lkpMessageConsole == null) {
			console = new XpectConsole(createMessageConsoleStream(name));
		} else {
			console = new XpectConsole(lkpMessageConsole);
		}
		map.put(name, console);
	}

	return console;
}
 
Example #14
Source File: YangToPNG.java    From yang-design-studio with Eclipse Public License 1.0 6 votes vote down vote up
private static MessageConsole findConsole(String name) {//Find and return console, otherwise make one

		if (ConsolePlugin.getDefault() == null)
			return null;
		ConsolePlugin plugin = ConsolePlugin.getDefault();
		IConsoleManager YangConsole = plugin.getConsoleManager();
		IConsole[] existing = YangConsole.getConsoles();
		for (int i = 0; i < existing.length; i++)
			if (name.equals(existing[i].getName())) {
				YangConsole.showConsoleView(existing[i]);
				return (MessageConsole) existing[i];
			}
		MessageConsole myConsole = new MessageConsole(name, null);
		YangConsole.addConsoles(new IConsole[] { myConsole });
		return myConsole;
	}
 
Example #15
Source File: Console.java    From cppcheclipse with Apache License 2.0 5 votes vote down vote up
private static MessageConsole findMessageConsole(String name) {
	ConsolePlugin plugin = ConsolePlugin.getDefault();
	IConsoleManager conMan = plugin.getConsoleManager();
	IConsole[] existing = conMan.getConsoles();
	for (int i = 0; i < existing.length; i++)
		if (name.equals(existing[i].getName()))
			return (MessageConsole) existing[i];
	// no console found, so create a new one
	MessageConsole myConsole = new MessageConsole(name, null);
	conMan.addConsoles(new IConsole[] { myConsole });
	return myConsole;
}
 
Example #16
Source File: EclipseConsoleLogger.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected MessageConsole getConsole() {
	IConsoleManager consoleManager = getConsoleManager();
	IConsole[] existing = consoleManager.getConsoles();
	for (int i = 0; i < existing.length; i++) {
		if (SCT_GENERATOR_CONSOLE.equals(existing[i].getName())) {
			return (MessageConsole) existing[i];
		}
	}
	MessageConsole console = new MessageConsole(SCT_GENERATOR_CONSOLE, null);
	consoleManager.addConsoles(new IConsole[] { console });
	return console;
}
 
Example #17
Source File: TLAPMConsoleFactory.java    From tlaplus with MIT License 5 votes vote down vote up
/**
 * Returns a handle on the console for
 * the TLAPM.
 * @return
 */
public static MessageConsole getTLAPMConsole()
{
    MessageConsole console = findConsole(TLAPM_CONSOLE_ID);

    return console;
}
 
Example #18
Source File: SootPlugin.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
private MessageConsole findConsole(String name) {
	ConsolePlugin plugin = ConsolePlugin.getDefault();
	IConsoleManager conMan = plugin.getConsoleManager();
	IConsole[] existing = conMan.getConsoles();
	for (int i = 0; i < existing.length; i++)
		if (name.equals(existing[i].getName()))
			return (MessageConsole) existing[i];
	// no console found, so create a new one
	MessageConsole myConsole = new MessageConsole(name, null);
	conMan.addConsoles(new IConsole[] { myConsole });
	return myConsole;
}
 
Example #19
Source File: CloudSdkModifyJob.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
MessageConsoleStream createNewMessageConsole() {
  MessageConsole console = MessageConsoleUtilities.getMessageConsole(
      Messages.getString("configuring.cloud.sdk"), // $NON-NLS-1$
      null /* imageDescriptor */);

  setProperty(IProgressConstants.ACTION_PROPERTY, new ShowConsoleViewAction(console));

  return console.newMessageStream();
}
 
Example #20
Source File: MessageConsoleUtilities.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
public static <C extends MessageConsole> C findOrCreateConsole(
    String name, ConsoleFactory<C> factory) {
  IConsole[] consoles = consoleManagerSupplier.get().getConsoles();
  for (IConsole console : consoles) {
    if (name.equals(console.getName())) {
      @SuppressWarnings("unchecked")
      C result = (C) console;
      return result;
    }
  }
  // console not found, so create a new one
  return createConsole(name, factory);
}
 
Example #21
Source File: MessageConsoleUtilitiesTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testFindOrCreateConsole_newConsole() {
  MessageConsole newConsole = mock(MessageConsole.class);
  IConsole created = MessageConsoleUtilities.findOrCreateConsole(
      "new console", unused -> newConsole);
  assertEquals(created, newConsole);
  verify(consoleManager).addConsoles(new IConsole[] {created});
}
 
Example #22
Source File: MessageConsoleUtilitiesTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateConsole() {
  MessageConsole newConsole = mock(MessageConsole.class);
  IConsole created = MessageConsoleUtilities.createConsole("new console", unused -> newConsole);
  assertEquals(created, newConsole);
  verify(consoleManager).addConsoles(new IConsole[] {created});
}
 
Example #23
Source File: MessageConsoleUtilities.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a {@link MessageConsole} with the given <code>consoleName</code>. If no console by that
 * name exists then one is created. Callers of this method can decide when to activate it.
 *
 * @param consoleName name of the console
 * @param imageDescriptor image descriptor to use
 * @param show if true the console will be brought to the front
 * @return {@link MessageConsole} with the given <code>consoleName</code>
 */
public static MessageConsole getMessageConsole(String consoleName,
    ImageDescriptor imageDescriptor, boolean show) {
  MessageConsole messageConsole = findOrCreateConsole(
      consoleName,
      unused -> new MessageConsole(consoleName, imageDescriptor));

  if (show) {
    consoleManagerSupplier.get().showConsoleView(messageConsole);
  }
  return messageConsole;
}
 
Example #24
Source File: RunSelectedSequenceDiagramHandler.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Loads the the given sequence diagram with URLClassloader, runs it with a
 * {@link SequenceDiagramExecutor}, waits for its termination and writes the
 * result to the given console.
 * <p>
 * The user can cancel the execution.
 */
@SuppressWarnings("unchecked")
private void runSequenceDiagram(IType sequenceDiagramType, MessageConsole console, IProgressMonitor monitor)
		throws Exception {
	monitor.subTask("Execution of " + sequenceDiagramType.getElementName());
	String projectName = sequenceDiagramType.getJavaProject().getElementName();
	URLClassLoader classLoader = ClassLoaderProvider.getClassLoaderForProject(projectName,
			this.getClass().getClassLoader());
	Class<? extends SequenceDiagram> myClass = (Class<? extends SequenceDiagram>) classLoader
			.loadClass(sequenceDiagramType.getFullyQualifiedName());
	SequenceDiagramExecutor executor = SequenceDiagramExecutor.create();
	Constructor<? extends SequenceDiagram> constructor = myClass.getDeclaredConstructor();

	if (!constructor.isAccessible())
		constructor.setAccessible(true);

	executor.setDiagram(constructor.newInstance());
	executor.startNoWait().shutdown();
	while (executor.getStatus().equals(ModelExecutor.Status.ACTIVE)) {
		if (monitor.isCanceled()) {
			executor.shutdownNow().awaitTermination();
			classLoader.close();
			throw new InterruptedException("Job was canceled.");
		}
	}
	classLoader.close();
	writeToConsole(console, executor.getErrors(), sequenceDiagramType.getElementName());
}
 
Example #25
Source File: CommandConsoleFactoryImpl.java    From eclipse with Apache License 2.0 5 votes vote down vote up
private static MessageConsole findConsole(String name) {
  ConsolePlugin plugin = ConsolePlugin.getDefault();
  IConsoleManager conMan = plugin.getConsoleManager();
  IConsole[] existing = conMan.getConsoles();
  for (int i = 0; i < existing.length; i++) {
    if (name.equals(existing[i].getName())) {
      return (MessageConsole) existing[i];
    }
  }
  // no console found, so create a new one
  MessageConsole myConsole = new MessageConsole(name, null);
  conMan.addConsoles(new IConsole[] {myConsole});
  return myConsole;
}
 
Example #26
Source File: CommandConsoleFactoryImpl.java    From eclipse with Apache License 2.0 5 votes vote down vote up
@Override
public CommandConsole get(String name, String title) throws IOException {
  MessageConsole console = findConsole(name);
  MessageConsoleStream stream = console.newMessageStream();
  stream.setActivateOnWrite(true);
  stream.write("*** " + title + " ***\n");
  return new CommandConsoleImpl(console);
}
 
Example #27
Source File: OscarValidatorHandler.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void runFile ( final IFile file, final IProgressMonitor monitor ) throws Exception
{

    final MessageConsole mc = new MessageConsole ( String.format ( "OSCAR Validation: %s", file ), "org.eclipse.scada.configuration.oscar.validation", null, true );

    ConsolePlugin.getDefault ().getConsoleManager ().addConsoles ( new IConsole[] { mc } );
    mc.activate ();

    final File dataFile = file.getLocation ().toFile ();

    Map<String, Map<String, Map<String, String>>> data;

    if ( OscarLoader.isOscar ( dataFile ) )
    {
        data = new OscarLoader ( dataFile ).getData ();
    }
    else
    {
        try (FileInputStream stream = new FileInputStream ( dataFile ))
        {
            data = OscarLoader.loadJsonData ( stream );
        }
    }

    final PrintStream consoleStream = new PrintStream ( mc.newOutputStream () );
    try
    {
        new LoopValidator ( data, consoleStream ).validate ();
    }
    finally
    {
        consoleStream.close ();
    }
}
 
Example #28
Source File: ConsoleContext.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
public ConsoleContext ( final MessageConsole messageConsole )
{
    this.writerStream = messageConsole.newMessageStream ();

    final MessageConsoleStream errorStream = messageConsole.newMessageStream ();
    errorStream.setColor ( Display.getDefault ().getSystemColor ( SWT.COLOR_RED ) );
    this.errorPrintWriter = new PrintWriter ( new OutputStreamWriter ( errorStream ) );

    this.logStream = messageConsole.newMessageStream ();
    this.logStream.setColor ( Display.getDefault ().getSystemColor ( SWT.COLOR_GRAY ) );
}
 
Example #29
Source File: SymbolController.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private ConsoleContext createOrGetConsole ()
{
    if ( this.parentController != null && this.parentController.getConsole () != null )
    {
        return this.parentController.getConsole ();
    }

    final IConsoleManager manager = ConsolePlugin.getDefault ().getConsoleManager ();
    final MessageConsole messageConsole = new MessageConsole ( String.format ( "Symbol Debug Console: %s", this.symbolInfoName ), null, null, true );
    manager.addConsoles ( new IConsole[] { messageConsole } );
    this.createdConsole = messageConsole;
    return new ConsoleContext ( messageConsole );
}
 
Example #30
Source File: EclipseStreamingTextWidget.java    From ice with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * (non-Javadoc)
 * 
 * @see IStreamingTextWidget#display()
 */
@Override
public void display() {

	// Must sync with the display thread
	Display.getDefault().asyncExec(new Runnable() {
		@Override
		public void run() {
			// Get the currently active page
			IWorkbenchPage page = PlatformUI.getWorkbench()
					.getActiveWorkbenchWindow().getActivePage();
			try {
				// Load the console view
				consoleView = (IConsoleView) page
						.showView(IConsoleConstants.ID_CONSOLE_VIEW);
				// Create the console instance that will be used to display
				// text from this widget.
				console = new MessageConsole("CLI", null);
				// Add the console to the console manager
				ConsolePlugin.getDefault().getConsoleManager()
						.addConsoles(new IConsole[] { console });
				// Show the console in the view
				consoleView.display(console);
				console.activate();
				// Get an output stream for the console
				msgStream = console.newMessageStream();
				msgStream.setActivateOnWrite(true);
				msgStream.println("Streaming output console activated.");
			} catch (PartInitException e) {
				// Complain
				logger.error("EclipseStreamingTextWidget Message: "
						+ "Unable to stream text!");
				logger.error(getClass().getName() + " Exception!", e);
			}

		}
	});

	return;
}