Search in sources :

Example 46 with IConsole

use of org.eclipse.ui.console.IConsole in project titan.EclipsePlug-ins by eclipse.

the class ConsoleWriter method findConsole.

/**
 * Try to get a console with a given name. If a Console is not found
 * a new console will be created
 * @param name of the given console
 * @return The Console
 */
private MessageConsole findConsole(final String name) {
    ConsolePlugin plugin = ConsolePlugin.getDefault();
    // Protection, Activator.stop exception...
    if (plugin == null) {
        return null;
    }
    IConsoleManager conMan = plugin.getConsoleManager();
    IConsole[] existing = conMan.getConsoles();
    for (IConsole anExisting : existing) {
        if (name.equals(anExisting.getName())) {
            return (MessageConsole) anExisting;
        }
    }
    // no console found, so create a new one
    MessageConsole myConsole = new MessageConsole(name, null);
    conMan.addConsoles(new IConsole[] { myConsole });
    return myConsole;
}
Also used : IConsoleManager(org.eclipse.ui.console.IConsoleManager) MessageConsole(org.eclipse.ui.console.MessageConsole) ConsolePlugin(org.eclipse.ui.console.ConsolePlugin) IConsole(org.eclipse.ui.console.IConsole)

Example 47 with IConsole

use of org.eclipse.ui.console.IConsole in project titan.EclipsePlug-ins by eclipse.

the class ExecutorMonitorView method createPartControl.

@Override
public void createPartControl(final Composite parent) {
    viewer = new TreeViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL);
    contentProvider = new ExecutorMonitorContentProvider();
    viewer.setContentProvider(contentProvider);
    labelProvider = new ExecutorMonitorLabelProvider();
    viewer.setLabelProvider(labelProvider);
    createActions();
    manager = new MenuManager("menuManager");
    createEmptyContextMenu();
    createToolBar();
    Activator.setMainView(this);
    viewer.setInput(getInitialInput());
    viewer.expandToLevel(2);
    updateActions();
    getSite().setSelectionProvider(viewer);
    launchListener = new LaunchesListener(this);
    DebugPlugin.getDefault().getLaunchManager().addLaunchListener(launchListener);
    selectionChangedListener = new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            ITreeLeaf element = (ITreeLeaf) selection.getFirstElement();
            updateActions();
            if (null == element) {
                return;
            }
            if (element instanceof LaunchElement) {
                createLauncherContextMenu();
            } else if (element instanceof MainControllerElement) {
                createExecutorContextMenu((MainControllerElement) element);
                BaseExecutor executor = ((MainControllerElement) element).executor();
                IProcess process = executor.getProcess();
                if (null == process) {
                    return;
                }
                IConsole console = DebugUITools.getConsole(process);
                if (null == console) {
                    return;
                }
                IConsole[] consoles = ConsolePlugin.getDefault().getConsoleManager().getConsoles();
                boolean exists = false;
                for (IConsole console2 : consoles) {
                    if (console2.equals(console)) {
                        exists = true;
                    }
                }
                if (!exists) {
                    ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { console });
                }
                ConsolePlugin.getDefault().getConsoleManager().showConsoleView(console);
                ConsolePlugin.getDefault().getConsoleManager().refresh(console);
            } else {
                createEmptyContextMenu();
            }
        }
    };
    viewer.addSelectionChangedListener(selectionChangedListener);
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IConsole(org.eclipse.ui.console.IConsole) BaseExecutor(org.eclipse.titan.executor.executors.BaseExecutor) MenuManager(org.eclipse.jface.action.MenuManager) ITreeLeaf(org.eclipse.titan.executor.executors.ITreeLeaf) IProcess(org.eclipse.debug.core.model.IProcess)

Example 48 with IConsole

use of org.eclipse.ui.console.IConsole in project titan.EclipsePlug-ins by eclipse.

the class AstWalkerRunnerJava method findConsole.

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;
}
Also used : IConsoleManager(org.eclipse.ui.console.IConsoleManager) MessageConsole(org.eclipse.ui.console.MessageConsole) ConsolePlugin(org.eclipse.ui.console.ConsolePlugin) IConsole(org.eclipse.ui.console.IConsole)

Example 49 with IConsole

use of org.eclipse.ui.console.IConsole in project ow by vtst.

the class SoyCompilerLaunchConfigurationDelegate method addProcessListeners.

