値エディターの実装例として、ユーザー・インターフェースを備えたカスタム・エディターとして色エディターを定義できます。この定義では、Rule Designer の AWT ツールキットを使用します。
このタスクについて
この例では、BOM クラス sample.Color の値エディターを定義します。 この色エディターは、ユーザー・インターフェースを備えたカスタム・エディターです。 これは、Rule Designer の AWT ツールキットを使用して定義します。
手順
BOM クラス sample.Color の値エディターを定義するには、以下のようにします。
- 以下のようにして、抽象クラス IlrAWTValueEditor を拡張します。
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;
}
}
- このクラスでカスタム・プロパティー valueEditor を定義することによって、BOM クラス sample.Color に値エディターを付加します。
valueEditor = sample.valueEditor.Color
- 以下のように拡張ポイント ilog.rules.studio.model.brl.valueEditors を宣言して、色値エディターを Rule Designer に統合します。
ID: sample.valueEditor.Color
キー: sample.valueEditor.Color
クラス: sample.ValueColorEditor
タスクの結果
Rule Designer で色値エディターを使用できるようになりました。