Try OpenEdge Now
skip to main content
Application Developer's Guide
Using the Rule Wizard framework : Skipping a macro
 

Skipping a macro

The following template provides a simple technique that enables you to decide at run time what macros to show in one of the wizard steps.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE template SYSTEM "resources/ruleTemplate.dtd" >
<template name="test">
<label>
    <istring lang="en">test</istring>
</label>
<screen number="10">
    <editor macro="list" label="List"/>
</screen>
    
<screen number="20">
    <editor macro="ref1" label="Reference 1"
class="com.savvion.rulewizard.gui.TextEditor"/>
</screen>
    
<screen number="25">
    <editor macro="ref2" label="Reference 2"
class="com.savvion.rulewizard.gui.TextEditor"/>
</screen>
    
<screen number="30">
    <editor macro="text" label="Text"/>
</screen>
    
<macro name="list" type="combo-box">
    <vector-property name="listLabels">
        <vector-elem>Optional macro 1</vector-elem>
        <vector-elem>Optional macro 2</vector-elem>
        <vector-elem>None</vector-elem>
    </vector-property>
    <vector-property name="listValues">
        <vector-elem>ref1</vector-elem>
        <vector-elem>ref2</vector-elem>
        <vector-elem>none</vector-elem>
    </vector-property>
    <property name="listSelectedValue">option_a</property>
</macro>
    
<macro name="ref1" class="MyVarname">
    <reference name="option" value="list.selectedValue"/>
    <property name="show_for_option">ref1</property>
</macro>
    
<macro name="ref2" class="MyVarname">
    <reference name="option" value="list.selectedValue"/>
    <property name="show_for_option">ref2</property>
</macro>
    
<macro name="text" type="varname">
</macro>
    
<text>
Value of list is $list.selectedValue.
Value of ref1 is $ref1.
Value of ref2 is $ref2.
Value of text is $text.
</text>
</template>
When you run the above template, what you see in the second step of the Wizard depends on the value chosen in the list box presented in the first step. For example, if the chosen value is "Optional macro 1," then you will receive the macro ref1 in the second step. Otherwise, you will receive the macro ref2. Although the same editor is used for both macros, note the difference in the labels, "Reference 1" and "Reference 2", as well as the changes in the Wizard output.
The following example shows the Wizard output in the case where "Optional macro 2" is chosen.
Figure 29. Optional Macro 2 choice
The output for this example is as follows:
Value of list is ref2.
Value of ref1 is null.
Value of ref2 is value2.
Value of text is text_value.
In the template, the screen numbered 20 was skipped because the only macro it contained, ref1, returned the value SKIP from the method getSkipStatus. The following code of the MyVarname Java class, represents the macro type for the macros ref1 and ref2.
import java.util.Hashtable;
import com.savvion.rulewizard.data.*;
import com.savvion.rulewizard.util.Debugger;
public class MyVarname extends MacroString {
    String show_for_option = null;
    
    public int getSkipStatus() {
        if (show_for_option == null)
            return NO_SKIP;
    
        Debugger.println("MyVarname.getSkipStatus");
        String option =
            (String)references.get("option");
        if (option != null) {String optionName = (String)macroContext.getReference(option);
            Debugger.println("MyVarname: option " + optionName);
        return show_for_option.equalsIgnoreCase(optionName) ? NO_SKIP :
SKIP;
        }
        else
            return NO_SKIP;
    }
    
    public void addProperty(String name, String value) {
        super.addProperty(name, value);
        if (name != null && name.equals("show_for_option"))
            show_for_option = value;
    }
    
    public Hashtable getPropertiesToSave() {
        Hashtable pts = super.getPropertiesToSave();
        if (show_for_option != null)
            pts.put("show_for_option", show_for_option);
        return pts;
    }
}
The addProperty and getPropertiesToSave methods just read and save the property show_for_option, which indicates which value of the option reference the macro should be present. The getSkipStatus method reads the value of the option reference and compares it to the value of the property show_for_option. If the values are equal, then the NO_SKIP value returns, meaning the macro is present. Otherwise, SKIP is returned, meaning the macro is invisible.