Skip Navigation

Adding an Activator Class to a Plugin

Before you begin, you need a plug-in that requires an Activator class.

This procedure shows how to implement an Activator class using the AbstractEdgeBasePlugin and AbstractUiPlugin classes. The procedure excludes the use of the BundleActivator class.

  1. Open the plug-in project to which you will add an Activator.

  2. On the Dependencies tab in the manifest editor, add com.sabre.edge.platform.core.common.

  3. Open the Overview tab.

image002
  1. Select This plug-in is a singleton.

        If your plug-in already has an Activator class, this class is displayed in the Activator field.

  1. If your plug-in does not have an Activator class, click the Activator link in the General Information group.

        On the New Java Class dialog, you will extend the Activator class.

image004

 

  1. In the Package field, type the name of your package.

  1. In the Name field, type the name of your class. The recommended name is Activator.

  1. For Superclass, type one of the following values for the implementation that you want:

Does your plug-in contribute to the UI?

Extend this superclass in the Superclass field.

The superclass is located as follows.

No

AbstractEdgeBasePlugin

com.sabre.edge.platform.core.common.plugin.base + AbstractEdgeBasePlugin

Yes

AbstractUiPlugin

org.eclipse.ui.plugin.AbstractUIPlugin

  1. Select the following check boxes:

    •         Constructor from superclass

    •         Inherit abstract methods

  1. Click Finish.

  1. Save MANIFEST.MF.

  2. In a Java editor, do the following:

    • Override the start() and stop() methods.

    • Implement the static method getDefault() .

    • Substitute the name of your plug-in for plugin. The name should match the plug-in in the manifest.

        Extending AbstractEdgeBasePlugin forces the plug-in to use org.eclipse.ui .

        Call getDefault() at runtime to return the plugin instance.

        The code sample below shows an Activator.

import org.osgi.framework.BundleContext;
import com.sabre.edge.platform.core.common.plugin.base.AbstractEdgeBasePlugin;

public class Activator extends AbstractEdgeBasePlugin {

  private static Activator plugin;

  public Activator() {
  }

  public void start(BundleContext context) throws Exception {
    super.start(context);
    plugin = this;
  }

  public void stop(BundleContext context) throws Exception {
    plugin = null;
    super.stop(context);
  }

  public static Activator getDefault() {
    return plugin;
  }
}

 

  1. Save the changes to your Java code.

  1. Open MANIFEST.MF. On the Overview tab, select Activate This Plug-in When One of Its Classes Is Loaded.

image006
  1. Save MANIFEST.MF.

Using Activator with a Website

  1. If your plug-in integrates a website that is based on HTML, you must add the PLUGIN_NAME constant to your Activator. You can either hard code this constant, or you can use internationalization methods.

public static final String PLUGIN_NAME = "Example Browser";
  1. If you want to translate or internationalize a plug-in that is based on a browser, you can add the following code to define PLUGIN_NAME. You will also add the keys to Messages.java and add messages.properties for the languages that you want.

public static final String PLUGIN_NAME = Messages.PLUGIN_NAME;