Text Folding
Text folding (folding) In fact, at Eclipse 2.1, there has been a symptom, after Eclipse 3.0, the text collapsed architecture has been redesigned, beginning to become practical. Let's take a look at what JTF does for text folding.
Projectionviewer
Sourceviewer itself does not support text folding, so JTF adds a projectionviewer specifically supports text folding, which is a subclass of Sourceviewer.
Master-Slave Document structure
JTF It is impossible to wonder which texts can be folded, and these things have to be told. In the case of text folding, we can see only a part of the text, but the created IDocument instance contains all the text, how can we know what should not be displayed? So JTF introduces a master/slave (master/detail) document schema, where the main document is a document that contains all the content, while the document contains only what the user can see, and the implementation class from the document is projectiondocument. Since there are two of documents, then there is the problem of synchronization, so the introduction of Projectiondocumentmanager to maintain the master-slave document synchronization. It is important to note that Projectiondocument cannot be created directly, and must be created by the Projectiondocumentmanager Createslavedocument method.
The good news is that we don't have to care about the master-slave document architecture When we implement text folding, because it's all wrapped up in JTF, and at the top we see only one document.
Projectionannotation
As you can see in the Java editor, there is a small icon next to the fold, which shows the current folding state and can be clicked to change the folding state. From the interface, you should be able to think: this is not a callout? Yes, it is, but the callout is displayed on another ruler, which is different from the ruler that displays the error annotation. The implementation class of text folding annotation is projectionannotation, in the process of realizing text folding, it is very important to refresh projectionannotation in time.
I mentioned a lot of concepts related to annotations when I covered the text in part V of this series, and they also apply to text folding annotations. For example, you can customize the appearance of callouts by Idrawingstrategy, which by default is an ellipsis. As shown in the following illustration:
Figure 1. Default text collapse callout appearance