/*******************************************************************************
* Copyright (c) 2008 Hallvard Traetteberg.
* 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:
* Hallvard Traetteberg - initial API and implementation
******************************************************************************/
package org.eclipse.e4.tm.ui;
import java.util.ArrayList;
import java.util.List;
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.Platform;
import org.eclipse.e4.tm.ui.editor.IPostProcessor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.e4.tm.ui";
// The shared instance
private static Activator plugin;
/**
* The constructor
*/
public Activator() {
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
Activator.plugin = this;
}
/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
Activator.plugin = null;
super.stop(context);
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static Activator getDefault() {
return Activator.plugin;
}
private List<IPostProcessor> postProcessors = null;
private void processPostProcessModelExtensionPoint() {
IExtensionPoint ep = Platform.getExtensionRegistry().getExtensionPoint(getBundle().getSymbolicName(), "postProcessor");
IExtension[] extensions = ep.getExtensions();
for (int i = 0; i < extensions.length; i++) {
for (IConfigurationElement ces: extensions[i].getConfigurationElements()) {
String name = ces.getName();
if ("postProcessor".equals(name)) {
processPostProcessModelElement(ces);
}
}
}
}
private void processPostProcessModelElement(IConfigurationElement ces) {
try {
IPostProcessor postModelProcessor = (IPostProcessor)ces.createExecutableExtension("postProcessorClass");
postProcessors.add(postModelProcessor);
} catch (CoreException e) {
System.err.println("Couldn't create a IPostProcessModel for " + ces.getAttribute("postProcessorClass"));
}
}
public IPostProcessor[] getPostProcessors() {
if (postProcessors == null) {
postProcessors = new ArrayList<IPostProcessor>();
processPostProcessModelExtensionPoint();
}
return postProcessors.toArray(new IPostProcessor[postProcessors.size()]);
}
}