Module platform

Class TemplateCompletion

java.lang.Object
de.grogra.pf.ui.autocomplete.impl.AbstractCompletion
de.grogra.pf.ui.autocomplete.impl.TemplateCompletion
All Implemented Interfaces:
Completion, ParameterizedCompletion, Comparable<Completion>

public class TemplateCompletion extends AbstractCompletion implements ParameterizedCompletion
A completion made up of a template with arbitrary parameters that the user can tab through and fill in. This completion type is useful for inserting common boilerplate code, such as for-loops.

The format of a template is similar to those in Eclipse. The following example would be the format for a for-loop template:

 for (int ${i} = 0; ${i} < ${array}.length; ${i}++) {
    ${cursor}
 }
 
In the above example, the first ${i} is a parameter for the user to type into; all the other ${i} instances are automatically changed to what the user types in the first one. The parameter named ${cursor} is the "ending position" of the template. It's where the caret moves after it cycles through all other parameters. If the user types into it, template mode terminates. If more than one ${cursor} parameter is specified, behavior is undefined.

Two dollar signs in a row ("$$") will be evaluated as a single dollar sign. Otherwise, the template parsing is pretty straightforward and fault-tolerant.

Leading whitespace is automatically added to lines if the template spans more than one line, and if used with a text component using a PlainDocument, tabs will be converted to spaces if requested.

In order to use any instance of a ParameterizedCompletion, you need to call AutoCompletion#setParameterAssistanceEnabled(boolean) with a value of true first. Otherwise, any completion choices will be visible in the completion list, but won't insert anything when selected.

Version:
1.0
Author:
Robert Futrell