by Eric Clayberg » Mon Jun 28, 2010 8:20 am
The life cycle is subject to change at any time, and you should rely solely on the JavaBean spec itself for that info. As long as your editor complies with the JavaBean spec (and does not make any assumptions not supported by that spec), it should work fine. You should not code it for a specific life cycle as that can be different for different tools and can even change within a given tool. Your original problem sounds like you were expecting getValue() to be called as a precondition for getJavaInitializationString(). Nothing in the spec indicates that will be the case. In fact, both of those methods are independent of one another and should be callable in any order.
That said, the following is the current life cycle we are using. As said above, this is subject to change at any time.
1. Initialization.
1.1. Call java.beans.PropertyEditor.supportsCustomEditor() to check if it has custom AWT component used for editing, which we show in dialog after clicking "..." button.
1.2. Call java.beans.PropertyEditor.getTags() to check if property value must be one of a set of known tagged values. In this case we create combo-box based editor.
1.3. If no tags, then editor is text based.
1.4. Before calling any PropertyEditor method, always check if it has java.beans.PropertyEditorSupport.setSource(Object) and call this method with value of toolkit object.
2. Painting.
2.1. In any case call java.beans.PropertyEditor.setValue(Object).
2.2. If java.beans.PropertyEditor.isPaintable() then use java.beans.PropertyEditor.paintValue(Graphics, Rectangle)
2.3. In other case call java.beans.PropertyEditor.getAsText() and paint this text.
3. Editing.
3.1. Text based editor.
3.1.1. To get text to edit call java.beans.PropertyEditor.setValue(Object) then java.beans.PropertyEditor.getAsText().
3.1.2. To set text after editing call java.beans.PropertyEditor.setAsText(String), then to get Java source call java.beans.PropertyEditor.getValue() and java.beans.PropertyEditor.getJavaInitializationString().
3.2. Tags based editor.
3.2.1. When user drops-down combo-box, call java.beans.PropertyEditor.getTags().
3.2.2. After item selection do same as for text-based editor - use setAsText(String), see 3.1.2.
3.3. Custom component editor.
3.3.1. When user clicks "..." ask for editor java.beans.PropertyEditor.getCustomEditor() and show it in modal dialog.
3.3.2. If user closes dialog using OK, use current java.beans.PropertyEditor value, so call java.beans.PropertyEditor.getValue() and java.beans.PropertyEditor.getJavaInitializationString().