Skip to content

Latest commit

 

History

History
55 lines (42 loc) · 3.26 KB

structure_view_factory.md

File metadata and controls

55 lines (42 loc) · 3.26 KB
title
14. Structure View Factory

The structure view can be customized for a specific file type. Creating a structure view factory allows showing the structure of any file in a Structure Tool Window for easy navigation between items in the current editor.

Reference: Structure View

  • bullet list {:toc}

14.1. Define a Structure View Factory

The structure view factory implements PsiStructureViewFactory. The getStructureViewBuilder() implementation reuses the IntelliJ Platform class TreeBasedStructureViewBuilder. At this point the project will not compile until SimpleStructureViewModel is implemented below.

{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleStructureViewFactory.java %}

14.2. Define a Structure View Model

The SimpleStructureViewModel is created by implementing StructureViewModel, which defines the model for data displayed in the standard structure view. It also extends StructureViewModelBase, an implementation that links the model to a text editor.

{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleStructureViewModel.java %}

14.3. Define a Structure View Element

The SimpleStructureViewElement implements StructureViewTreeElement and SortableTreeElement. The StructureViewTreeElement represents an element in the Structure View tree model. The SortableTreeElement represents an item in a smart tree that allows using text other than the presentable text as a key for alphabetic sorting.

{% include /code_samples/simple_language_plugin/src/main/java/org/intellij/sdk/language/SimpleStructureViewElement.java %}

14.4. Register the Structure View Factory

The SimpleStructureViewFactory implementation is registered with the IntelliJ Platform in the plugin configuration file using the com.intellij.lang.psiStructureViewFactory extension point.

  <extensions defaultExtensionNs="com.intellij">
    <lang.psiStructureViewFactory language="Simple" 
            implementationClass="org.intellij.sdk.language.SimpleStructureViewFactory"/>
  </extensions>

14.5. Run the Project

Rebuild the project, and run simple_language_plugin in a Development Instance. Open the test.simple file and choose View | Tool Windows | Structure. The IDE now supports a structure view of the Simple Language:

Structure View