Bug 488959 - TerminalConsole toolbar extensibility.
Allow other plugins to contribute Actions to
TerminalConsole toolbar. Upversion the console plug-ins
to 1.1 for the new APIs.
Change-Id: Ife6f54e0d294f766dff2a88841b6807b259fad1d
Signed-off-by: Jonathan Williams <jonwilliams@qnx.com>
diff --git a/bundles/org.eclipse.remote.console/.project b/bundles/org.eclipse.remote.console/.project
index 0d4f3af..da0bcc4 100644
--- a/bundles/org.eclipse.remote.console/.project
+++ b/bundles/org.eclipse.remote.console/.project
@@ -20,9 +20,15 @@
<arguments>
</arguments>
</buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.api.tools.apiAnalysisBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.pde.api.tools.apiAnalysisNature</nature>
</natures>
</projectDescription>
diff --git a/bundles/org.eclipse.remote.console/META-INF/MANIFEST.MF b/bundles/org.eclipse.remote.console/META-INF/MANIFEST.MF
index 07fd923..581674f 100644
--- a/bundles/org.eclipse.remote.console/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.remote.console/META-INF/MANIFEST.MF
@@ -2,13 +2,14 @@
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.remote.console;singleton:=true
-Bundle-Version: 1.0.0.qualifier
+Bundle-Version: 1.1.0.qualifier
Bundle-Activator: org.eclipse.remote.internal.console.Activator
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %pluginProvider
-Export-Package: org.eclipse.remote.console
+Export-Package: org.eclipse.remote.console,
+ org.eclipse.remote.console.actions
Import-Package: org.eclipse.core.commands,
org.eclipse.core.runtime,
org.eclipse.core.runtime.jobs,
diff --git a/bundles/org.eclipse.remote.console/plugin.xml b/bundles/org.eclipse.remote.console/plugin.xml
index 592289c..c016588 100644
--- a/bundles/org.eclipse.remote.console/plugin.xml
+++ b/bundles/org.eclipse.remote.console/plugin.xml
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
+ <extension-point id="org.eclipse.remote.console.toolbar" name="org.eclipse.remote.console.toolbar" schema="schema/consoleToolbar.exsd"/>
<extension
point="org.eclipse.ui.console.consoleFactories">
<consoleFactory
diff --git a/bundles/org.eclipse.remote.console/pom.xml b/bundles/org.eclipse.remote.console/pom.xml
index 68b1b00..0251ef1 100644
--- a/bundles/org.eclipse.remote.console/pom.xml
+++ b/bundles/org.eclipse.remote.console/pom.xml
@@ -11,6 +11,6 @@
</parent>
<artifactId>org.eclipse.remote.console</artifactId>
- <version>1.0.0-SNAPSHOT</version>
+ <version>1.1.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
diff --git a/bundles/org.eclipse.remote.console/schema/consoleToolbar.exsd b/bundles/org.eclipse.remote.console/schema/consoleToolbar.exsd
new file mode 100644
index 0000000..0b1adee
--- /dev/null
+++ b/bundles/org.eclipse.remote.console/schema/consoleToolbar.exsd
@@ -0,0 +1,116 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.remote.console" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.remote.console" id="org.eclipse.remote.console.toolbar" name="Terminal Console Toolbar Contributions"/>
+ </appinfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="action" minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="action">
+ <complexType>
+ <attribute name="id" type="string" use="required">
+ <annotation>
+ <documentation>
+ Identifier for this action
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="connectionType" type="string" use="required">
+ <annotation>
+ <documentation>
+ The connection type this Action applies to
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="actionFactory" type="string" use="required">
+ <annotation>
+ <documentation>
+ A class implementing IConsoleActionFactory to be called to create the Action
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.remote.console.actions.IConsoleActionFactory"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="examples"/>
+ </appinfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="apiinfo"/>
+ </appinfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="implementation"/>
+ </appinfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+
+</schema>
diff --git a/bundles/org.eclipse.remote.console/src/org/eclipse/remote/console/TerminalConsoleUtility.java b/bundles/org.eclipse.remote.console/src/org/eclipse/remote/console/TerminalConsoleUtility.java
index a9af9f2..ff53269 100644
--- a/bundles/org.eclipse.remote.console/src/org/eclipse/remote/console/TerminalConsoleUtility.java
+++ b/bundles/org.eclipse.remote.console/src/org/eclipse/remote/console/TerminalConsoleUtility.java
@@ -17,13 +17,15 @@
import org.eclipse.ui.console.IConsole;
/**
- * A collection of public API utility methods to open
- * consoles to IRemoteConnection objects
+ * A collection of public API utility methods to open consoles to
+ * IRemoteConnection objects
+ *
+ * @since 1.1
*/
public class TerminalConsoleUtility {
/**
- * Opens a dialog to allow selection of an IRemoteConnection,
- * encoding, etc. and then open a console to it.
+ * Opens a dialog to allow selection of an IRemoteConnection, encoding, etc.
+ * and then open a console to it.
*/
public void openConsole() {
new TerminalConsoleFactory().openConsole();
diff --git a/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/actions/ConsoleAction.java b/bundles/org.eclipse.remote.console/src/org/eclipse/remote/console/actions/ConsoleAction.java
similarity index 67%
rename from bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/actions/ConsoleAction.java
rename to bundles/org.eclipse.remote.console/src/org/eclipse/remote/console/actions/ConsoleAction.java
index 9df1416..0b5d60c 100644
--- a/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/actions/ConsoleAction.java
+++ b/bundles/org.eclipse.remote.console/src/org/eclipse/remote/console/actions/ConsoleAction.java
@@ -8,13 +8,16 @@
* Contributors:
* QNX Software Systems - Initial API and implementation
*******************************************************************************/
-package org.eclipse.remote.internal.console.actions;
+package org.eclipse.remote.console.actions;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.remote.internal.console.Activator;
+/**
+ * @since 1.1
+ */
public abstract class ConsoleAction extends Action {
public ConsoleAction(String id) {
this(id, 0);
@@ -25,27 +28,20 @@
setId(id);
}
- protected void setupAction(String text, String tooltip,
- String image, String enabledImage, String disabledImage,
+ protected void setupAction(String text, String tooltip, String image, String enabledImage, String disabledImage,
boolean enabled) {
ImageRegistry imageRegistry = Activator.getDefault().getImageRegistry();
setupAction(text, tooltip, image, enabledImage, disabledImage, enabled, imageRegistry);
}
- protected void setupAction(String text, String tooltip,
- String hoverImage, String enabledImage, String disabledImage,
- boolean enabled, ImageRegistry imageRegistry) {
- setupAction(text,
- tooltip,
- imageRegistry.getDescriptor(hoverImage),
- imageRegistry.getDescriptor(enabledImage),
- imageRegistry.getDescriptor(disabledImage),
- enabled);
+ protected void setupAction(String text, String tooltip, String hoverImage, String enabledImage,
+ String disabledImage, boolean enabled, ImageRegistry imageRegistry) {
+ setupAction(text, tooltip, imageRegistry.getDescriptor(hoverImage), imageRegistry.getDescriptor(enabledImage),
+ imageRegistry.getDescriptor(disabledImage), enabled);
}
- protected void setupAction(String text, String tooltip,
- ImageDescriptor hoverImage, ImageDescriptor enabledImage, ImageDescriptor disabledImage,
- boolean enabled) {
+ protected void setupAction(String text, String tooltip, ImageDescriptor hoverImage, ImageDescriptor enabledImage,
+ ImageDescriptor disabledImage, boolean enabled) {
setText(text);
setToolTipText(tooltip);
setEnabled(enabled);
diff --git a/bundles/org.eclipse.remote.console/src/org/eclipse/remote/console/actions/IConsoleActionFactory.java b/bundles/org.eclipse.remote.console/src/org/eclipse/remote/console/actions/IConsoleActionFactory.java
new file mode 100644
index 0000000..fff843a
--- /dev/null
+++ b/bundles/org.eclipse.remote.console/src/org/eclipse/remote/console/actions/IConsoleActionFactory.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2016 QNX Software Systems 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:
+ * QNX Software Systems - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.remote.console.actions;
+
+import org.eclipse.core.runtime.IAdaptable;
+
+/**
+ * @since 1.1
+ */
+public interface IConsoleActionFactory {
+ public ConsoleAction createAction(String actionId, String connectionType, IAdaptable adapter);
+}
diff --git a/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/TerminalConsole.java b/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/TerminalConsole.java
index 8fdfc7b..011ad72 100644
--- a/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/TerminalConsole.java
+++ b/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/TerminalConsole.java
@@ -20,7 +20,6 @@
import org.eclipse.ui.part.IPageBookViewPage;
import org.eclipse.ui.progress.UIJob;
-@SuppressWarnings("restriction")
public class TerminalConsole extends AbstractConsole {
private final String encoding;
private final TerminalConsoleConnector terminalConnector;
diff --git a/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/TerminalConsoleExtensionManager.java b/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/TerminalConsoleExtensionManager.java
new file mode 100644
index 0000000..f9cbdb6
--- /dev/null
+++ b/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/TerminalConsoleExtensionManager.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2016 QNX Software Systems 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:
+ * QNX Software Systems - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.remote.internal.console;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.remote.console.actions.IConsoleActionFactory;
+
+public class TerminalConsoleExtensionManager {
+ private static TerminalConsoleExtensionManager instance;
+ private Map<String, List<String>> actions;
+ private Map<String, IConsoleActionFactory> factories;
+ private Map<String, IConfigurationElement> elements;
+
+ private TerminalConsoleExtensionManager() {
+ }
+
+ public static TerminalConsoleExtensionManager getInstance() {
+ if (instance == null) {
+ instance = new TerminalConsoleExtensionManager();
+ }
+ return instance;
+ }
+
+ public List<String> getActionsForType(String id) {
+ initialize();
+ List<String> list = actions.get(id);
+ return list == null ? new ArrayList<String>() : list;
+ }
+
+ public IConsoleActionFactory getFactory(String id) {
+ return factories.get(id);
+ }
+
+ private void initialize() {
+ if (actions == null) {
+ actions = new LinkedHashMap<>();
+ elements = new LinkedHashMap<>();
+ factories = new HashMap<>();
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IExtensionPoint point = registry
+ .getExtensionPoint(Activator.getDefault().getBundle().getSymbolicName() + ".toolbar");
+ for (IExtension extension : point.getExtensions()) {
+ for (IConfigurationElement element : extension.getConfigurationElements()) {
+ String id = element.getAttribute("id"); //$NON-NLS-1$
+ if (id != null) {
+ elements.put(id, element);
+ IConsoleActionFactory factory = null;
+ try {
+ factory = (IConsoleActionFactory) element.createExecutableExtension("actionFactory");
+ } catch (CoreException e) {
+ Activator.log(e);
+ }
+ if (factory != null) {
+ String connectionType = element.getAttribute("connectionType");
+ if (connectionType != null) {
+ List<String> actionList = actions.get(connectionType);
+ if (actionList == null) {
+ actionList = new ArrayList<>();
+ }
+ actionList.add(id);
+ actions.put(connectionType, actionList);
+ factories.put(id, factory);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/TerminalConsolePage.java b/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/TerminalConsolePage.java
index c426ecf..4e10ee6 100644
--- a/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/TerminalConsolePage.java
+++ b/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/TerminalConsolePage.java
@@ -11,7 +11,9 @@
package org.eclipse.remote.internal.console;
import java.io.UnsupportedEncodingException;
+import java.util.List;
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@@ -20,6 +22,9 @@
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.osgi.util.NLS;
+import org.eclipse.remote.console.actions.ConsoleAction;
+import org.eclipse.remote.console.actions.IConsoleActionFactory;
+import org.eclipse.remote.core.IRemoteConnection;
import org.eclipse.remote.internal.console.actions.ConsoleActionConnect;
import org.eclipse.remote.internal.console.actions.ConsoleActionDisconnect;
import org.eclipse.remote.internal.console.actions.ConsoleActionScrollLock;
@@ -40,9 +45,9 @@
import org.eclipse.ui.part.Page;
import org.eclipse.ui.progress.UIJob;
-@SuppressWarnings("restriction")
-public class TerminalConsolePage extends Page {
+public class TerminalConsolePage extends Page implements IAdaptable {
public static final String TOOLBAR_GROUP_ID = "org.eclipse.remote.internal.terminal.console.Toolbar"; //$NON-NLS-1$
+ public static final String CONTRIBUTIONS_GROUP_ID = "org.eclipse.remote.internal.terminal.console.Toolbar.contributions"; //$NON-NLS-1$
private final ConsoleActionConnect connectAction;
private final ConsoleActionDisconnect disconnectAction;
@@ -89,10 +94,29 @@
super.init(pageSite);
IToolBarManager toolBarManager = pageSite.getActionBars().getToolBarManager();
toolBarManager.insertBefore(IConsoleConstants.OUTPUT_GROUP, new GroupMarker(TOOLBAR_GROUP_ID));
+
toolBarManager.appendToGroup(TOOLBAR_GROUP_ID, connectAction);
toolBarManager.appendToGroup(TOOLBAR_GROUP_ID, disconnectAction);
toolBarManager.appendToGroup(TOOLBAR_GROUP_ID, new ConsoleActionScrollLock(this));
toolBarManager.appendToGroup(TOOLBAR_GROUP_ID, new CloseConsoleAction(terminalConsole));
+
+ toolBarManager.insertAfter(TOOLBAR_GROUP_ID, new GroupMarker(CONTRIBUTIONS_GROUP_ID));
+
+ addToolbarContributions(toolBarManager);
+ }
+
+ private void addToolbarContributions(IToolBarManager toolBarManager) {
+ String connectionType = terminalConsole.getConnection().getConnectionType().getId();
+ List<String> actions = TerminalConsoleExtensionManager.getInstance().getActionsForType(connectionType);
+ for (String id : actions) {
+ IConsoleActionFactory factory = TerminalConsoleExtensionManager.getInstance().getFactory(id);
+ if (factory != null) {
+ ConsoleAction action = factory.createAction(id, connectionType, this);
+ if (action != null) {
+ toolBarManager.appendToGroup(CONTRIBUTIONS_GROUP_ID, action);
+ }
+ }
+ }
}
@Override
@@ -175,4 +199,22 @@
return Status.OK_STATUS;
}
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T getAdapter(Class<T> adapter) {
+ if (adapter.equals(IRemoteConnection.class)) {
+ return (T) terminalConsole.getConnection();
+ }
+ if (adapter.equals(TerminalConsole.class)) {
+ return (T) terminalConsole;
+ }
+ if (adapter.equals(TerminalConsolePage.class)) {
+ return (T) this;
+ }
+ return null;
+ }
}
diff --git a/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/actions/ConsoleActionConnect.java b/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/actions/ConsoleActionConnect.java
index e3c97bf..a830e80 100644
--- a/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/actions/ConsoleActionConnect.java
+++ b/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/actions/ConsoleActionConnect.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.remote.internal.console.actions;
+import org.eclipse.remote.console.actions.ConsoleAction;
import org.eclipse.remote.internal.console.ImageConsts;
import org.eclipse.remote.internal.console.TerminalConsole;
diff --git a/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/actions/ConsoleActionDisconnect.java b/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/actions/ConsoleActionDisconnect.java
index b567063..3bece3b 100644
--- a/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/actions/ConsoleActionDisconnect.java
+++ b/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/actions/ConsoleActionDisconnect.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.remote.internal.console.actions;
+import org.eclipse.remote.console.actions.ConsoleAction;
import org.eclipse.remote.internal.console.ImageConsts;
import org.eclipse.remote.internal.console.TerminalConsole;
diff --git a/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/actions/ConsoleActionScrollLock.java b/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/actions/ConsoleActionScrollLock.java
index 28c7e4a..19c4596 100644
--- a/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/actions/ConsoleActionScrollLock.java
+++ b/bundles/org.eclipse.remote.console/src/org/eclipse/remote/internal/console/actions/ConsoleActionScrollLock.java
@@ -11,6 +11,7 @@
package org.eclipse.remote.internal.console.actions;
import org.eclipse.jface.action.IAction;
+import org.eclipse.remote.console.actions.ConsoleAction;
import org.eclipse.remote.internal.console.ImageConsts;
import org.eclipse.remote.internal.console.TerminalConsolePage;
diff --git a/features/org.eclipse.remote.console-feature/feature.xml b/features/org.eclipse.remote.console-feature/feature.xml
index 14ed391..49d35e7 100644
--- a/features/org.eclipse.remote.console-feature/feature.xml
+++ b/features/org.eclipse.remote.console-feature/feature.xml
@@ -2,7 +2,7 @@
<feature
id="org.eclipse.remote.console"
label="%featureName"
- version="2.0.2.qualifier"
+ version="2.1.0.qualifier"
provider-name="%providerName"
license-feature="org.eclipse.license"
license-feature-version="0.0.0">
diff --git a/features/org.eclipse.remote.console-feature/pom.xml b/features/org.eclipse.remote.console-feature/pom.xml
index df3490c..b472f1d 100644
--- a/features/org.eclipse.remote.console-feature/pom.xml
+++ b/features/org.eclipse.remote.console-feature/pom.xml
@@ -12,7 +12,7 @@
<groupId>org.eclipse.remote.features</groupId>
<artifactId>org.eclipse.remote.console</artifactId>
- <version>2.0.2-SNAPSHOT</version>
+ <version>2.1.0-SNAPSHOT</version>
<packaging>eclipse-feature</packaging>
<build>