@Override
protected void addProcessListeners(final ILaunchConfiguration config, final Fixture fixture, IProcessListenerAcceptor acceptor) {
    acceptor.acceptTerminationListener(new IProcessTerminationListener() {

        public void terminated(IProcess process, int exitValue) {
            IConsole console = DebugUITools.getConsole(process);
            if (console instanceof IOConsole) {
                IOConsole ioConsole = (IOConsole) console;
                IOConsoleOutputStream stream = ioConsole.newOutputStream();
                if (exitValue == 0) {
                    try {
                        stream.write(messages.getString("soy_compiler_success"));
                        stream.write("\n");
                        stream.flush();
                        for (IFile file : configHelper.getOutputFiles(config)) {
                            try {
                                file.refreshLocal(0, null);
                            } catch (CoreException e) {
                            }
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                } else {
                    try {
                        stream.write(messages.getString("soy_compiler_error"));
                        stream.write("\n");
                        stream.flush();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        // try { fixture.outputFile.refreshLocal(0, null); } catch (CoreException e) {}
        }
    });
    acceptor.acceptPatternMatchListener(new EasyPatternMatchListener() {

        private Pattern pattern = Pattern.compile("Exception [^:]*com.google.template.soy.base.SoySyntaxException: " + "(In file ([^:]*)(:([0-9]+))?(, template [^:]*)?: )?(.*)");

        @Override
        public void connect(TextConsole console) {
            super.connect(console);
            try {
                for (IMarker marker : fixture.inputFile.findMarkers(MARKER_TYPE, true, IResource.DEPTH_ZERO)) {
                    if (MARKER_SOURCE_ID.equals(marker.getAttribute(IMarker.SOURCE_ID))) {
                        marker.delete();
                    }
                }
            } catch (CoreException e) {
            }
        }

        private void processLine(int offset, int length) throws BadLocationException {
            String line = document.get(offset, length);
            Matcher matcher = pattern.matcher(line);
            if (matcher.matches()) {
                String lineNumberAsString = matcher.group(4);
                int lineNumber = (lineNumberAsString == null ? 1 : Integer.parseInt(lineNumberAsString));
                String errorMessage = matcher.group(6);
                IMarker marker;
                try {
                    marker = fixture.inputFile.createMarker(MARKER_TYPE);
                    marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
                    marker.setAttribute(IMarker.MESSAGE, errorMessage);
                    marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_NORMAL);
                    marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
                    marker.setAttribute(IMarker.SOURCE_ID, MARKER_SOURCE_ID);
                } catch (CoreException e) {
                    e.printStackTrace();
                }
            }
        }

        @Override
        public void matchFound(PatternMatchEvent matchEvent) {
            try {
                processLine(matchEvent.getOffset(), matchEvent.getLength());
            } catch (BadLocationException e) {
            // This should never arise if the code is correct
            }
        }

        @Override
        public String getPattern() {
            return ".+";
        }
    });
}
Also used : Pattern(java.util.regex.Pattern) IFile(org.eclipse.core.resources.IFile) IOConsoleOutputStream(org.eclipse.ui.console.IOConsoleOutputStream) Matcher(java.util.regex.Matcher) IProcessTerminationListener(net.vtst.eclipse.easyxtext.ui.launching.EasyLaunchConfigurationDelegateUtils.IProcessTerminationListener) IConsole(org.eclipse.ui.console.IConsole) IOException(java.io.IOException) PatternMatchEvent(org.eclipse.ui.console.PatternMatchEvent) CoreException(org.eclipse.core.runtime.CoreException) EasyPatternMatchListener(net.vtst.eclipse.easyxtext.ui.launching.EasyPatternMatchListener) TextConsole(org.eclipse.ui.console.TextConsole) IMarker(org.eclipse.core.resources.IMarker) IProcess(org.eclipse.debug.core.model.IProcess) IOConsole(org.eclipse.ui.console.IOConsole) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 50 with IConsole

use of org.eclipse.ui.console.IConsole in project ow by vtst.

the class LessCompilerLaunchConfigurationDelegate method addProcessListeners.

protected void addProcessListeners(ILaunchConfiguration config, final Fixture fixture, IProcessListenerAcceptor acceptor) {
    acceptor.acceptTerminationListener(new IProcessTerminationListener() {

        public void terminated(IProcess process, int exitValue) {
            IConsole console = DebugUITools.getConsole(process);
            if (console instanceof IOConsole) {
                IOConsole ioConsole = (IOConsole) console;
                IOConsoleOutputStream stream = ioConsole.newOutputStream();
                if (exitValue == 0) {
                    try {
                        stream.write(messages.getString("less_compiler_success"));
                        stream.write("\n");
                        stream.flush();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                /*
            FileLink link = new FileLink(destinationFile, null, -1, -1, -1);
            console.defaultStream.hyperlink(link, messages.getString("less_link_to_output"));
            console.defaultStream.println();
            */
                } else {
                    try {
                        stream.write(messages.getString("less_compiler_error"));
                        stream.write("\n");
                        stream.flush();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            try {
                fixture.outputFile.refreshLocal(0, null);
            } catch (CoreException e) {
            }
        }
    });
    acceptor.acceptPatternMatchListener(new EasyPatternMatchListener() {

        private Pattern pattern = Pattern.compile("([0-9]+)( .*)");

        private int numberOfLines = 0;

        private int errorLineNumber = 0;

        private String errorMessage = null;

        @Override
        public void connect(TextConsole console) {
            super.connect(console);
            try {
                for (IMarker marker : fixture.inputFile.findMarkers(MARKER_TYPE, true, IResource.DEPTH_ZERO)) {
                    if (MARKER_SOURCE_ID.equals(marker.getAttribute(IMarker.SOURCE_ID))) {
                        marker.delete();
                    }
                }
            } catch (CoreException e) {
            }
        }

        @Override
        public void disconnect() {
            if (errorLineNumber != 0 && errorMessage != null) {
                try {
                    IMarker marker = fixture.inputFile.createMarker(MARKER_TYPE);
                    marker.setAttribute(IMarker.LINE_NUMBER, this.errorLineNumber);
                    marker.setAttribute(IMarker.MESSAGE, this.errorMessage);
                    marker.setAttribute(IMarker.PRIORITY, IMarker.PRIORITY_NORMAL);
                    marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
                    marker.setAttribute(IMarker.SOURCE_ID, MARKER_SOURCE_ID);
                } catch (CoreException e) {
                    e.printStackTrace();
                }
            }
        }

        private void processLine(int offset, int length) throws BadLocationException {
            String line = document.get(offset, length);
            Matcher matcher = pattern.matcher(line);
            if (matcher.matches()) {
                this.numberOfLines++;
                int lineNumber = Integer.parseInt(matcher.group(1));
                if (this.numberOfLines <= 2)
                    errorLineNumber = lineNumber;
                FileLink link = new FileLink(fixture.inputFile, null, -1, -1, lineNumber);
                console.addHyperlink(link, offset, matcher.group(1).length());
            } else {
                if (this.numberOfLines == 0)
                    errorMessage = line;
            }
        }

        @Override
        public void matchFound(PatternMatchEvent matchEvent) {
            try {
                processLine(matchEvent.getOffset(), matchEvent.getLength());
            } catch (BadLocationException e) {
            // This should never arise if the code is correct
            }
        }

        @Override
        public String getPattern() {
            return ".+";
        }
    });
}
Also used : Pattern(java.util.regex.Pattern) IOConsoleOutputStream(org.eclipse.ui.console.IOConsoleOutputStream) Matcher(java.util.regex.Matcher) IProcessTerminationListener(net.vtst.eclipse.easyxtext.ui.launching.EasyLaunchConfigurationDelegateUtils.IProcessTerminationListener) FileLink(org.eclipse.debug.ui.console.FileLink) IConsole(org.eclipse.ui.console.IConsole) IOException(java.io.IOException) PatternMatchEvent(org.eclipse.ui.console.PatternMatchEvent) CoreException(org.eclipse.core.runtime.CoreException) EasyPatternMatchListener(net.vtst.eclipse.easyxtext.ui.launching.EasyPatternMatchListener) TextConsole(org.eclipse.ui.console.TextConsole) IMarker(org.eclipse.core.resources.IMarker) IProcess(org.eclipse.debug.core.model.IProcess) IOConsole(org.eclipse.ui.console.IOConsole) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

IConsole (org.eclipse.ui.console.IConsole)50 IConsoleManager (org.eclipse.ui.console.IConsoleManager)32 ConsolePlugin (org.eclipse.ui.console.ConsolePlugin)28 MessageConsole (org.eclipse.ui.console.MessageConsole)22 IOConsole (org.eclipse.ui.console.IOConsole)6 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)4 PartInitException (org.eclipse.ui.PartInitException)4 IOException (java.io.IOException)3 CoreException (org.eclipse.core.runtime.CoreException)3 IProcess (org.eclipse.debug.core.model.IProcess)3 IConsoleView (org.eclipse.ui.console.IConsoleView)3 TextConsole (org.eclipse.ui.console.TextConsole)3 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 IProcessTerminationListener (net.vtst.eclipse.easyxtext.ui.launching.EasyLaunchConfigurationDelegateUtils.IProcessTerminationListener)2 EasyPatternMatchListener (net.vtst.eclipse.easyxtext.ui.launching.EasyPatternMatchListener)2 IMarker (org.eclipse.core.resources.IMarker)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 IOConsoleOutputStream (org.eclipse.ui.console.IOConsoleOutputStream)2