From f4b6746d8b4e30567c352b21e8dc8253b1499665 Mon Sep 17 00:00:00 2001 From: Artem Zatsarynnyi Date: Tue, 30 Aug 2016 12:22:58 +0300 Subject: [PATCH] Add possibility to install Orion plugins for the CHE editor --- .../inject/OrionCodeEditWidgetProvider.java | 22 +++++++++++++++- .../orion/client/inject/OrionPlugin.java | 25 +++++++++++++++++++ .../jso/OrionCodeEditWidgetOverlay.java | 16 ++++++++---- 3 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/inject/OrionPlugin.java diff --git a/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/inject/OrionCodeEditWidgetProvider.java b/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/inject/OrionCodeEditWidgetProvider.java index 9fdcd7026ab..4345ebd6c78 100644 --- a/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/inject/OrionCodeEditWidgetProvider.java +++ b/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/inject/OrionCodeEditWidgetProvider.java @@ -10,6 +10,9 @@ *******************************************************************************/ package org.eclipse.che.ide.editor.orion.client.inject; +import com.google.gwt.core.client.GWT; +import com.google.gwt.core.client.JavaScriptObject; +import com.google.gwt.core.client.JsArrayString; import com.google.inject.Inject; import com.google.inject.Provider; import com.google.inject.Singleton; @@ -17,6 +20,9 @@ import org.eclipse.che.ide.editor.orion.client.jso.OrionCodeEditWidgetOverlay; import org.eclipse.che.ide.requirejs.ModuleHolder; +import java.util.HashSet; +import java.util.Set; + /** * Provider of Orion CodeEdit widget instance. * @@ -26,18 +32,32 @@ public class OrionCodeEditWidgetProvider implements Provider { private final ModuleHolder moduleHolder; + private final Set orionPlugins; private OrionCodeEditWidgetOverlay orionCodeEditWidgetOverlay; @Inject public OrionCodeEditWidgetProvider(ModuleHolder moduleHolder) { this.moduleHolder = moduleHolder; + orionPlugins = new HashSet<>(); + } + + @Inject(optional = true) + private void registerPlugins(Set plugins) { + for (OrionPlugin registrar : plugins) { + orionPlugins.add(registrar); + } } @Override public OrionCodeEditWidgetOverlay get() { if (orionCodeEditWidgetOverlay == null) { + JsArrayString plugins = JavaScriptObject.createArray().cast(); + for (OrionPlugin orionPlugin : orionPlugins) { + plugins.push(GWT.getModuleBaseURL() + orionPlugin.getRelPath()); + } + OrionCodeEditWidgetOverlay codeEditWidgetModule = moduleHolder.getModule("CodeEditWidget").cast(); - orionCodeEditWidgetOverlay = codeEditWidgetModule.create(); + orionCodeEditWidgetOverlay = codeEditWidgetModule.create(plugins); } return orionCodeEditWidgetOverlay; } diff --git a/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/inject/OrionPlugin.java b/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/inject/OrionPlugin.java new file mode 100644 index 00000000000..de437de862a --- /dev/null +++ b/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/inject/OrionPlugin.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2012-2016 Codenvy, S.A. + * 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: + * Codenvy, S.A. - initial API and implementation + *******************************************************************************/ +package org.eclipse.che.ide.editor.orion.client.inject; + +/** + * Interface for providing information needed for registering Orion plugin. + *

+ * Implementations of this interface need to be registered using + * a multibinder in order to be picked-up by CHE. + * + * @author Artem Zatsarynnyi + */ +public interface OrionPlugin { + + /** Returns path to the Orion plugin's html file. Path should be relative to the GWT's 'public' folder. */ + String getRelPath(); +} diff --git a/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/jso/OrionCodeEditWidgetOverlay.java b/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/jso/OrionCodeEditWidgetOverlay.java index c751f88ce36..fef2fa113f4 100644 --- a/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/jso/OrionCodeEditWidgetOverlay.java +++ b/plugins/plugin-orion/che-plugin-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/jso/OrionCodeEditWidgetOverlay.java @@ -11,6 +11,7 @@ package org.eclipse.che.ide.editor.orion.client.jso; import com.google.gwt.core.client.JavaScriptObject; +import com.google.gwt.core.client.JsArrayString; import com.google.gwt.dom.client.Element; import org.eclipse.che.api.promises.client.Promise; @@ -25,9 +26,14 @@ public class OrionCodeEditWidgetOverlay extends JavaScriptObject { protected OrionCodeEditWidgetOverlay() { } - /** Creates an Orion CodeEdit widget instance. */ - public final native OrionCodeEditWidgetOverlay create() /*-{ - return new this(); + /** + * Creates an Orion CodeEdit widget instance. + * + * @param plugins + * array of URLs of plugins that should be installed before CodeEdit widget initialization + */ + public final native OrionCodeEditWidgetOverlay create(JsArrayString plugins) /*-{ + return new this({userPlugins: plugins}); }-*/; /** @@ -43,10 +49,10 @@ public final native Promise createEditorView(final Eleme options.parent = element; return this.create(options); }-*/; - + /** * Provides Access to Orion's service registry. - * + * * @return the service registry */ public final native OrionServiceRegistryOverlay getServiceRegistry() /*-{