Adding custom code templates

Textual patterns, or templates, can be regarded as an abstraction like a form ready for "filling in" for a specific instance. See Using Code Templates for details of the code templates handling.

Templates replace blueprints of the older versions, which are now obsolete, but still supported.

Templates reside in the $TGH$/Templates folder that contain separate sub-folders for Java, C++ and IDL templates. Each language provides support for class, link and member templates. Each class template is stored in a subfolder whose name corresponds to the name of this template and called %Name%.*, with the expension for the appropriate language. Link and member templates have the template name with the *.link and *.member extension respectively. Properties of the template are defined in an optional file template_name.properties in the same subfolder. This file includes values that will be substituted instead of the macros, when a new object is generated, flag that specifies whether this template will be displayed in the Pattern Chooser, and other information.

Possible properties are:

defaultName

The name on the created object, that is used as a starting value. For example, Class1 for the first generated class, Class2 for the next one etc.

defaultType

Defines types of the attributes and return types of the operations.

hideInChooseList

If this property is present in the *.properties file, the template will be ignored by the Pattern Chooser panel.

generatePrologueEpilogue

If true, pre-defined prologue and epilogue will be generated

pasteClassesToOneFile

Some of the class and interface templates stipulate generation of two classes. If this flag is true, both objects are generated in a single file.

singleOccurrencePerClass

This property refers to the operators and members, and specifies that this operator or member can occur in the generated class only once.

patternDescription

Contains brief description of this pattern in HTML format.

doNotKeepTag

Contains the tag name that should not be preserved when an object is replaced with another one. For example, doNotKeepTag=link means that the link tag should be ommitted in a new link.

Textual pattern Default class is used every time a new class is created. Same refers to the interfaces, associations, aggregations, dependencies etc., whose names begin with "Default_". These templates never show up in the Pattern Chooser panel.

WARNING:  NEVER play around the default templates. Improper modifications can result in improper functioning of Together, and make it impossible to create classes, interfaces etc. in the diagrams.

Creating custom code templates


  1. According to the type of the required template type (class, link or member) and language, create a folder in the appropriate location. The name of this folder should be the same as the name of template being created. Spaces in the folder name are not allowed and should be replaced with underscores. Further, when this pattern is displayed in the Pattern Chooser panel, the underscores in the folder name will be substituted with spaces. For example: Templates\CPP\CLASS\My_pattern.

  2. In this folder create file %Name%.h (for C++), %Name%.idl (for IDL) or %Name%.java (for Java), and optional properties file, whose name is the same as the template folder name.

  3. Write your contents of these files. If you want your template to show up in the Pattern Chooser panel, do not include hideInChooseList=true in the properties file.

Tip: Even if you set this flag false, the Pattern Chooser panel still ignores the template. This line should be ommitted.

  1. The newly created templates show up in Together's Explorer pane with the next start. Now you can use the new templates to create classes and links by patterns.

  2. There is a rigid dependency between the template type and contents of the inspector. For the classes and interfaces a single control with the class name appears in the inspector. The value of the class name replaces %Name% macro in the template.

For the Links the field "Name" is related to the %Name% macro, and the field "Link destination" is related to $Dst$ macro.

For the Members (attributes or operations) there is the field "Name" for %Name% macro, and the field "Type" for %Type% macro.

If a certain macro is not included into the template body, the corresponding field does not show up in the inspector. Besides the standard macros, unlimited amount of the user-defined macros are allowed for all template types.

The names of the user-defined macros follow the same syntax rules as the template folder names (spaces not allowed). Inspector provides special control for each macro with the name of this macro, with the underscores replaced with the spaces. Example: Control "Some name" corresponds to the macro %Some_name%.