org.openbp.jaspira.propertybrowser.editor
Class AbstractPropertyEditor

java.lang.Object
  extended by org.openbp.jaspira.propertybrowser.editor.AbstractPropertyEditor
All Implemented Interfaces:
java.awt.event.FocusListener, java.awt.event.KeyListener, java.lang.Cloneable, java.util.EventListener, Copyable, PropertyEditor
Direct Known Subclasses:
BooleanEditor, MultiLineStringEditor, SelectionEditor, StringEditor

public abstract class AbstractPropertyEditor
extends java.lang.Object
implements PropertyEditor, java.awt.event.KeyListener, java.awt.event.FocusListener

The abstract property editor provides some of the generic methods needed by any property editor implementing the property editor interface.

Author:
Erich Lauterbach

Field Summary
protected  javax.swing.JComponent component
          Display component
protected  PropertyEditorListener listener
          Editor listener
protected  java.lang.Object object
          The object to edit (object that owns the property)
protected  PropertyEditorOwner owner
          The owner of the editor.
protected  EditorParameterParser parameterParser
          Parameter parser
protected  java.lang.String params
          Editor parameter values
protected  PropertyBrowser propertyBrowser
          property browser instance if this property is used within the context of an property browser
protected  java.lang.String propertyName
          Property name
protected  boolean readonly
          Determines if the property is read only
protected  PropertyValidator validator
          The property validator used by this property editor.
protected  java.lang.Object value
          The actual property value
protected  boolean valueChanged
          Flag set when the value has been edited
protected  boolean valueLoaded
          Flag set when the value has been loaded from the property
 
Fields inherited from interface org.openbp.common.generic.Copyable
COPY_DEEP, COPY_FIRST_LEVEL, COPY_SHALLOW
 
Constructor Summary
AbstractPropertyEditor()
           
 
Method Summary
 java.lang.Object clone()
          Returns a clone of this.
 void copyFrom(java.lang.Object source, int copyMode)
          Copies the values of the source object to this object.
protected abstract  void createComponent()
          Creates the editor component of the property editor.
 void focusGained(java.awt.event.FocusEvent e)
          Invoked when a component gains the keyboard focus.
 void focusLost(java.awt.event.FocusEvent e)
          Invoked when a component loses the keyboard focus.
protected  void forwardKeyEvent(java.awt.event.KeyEvent e)
          Forwards the given key event to the parent of the property editor component.
 javax.swing.JComponent getComponent()
          Get the editor for the property.
protected abstract  java.lang.Object getComponentValue()
          Gets the current editor component value.
 java.lang.Object getObject()
          Gets the the object to edit (object that owns the property).
 PropertyEditorOwner getOwner()
          Gets the the owner of the editor.
 EditorParameterParser getParameterParser()
          Gets the parameter parser.
 java.lang.String getParams()
          Gets the editor parameter values.
 PropertyBrowser getPropertyBrowser()
          Gets the property browser instance if this property is used within the context of an property browser.
 javax.swing.JComponent getPropertyComponent()
          Get the editor for the property.
 java.lang.String getPropertyName()
          Gets the property name.
protected  java.lang.String getSafeString(java.lang.Object value)
          Gets the string representation of the specified value.
 PropertyValidator getValidator()
          Gets the the property validator used by this property editor.
 java.lang.Object getValue()
          Gets the the actual property value.
protected  void highlight(boolean on)
          Highlights the content of the component.
 void initialize(java.lang.String params)
          Sets the editor parameters and initializes the editor.
protected  void initializeComponent()
          Initializes the editor component.
 boolean isReadonly()
          Gets the read only flag.
 void keyPressed(java.awt.event.KeyEvent e)
          Invoked when a key has been pressed.
 void keyReleased(java.awt.event.KeyEvent e)
          Invoked when a key has been released.
 void keyTyped(java.awt.event.KeyEvent e)
          Invoked when a key has been typed.
 void loadProperty()
          Loads the property value from the object and displays it in the property component.
protected  void parseParams(EditorParameterParser parser)
          Parses the editor parameters specified in the property descriptor.
 void propertyChanged()
          When a change in the property value has occurred, then this method is to be called.
 void resetComponentDisplay()
          Resets the display of the editor.
 void resetProperty()
          Resets the property to its original value.
 boolean saveProperty()
          Saves the changes made to the property value if the property was modified.
