| Samples > Rule Studio Authoring Extensions > How to Use a Custom Value Editor in the Rule Editor |
How to Use a Custom Value Editor in the Rule Editor |
PREVIOUS NEXT |
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 include:
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:
<InstallDir>/studio/samples/eclipse folder.
To check that the Value Editor Sample feature is enabled:
C:\ILOG\JRules\studio\samples\eclipse and check that Value Editor Sample 1.0.0. is listed.
To import the valueeditor sample:
ILOG Rule Studio Samples and Tutorials.
samples > authoring > valueeditor.
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:
valueeditor-rules > offer rule in the Guided Editor.
#BFGHFDF in the condition part of the rule.
You can also access the custom value editor from within the Intellirule Editor:
| 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. |
All classes for this sample are located in the package ilog.rules.studio.samples.valueeditor, in an Eclipse plug-in with the same name.
FilterValueEditor class extends ilog.rules.brl.ui.value.editor.IlrAWTValueEditor, which is needed to integrate the custom value editor in Rule Studio by extending the extension point ilog.rules.studio.model.brl.valueEditors.
getValue and setValue methods are used to handle communication between the value editor integrated Swing component and the rule editors.
getEditorComponent method returns the Swing component used by the value editor. It is called each time the component is displayed.
FilterControl class is our Swing component class. We use the setValue and getValue methods to perform Input and Output operations in the Swing component:
setValue is used to pass an existing promotional offer code value, if any, which will ideally map an element of the filter list.
getValue is performed when the OK button is clicked or the Enter key is pressed. It returns the new promotional offer code value to display in the rule.
setValue and getValue methods to perform the required I/O operations.
FilterDataProvider class and its implementation, FilterDataProviderImpl, are used to populate the value editor list and its items descriptions. It is possible to make more complex implementations that include XML or database integration.
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:
ilog.rules.brl.value.descriptor.IlrValueDescriptor (or is more conveniently extending ilog.rules.brl.value.descriptor.IlrAbstractValueDescriptor) and is referenced in an extension of ilog.rules.studio.model.brl.valueDescriptors in your plug-in.
# "<promotional offer>") is needed because Rule Studio is working with regular expressions in order to distinguish different types of values and to know how to persist and represent them.
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:
External Plug-ins and Fragments and click Next.
ilog.rules.studio.samples.valueeditor plug-in (be careful not to select ilog.rules.studio.samples.valueeditor.source), then click Add.
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:
valueditor).
valueDescriptor and DecoratedValueDescriptor.prefix)
valueTranslator)
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:
valueEditor = sample.myeditor.editor: This is the key of our value editor extension.
DecoratedValueDescriptor.prefix #: This is needed because we want to add a prefix to our value representation.
valueDescriptor sample.PromotionalOffer#Decorated(ilog.rules.brl.String): We are using an existing value descriptor. If you need to code a value descriptor, you must put the key of the value descriptor extension here, like for the value editor.
valueTranslator servervalueeditor.FilterValueTranslator: This is the key of our value translator extension.
| 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. |
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |