IntelliJ Community . PlusLibraryTutorial

 
PlusLibraryTutorial 

HOME INDEX SEARCH CHANGES GO  

Tutorial of extending PlusLibrary


Getting PLUS API

PLUS library jar distributed with PLUS plugin. You can get it throught Plugin Manager in IDEA (Pallada).

PLUS library archive have follow directory structure:

  + lib
     + src
         src_plus_jdk1.5.zip
     plus.jar
     forms_rt.jar
  CHANGES.txt

  • plus.jar - it PLUS API jar, requered to user library.
  • src_plus_jdk1.5.zip - is a sources for PLUS library writen in JDK 1.5

Using PLUS API

Reading plugin info from plugin.xml descriptor

Then you need to get info from plugin.xml descriptor of your plugin, you may use follow PLUS API:

  PluginDescriptorManager descriptorManager = PluginDescriptorManager.getInstance();
  PluginDescriptor descriptor = descriptorManager.getDescriptor();

  String pluginName = descriptor.getPluginName();
  String authorName = descriptor.getAuthorName();

  VirtualFile pluginHome = descriptor.getPluginDirectory();

  // ... etc

Reading options of other components in $IDEA_CONFIG_HOME/options/*.xml files

Then you need to get info from other components settings in IDEA config directory, such as "Browser Path" from IDE settings, you can use Options api:

  OptionsManager opm = OptionsManager.getInstance();
  OptionsDescriptor options = opm.getOptions(OptionsManager.IDE_GENERAL);
 
  // Read path to HTML browser
  String browserPath = options.getComponentOption("GeneralSettings", "browserPath");
 
  // Get whole XML element for component "GeneralSettings"
  Element element = options.getComponentElement("GeneralSettings");

  // ... etc

Localization of your plugin

If you like to support different languages, you need for localization. PLUS API support universal localizer, that concatenate two classes - ResourceBundle and MessageFormat:

  LocalizerManager lm = LocalizerManager.getInstance();
  Localizer localizer = lm.getLocalizer("my.bundle.name");
 
  String myValue = localizer.getString("myKey");
  String myFormatedValue = localizer.format("myFormatKey", new Object[] {"Hello!", new Date()});

Custom FileType registration

Then you design your ouw FileEditor you maybe need for file type registration for your editor. Then you may use PLUS API, FileTypeDescriptorManager class for it.

    FileTypeDescriptor ftd = new FileTypeDescriptor();
    ftd.setName("MyFileType");
    ftd.setDescription("My test FileType");
    ftd.setDefaultExtension("myext");
    ftd.setIconPath("/org/intellij/myEditor/resources/ext.png");
    FileTypeDescriptorManager ftdManager = FileTypeDescriptorManager.getInstance();
    ftdManager.registerFileType(ftd);

Real using in your plugin

How you can use PLUS API for real. There are very simple way - just create follow utility class for every your plugin:

  /**
   * Plugin utility.
   */
  public interface Plugin {
    /**
     * Localizer
     */
    Localizer localizer = LocalizerManager.getInstance().getLocalizer("org.intellij.yourPlugin.resources.strings");
  
    /**
     * Descriptor
     */
    PluginDescriptor descriptor = PluginDescriptorManager.getInstance().getDescriptor();
  
    /**
     * Default logger
     */
    Logger logger = Logger.getInstance(descriptor.getPluginName());
  
  }

Then you may just call to static fields of Plugin interface. Such as:

  // ...
  setTitle(Plugin.localizer.getString("wizard.panel.title"));
  // ...

-- AlexeyEfimov - 27 Oct 2004

e d i t a t t a c h r e f - b y d i f f s m o r e
Have ideas, requests, problems regarding this site? Send feedback.
Copyright © 2000-2003 by the contributing authors. All materials at intellij.org are the property of the contributing authors.