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}
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 %}
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 %}
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 %}
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>
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: