de.mguennewig.pobjform.swing
Class SwingReferenceElement

java.lang.Object
  extended by de.mguennewig.pobjform.AbstractFormElement
      extended by de.mguennewig.pobjform.AbstractValueElement
          extended by de.mguennewig.pobjform.AbstractInputElement
              extended by de.mguennewig.pobjform.swing.SwingInputElement
                  extended by de.mguennewig.pobjform.swing.SwingReferenceElement
All Implemented Interfaces:
FormElement, InputElement, ReferenceElement, SwingFormElement, ValueElement, java.awt.event.ActionListener, java.util.EventListener

public final class SwingReferenceElement
extends SwingInputElement
implements ReferenceElement, java.awt.event.ActionListener

A Swing implementation of a ReferenceElement.

The Swing component for this element as well as the model are created lazily to safe resources.

Author:
Michael Günnewig

Field Summary
 
Fields inherited from interface de.mguennewig.pobjform.InputElement
MAX_INPUT_SIZE, RENDER_AS_DISABLED, RENDER_AS_HIDDEN, RENDER_AS_HIDDEN_WITH_LABEL, RENDER_AS_INPUT, RENDER_AS_TEXT
 
Constructor Summary
SwingReferenceElement(PObjSwingForm form, InputEntry entry)
          Creates a new SwingReferenceElement.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
           
 javax.swing.JComboBox getComponent()
          Returns the Swing component for the input element.
 java.lang.String getCurrentString()
          Returns the string representation of the current object.
 java.lang.Object getInitialObject()
          Returns the initial object.
 java.lang.Object getObject()
          Returns the current object.
 java.lang.String getVisualString()
          Returns the human readable textual representation of the current value.
 boolean isStaticIfOneOption()
          Tests whether the input element will be rendered as static if the number of non-null options is exactly one.
 void setGroupBy(Member designator, boolean ascending)
          Group the set by the designator.
 void setObject(java.lang.Object obj)
          Sets the current object to the new value.
 void setProperty(java.lang.String property)
          Sets the property to a new value, and propagates the change to all child elements.
 void setRestriction(java.lang.Class<? extends PObject>[] tableClasses, Predicate[] filters)
          Restrict the set of values to an arbitrary subset of the entries of the referenced table.
 void setRestriction(ClassDecl[] tableExprs, Predicate[] filters)
          Restrict the set of values to an arbitrary subset of the entries of the referenced table.
 void setRestriction(Predicate filter)
          Restrict the set of values to an arbitrary subset of the entries of the referenced table.
 void setRightAligned(boolean rightAligned)
          Sets whether the data should be right aligned.
 void setStaticIfOneOption(boolean staticIfOneOption)
          Sets whether the input element will be rendered as static if the number on non-null options is exactly one.
 
Methods inherited from class de.mguennewig.pobjform.swing.SwingInputElement
getErrorComponent, getInitialString, getLabelComponent, hasChanged, setCurrentAsInitialState, setInitialString, setLabel, setRenderAs, updateErrorComponent
 
Methods inherited from class de.mguennewig.pobjform.AbstractInputElement
addChangeListener, getChangeListeners, getInputEntry, getRenderAs, getType, isHiddenInput, isMandatory, isRightAligned, isVisible, removeChangeListener, setMandatory, setVisible, validate
 
Methods inherited from class de.mguennewig.pobjform.AbstractFormElement
appendToList, getContainer, getEntry, getForm, getLabel, getProperty, getPullInPrefix, isPulledIn, omitRowHeader, setPullInPrefix, startsNewCell
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.mguennewig.pobjform.InputElement
addChangeListener, getInputEntry, getRenderAs, getType, isHiddenInput, isMandatory, isRightAligned, isVisible, removeChangeListener, setMandatory, setRenderAs
 
Methods inherited from interface de.mguennewig.pobjform.ValueElement
getInitialString, setCurrentAsInitialState
 
Methods inherited from interface de.mguennewig.pobjform.FormElement
appendToList, getContainer, getEntry, getForm, getLabel, getProperty, getPullInPrefix, hasChanged, isPulledIn, omitRowHeader, setLabel, setPullInPrefix, setVisible, startsNewCell, validate
 

Constructor Detail

SwingReferenceElement

