com.metamatrix.toolbox.ui.widget.property
Class PropertyChangeAdapter

java.lang.Object
  extended by java.awt.event.KeyAdapter
      extended by com.metamatrix.toolbox.ui.widget.property.PropertyChangeAdapter
All Implemented Interfaces:
PropertyValidationListener, java.awt.event.KeyListener, java.util.EventListener

public class PropertyChangeAdapter
extends java.awt.event.KeyAdapter
implements PropertyValidationListener

PropertyChangeAdapter is a class for obtaining, validating, and setting property values for all editable properties in the PropertiesPanel. The class listens to key and selection events from the various types of JComponent TableCellEditor implementations for the various PropertyDefinition types and adapts them to use the PropertiedObject methods isValidValue() and setValue().


Constructor Summary
PropertyChangeAdapter(PropertiedObjectEditor editor, java.lang.Object transactionSource)
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Invoked when a component loses the keyboard focus.
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Registers the specified listener to be notified whenever the value of one of the displayed components changes.
protected  void firePropertyChangeEvent(java.lang.Object source, java.lang.Object value)
          Fires a PropertyChangeEvent to all registered listeners.
 void focusLost(java.awt.event.FocusEvent event)
          Invoked when a component loses the keyboard focus.
static java.lang.Object getValueFromJComponent(javax.swing.JComponent comp, boolean finished)
          Return the value object controlled by the specified JComponent TreeCellEditor.
 boolean isEditing()
          determine if this Adapter is in the middle of a user edit.
 boolean isTransactionPending()
          sets or clears the transactionPending flag
 boolean isValid(java.lang.Object value, java.lang.Object nullObject)
           
 void isValueValid(PropertyComponent source, java.lang.Object value)
          Callback from a custom component to check the validity of a partial entry.
 void keyReleased(java.awt.event.KeyEvent e)
          Invoked when a key has been released.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Unregisters the specified listener from getting notifications of value changes within the component displaying values for one of the PropertiedObject's properties.
protected  void removeValidityListenerForJComponent(javax.swing.JComponent comp)
          Remove this adapter from the specified component's listener list.
protected  void setEditorComponentAfterEdit(javax.swing.JComponent editor)
          set this property's TableCellEditor just after editing of the value has completed.
 void setEditorComponentBeforeEdit(javax.swing.JComponent editor)
          set this property's TableCellEditor just before editing of the value begins.
 void setJComponentValue(javax.swing.JComponent component, java.lang.Object value)
           
 void setPropertiedObject(PropertiedObject entity)
          set the PropertiedObject that this adapter will be using for validation and setting of new property values.
 void setPropertyDefinition(PropertyDefinition propertyDefinition)
          set the PropertyDefinition that this adapter will be controlling the value of for the PropertiedObject.
 void setTransactionPending(boolean isPending)
          sets or clears the transactionPending flag
protected  void setValidityListenerForJComponent(javax.swing.JComponent comp)
          Set this adapter as a listener to validate partial entries of non-constrained properties.
 
Methods inherited from class java.awt.event.KeyAdapter
keyPressed, keyTyped
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyChangeAdapter

public PropertyChangeAdapter(PropertiedObjectEditor editor,
                             java.lang.Object transactionSource)
Since:
2.0
Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Registers the specified listener to be notified whenever the value of one of the displayed components changes. An event will be fired to the listener regardless of whether the new value if valid. Since the property whose value the component is displaying is only changed if the value if valid, the PropertiedObjectEditor's getValue may return the either the new or old value depending on the validity of the new value.

Parameters:
listener - The PropertyChangeListener
Since:
2.0

setTransactionPending

public void setTransactionPending(boolean isPending)
sets or clears the transactionPending flag


isTransactionPending

public boolean isTransactionPending()
sets or clears the transactionPending flag


firePropertyChangeEvent

protected void firePropertyChangeEvent(java.lang.Object source,
                                       java.lang.Object value)
Fires a PropertyChangeEvent to all registered listeners.

Since:
2.0

setPropertiedObject

public void setPropertiedObject(PropertiedObject entity)
set the PropertiedObject that this adapter will be using for validation and setting of new property values.

Parameters:
entity - the PropertiedObject for setting this property value.

setPropertyDefinition

public void setPropertyDefinition(PropertyDefinition propertyDefinition)
set the PropertyDefinition that this adapter will be controlling the value of for the PropertiedObject.

Parameters:
propertyDefinition - the PropertyDefinition of this property.

isEditing

public boolean isEditing()
determine if this Adapter is in the middle of a user edit.

Returns:
true if the property value has edit focus and has not yet been set on the Propertied Object. false if it is safe to use the PropertiedObject.

setEditorComponentBeforeEdit

public void setEditorComponentBeforeEdit(javax.swing.JComponent editor)
set this property's TableCellEditor just before editing of the value begins. The method obtains and saves the original value from the JComponent, and wires up to listen for the appropriate events to determine when the user has modified the value.

Parameters:
editor - the JComponent responsible for editing this property value.

setEditorComponentAfterEdit

protected void setEditorComponentAfterEdit(javax.swing.JComponent editor)
set this property's TableCellEditor just after editing of the value has completed. The method obtains new value from the JComponent and compares it to the original value. If the values differ, and the new value is valid, this method will set the property on the PropertiedObject.

Parameters:
editor - the JComponent responsible for editing this property value.

setValidityListenerForJComponent

protected void setValidityListenerForJComponent(javax.swing.JComponent comp)
Set this adapter as a listener to validate partial entries of non-constrained properties. For example, this adapter listens to every keystroke within a JTextComponent and validates the entry, turning the entry red if a keystroke has caused the entire entry to become in valid -- like when an alpha character is entered into an integer field.


removeValidityListenerForJComponent

protected void removeValidityListenerForJComponent(javax.swing.JComponent comp)
Remove this adapter from the specified component's listener list.


isValueValid

public void isValueValid(PropertyComponent source,
                         java.lang.Object value)
Callback from a custom component to check the validity of a partial entry.

Specified by:
isValueValid in interface PropertyValidationListener
Parameters:
source - the custom PropertyComponent requesting validation.
value - the property value that should be validated.

isValid

public boolean isValid(java.lang.Object value,
                       java.lang.Object nullObject)

keyReleased

public void keyReleased(java.awt.event.KeyEvent e)
Invoked when a key has been released. This KeyAdapter method will cause the full text entry of the source component to be validated by the PropertiedObject. If the entry is not valid, the foreground text color turns to red.

Specified by:
keyReleased in interface java.awt.event.KeyListener
Overrides:
keyReleased in class java.awt.event.KeyAdapter

focusLost

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


actionPerformed

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


getValueFromJComponent

public static java.lang.Object getValueFromJComponent(javax.swing.JComponent comp,
                                                      boolean finished)
Return the value object controlled by the specified JComponent TreeCellEditor. This method must support all JComponent types used by MetadataPropertiesPanel and MetadataPropertyTableEntry.

Parameters:
comp - the JComponent that this method will extract the value from.
Returns:
the object controlled by the JComponent editor. If a JComponent type is passed in that this method cannot support, the method will return a String containing a message that the PropertyChangeAdapter does not support this component.

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Unregisters the specified listener from getting notifications of value changes within the component displaying values for one of the PropertiedObject's properties.

Parameters:
listener - The PropertyChangeListener currently registered to receive events
Since:
2.0

setJComponentValue

public void setJComponentValue(javax.swing.JComponent component,
                               java.lang.Object value)


Copyright © 2009. All Rights Reserved.