Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to install Orion plugins for the CHE editor #2262

Merged
merged 1 commit into from
Aug 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@
*******************************************************************************/
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;

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.
*
Expand All @@ -26,18 +32,32 @@
public class OrionCodeEditWidgetProvider implements Provider<OrionCodeEditWidgetOverlay> {

private final ModuleHolder moduleHolder;
private final Set<OrionPlugin> orionPlugins;
private OrionCodeEditWidgetOverlay orionCodeEditWidgetOverlay;

@Inject
public OrionCodeEditWidgetProvider(ModuleHolder moduleHolder) {
this.moduleHolder = moduleHolder;
orionPlugins = new HashSet<>();
}

@Inject(optional = true)
private void registerPlugins(Set<OrionPlugin> 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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
* <p>
* 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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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});
}-*/;

/**
Expand All @@ -43,10 +49,10 @@ public final native Promise<OrionEditorViewOverlay> 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() /*-{
Expand Down