Saturday, November 17, 2007

Tips for Intellij IDEA plugins developers (my bloody experience)

1. How to get project with new API

Old fashion:

Project project = (Project)dataContext.getData(DataConstants.PROJECT);

New fashion:

Project project = DataKeys.PROJECT.getData(dataContext);

2. How to register tool window with new API

// Get toolwindow manager
ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);

// Register your tool window at desired location
ToolWindow toolWindow =
        toolWindowManager.registerToolWindow("your_toolwindow_id", true, ToolWindowAnchor.RIGHT);

// Prepare content panel of your tool window (all your controls)
JPanel yourContentPanel = ...

// Get peer factory
PeerFactory peerFactory = PeerFactory.getInstance();

// Create content
Content content = peerFactory.getContentFactory().createContent(yourContentPanel, "", false);

// Add created content

3. How to persist plugin properties with new API

If you did it for previous versions of IDEA, you probably have the following code:

public class YourPluginConfiguration
       implements ProjectComponent, Configurable, JDOMExternalizable {
  private final String COMPONENT_NAME = ...;
  publuc String yourProperty; // property to be persisted

  public String getComponentName() {
    return COMPONENT_NAME;

  public void readExternal(Element element) throws InvalidDataException {
    DefaultJDOMExternalizer.readExternal(this, element); // load

  public void writeExternal(Element element) throws WriteExternalException {
    DefaultJDOMExternalizer.writeExternal(this, element); // save


With new API you have to do something like this:

    name = YourPluginConfiguration.COMPONENT_NAME,
    storages = {@Storage(id = "your_id", file = "$PROJECT_FILE$")}
public final class YourPluginConfiguration
          implements ProjectComponent, Configurable, PersistentStateComponent<YourPluginConfiguration> {
  public static final String COMPONENT_NAME = ...;

  publuc String yourProperty; // property to be persisted

  public String getComponentName() {
    return COMPONENT_NAME;

  public YourPluginConfiguration getState() {
    return this; // load

  public void loadState(YourPluginConfigurationstate) {
    XmlSerializerUtil.copyBean(state, this); // save


In this example we use $PROJECT_FILE$ macro. You have to use appropriates macros according to component level.

There are 3 types of component level. Each of them has unique, only for this level macros:

- application-level components (ApplicationComponent): $APP_CONFIG$, $OPTIONS$;
- project-level components (ProjectComponent): $PROJECT_FILE$, $WORKSPACE_FILE$, $PROJECT_CONFIG_DIR$;
- module-level components (ModuleComponent): $MODULE_FILE$

4. How to register intention action

Usually intention action should be assoсiated with some analytical tool that recognizes important situation and indicates about it the user. We also can assoсiate intention action with changes in the editor.

First, your class should implement IntentionAction. Additionally, if you want to listen to editor changes,it should extend EditorAction:

public class YourIntentionAction extends EditorAction implements IntentionAction {

  public YourIntentionAction() {
    super(new YourEditorActionHandler());

  private static class YourEditorActionHandler extends EditorActionHandler /* or EditorWriteActionHandler */ {

    // This method is executed every time you do modifications in the editor.
    // Wev are trying to look for selections
    public void execute(Editor editor, DataContext dataContext) {
      String searchText = null;

      SelectionModel selection = editor.getSelectionModel();
      if (selection.hasSelection()) {
        searchText = selection.getSelectedText();

      if (searchText != null && searchText.trim().length() > 0) {
        // Displays pop up

        Project project = DataKeys.PROJECT.getData(dataContext);

        showPopup(project, editor, searchText);

   * Returns text to be shown in the list of available actions, if this action
   * is available.
  public String getText() {
    return "The text to show in the intention popup.";

   * Returns the identifier of the family of intentions. This id is used to externalize
   * "auto-show" state of intentions. When user clicks on a lightbulb in intention list,
   * all intentions with the same family name get enabled/disabled. The identifier
   * is also used to locate the description and preview text for the intention.
  public String getFamilyName() {
    return "popup";

   * Checks whether this intention is available at a caret offset in file.
   * If this method returns true, a light bulb for this intention is shown.
  public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
    return editor.getSelectionModel().hasSelection();

   * Called when user invokes intention. This method is called inside command.
   * If {@link #startInWriteAction()} returns true, this method is also called
   * inside write action.
  public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
    String searchText = null;

    SelectionModel selection = editor.getSelectionModel();

    if (selection.hasSelection()) {
      searchText = selection.getSelectedText();

    showPopup(project, editor, searchText);

   * Indicate whether this action should be invoked inside write action.
   * Should return false if e.g. modal dialog is shown inside the action.
   * If false is returned the action itself is responsible for starting write action
   * when needed, by calling {@link com.intellij.openapi.application.Application#runWriteAction(Runnable)}.
  public boolean startInWriteAction() {
    return false;

 private static void showPopup(Project project, Editor editor, String searchText) {
    JPanel panel = ... // Create your content here

    JBPopup jbPopup = JBPopupFactory.getInstance()
        .createComponentPopupBuilder(panel, panel)
        .setDimensionServiceKey(project, "popup", false)
        .setTitle("Your title")



You have to register your intention action. If you have project component, you can do it
in projectOpened() method:

  public void projectOpened() {
    IntentionManager.getInstance().addAction(new YourIntentionAction());

Useful links

1. Tutorial

2. Plugin Development FAQ

3. The Basics of Plugin Development for IntelliJ IDEA

4. IntelliJ IDEA 7.x Developers Documentation

5. IntelliJ Developing Custom Language Plugins for IntelliJ IDEA 5.0


Jacek Jaroczynski said...

Great article! There is very little information about new API so that short article is really helpful!!! Thanks!

Guy said...

Your post was a great help to me! Thanks man!

Anonymous said...

Do you like playing the game where you need to use flyff penya, when you do not have flyff money, you must borrow flyff gold from friends, or you buy flyff penya. If you get cheap penya, you can continue this game.
Do you like playing the game where you need to use priston tale Gold, when you do not have priston tale Money, you must borrow it from friends, or you buy priston tale Gold. If you getcheap priston tale Gold, you can continue this game.

Anonymous said...

Now do you worried about that in the game do not had enough second life linden to play the game, now you can not worried, my friend told me a website, in here you can buy a lot linden dollars and only spend a little money, do not hesitate, it was really, in here we had much secondlife money, we can sure that you will get the cheap linden, quick to come here to buy lindens.

Now do you worried about that in the game do not had enough requiem gold to play the game, now you can not worried, my friend told me a website, in here you can buy a lot requiem lant and only spend a little money, do not hesitate, it was really, in here we had much requiem money, we can sure that you will get the cheap requiem lant, quick to come here to buy requiem online gold.

Adi said...

Find Internet Marketing resource hare Online Marketing Strategy | Internet Marketing Tools | Online Marketing Campaign | Online Marketing Business | Online Marketing System | Online Business | Online Home Business | Online Business Tips | Internet Marketing Online

Anonymous said...

It was extremely interesting for me to read that blog. Thanx for it. I like such topics and everything that is connected to them. I definitely want to read a bit more soon.

Daniela said...

Interesting post. I have been wondering about this issue,so thanks for posting. I’ll likely be coming back to your blog. Keep up great writing. Find your great Travel News and sing the songs at Free Song Lyric or you can watch the drama at Korea Drama Online one of great korea drama is A Love to Kill if you go to travel to Indonesia learn Learn Indonesia Language first! And find your home cari rumah or make a blog Belajar membuat Blog find your home again rumah dijual and again at jual rumah then if you want buy a new laptop see the Laptop Price List or you can buy a New Blackberry and then take care your Health & Jewerly.

Anonymous said...

Hello everyone! Who knows where to upload the film Avatar?
I even bought the film Avatar for a SMS to , the link was, but download fails, the system will boot quite strange cocoa something.
Men, advise where to normal as quickly download film avatar?

Anonymous said...

Don't stop posting such articles. I love to read blogs like this. BTW add some pics :)

Anonymous said...

[url=]comercio digital escasino bonus [/url]
[url=]eurobet casino [/url]
[url=]casino terribles vegas [/url]
[url=]casino resort rio vegas [/url]
[url=]mirage vegas casino [/url]
[url=]pop 9 casino game [/url]
[url=]banda sonora casino royal [/url]
[url=]bingos y casinos [/url]
[url=]stardust casino vegas [/url]
[url=]san juan intercontinental resort casino san juan [/url]
[url=]best online casino directory [/url]
[url=]casino streep poker [/url]
[url=]casino agua caliente tijuana [/url]
[url=]sabadell casino sevilla [/url]
[url=]juego casino internet ruleta [/url]
linea casino
[b]fallsview casino niagara fall canada[/b]
descarga juego on line casino gratis
casinos online en espana
[b]black jack casino game[/b]
jeu casino
[u]add link online casino[/u]
sistemas casino
casinos en montevideo
[b]online casino[/b]
casino virtual pagina web
trucos casino

Anonymous said...

I sell a boat-program which will help you to outwit auction and to win, initially the boat was created for the Scandinavian auction but now the program can work with similar auctions: gagen ru, vezetmne ru and with ten.
The program-boat stakes for you, i.e. for this purpose it is not necessary to sit constantly at the monitor. The boat can set time when it is necessary to stake, thus you as much as possible will lower expenses for rates, and as much as possible increase the chances of a victory.

The price of the program a boat for the Scandinavian auctions 20$

For the first 10 clients the price 15$

To all clients free updating and support.

Behind purchases I ask in icq: 588889590 Max.

Anonymous said...

[b]Set software LoveBots v 5.2[/b]

All for a mass mailing dating

The script is written in php5


[i]registration, account activation
manual input captures, or the solution through antikapchu
filling data accounts:
- Gulf desired photo
- Инфы about yourself
- Diary
- Sexual preference[/i]

gulyalka on questionnaires spammer on lichku
- Randomization Posts: replacement of Russian letters in Latin analogues

optimized to work in a continuous loop
check-activation-filling-spam check ..

Updates and support free of charge.

Price per set 100 wmz

For the first 10 buyers price 70 wmz (your feedback on the software).

For shopping I ask in icq: 588889590 Max.

Scrin program:




Flooding in the subject no! Write to feedback after the purchase.

Anonymous said...


[url=]buy cigarette cards [/url]
buy cigarettes online from the states buy cigarette tubes aqua filter cigarette holders buy online
[url=]buy cigarette filters [/url]
buying cigarettes over the enternet buy carlton menthol 100 cigarettes where can you buy rockets cigarettes
[url=]order newport cigarettes [/url]
were to buy charter menthol cigarettes to buy e cigarette buying cigarette receptacles calgary alberta
[url=]buy cigarettes with check account [/url]
buying cigarettes online buy marlboro menthol cigarettes buying cigarettes on line
[url=]buy malboro cigarettes [/url]
cigarettes native indian mail order alternative cigaretts buy buy barclay 100 cigarettes
[url=]buy cigarettes online new york [/url]
safe site to buy cigarettes online buy some candy and cigarettes lyrics buy cigarettes in kentucky
[url=]how to order cigarettes online [/url]
cannabis cigarettes buy buy smokeless cigarettes uk law buying cigarette lighter

Anonymous said...

These online sports betting become widely patronized especially among the global masses. Since the globe contains a huge number of masses compared to the other two social statuses, the online sports betting is pouring a lot of money compared to Las Vegas - the betting capital of the world. [url=]bet online[/url] [url=]bet online[/url] [url=]bet online[/url] [url=]apuestas[/url] [url=]jouer en ligne[/url] [url=]bet online[/url] [url=]bet online[/url] [url=]bet online[/url] [url=]bet online[/url] [url=]bet online[/url] [url=]bet online[/url] [url=]bet online[/url] [url=]bet online[/url] [url=]bet online[/url] [url=]bet online[/url] When it comes time to place your wager, you should know how to bet the two most common types of wagers which is against the spread and betting the over/under.

Anonymous said...

Microsoft Office 2010
Office 2010
Office 2007
Microsoft Office
Microsoft Office 2007
Office 2007 key
Office 2007 download
Office 2007 Professional
Windows 7
Microsoft outlook 2010

power2balance said...

power balance
winter boots
Movado Bold
Baby Carriers
ecco shoes
Bakugan Toys
coach outlet store online purses 
Coach Outlet Store
2011 Coach Outlet Store Online
Coach Purses
coach outlet 
Coach Leather Hangbags
Cheap Coach Purses Wholesale 
Cheap Coach Bags Store
Coach Shoulder bags Outlet 
Coach Crossbody leather bags 
Coach Wallets Outlet
Coach Business Bags
Cheap Coach Backpacks 
Coach Sling Bags
Coach Hobos Bags 

Invertir en oro said...

hello, i think that this post is the best that i have read.

buy Crestor said...

greatest post I have seen.

hosted virtual call center said...

Thanks for the list, just submitted to them. Keep up the good work.

Anonymous said...

Viagra Online[url=] Viagra Online Without Prescription [/url]
Cheap Viagra[url=]Viagra [/url]
Cialis [url=] Non Prescription Cialis[/url]

Anonymous said...

Viagra Online Without Prescription[url=]Viagra Online Without Prescription[/url]

Anonymous said...

Viagra [url=]Viagra [/url]
Cialis [url=] Buy Cialis[/url]

Anonymous said...

valium, [url=]valium[/url],

valium, [url=]valium[/url],

valium, [url=]valium[/url],

valium, [url=]valium[/url],

valium, [url=]valium[/url],

Anonymous said...

Adderall Adderall Online
Adderall Online Adderall Online
Cheap Viagraviagra
Viagra Without Prescription viagra

Anonymous said...

Epgtqniwf [url=]オークリー サングラス[/url] Vfwmjlgcu Xcwtqijhs [url=]オークリー アウトレット[/url] Itstpilxq Rxjyukdwy [url=]オークリー ゴルフ[/url] Ynlkcudyi Eapwvdusa [url=]オークリー メガネ[/url] Vyrgfqhym Jjcgiqygo Jymyvywgx

Anonymous said...

Cheap Cialis Cheap Cialis

Anonymous said...

Duagegealiare Nike Justin Tucker Jersey
Duagegealiare Ray Lewis Jersey Super Bowl
usargoruist Jacoby Jones Super Bowl Jersey

Anonymous said...

Duagegealiare Ahmad Brooks Super Bowl Jersey
Duagegealiare Randy Moss Women's Jersey
usargoruist Haloti Ngata Super Bowl Jersey