org.formaria.swing.pojo
Class PojoPanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by org.formaria.swing.Panel
                      extended by org.formaria.swing.pojo.PojoPanel
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, MultiAttributedComponent, PersistentState

public class PojoPanel
extends Panel
implements MultiAttributedComponent

A panel that accepts a POJO as an argument and constructs a form in response

Copyright (c) Formaria Ltd., 2001-2008, This software is licensed under the GNU Public License (GPL), please see license.txt for more details. If you make commercial use of this software you must purchase a commercial license from Formaria.

See Also:
Serialized Form

Nested Class Summary
 class PojoPanel.PojoPanelFocusTraversalPolicy
           
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  boolean alwaysDirty
           
protected  java.util.Hashtable<java.lang.String,java.lang.Object> backingStore
           
protected  AriaBuilder builder
           
protected  int colWidth
           
protected  StyleFactory componentFactory
           
protected  java.lang.String dataPath
           
protected  boolean enabledByDefault
           
protected  java.util.ArrayList<java.lang.String> excludes
           
protected  java.util.ArrayList<java.beans.PropertyDescriptor> fields
           
protected  java.lang.String fieldValidationRule
           
protected  boolean includeByDefault
           
protected  boolean inputEnabled
           
protected  int labelWidth
           
protected  int numCols
           
protected  java.util.ArrayList<java.lang.String> paths
           
protected  java.lang.Class pojoClass
           
protected  Project project
           
protected  java.beans.PropertyDescriptor[] properties
           
protected  DataModel rootModel
           
protected  int rowHeight
           
protected  int spacing
           
protected  Translator translator
           
protected  boolean useColumnOrder
           
protected  java.util.Hashtable<java.lang.String,XmlElement> viewFields
           
protected  XmlElement viewModel
           
protected  java.util.ArrayList<java.lang.String> viewOrder
           
protected  java.lang.String viewPath
           
 
Fields inherited from class org.formaria.swing.Panel
arc, BORDER_BEVEL, BORDER_FLAT, BORDER_NONE, drawBorder, padding, translucent, usesLaf
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
PojoPanel()
           
 
Method Summary
 void allAttributesSet()
          Called when all the attributes have been set
 void backupInputs()
          Store the input values to a backing store
 void enableInputs(boolean state)
          Enabled the input fields
 int getColWidth()
          Get the column width
protected  void getCompoundProperty(java.beans.PropertyDescriptor[] pp, java.lang.String target)
          Get the property descriptor corresponding to a compound path using '.' separators.
protected  void getCompoundProperty(java.beans.PropertyDescriptor properties, java.lang.String target)
           
 java.lang.String getDataPath()
          Get the POJO path within the data model
protected  java.lang.String getDisplayName(java.lang.String fieldName, java.lang.String defaultName)
          Try to get the display name
 java.lang.String getFieldValidationRule()
          Get the name of the field validation rule
 int getLabelWidth()
          Get the label width
 int getNumCols()
          Get the number of columns
 java.awt.Dimension getPreferredSize()
          Get the preferred size of the panel.
 int getRowHeight()
          Get the row height
 int getSpacing()
          Get the input field spacing
 boolean isAlwaysDirty()
          Get the alwaysDirty flag
 boolean isEnabledByDefault()
          Are the input fields enabled by default?
protected  boolean isFieldEnabled(java.lang.String fieldName)
           
protected  boolean isFieldExcluded(java.lang.String name)
          Is the field excluded from the form?
protected  boolean isFieldVisible(java.lang.String fieldName)
           
 boolean isFocusCycleRoot()
          Provide to support setting of the focus traversal policy
 boolean isIncludeByDefault()
          Get the include by default flag
 boolean isInputEnabled()
          Are the inputs enabled?
 boolean isUseColumnOrder()
          Get the input field traversal mode
 void loadDefaultViewFile()
          Attempt to load the default view file.
