2.6.3 Data types
In this section we discuss the data types available in
MetaEdit+ and how they appear to users in property dialogs. To set the data type
for a property, use the Data Type pull-down list in the Property Tool. If
you select a metatype (Graph..., Object..., Port..., Relationship... or Role...)
a dialog will prompt for selection of a particular type of that
metatype.
Figure 2–17. Data type selection.
String
The string data type is an ordinary character string without
any formatting. Each String property type can have its own Default Value; by
default it is empty.
Figure 2–18. Widget selection.
The
Widget
pull-down list (
Figure 2–18)
is used to select among a list of possible widgets used in property dialogs for
entering a string value. The possible widgets and their settings are described
in Section
2.6.4.
Text
Text is used for longer descriptions. The text can contain
carriage returns, tabs etc., and also basic text formatting (fonts, bold, italic
etc.). The text widget
is shown as a multi-line text box
with a vertical scroll bar
. Text properties can also be
opened in a Text Editor, useful for text formatting or longer texts. Each Text
property type can have its own Default Value; by default it is
empty.
Number
Number can contain any integer, scientific or real number. The
widget
for number is a single line box. Each Number
property type can have its own Default Value; by default it is 0.
Normally, it is better to use a String, since although a
property may initially appear to only contain numbers, it may later be found
useful to allow some strings too, e.g. to represent common constants. Input can
be restricted with the
Value Regex field, e.g. using the regex generator
at
http://utilitymill.com/utility/Regex_For_Range.
Boolean
A Boolean property holds the value true or false. The
widget
for a Boolean property is a check box. When a
Boolean property must be displayed as a string elsewhere in the user interface,
it will show T or F. Each Boolean property type can have its own Default Value;
by default it is false.
Figure 2–19. Property Tool for Boolean.
Creation Timestamp
A creation timestamp stores the element creation time. The
value is stored as a UTC timestamp, and offset by the local timezone when
displaying. Its value cannot be changed, thus the widget
for timestamp is a read-only input field. Creating a new copy of an element
containing a creation timestamp (e.g. by Paste Special with deep copy) will
result in an entirely new timestamp too.
Collection
The Collection data type defines a list of strings or objects,
initially empty, in which the user can add and delete items. The
widget
for Collection is a list box with a vertical
scroll bar.
An example of a collection can be found from the Watch
example in type Display, which includes collections of Icons, UnitZones and
Buttons. Each of these has properties of their own and these properties could
again be collections themselves. MetaEdit+ does not limit the number of such
levels of complex properties.
Selecting the Collection data type adds an
Item
type pull-down list to the Property Tool window,
showing the data type of the members of this list. The list members can be
strings, graphs, objects, ports, roles or relationships. If you select a
metatype (i.e. anything other than String) a dialog will prompt for selection of
a particular type of that metatype. That type will then be shown in the
Item
type field.
When a type is chosen the list members can always be not
only of the type specified in the
Item type field, but also of any type
which inherits from that type. In some exceptional circumstances it may be
desirable to specify the supertype of all the types of that metatype, e.g.
Object: you can do this by selecting the metatype from the
Item type
pull-down list with shift held down, and that metatype will then be included in
the list of types to select from.
Graph, Object, Relationship,
Role
An individual graph, object, relationship or role can also be
used as the value of a property. In this section we discuss object types, but
the same applies for the other non-property types as well.
The Object data type allows you to specify a property
whose content will be an object of a selected type. When you select this data
type, the tool further asks you to specify the object type, which is the type of
the objects that can be attached to this field. Again, instances of subtypes of
this type are also allowed as values for this kind of property. In some
exceptional circumstances it may be desirable to specify the supertype of all
the types of that metatype, e.g. Object: you can do this by selecting the
metatype from the pull-down list with shift held down, and that metatype will
then be included in the list of types to select from.
The widget
for the Object data type
is similar to a String property’s Input Field, except that the background
is gray, showing that you cannot type directly there. The box shows the
identifier of the currently attached object. In place of the normal text editing
operations in the pop-up menu, there are operations for editing the attached
object, or opening its representation.
Figure 2–20. Property Tool with a DisplayFn object as the data type.
This
data type — containing other non-property instances — is a very
powerful tool for several purposes. It can be used for attaching whole objects
or graphs into one property of another object or graph type and thus allowing
complex data structures.
When the modeler is adding a new element in such a
property, if the data type specified in the Property type has subtypes then he
will be prompted to choose a subtype to instantiate. Abstract types (i.e. types
whose name begins with an underscore, ‘_’) cannot be instantiated,
so choosing one will prompt to choose from one of its subtypes. Hidden types
(i.e. types whose name begins with a double underscore, ‘__’) will
not be shown, but instead replaced in the hierarchy by their subtypes, raised up
a level in the hierarchy as if the intermediate level of the hidden type had not
been present at
all.