Example: Creating a color value descriptor

For a value type that represents a color, you define a color value descriptor.

About this task

If you want to use the BOM class sample.Color as a value type that represents a color, you must define a color value descriptor.

Procedure

To define a color value descriptor:

  1. Extend the IlrAbstractValueDescriptor class:
    class ValueColorDescriptor extends IlrAbstractValueDescriptor {
    
     public ValueColorDescriptor(Concept concept) { super(concept); }
     {
       // Checks the value (but here no check is needed)
       public boolean checkValue(IlrSyntaxTree.Node node, Object value) {
           return true; 
        }
    
       // Converts the persistent text form of the value to an instance of Color
       public Object getValue(String persistentText) {
           return Color.decode(persistentText);
        }
    
       // Converts the instance of Color into a persistent text form
       public String getPersistentText(Object value) {
          return '#' + Integer.toHexString(((Color) value).getRGB());
        }
    
       //Converts the localized text form of the value into an instance of Color
       public Object getValue(String text, IlrBRLDefinition definition) {
          return Color.decode(text); 
          // Here the text form is not locale dependent
        }
    
       // Converts the instance of Color into a localized text form
       public String getLocalizedText(Object value, 
                                      IlrBRLDefinition definition) {
           return '#' + Integer.toHexString(((Color) value).getRGB()); 
           // Here the text form is still not locale dependent
        }
    
       // Returns the default value in a localized text form
       public String getDefaultValue(IlrBRLDefinition definition) {
           return "#000000";
           // By default, returns the value black
        }
     }
  2. Attach the value descriptor to the BOM class sample.Color by defining a custom property valueDescriptor on this class:
    valueDescriptor = sample.valueDescriptor.Color
  3. Specify a representation of the value that can be parsed. To do this, in the BOM Editor, add a custom property valueDescriptor.parsableRepresentation to the class sample.Color, and give it the following value:
    #[0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F]
  4. Integrate the value descriptor into Rule Designer by declaring an extension point ilog.rules.studio.model.brl.valueDescriptors, with the following parameters:

    ID: sample.valueDescriptor.Color

    Key: sample.valueDescriptor.Color

    Class: sample.ValueColorDescriptor

Results

You can now use the color value descriptor in Rule Designer.