Making a Plug-in Task

In order to ensure that your plug-in does not make the Content Studio user interface freeze up, you must never directly include any code that executes potentially time-consuming operations. You must always create plug-in tasks for such operations, in order to ensure that they are handled correctly.

You can create a plug-in task by extending the com.escenic.studio.plugins.PluginTask class. The following example shows the outline of an IconFetcherClass that is intended to retrieve an icon from the web or a file system and do something with it. Any code involving such a retrieval operation should always be implemented as a plug-in task.

  private class IconFetcherTask extends PluginTask<Icon> {
    
    @Override
    public String getTitle() {
      return "Icon Fetcher";
    }

    @Override
    public Icon doInBackground() throws Exception {
      // In this method you can do some long running operations.
      Icon icon = fetchIconFromSomePlace();
      return icon;
    }

    @Override
    public void succeeded(Icon pIcon) {
      // Do something with the icon here
    }
  }

Once you have defined a plug-in task in this way, you can call it from your plug-in class using StudioContext.execute():

getContext().execute(new IconFetcherTask());

For further information see the PluginTask Javadoc.