public SwingReferenceElement(PObjSwingForm form,
                             InputEntry entry)
Creates a new SwingReferenceElement.

Method Detail

setProperty

public void setProperty(java.lang.String property)
Sets the property to a new value, and propagates the change to all child elements.

Specified by:
setProperty in interface FormElement
Overrides:
setProperty in class AbstractFormElement

setRightAligned

public void setRightAligned(boolean rightAligned)
Sets whether the data should be right aligned.

Specified by:
setRightAligned in interface InputElement
Overrides:
setRightAligned in class AbstractInputElement

getObject

public java.lang.Object getObject()
Returns the current object.

Specified by:
getObject in interface ValueElement
Overrides:
getObject in class AbstractInputElement

setObject

public void setObject(java.lang.Object obj)
Sets the current object to the new value.

Specified by:
setObject in interface ValueElement
Overrides:
setObject in class AbstractInputElement
Throws:
java.lang.IllegalArgumentException - if obj is not null and not a persistent PObject instance.

getInitialObject

public java.lang.Object getInitialObject()
Description copied from interface: ValueElement
Returns the initial object.

Specified by:
getInitialObject in interface ValueElement
Overrides:
getInitialObject in class SwingInputElement
Throws:
PObjReadError - if any database error occurs.
See Also:
ReferenceModel.fromString(Container,ClassDecl,String)

getCurrentString

public java.lang.String getCurrentString()
Description copied from interface: ValueElement
Returns the string representation of the current object.

Specified by:
getCurrentString in interface ValueElement

getVisualString

public java.lang.String getVisualString()
Returns the human readable textual representation of the current value.

This is the value used to write the current value into the UI element. It is never null.

Specified by:
getVisualString in interface InputElement
Overrides:
getVisualString in class AbstractInputElement

getComponent

public javax.swing.JComboBox getComponent()
Returns the Swing component for the input element.

Specified by:
getComponent in interface SwingFormElement
Throws:
PObjReadError - if any database error occurs.

setGroupBy

public void setGroupBy(Member designator,
                       boolean ascending)
Group the set by the designator.

Specified by:
setGroupBy in interface ReferenceElement
See Also:
ReferenceElement.setRestriction(ClassDecl[],Predicate[]), Query.ASCENDING, Query.DESCENDING

setRestriction

public void setRestriction(Predicate filter)
Restrict the set of values to an arbitrary subset of the entries of the referenced table.

Specified by:
setRestriction in interface ReferenceElement
Throws:
PObjReadError - if any database error occurs.
See Also:
ReferenceElement.setRestriction(ClassDecl[],Predicate[])

setRestriction

public void setRestriction(java.lang.Class<? extends PObject>[] tableClasses,
                           Predicate[] filters)
Restrict the set of values to an arbitrary subset of the entries of the referenced table.

Specified by:
setRestriction in interface ReferenceElement
Throws:
PObjReadError - if any database error occurs.
See Also:
ReferenceElement.setRestriction(ClassDecl[],Predicate[])

setRestriction

public void setRestriction(ClassDecl[] tableExprs,
                           Predicate[] filters)
Restrict the set of values to an arbitrary subset of the entries of the referenced table.

By default the set of values is defined as part of the column which is used in the select box. The filter is used as part of the query that returns a list of values of the target table.

Specified by:
setRestriction in interface ReferenceElement
Parameters:
tableExprs - A list of table declarations that will be included in the query. The first element must be the declaration of the referenced table or null.
filters - A list of predicates to restrict the result set of the query or an empty list to clear any filter.
Throws:
PObjReadError - if any database error occurs.
See Also:
Query

isStaticIfOneOption

public boolean isStaticIfOneOption()
Tests whether the input element will be rendered as static if the number of non-null options is exactly one.

Specified by:
isStaticIfOneOption in interface ReferenceElement
See Also:
ReferenceElement.setStaticIfOneOption(boolean)

setStaticIfOneOption

public void setStaticIfOneOption(boolean staticIfOneOption)
Sets whether the input element will be rendered as static if the number on non-null options is exactly one.

Specified by:
setStaticIfOneOption in interface ReferenceElement
Throws:
PObjReadError - if any database error occurs.

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Specified by:
actionPerformed in interface java.awt.event.ActionListener