A value editor is a Java class that defines how to enter and display values of a particular type in a business rule. It allows you to edit a value and, if required, to specify a default value. It edits an object that represents the value, not the text. You can use a value editor with all types of rule editors (Intellirule Editor, Guided Editor, Web Guided Editor).
A value editor is associated with a value descriptor because, after editing the value, you must insert the text representing the value into the edited rule.
When you have created a value descriptor, you should then integrate it into Rule Studio,
Rule Team Server or Rule Solutions for Office, as appropriate. For more information,
see The following list shows the base class used to create a custom value
editor for the different products.
Customizing JRules > Customizing Rule Authoring > Tasks > Managing BOM
value types > Implementing a value editor > Integrating a value editor
.
Code Example
The following code example shows a custom value editor:
public class ValueColorEditor extends IlrAWTValueEditor implements ChangeListener { private AbstractColorChooserPanel chooser; public IlrValueDateEditor(IlrValueDescriptor valueDescriptor) { super(valueDescriptor); chooser = ColorChooserComponentFactory.getDefaultChooserPanels()[0]; // Gets the default chooser color panel // Registers this as a color model listener chooser.getColorSelectionModel().addChangeListener(this); // Register a key listener to cancel editing when ESC is pressed editor.registerKeyboardAction(new ActionListener() { public void actionPerformed(ActionEvent e) { fireEditionCanceled(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); } // Returns the edited value public Object getValue() { return chooser.getColorSelectionModel().getSelectedColor(); } // Sets the value to edit public void setValue(Object value) { chooser.getColorSelectionModel().setSelectedColor((Color) value); } // When the state has changed, stops the value editing // to validate the new selection public void stateChanged(ChangeEvent e) { if (chooser.isShowing()) fireEditionStopped(); } // Returns the user interface for editing the value public Object getEditorComponent(IlrBRLRuleEditingContext context) { Locale locale = context.getVocabulary().getLocale(); if (!locale.equals(editor.getLocale())) chooser.setLocale(locale); return chooser; } }@since JRules 6.0 @core