Samples > Rule Studio Authoring Extensions > How to Use a Custom Value Editor in the Rule Editor

This sample shows how to associate a custom value editor with a data type (that is, a BOM class) and its lexical representation in Rule Studio's text and guided editors.

Key Features

Key features include:

Installing this Sample

This sample extends the Rule Studio API, and the required sample plug-ins are delivered as pre-deployed. If you have not already done so, you must install the samples extension site in Eclipse before running this sample.

To install the plug-in samples extension site:

  1. Click Help > Software Updates > Manage Configuration.
  2. In the Product Configuration dialog, click the Add an Extension Location link.
  3. In the Browse dialog, select the following folder: <InstallDir>/studio/samples/eclipse folder.
  4. If prompted to restart the Eclipse Workbench, click Yes.
  5. Eclipse shuts down and restarts.

To check that the Value Editor Sample feature is enabled:

  1. Click Help > Software Updates > Manage Configuration.
  2. In the left pane of the Product Configuration page, expand C:\ILOG\JRules\studio\samples\eclipse and check that Value Editor Sample 1.0.0. is listed.

To import the valueeditor sample:

  1. Click File > Import.
  2. In the Import Wizard, select ILOG Rule Studio Samples and Tutorials.
  3. Click Next.
  4. On the Sample or Tutorial page, select the sample: samples > authoring > valueeditor.
  5. Click Finish.
  6. The sample project files are imported and displayed in the Rule Explorer.

Running this Sample

When you install this sample, a custom value editor, such as the ones provided for simple and full date representations, is added to Rule Studio. It demonstrates how to filter elements based on a pattern.

To test the custom value editor:

  1. Open the valueeditor-rules > offer rule in the Guided Editor.
  2. Click on #BFGHFDF in the condition part of the rule.
  3. The custom value editor appears:
    images/guidededitor.png

You can also access the custom value editor from within the Intellirule Editor:

images/texteditor.png

Note
This kind of customization is also available in Rule Team Server, with just a few minor changes: you will need to use a Web component instead of the Swing component used in Rule Studio.

Source Files

All classes for this sample are located in the package ilog.rules.studio.samples.valueeditor, in an Eclipse plug-in with the same name.

The value descriptor is used to transform values back and forth from the rule text to the value editor component. It is needed for representation and persistence purposes.

Here, we are using an existing value descriptor because our custom value editor deals with simple values that can be converted to an existing String type (ilog.rules.brl.String). We have also added a prefix decoration: #.

We could also have made a custom value descriptor by:

Once your rule is written, you must associate a value translator to your data type (BOM class) to help Rule Studio convert your rule to its IRL representation.

In the sample, this is done using the FilterValueTranslator class, which is referenced in our extension of ilog.rules.studio.model.brl.valueTranslators in the plugins.xml file.

To make our extension work, FilterValueTranslator implements ilog.rules.brl.translation.codegen.IlrValueTranslator.

The "promotional offer code" is translated into IRL by an instantiation of the sample.PromotionalOffer class. You can examine the translateValue method.

To display the source code of the valueeditor Eclipse plug-in:

  1. Click File > Import.
  2. In the Import Wizard, select External Plug-ins and Fragments and click Next.
  3. In the Import As section, select the Projects with source folders option and click Next.
  4. In the Plug-ins and Fragments Found list, scroll down and select the ilog.rules.studio.samples.valueeditor plug-in (be careful not to select ilog.rules.studio.samples.valueeditor.source), then click Add.
  5. Click Finish.
  6. The plug-in source code is imported and appears in the Rule Explorer.
  7. Switch to the Plug-in Development perspective. In the Package Explorer, navigate to the Java source files.

Highlights

Open the model BOM entry in the valueeditor-rules project and navigate to the PromotionalOffer class inside the sample package. A few custom properties are set on this BOM class.

The properties are used to:

To see how the custom value editor classes and extension points work, see the Source Files section of this sample documentation.

To associate your custom value editor, descriptor and translator to a BOM class, you need to set custom properties:

Notes
Tip
You can use a value info if you want to associate a value editor with a BOM member. Value infos supersede value editors set on the underlying BOM class.

See Managing BOM Value Types for more information.

Related Concepts

Value Descriptor
Value Editor
Value Translator

Related Tasks

Managing BOM Value Types

Related Samples and Tutorials

Import Samples and Tutorials Wizard