protected  void populatePanel()
           
 void resetEnabledState()
          Return the input fields to their default state
 void restoreInputs()
          Store the input values to a backing store
 void setAlwaysDirty(boolean alwaysDirty)
          Set the always dirty flag
 void setColWidth(int colWidth)
          Set the column width.
 void setDataPath(java.lang.String path)
          Set the path to the POJO instance
 void setEnabledByDefault(boolean enabledByDefault)
          Set the default enabled status
 void setExclude(java.lang.String attribValue)
          Set a comma separated list of excluded fields
 void setFieldOrder(java.lang.String fieldOrder)
          Set the order of the input fields.
 void setFieldValidationRule(java.lang.String fieldValidationRule)
          Set the name of the field validation rule
 void setIncludeByDefault(boolean includeByDefault)
          Flag that all fields are to be included by default
 void setInputEnabled(boolean inputEnabled)
           
 void setLabelWidth(int labelWidth)
          Set the label or prompt width in pixels.
 void setNumCols(int numCols)
          Set the number of columns over which to display the inputs
 void setPojoClass(java.lang.String className)
           
 void setRowHeight(int rowHeight)
          Set the row height in pixels.
 void setSpacing(int spacing)
          Set the input field spacing
 void setUseColumnOrder(boolean useColumnOrder)
          Set the column vs row input field traversal mode
 void setViewFile(java.lang.String resName)
          Read the view file
 void setViewPath(java.lang.String path)
          Read the view file
 
Methods inherited from class org.formaria.swing.Panel
addNotify, getArc, getDrawBorder, getInsets, getPainter, getUsesLaf, paintComponent, restoreState, saveState, setArc, setBlend, setBorder, setBounds, setDrawBorder, setImageName, setPad, setPainter, setSwingBorder, setTitle, setTitlePos, setTitlePosition, setTitleStyle, setToolTip, setTranslucent, setUsesLaf, update
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

excludes

protected java.util.ArrayList<java.lang.String> excludes

viewFields

protected java.util.Hashtable<java.lang.String,XmlElement> viewFields

viewOrder

protected java.util.ArrayList<java.lang.String> viewOrder

viewModel

protected XmlElement viewModel

viewPath

protected java.lang.String viewPath

fields

protected java.util.ArrayList<java.beans.PropertyDescriptor> fields

paths

protected java.util.ArrayList<java.lang.String> paths

properties

protected java.beans.PropertyDescriptor[] properties

numCols

protected int numCols

rowHeight

protected int rowHeight

labelWidth

protected int labelWidth

colWidth

protected int colWidth

spacing

protected int spacing

pojoClass

protected java.lang.Class pojoClass

project

protected Project project

translator

protected Translator translator

componentFactory

protected StyleFactory componentFactory

rootModel

protected DataModel rootModel

builder

protected AriaBuilder builder

dataPath

protected java.lang.String dataPath

enabledByDefault

protected boolean enabledByDefault

inputEnabled

protected boolean inputEnabled

alwaysDirty

protected boolean alwaysDirty

useColumnOrder

protected boolean useColumnOrder

includeByDefault

protected boolean includeByDefault

fieldValidationRule

protected java.lang.String fieldValidationRule

backingStore

protected java.util.Hashtable<java.lang.String,java.lang.Object> backingStore
Constructor Detail

PojoPanel

public PojoPanel()
Method Detail

allAttributesSet

public void allAttributesSet()
Description copied from interface: MultiAttributedComponent
Called when all the attributes have been set

Specified by:
allAttributesSet in interface MultiAttributedComponent

setPojoClass

public void setPojoClass(java.lang.String className)

getPreferredSize

public java.awt.Dimension getPreferredSize()
Get the preferred size of the panel. If no layout is used then the maximum X and y coordinates used in this panel are returned.

Overrides:
getPreferredSize in class Panel
Returns:
the preferred size of this panel

populatePanel

protected void populatePanel()

resetEnabledState

public void resetEnabledState()
Return the input fields to their default state


enableInputs

public void enableInputs(boolean state)
Enabled the input fields

Parameters:
state - the enabled state

isInputEnabled

public boolean isInputEnabled()
Are the inputs enabled?

Returns:
true if the user can inout data

backupInputs

public void backupInputs()
Store the input values to a backing store


restoreInputs

public void restoreInputs()
Store the input values to a backing store


loadDefaultViewFile

public void loadDefaultViewFile()
Attempt to load the default view file. The file name is taken from the data model path and it is assumed that the view files is in the pages/views folder. The method is called as part of the population of the panel with input fields.


setViewFile

public void setViewFile(java.lang.String resName)
Read the view file

Parameters:
resName -

setViewPath

public void setViewPath(java.lang.String path)
Read the view file

Parameters:
path - the name of the model path containing the view

isFieldExcluded

protected boolean isFieldExcluded(java.lang.String name)
Is the field excluded from the form?

