Try OpenEdge Now
skip to main content
Application Developer's Guide
Using the Rule Wizard framework : How to write additional macros and editors : Sample editor implementation
 

Sample editor implementation

This section presents the Java class implementing the editor for the boolean type. All implementation issues are commented in the source file.
package com.savvion.rulewizard.gui;
import com.savvion.rulewizard.data.MacroDataIF;
import com.savvion.rulewizard.data.BooleanMacro;
import java.util.Hashtable;
import javax.swing.JCheckBox;
import java.awt.BorderLayout;
/**
 * Editor class implementing the editor for the "boolean" type.
 */
public class CheckBoxEditor extends DefaultEditor {
    JCheckBox field = new JCheckBox();
    
    BooleanMacro boolMacro; // macro holding the data
    
    /**
     * No parameters constructor, builds the GUI.
     */
    public CheckBoxEditor() {
        super();
        add(field, BorderLayout.WEST);
    }
    
    /**
     * Transfer the data from GUI to the macro.
     */
    public void save() {
        boolMacro.setBoolValue(field.isSelected());
    }
    
    /**
     * Transfer the data from macro to the GUI.
     */
    public void load() {
        field.setSelected(boolMacro.getBoolValue());
    }
    
    /**
     * There are no validations to perform. We always return "true".
     */
    public boolean verify() {
        return true;
    }
    
    /**
     * Get the associated macro.
     * @return value of macro.
     */
    public MacroDataIF getMacroData() {
        return (MacroDataIF)boolMacro;
    }
    
    /**
     * Associate this editor with a macro. We cast the macro object to
     * BooleanMacro as we know this is the only kind of macro this editor
     * works with.
     * @param v Value to assign to macro.
     */
    public void setMacroData(MacroDataIF v) {
        this.boolMacro = (BooleanMacro)v;
    }
    
    /**
     * If any data-dependent GUI initialization is needed this is the place
     * to do it because showGUI is called after setMacroData(). For this      * editor there is none.
     */
    public void showGUI() {}
    
    /**
     * Called when this editor is to receive focus. We put the focus on the
     * check box.
     */
    public void setFocus() {
        field.requestFocus();
    }
    
    /**
     * Enable of disable the editor according to the value of parameter b.
     */
    public void setEnabled(boolean b) {
        field.setEnabled(b);
    }
}