Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
SV: [subversive-dev] Using "Core Configuration Options" extensionpoint

>Hello Jesper,
>
>As you wrote we take only first extension and unfortunately currently there's no way to work around it.


I found a way around the registration problem.

My option provider implementation (JbOptionProvider) is registered as an extension to "coreoptions".

The plugin the provider is placed in uses this Plugin class to hook into SVNTeamPlugin, replacing the default option provider with my own.

Works a charm, even though it is a bit of a hack.

Cheers,
Jesper



package jb.itu.ti.subversion.subversive.authentication.plugin;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
import org.eclipse.team.svn.core.SVNTeamPlugin;
import org.eclipse.team.svn.core.extension.CoreExtensionsManager;
import org.eclipse.team.svn.core.extension.options.IOptionProvider;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener;

/**
 * The activator class controls the plug-in life cycle.
 * It hooks into SVNTeamPlugin and replaces their IOptionProvider with the JB variant.
 */
public class Activator extends Plugin implements BundleListener {
	// The plug-in ID
	public static final String PLUGIN_ID = "jb.itu.ti.subversion.subversive.authentication.plugin";

	// The shared instance
	private static Activator plugin;
	
	/**
	 * The constructor
	 */
	public Activator() {}
	
	/*
	 * (non-Javadoc)
	 * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
	 */
	public void start(BundleContext context) throws Exception {
		super.start(context);
		plugin = this;

		// Register this class as a bundle listener, and hook into the SVNTeamPlugin
		// when the bundle loading has completed.
		context.addBundleListener(this);
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
	 */
	public void stop(BundleContext context) throws Exception {
		plugin = null;
		super.stop(context);
	}

	/**
	 * Returns the shared instance
	 *
	 * @return the shared instance
	 */
	public static Activator getDefault() {
		return plugin;
	}

	/**
	 * Write message to info log.
	 * @param msg message to write.
	 */
	public void logInfo(String msg) {
		getLog().log(new Status(IStatus.INFO, getDefault().getBundle().getSymbolicName(), msg));
	}

	/**
	 * This listener is set up to make the necessary hooks into SVNTeamPlugin after
	 * the containing bundle has completed loading.
	 * After it sees the containing bundle completing, it removes itself.
	 */
	@Override
	public void bundleChanged(BundleEvent bundleevent) {
		String bundleSymbolicName = bundleevent.getBundle().getSymbolicName();
		if (bundleSymbolicName.equals(PLUGIN_ID)) {
			// Remove the listener after first entry 
			bundleevent.getBundle().getBundleContext().removeBundleListener(this);

			// Replace SVNTeamPlugin IOptionProvider with JB variant
			IOptionProvider optionProvider = SVNTeamPlugin.instance().getOptionProvider();
			IOptionProvider jbOptionProvider = new JbOptionProvider(optionProvider);
			CoreExtensionsManager.instance().setOptionProvider(jbOptionProvider);
		}
	}
}



Back to the top