protected abstract  void setComponentValue()
          Sets the display component value from the associated property.
 void setObject(java.lang.Object object)
          Sets the object that holds the property specified by setPropertyName(java.lang.String)
 void setOwner(PropertyEditorOwner owner)
          Sets the the owner of the editor.
 void setParams(java.lang.String params)
          Sets the editor parameter values.
 void setPropertyBrowser(PropertyBrowser propertyBrowser)
          Sets the property browser instance if this property is used within the context of an property browser.
 void setPropertyName(java.lang.String propertyName)
          Sets the name of the property that should be edited by this editor instance.
 void setReadonly(boolean readonly)
          Sets the read only flag.
 void setValidator(PropertyValidator validator)
          Sets the the property validator used by this property editor.
 void setValue(java.lang.Object value)
          Sets the the actual property value.
protected  boolean validateProperty(boolean complete)
          Validates the edited value for this property, if a validator has been specified in the property descriptor file.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

propertyName

protected java.lang.String propertyName
Property name


params

protected java.lang.String params
Editor parameter values


readonly

protected boolean readonly
Determines if the property is read only


validator

protected PropertyValidator validator
The property validator used by this property editor.


listener

protected PropertyEditorListener listener
Editor listener


owner

protected PropertyEditorOwner owner
The owner of the editor. This can be a component or a tree node if the pe is used by the property browser.


component

protected javax.swing.JComponent component
Display component


parameterParser

protected EditorParameterParser parameterParser
Parameter parser


propertyBrowser

protected PropertyBrowser propertyBrowser
property browser instance if this property is used within the context of an property browser


object

protected java.lang.Object object
The object to edit (object that owns the property)


value

protected java.lang.Object value
The actual property value


valueLoaded

protected boolean valueLoaded
Flag set when the value has been loaded from the property


valueChanged

protected boolean valueChanged
Flag set when the value has been edited

Constructor Detail

AbstractPropertyEditor

public AbstractPropertyEditor()
Method Detail

initialize

public void initialize(java.lang.String params)
Sets the editor parameters and initializes the editor.

Specified by:
initialize in interface PropertyEditor
Parameters:
params - Editor parameters from the property descriptor or null

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Returns a clone of this. The clone method is defined by default to be protected (who did this?!?). However, we define it to be public in order to be able to invoke it directly from outside the class and not needing to use reflections to call it.

Specified by:
clone in interface Copyable
Overrides:
clone in class java.lang.Object
Returns:
The clone (a deep copy of this object)
Throws:
java.lang.CloneNotSupportedException - If the cloning of one of the contained objects failed

copyFrom

public void copyFrom(java.lang.Object source,
                     int copyMode)
              throws java.lang.CloneNotSupportedException
Copies the values of the source object to this object.

Specified by:
copyFrom in interface Copyable
Parameters:
source - The source object. Must be of the same type as this object.
copyMode - Determines if a deep copy, a first level copy or a shallow copy is to be performed. See the constants of the org.openbp.common.generic.description.Copyable class.
Throws:
java.lang.CloneNotSupportedException - If the cloning of one of the contained objects failed

getParameterParser

public EditorParameterParser getParameterParser()
Gets the parameter parser.


setComponentValue

protected abstract void setComponentValue()
Sets the display component value from the associated property.


getComponentValue

protected abstract java.lang.Object getComponentValue()
Gets the current editor component value.

Returns:
The current value of the component (can be null)
Note that this value might be different from the actual property value if the property hasn't been saved yet.

createComponent

protected abstract void createComponent()
Creates the editor component of the property editor.


highlight

protected void highlight(boolean on)
Highlights the content of the component.

Parameters:
on - true Turns the highlight on if the component has the focus
false Turns the highlight off

propertyChanged

public void propertyChanged()
When a change in the property value has occurred, then this method is to be called.

Specified by:
propertyChanged in interface PropertyEditor

loadProperty

public void loadProperty()
Loads the property value from the object and displays it in the property component.

Specified by:
loadProperty in interface PropertyEditor

saveProperty

public boolean saveProperty()
Saves the changes made to the property value if the property was modified. The method will will validate the modified value, if a PropertyValidator has been set and then on success save the property value.

Specified by:
saveProperty in interface PropertyEditor
Returns:
true The property value has been successfully validated and saved.
false Validation or saving failed.

resetProperty

public void resetProperty()
Resets the property to its original value.

Specified by:
resetProperty in interface PropertyEditor

validateProperty

protected boolean validateProperty(boolean complete)
Validates the edited value for this property, if a validator has been specified in the property descriptor file. This method is called by the saveProperty() method.

Parameters:
complete - true The value has been completely entered. This is the case if the user wishes to leave the field.
false The value is being typed/edited.
Returns:
true If the validation succeeded and the edited value is valid.
false If the value is not valid.

getPropertyComponent

public javax.swing.JComponent getPropertyComponent()
Get the editor for the property. This will also initialize the component (if not done yet) and load the current property value from the object to be displayed.

