Creating a Jira plugin which creates screens on installation

Sometimes you want to create a Jira plugin which uses screens on it, but you don’t want to add the screens manually, thus the plugin itself has to install its own screens on installation which it is going to use.

Now in the plugin framework you have a file “atlassian-plugin.xml” which is where you insert modules which are going to be used by the plugin. This line of code:

<component key=”pluginInstaller” class=path-to-the-class-PluginInstaller /> 

has to be added in the ‘atlassian-plugin.xml’ and the class should have the following:

import com.atlassian.jira.component.ComponentAccessor;

import com.atlassian.jira.issue.fields.screen.FieldScreenImpl;

import com.atlassian.jira.issue.fields.screen.FieldScreen;

import com.atlassian.jira.issue.fields.screen.FieldScreenManager;

import org.springframework.beans.factory.DisposableBean;

import org.springframework.beans.factory.InitializingBean; 

public class PluginInstaller implements InitializingBean {

 

@Override

    public void afterPropertiesSet() throws Exception{

    // the code which add the screen

    }

now the class ‘PluginInstaller’ will be run on plugin installation and/or plugin enabling because it implements the interface “InitializingBean”.

Now lets add the screens :

First lets do a bit of background.

The screen (FieldScreen) doesn’t work on its own, it should have tabs (FieldScreenTab) which is where the fields will be added. And then the screen scheme (FieldScreenScheme) has to be added and associated to the screen (FieldScreen) so that the screen can be linked to the issue type or where ever you wish to use the screen.

Now here we are only covering the screens (the screen scheme and screen tabs will be covered later). Here is how to add screens:

FieldScreenManager fieldScreenManager =ComponentAccessor.getFieldScreenManager();

FieldScreen fieldScreen = new FieldScreenImpl(fieldScreenManager);

fieldScreen.setName(screenName);

fieldScreen.setDescription(screenDescription);

fieldScreenManager.createFieldScreen(fieldScreen);

Now this code above should add a screen of name ‘screenName’ and description ‘screenDescription


BY: CHRIS M, SOFTWARE DEVELOPER AT INFOWARE STUDIOS


Enhanced by Zemanta

Interesting Infoware Studios Bookmarks

1
  Related Posts

Comments

  1. jrcinco  January 7, 2015

    Thanks.. for the example.