Search in sources :

Example 1 with IConsoleListener

use of org.eclipse.ui.console.IConsoleListener in project sling by apache.

the class SlingConsoleEventListener method handleEvent.

@Override
public void handleEvent(Event event) {
    synchronized (sync) {
        initSlingConsole();
        if (slingConsole != null) {
            logEvent(event, slingConsole);
            return;
        }
        delayedEvents.add(event);
        final IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager();
        if (listener == null) {
            listener = new IConsoleListener() {

                @Override
                public void consolesRemoved(IConsole[] consoles) {
                    synchronized (sync) {
                        for (IConsole console : consoles) {
                            if (console.equals(slingConsole)) {
                                slingConsole = null;
                            }
                        }
                    }
                }

                @Override
                public void consolesAdded(IConsole[] consoles) {
                    synchronized (sync) {
                        for (IConsole console : consoles) {
                            if (console.getType().equals(SlingConsoleFactory.CONSOLE_TYPE_SLING)) {
                                slingConsole = (MessageConsole) console;
                                synchronized (delayedEvents) {
                                    for (Iterator<Event> it = delayedEvents.iterator(); it.hasNext(); ) {
                                        logEvent(it.next(), slingConsole);
                                        it.remove();
                                    }
                                }
                                consoleManager.removeConsoleListener(listener);
                                listener = null;
                                break;
                            }
                        }
                    }
                }
            };
            consoleManager.addConsoleListener(listener);
        }
    }
}
Also used : IConsoleManager(org.eclipse.ui.console.IConsoleManager) MessageConsole(org.eclipse.ui.console.MessageConsole) IConsoleListener(org.eclipse.ui.console.IConsoleListener) Iterator(java.util.Iterator) IConsole(org.eclipse.ui.console.IConsole)

Aggregations

Iterator (java.util.Iterator)1 IConsole (org.eclipse.ui.console.IConsole)1 IConsoleListener (org.eclipse.ui.console.IConsoleListener)1 IConsoleManager (org.eclipse.ui.console.IConsoleManager)1 MessageConsole (org.eclipse.ui.console.MessageConsole)1