"Eclipse plug-in Development" based on WTP development of custom JSP editors (12)

Source: Internet
Author: User

Custom Auto Edit policy (auto Edit strategy)

An important feature of the JFace Text Framework is the automatic editing strategy, which allows the user to edit the input content (accurately, the upcoming document modification ^_^), and then transparently put the user's changes into effect (i.e. Apply to the current document). In this section, we will develop an automatic editing strategy based on the previous two sections on the TLD Content model.

"JFace Text Framework Automatic editing Strategy principle Introduction"

"JDT Java Source Editor auto edit Policy Demo"

Each of our developers using the Eclipse JDT for Java programming will be impressed by the automatic editing strategy for the Java source Editor in Jdt, which is a great convenience to coders. Examples are as follows:

As shown in the figure above, we are writing a new function, the black vertical line "|" in the figure Where the cursor is, when we press the ENTER key, the effect changes as follows:

As shown in the figure above, when we enter the ENTER key, the JDT Java Source Editor automatically corrects the content (text) and location (offset): The original input should be "\ r \ n", JDT the Java source Editor to automatically help us to correct the "\r\n\t\t\r\n\t} According to the "\ r \ n" content, the cursor position should be positioned at the beginning of Line 28, and the JDT Java Source Editor will automatically help us to correct the distance of two "T" from 28 lines.

"Automatic editing processes and primary roles"

The following illustration shows the automatic editing process:

1, user edit, keyboard events

2, according to the keyboard events, analysis of event information, assembled into a data structure named Documentcommand, which contains the user's input (text), cursor position (offset) and other information, for example, the above JDT example of the user's input is "\ r \ n ”。 This step jface Text framework to help users solve.

3, call the automatic editing strategy, corresponding to the Documentcommand data for customization, for example, JDT Java Source Editor's automatic editing policy to correct the input content to "\r\n\t\t\r\n\t}". The user is responsible for the JDT Java Source Editor working here, providing its own iautoeditstrategy ^_^

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.