diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/icons/rem_co.png b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/icons/rem_co.png new file mode 100644 index 000000000..38ab8a480 Binary files /dev/null and b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/icons/rem_co.png differ diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/icons/rem_co@2x.png b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/icons/rem_co@2x.png new file mode 100644 index 000000000..b9d378682 Binary files /dev/null and b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/icons/rem_co@2x.png differ diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/plugin.xml b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/plugin.xml index b3208c356..69f72c3e0 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/plugin.xml +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/plugin.xml @@ -40,4 +40,14 @@ class="org.springframework.tooling.ls.eclipse.commons.console.preferences.LanguageServerConsolesPrefsInitializer"> + + + + + + + diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/LanguageServerCommonsActivator.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/LanguageServerCommonsActivator.java index 727e3d71f..5588de19c 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/LanguageServerCommonsActivator.java +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/LanguageServerCommonsActivator.java @@ -10,13 +10,22 @@ *******************************************************************************/ package org.springframework.tooling.ls.eclipse.commons; +import java.net.URL; + +import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; +import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; public class LanguageServerCommonsActivator extends AbstractUIPlugin { + public static final String PLUGIN_ID = "org.springframework.tooling.ls.eclipse.commons"; + private static LanguageServerCommonsActivator instance; public LanguageServerCommonsActivator() { @@ -28,6 +37,19 @@ public class LanguageServerCommonsActivator extends AbstractUIPlugin { super.start(context); } + public final static ImageDescriptor getImageDescriptor(String path) { + ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor(); + Bundle bundle = Platform.getBundle(PLUGIN_ID); + URL url = null; + if (bundle != null) { + url = FileLocator.find(bundle, new Path(path), null); + if (url != null) { + desc = ImageDescriptor.createFromURL(url); + } + } + return desc; + } + public static LanguageServerCommonsActivator getInstance() { return instance; } diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/console/CloseConsoleAction.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/console/CloseConsoleAction.java new file mode 100644 index 000000000..0375613b5 --- /dev/null +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/console/CloseConsoleAction.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2018 Pivotal, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Pivotal, Inc. - initial API and implementation + *******************************************************************************/ +package org.springframework.tooling.ls.eclipse.commons.console; + +import org.eclipse.jface.action.Action; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; +import org.springframework.tooling.ls.eclipse.commons.LanguageServerCommonsActivator; + +public class CloseConsoleAction extends Action { + + private LanguageServerIOConsole fConsole; + + public CloseConsoleAction(IWorkbenchWindow workbenchWindow, LanguageServerIOConsole fConsole) { + super("Close Console", LanguageServerCommonsActivator.getImageDescriptor("icons/rem_co.png")); + this.fConsole = fConsole; + } + + public void dispose() { + //TODO: anything to clean up? + } + + @Override + public void run() { + ConsolePlugin.getDefault().getConsoleManager().removeConsoles(new IConsole[]{fConsole}); + } + +} diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/console/ConsoleUtil.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/console/ConsoleUtil.java index 80ab01ffa..935ebcc1c 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/console/ConsoleUtil.java +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/console/ConsoleUtil.java @@ -29,7 +29,7 @@ import org.eclipse.ui.console.IOConsoleOutputStream; */ @SuppressWarnings("restriction") public class ConsoleUtil { - + public static class Console { public final InputStream in; public final OutputStream out; @@ -67,15 +67,15 @@ public class ConsoleUtil { public static Color getOutputColor() { return DebugUIPlugin.getPreferenceColor(IDebugPreferenceConstants.CONSOLE_SYS_OUT_COLOR); } - + public static Color getErrorColor() { return DebugUIPlugin.getPreferenceColor(IDebugPreferenceConstants.CONSOLE_SYS_ERR_COLOR); } - + public static Color getInputColor() { return DebugUIPlugin.getPreferenceColor(IDebugPreferenceConstants.CONSOLE_SYS_IN_COLOR); } - + private LinkedList history = new LinkedList(); private void add(IOConsole console) { @@ -96,18 +96,18 @@ public class ConsoleUtil { private static void close(IOConsole console) { ConsolePlugin.getDefault().getConsoleManager().removeConsoles(new IConsole[] {console}); } - + public Console getConsole(String title) { - - final IOConsole console = new IOConsole(title, null); + + final IOConsole console = new LanguageServerIOConsole(title); final IOConsoleInputStream in = console.getInputStream(); final IOConsoleOutputStream out = console.newOutputStream(); final IOConsoleOutputStream err = console.newOutputStream(); - + in.setColor(getInputColor()); out.setColor(getOutputColor()); err.setColor(getErrorColor()); - + add(console); return new Console(in, out, err); } diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/console/LanguageServerConsolePageParticipant.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/console/LanguageServerConsolePageParticipant.java new file mode 100644 index 000000000..d68b12629 --- /dev/null +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/console/LanguageServerConsolePageParticipant.java @@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright (c) 2000, 2009, 2017 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + * Kris De Volder - copied from org.eclipse.debug.internal.ui.views.console.ProcessConsolePageParticipant + * - modified to create similar functionality for GrailsIOConsole + * Kris De Volder - copied and modified to support lsp console close action + *******************************************************************************/ +package org.springframework.tooling.ls.eclipse.commons.console; + +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.IConsoleConstants; +import org.eclipse.ui.console.IConsolePageParticipant; +import org.eclipse.ui.console.IConsoleView; +import org.eclipse.ui.part.IPageBookViewPage; + +public class LanguageServerConsolePageParticipant implements IConsolePageParticipant { + + // actions + private CloseConsoleAction fClose; + + private IPageBookViewPage fPage; + + private IConsoleView fView; + + private LanguageServerIOConsole fConsole; + + @Override + public void init(IPageBookViewPage page, IConsole console) { + fPage = page; + fConsole = (LanguageServerIOConsole) console; + + fClose = new CloseConsoleAction(page.getSite().getWorkbenchWindow(), fConsole); + + fView = (IConsoleView) fPage.getSite().getPage().findView(IConsoleConstants.ID_CONSOLE_VIEW); + + // contribute to toolbar + IActionBars actionBars = fPage.getSite().getActionBars(); + configureToolBar(actionBars.getToolBarManager()); + } + + @Override + public T getAdapter(Class arg0) { + return null; + } + + @Override + public void dispose() { + if (fClose != null) { + fClose.dispose(); + fClose = null; + } + // if (fStdOut != null) { + // fStdOut.dispose(); + // fStdOut = null; + // } + // if (fStdErr != null) { + // fStdErr.dispose(); + // fStdErr = null; + // } + fConsole = null; + } + + /** + * Contribute actions to the toolbar + */ + protected void configureToolBar(IToolBarManager mgr) { + mgr.appendToGroup(IConsoleConstants.LAUNCH_GROUP, fClose); + + // mgr.appendToGroup(IConsoleConstants.LAUNCH_GROUP, fRemoveTerminated); + // mgr.appendToGroup(IConsoleConstants.LAUNCH_GROUP, fRemoveAllTerminated); + // mgr.appendToGroup(IConsoleConstants.OUTPUT_GROUP, fStdOut); + // mgr.appendToGroup(IConsoleConstants.OUTPUT_GROUP, fStdErr); + } + + @Override + public void activated() { + // add EOF submissions + // IPageSite site = fPage.getSite(); + // IHandlerService handlerService = (IHandlerService)site.getService(IHandlerService.class); + // IContextService contextService = (IContextService)site.getService(IContextService.class); + // fActivatedContext = contextService.activateContext(fContextId); + // fActivatedHandler = handlerService.activateHandler("org.eclipse.debug.ui.commands.eof", fEOFHandler); //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see org.eclipse.ui.console.IConsolePageParticipant#deactivated() + */ + @Override + public void deactivated() { + // remove EOF submissions + // IPageSite site = fPage.getSite(); + // IHandlerService handlerService = (IHandlerService)site.getService(IHandlerService.class); + // IContextService contextService = (IContextService)site.getService(IContextService.class); + // handlerService.deactivateHandler(fActivatedHandler); + // contextService.deactivateContext(fActivatedContext); + } + +} \ No newline at end of file diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/console/LanguageServerIOConsole.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/console/LanguageServerIOConsole.java new file mode 100644 index 000000000..0f73e0480 --- /dev/null +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/console/LanguageServerIOConsole.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2018 Pivotal, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Pivotal, Inc. - initial API and implementation + *******************************************************************************/ +package org.springframework.tooling.ls.eclipse.commons.console; + +import org.eclipse.ui.console.IOConsole; + +public class LanguageServerIOConsole extends IOConsole { + + private static final String CONSOLE_TYPE = LanguageServerIOConsole.class.getName(); + + public LanguageServerIOConsole(final String title) { + super(title, CONSOLE_TYPE, null); + } + +} \ No newline at end of file