blob: f8d790ab4560abf3508dbecf02a07715af2f981c [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2018 Agence spatiale canadienne / Canadian Space Agency
* 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:
* Pierre Allard,
* Regent L'Archeveque,
* Sebastien Gemme - initial API and implementation
*
* SPDX-License-Identifier: EPL-1.0
*
*******************************************************************************/
package org.eclipse.apogy.common.topology.ui.jme3;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.apogy.common.topology.Node;
import org.eclipse.apogy.common.topology.ui.AdapterFactory;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.Platform;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Activator implements BundleActivator {
private static final Logger Logger = LoggerFactory.getLogger(Activator.class);
public static final String ID = "org.eclipse.apogy.common.topology.ui.jme3";
public static final String JME3_EXTENSION_POINT_ID = "org.eclipse.apogy.common.topology.ui.jme3.jme3Adapter";
private static final String JME3_EXTENSION_POINT_ID_CLASS = "Class";
private static BundleContext context;
private static Activator plugin;
private AdapterFactory<JME3Adapter, JME3SceneObject, Node, Object> jme3AdapterFactory;
public static BundleContext getContext() {
return context;
}
/*
* (non-Javadoc)
*
* @see
* org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext )
*/
@Override
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
Activator.plugin = this;
}
/*
* (non-Javadoc)
*
* @see
* org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
@Override
public void stop(BundleContext bundleContext) throws Exception {
Activator.context = null;
}
public AdapterFactory<JME3Adapter, JME3SceneObject, Node, Object> getJME3AdapterFactory() {
if (this.jme3AdapterFactory == null) {
List<JME3Adapter> adapters = getRegisteredJME3Adapters();
this.jme3AdapterFactory = new AdapterFactory<JME3Adapter, JME3SceneObject, Node, Object>(adapters);
}
return this.jme3AdapterFactory;
}
public List<JME3Adapter> getRegisteredJME3Adapters() {
List<JME3Adapter> adapters = new ArrayList<JME3Adapter>();
IExtensionPoint nodePresentationExtPoint = Platform.getExtensionRegistry()
.getExtensionPoint(JME3_EXTENSION_POINT_ID);
IConfigurationElement[] contributors = nodePresentationExtPoint.getConfigurationElements();
for (int i = 0; i < contributors.length; i++) {
IConfigurationElement contributor = contributors[i];
try {
JME3Adapter adapter = (JME3Adapter) contributor
.createExecutableExtension(JME3_EXTENSION_POINT_ID_CLASS);
adapters.add(adapter);
} catch (CoreException e) {
Logger.error(e.getMessage(), e);
}
}
return adapters;
}
public static Activator getDefault() {
return plugin;
}
}