Parameters:
name - the field/property name
Returns:
true if the field is to be excluded

getDisplayName

protected java.lang.String getDisplayName(java.lang.String fieldName,
                                          java.lang.String defaultName)
Try to get the display name

Parameters:
fieldName -
defaultName -
Returns:

isFieldEnabled

protected boolean isFieldEnabled(java.lang.String fieldName)

isFieldVisible

protected boolean isFieldVisible(java.lang.String fieldName)

getCompoundProperty

protected void getCompoundProperty(java.beans.PropertyDescriptor[] pp,
                                   java.lang.String target)
                            throws java.beans.IntrospectionException
Get the property descriptor corresponding to a compound path using '.' separators.

Parameters:
pp -
target -
Throws:
java.beans.IntrospectionException

getCompoundProperty

protected void getCompoundProperty(java.beans.PropertyDescriptor properties,
                                   java.lang.String target)
                            throws java.beans.IntrospectionException
Throws:
java.beans.IntrospectionException

isFocusCycleRoot

public boolean isFocusCycleRoot()
Provide to support setting of the focus traversal policy

Overrides:
isFocusCycleRoot in class java.awt.Container
Returns:

setFieldOrder

public void setFieldOrder(java.lang.String fieldOrder)
Set the order of the input fields. A comma separated list of fields

Parameters:
fieldOrder -

getNumCols

public int getNumCols()
Get the number of columns

Returns:

setNumCols

public void setNumCols(int numCols)
Set the number of columns over which to display the inputs

Parameters:
numCols - the number of columns

getRowHeight

public int getRowHeight()
Get the row height

Returns:
the height in pixels

setRowHeight

public void setRowHeight(int rowHeight)
Set the row height in pixels. The input field will be the height of the row less the row spacing

Parameters:
rowHeight - the row height

getLabelWidth

public int getLabelWidth()
Get the label width

Returns:
the width in pixels

setLabelWidth

public void setLabelWidth(int labelWidth)
Set the label or prompt width in pixels. This width is fixes and does not relate to the panel size

Parameters:
labelWidth - the width in pixels

getColWidth

public int getColWidth()
Get the column width

Returns:
the width in pixels

setColWidth

public void setColWidth(int colWidth)
Set the column width. The column width is fixed and does not relate to the size of the panel

Parameters:
colWidth - the width in pixels

getSpacing

public int getSpacing()
Get the input field spacing

Returns:

setSpacing

public void setSpacing(int spacing)
Set the input field spacing

Parameters:
spacing - the spacing in pixels

getDataPath

public java.lang.String getDataPath()
Get the POJO path within the data model

Returns:

setDataPath

public void setDataPath(java.lang.String path)
Set the path to the POJO instance


isEnabledByDefault

public boolean isEnabledByDefault()
Are the input fields enabled by default?

Returns:

setEnabledByDefault

public void setEnabledByDefault(boolean enabledByDefault)
Set the default enabled status

Parameters:
enabledByDefault -

setInputEnabled

public void setInputEnabled(boolean inputEnabled)

isAlwaysDirty

public boolean isAlwaysDirty()
Get the alwaysDirty flag

Returns:

setAlwaysDirty

public void setAlwaysDirty(boolean alwaysDirty)
Set the always dirty flag

Parameters:
alwaysDirty - true to always mark the POJO as dirty

isUseColumnOrder

public boolean isUseColumnOrder()
Get the input field traversal mode

Returns:

setUseColumnOrder

public void setUseColumnOrder(boolean useColumnOrder)
Set the column vs row input field traversal mode

Parameters:
useColumnOrder - if true traverse the input fields column by column

isIncludeByDefault

public boolean isIncludeByDefault()
Get the include by default flag

Returns:
true if all fields are automatically included (unless explicitly excluded)

setIncludeByDefault

public void setIncludeByDefault(boolean includeByDefault)
Flag that all fields are to be included by default

Parameters:
includeByDefault - true to include all fields

getFieldValidationRule

public java.lang.String getFieldValidationRule()
Get the name of the field validation rule


setFieldValidationRule

public void setFieldValidationRule(java.lang.String fieldValidationRule)
Set the name of the field validation rule

Parameters:
fieldValidationRule -

setExclude

public void setExclude(java.lang.String attribValue)
Set a comma separated list of excluded fields

Parameters:
attribValue - the list of fields