Try OpenEdge Now
skip to main content
Application Developer's Guide
Using the Rule Wizard framework : Composing macros and editors
 

Composing macros and editors

In order to define more complex GUIs and data structures, you can define macros that contain macros and editors that contain editors. An example follows:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE template SYSTEM "resources/ruleTemplate.dtd" >
<template name="ex2">
<screen number="10">
    <editor macro="aggregate">
        <editor macro="text" label="Text">
        <parameter name="columns" value="30"/>
        </editor>
        <editor macro="list" label="List"/>
    </editor>
</screen>
<macro name="aggregate" type="composite">
    <macro name="text" type="varname"/>
    <macro name="list" type="combo-box">
        <vector-property name="listLabels">
            <vector-elem>Option A</vector-elem>
            <vector-elem>Option B</vector-elem>
            <vector-elem>Option C</vector-elem>
        </vector-property>
        <vector-property name="listValues">
            <vector-elem>option_a</vector-elem>
            <vector-elem>option_b</vector-elem>
            <vector-elem>option_c</vector-elem>
        </vector-property>
        <property name="listSelectedValue">option_b</property>
    </macro>
</macro>
<text>
Value of text is $aggregate.getMacro("text").
Value of list is $aggregate.getMacro("list").selectedValue.
</text>
</template>
Run as follows:
RuleWizard -t ex2.rtu
The List box is now added, as shown in Figure 24.
Figure 24. Rule wizard example 2
In this example, the composite macro contains two components: one is the varname macro, also used in the first example, and the combo-box macro.
The combo-box macro provide users with a list of possible values allowing them to choose. The listLabels vector property specifies the display names of the values and the actual values are specified in the listValues property. The listSelectedValue property is used to display the selected default value. Notice the new notion of a macro property. These properties are of type string, vector of strings, and hashtable containing strings as keys and values.
In this example, the <editor> tag contains other editors. The top editor is associated with the macro of type composite, with the name aggregate. Simple, non-qualified names are used to specify the macros for the editors inside, since associating the top editor with the macro aggregate makes the component editors search for their macros within this macro. The composite editor is able to generate an automatic layout for the component editor.
The size of the JTextField control has changed due to use of the <parameter> tag inside the <editor> tag.
Type Example2 in the text field, select Option C in the list, and click Finish. The following message appears on the console:
Value of text is Example2.
Value of list is option_c.
Notice how the macros within the aggregate macro are addressed in the code generation part of the rule template:
$aggregate.getMacro(list).selectedValue
In fact, you can invoke the getMacro method with the argument list, which is the component macro name. You can then request the value of the selectedValue property.