Writing a Basic Plug-in

Follow these steps to write a basic plug-in for Content Studio:

  1. Set up the classpath

    In order to write the plug-in you need studio-api.jar and client-core.jar in your classpath. You will find these in either engine-distribution/contrib/lib or engine-distribution/lib.

  2. Create a subclass of StudioPlugin

    Use the following example as a basis. You must implement an initialize() method that uses the StudioContext object to retrieve the information it needs from Content Studio.

    public class CustomStudioPlugin extends StudioPlugin {
      
      public CustomStudioPlugin(final StudioPluginSpi pPluginSpi, final StudioContext pContext) {
        super(pPluginSpi, pContext);
      }
    
      @Override
      public void initialize() {    
        // You need to put your initialization code here.
        getContext().addLifeCycleListener(new StudioLifeCycleListener.Stub() {
          @Override
          public void userSessionStarted(final SessionEvent pEvent) {
            getContext().getContentEditorContainer().addEditorListener(new EditorListener.Stub() {
              @Override
              public void editorOpened(final EditorEvent pEvent) {
                // This example starts a background task when the editor is opened.
                // But you can do whatever you want.
                // You can also use other listener methods like editorClosed() etc.
                ResourceHandle handle = pEvent.getEditor().getResourceHandle();
                getContext().execute(new IconFetcherTask(getContext().getContentService(), handle));
              }
            });
          }
        });
      }
    }

    Note that getContentEditorContainer() is called inside the userSessionStarted() method implementation. This ensures that it does not get called until Content Studio is fully initialized and the ContentEditorContainer is available.

  3. Create a subclass of StudioPluginSpi

    Your subclass must override the createStudioPlugin() method and return an instance of the StudioPlugin subclass you created in the previous step.

    public class CustomStudioPluginSpi extends StudioPluginSpi {
      public CustomStudioPluginSpi() {
        super("Custom Studio Plugin", "1.0", "Escenic");
      }
    
      @Override
      public StudioPlugin createStudioPlugin(final String pId, final StudioContext pContext) {
        return new CustomStudioPlugin(this, pContext);
      }
    }