Specified by:
getPropertyComponent in interface PropertyEditor
Returns:
The property editor or null if the property cannot be accessed

getComponent

public javax.swing.JComponent getComponent()
Get the editor for the property. This will also initialize the component (if not done yet), however it will \bnot\b load the current property value from the object to be displayed.

Specified by:
getComponent in interface PropertyEditor
Returns:
The property editor or null if the property cannot be accessed

initializeComponent

protected void initializeComponent()
Initializes the editor component.


resetComponentDisplay

public void resetComponentDisplay()
Resets the display of the editor. Shows the editor component in an 'unfocused' state.

Specified by:
resetComponentDisplay in interface PropertyEditor

parseParams

protected void parseParams(EditorParameterParser parser)
Parses the editor parameters specified in the property descriptor.

Parameters:
parser - Parameter parser

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Invoked when a key has been released.

Specified by:
keyReleased in interface java.awt.event.KeyListener

keyPressed

public void keyPressed(java.awt.event.KeyEvent e)
Invoked when a key has been pressed.

Specified by:
keyPressed in interface java.awt.event.KeyListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent e)
Invoked when a key has been typed.

Specified by:
keyTyped in interface java.awt.event.KeyListener

focusGained

public void focusGained(java.awt.event.FocusEvent e)
Invoked when a component gains the keyboard focus.

Specified by:
focusGained in interface java.awt.event.FocusListener

focusLost

public void focusLost(java.awt.event.FocusEvent e)
Invoked when a component loses the keyboard focus.

Specified by:
focusLost in interface java.awt.event.FocusListener

setPropertyName

public void setPropertyName(java.lang.String propertyName)
Sets the name of the property that should be edited by this editor instance.

Specified by:
setPropertyName in interface PropertyEditor
Parameters:
propertyName - The property name

getPropertyName

public java.lang.String getPropertyName()
Gets the property name.

Specified by:
getPropertyName in interface PropertyEditor

setObject

public void setObject(java.lang.Object object)
Sets the object that holds the property specified by setPropertyName(java.lang.String)

Specified by:
setObject in interface PropertyEditor
Parameters:
object - The object to edit

getObject

public java.lang.Object getObject()
Gets the the object to edit (object that owns the property).

Specified by:
getObject in interface PropertyEditor

getValue

public java.lang.Object getValue()
Gets the the actual property value.

Specified by:
getValue in interface PropertyEditor

setValue

public void setValue(java.lang.Object value)
Sets the the actual property value.

Specified by:
setValue in interface PropertyEditor

isReadonly

public boolean isReadonly()
Gets the read only flag.

Specified by:
isReadonly in interface PropertyEditor

setReadonly

public void setReadonly(boolean readonly)
Sets the read only flag.

Specified by:
setReadonly in interface PropertyEditor

getParams

public java.lang.String getParams()
Gets the editor parameter values.

Specified by:
getParams in interface PropertyEditor

setParams

public void setParams(java.lang.String params)
Sets the editor parameter values.

Specified by:
setParams in interface PropertyEditor

getValidator

public PropertyValidator getValidator()
Gets the the property validator used by this property editor.

Specified by:
getValidator in interface PropertyEditor

setValidator

public void setValidator(PropertyValidator validator)
Sets the the property validator used by this property editor.

Specified by:
setValidator in interface PropertyEditor

getOwner

public PropertyEditorOwner getOwner()
Gets the the owner of the editor. This can be a component or a tree node if the pe is used by the property browser.

Specified by:
getOwner in interface PropertyEditor

setOwner

public void setOwner(PropertyEditorOwner owner)
Sets the the owner of the editor. This can be a component or a tree node if the pe is used by the property browser.

Specified by:
setOwner in interface PropertyEditor

getPropertyBrowser

public PropertyBrowser getPropertyBrowser()
Gets the property browser instance if this property is used within the context of an property browser.

Specified by:
getPropertyBrowser in interface PropertyEditor

setPropertyBrowser

public void setPropertyBrowser(PropertyBrowser propertyBrowser)
Sets the property browser instance if this property is used within the context of an property browser.

Specified by:
setPropertyBrowser in interface PropertyEditor

getSafeString

protected java.lang.String getSafeString(java.lang.Object value)
Gets the string representation of the specified value.

Parameters:
value - Value or null
Returns:
The toString value or null

forwardKeyEvent

protected void forwardKeyEvent(java.awt.event.KeyEvent e)
Forwards the given key event to the parent of the property editor component.

Parameters:
e - Event
The event will be consumed by this method.


Copyright © 2011. All Rights Reserved.