예제: Rule Designer에서 색상 값 편집기 구현

값 편집기 구현의 예로 Rule Designer에서 AWT 툴킷을 사용하여 색상 편집기를 사용자 인터페이스가 있는 사용자 정의 편집기로 정의할 수 있습니다.

이 태스크 정보

이 예제에서는 BOM 클래스 sample.Color에 대한 값 편집기를 정의합니다. 이 색상 편집기는 사용자 인터페이스가 있는 사용자 정의 편집기입니다. Rule Designer에서 AWT 툴킷을 사용하여 값 편집기를 정의합니다.

프로시저

BOM 클래스 sample.Color에 대한 값 편집기를 정의하려면 다음을 수행하십시오.

  1. 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;
     }
    }
  2. 이 클래스에서 사용자 정의 특성 valueEditor를 정의하여 BOM 클래스 sample.Color에 값 편집기를 첨부하십시오.
    valueEditor = sample.valueEditor.Color
  3. 확장점 ilog.rules.studio.model.brl.valueEditors를 선언하여 Rule Designer에 색상 값 편집기를 통합하십시오.

    ID: sample.valueEditor.Color

    키: sample.valueEditor.Color

    클래스: sample.ValueColorEditor

결과

Rule Designer에서 색상 값 편집기를 사용할 수 있습니다.