org.springframework.richclient.table.support
Class AbstractObjectTable

Show UML class diagram
java.lang.Object
  extended by org.springframework.richclient.application.support.ApplicationServicesAccessor
      extended by org.springframework.richclient.factory.AbstractControlFactory
          extended by org.springframework.richclient.table.support.AbstractObjectTable
All Implemented Interfaces:
EventListener, ApplicationListener, ControlFactory
Direct Known Subclasses:
ContactTable

public abstract class AbstractObjectTable
extends AbstractControlFactory
implements ApplicationListener

This class provides a standard table representation for a set of objects with properties of the objects presented in the columns of the table. The table created offers the following features:

  1. It uses Glazed Lists as the underlying data model and this provides for multi-column sorting and text filtering.
  2. It handles row selection.
  3. It offers simple, delegated handling of how to handle a double-click on a row, by setting a command executor. See setDoubleClickHandler(ActionCommandExecutor).
  4. It supports display of a configured pop-up context menu.
  5. It can report on row counts (after filtering) and selection counts to a status bar

Several I18N messages are needed for proper reporting to a configured status bar. The message keys used are:

Message key Usage
modelId.objectName.singular The singular name of the objects in the table
modelId.objectName.plural The plural name of the objects in the table
[modelId].objectTable.showingAll.message The message to show when all objects are being shown, that is no objects have been filtered. This is typically something like "Showing all nn contacts". The message takes the number of objects nd the object name (singular or plural) as parameters.
[modelId].objectTable.showingN.message The message to show when some of the objects have been filtered from the display. This is typically something like "Showing nn contacts of nn". The message takes the shown count, the total count, and the object name (singular or plural) as parameters.
[modelId].objectTable.selectedN.message The message to append to the filter message when the selection is not empty. Typically something like ", nn selected". The message takes the number of selected entries as a parameter.

Note that the message keys that show the model id in brackets, like this [modelId], indicate that the model id is optional. If no message is found using the model id, then the key will be tried without the model id and the resulting string will be used. This makes it easy to construct one single message property that can be used on numerous tables.

Note: If you are using application events to inform UI components of changes to domain objects, then instances of this class have to be wired into the event distribution. To do this, you should construct instances (of concrete subclasses) in the application context. They will automatically be wired into the epplication event mechanism because this class implements ApplicationListener.

Author:
Larry Streepy

Field Summary
static String SELECTEDN_MSG_KEY
           
static String SHOWINGALL_MSG_KEY
           
static String SHOWINGN_MSG_KEY
           
 
Fields inherited from class org.springframework.richclient.application.support.ApplicationServicesAccessor
logger
 
Constructor Summary
AbstractObjectTable(String modelId, String[] columnPropertyNames)
          Constructor.
 
Method Summary
protected  void configureTable(JTable table)
          Configure the newly created table as needed.
protected  JComponent createControl()
          Subclasses must override this method to create a new instance of the control that this factory produces.
protected  JPopupMenu createPopupContextMenu()
          Create the context popup menu, if any, for this table.
protected  JPopupMenu createPopupContextMenu(MouseEvent e)
          Create the context popup menu, if any, for this table.
protected  GlazedTableModel createTableModel(ca.odell.glazedlists.EventList eventList)
          Construct the table model for this table.
protected  ca.odell.glazedlists.gui.AbstractTableComparatorChooser createTableSorter(JTable table, ca.odell.glazedlists.SortedList sortedList)
           
 ca.odell.glazedlists.EventList getBaseEventList()
          Get the base event list for the table model.
 String[] getColumnPropertyNames()
          Get the names of the properties to display in the table columns.
protected abstract  Object[] getDefaultInitialData()
          Get the default set of objects for this table.
 ActionCommandExecutor getDoubleClickHandler()
           
 ca.odell.glazedlists.EventList getFinalEventList()
          Get the event list to be use for constructing the table model.
 Object[] getInitialData()
          Get the initial data to display.
protected  int getInitialSortColumn()
          Get the default sort column.
 String getModelId()
           
 CommandGroup getPopupCommandGroup()
           
 ListSelectionModel getSelectionModel()
          Get the selection model.
protected  JTable getTable()
          Returns the created JTable.
 GlazedTableModel getTableModel()
          Get the data model for the table.
protected  ca.odell.glazedlists.gui.AbstractTableComparatorChooser getTableSorter()
          Returns the sorter which is used to sort the content of the table
protected  void handleDeletedObject(Object object)
          Handle the deletion of an object in this table.
protected  void handleNewObject(Object object)
          Handle the creation of a new object.
protected  void handleUpdatedObject(Object object)
          Handle an updated object in this table.
protected  void init()
          Initialize our internal values.
protected  boolean isMultipleColumnSort()
           
 void onApplicationEvent(ApplicationEvent e)
          Handle an application event.
protected  void onDoubleClick()
          Handle a double click on a row of the table.
protected  void runWithReadLock(Runnable runnable)
          Executes the runnable with a read lock on the event list.
protected  void runWithWriteLock(Runnable runnable)
          Executes the runnable with a write lock on the event list.
 void setColumnPropertyNames(String[] columnPropertyNames)
          Set the names of the properties to display in the table columns.
 void setDoubleClickHandler(ActionCommandExecutor doubleClickHandler)
          Set the handler (action executor) that should be invoked when a row in the table is double-clicked.
 void setFinalEventList(ca.odell.glazedlists.EventList finalEventList)
          Set the event list to be used for constructing the table model.
 void setInitialData(Object[] initialData)
          Set the initial data to display.
 void setPopupCommandGroup(CommandGroup popupCommandGroup)
          Set the command group that should be used to construct the popup menu when a user initiates the UI gesture to show the context menu.
 void setStatusBar(StatusBar statusBar)
          Set the status bar associated with this table.
protected  boolean shouldHandleEvent(ApplicationEvent event)
          Determine if the event should be handled on this table.
protected  void updateStatusBar()
          Update the status bar with the current display counts.
 
Methods inherited from class org.springframework.richclient.factory.AbstractControlFactory
createControlIfNecessary, getControl, isControlCreated, isSingleton, setSingleton
 
Methods inherited from class org.springframework.richclient.application.support.ApplicationServicesAccessor
getActiveWindow, getApplication, getApplicationContext, getApplicationName, getApplicationServices, getCommandConfigurer, getComponentFactory, getConversionService, getIconSource, getImageSource, getMessage, getMessage, getMessage, getMessage, getMessages, getMessageSource, getObjectConfigurer, getService
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SHOWINGALL_MSG_KEY

public static final String SHOWINGALL_MSG_KEY
See Also:
Constant Field Values

SHOWINGN_MSG_KEY

public static final String SHOWINGN_MSG_KEY
See Also:
Constant Field Values

SELECTEDN_MSG_KEY

public static final String SELECTEDN_MSG_KEY
See Also:
Constant Field Values
Constructor Detail

AbstractObjectTable

public AbstractObjectTable(String modelId,
                           String[] columnPropertyNames)
Constructor.

Parameters:
modelId - used for generating message keys
objectType - The type of object held in the table
Method Detail

setInitialData

public void setInitialData(Object[] initialData)
Set the initial data to display.

Parameters:
initialData - Array of objects to display

getInitialData

public Object[] getInitialData()
Get the initial data to display. If none has been set, then return the default initial data.

Returns:
initial data to display
See Also:
getDefaultInitialData()

getBaseEventList

public ca.odell.glazedlists.EventList getBaseEventList()
Get the base event list for the table model. This can be used to build layered event models for filtering.

Returns:
base event list

setFinalEventList

public void setFinalEventList(ca.odell.glazedlists.EventList finalEventList)
Set the event list to be used for constructing the table model. The event list provided MUST have been constructed from the list returned by getBaseEventList() or this table will not work properly.

Parameters:
event - list to use

getFinalEventList

public ca.odell.glazedlists.EventList getFinalEventList()
Get the event list to be use for constructing the table model.

Returns:
final event list

getTableModel

public GlazedTableModel getTableModel()
Get the data model for the table.

Note: This method returns null unless getTable() or #createTable() is called

Returns:
model the table model which is used for the table

getColumnPropertyNames

public String[] getColumnPropertyNames()
Get the names of the properties to display in the table columns.

Returns:
array of columnproperty names

setColumnPropertyNames

public void setColumnPropertyNames(String[] columnPropertyNames)
Set the names of the properties to display in the table columns.

Parameters:
columnPropertyNames -

getDoubleClickHandler

public ActionCommandExecutor getDoubleClickHandler()
Returns:
the doubleClickHandler

setDoubleClickHandler

public void setDoubleClickHandler(ActionCommandExecutor doubleClickHandler)
Set the handler (action executor) that should be invoked when a row in the table is double-clicked.

Parameters:
doubleClickHandler - the doubleClickHandler to set

getTableSorter

protected ca.odell.glazedlists.gui.AbstractTableComparatorChooser getTableSorter()
Returns the sorter which is used to sort the content of the table

Returns:
the sorter, null if getTable() or #createTable() is not called before

getPopupCommandGroup

public CommandGroup getPopupCommandGroup()
Returns:
the popupCommandGroup

setPopupCommandGroup

public void setPopupCommandGroup(CommandGroup popupCommandGroup)
Set the command group that should be used to construct the popup menu when a user initiates the UI gesture to show the context menu. If this is null, then no popup menu will be shown.

Parameters:
popupCommandGroup - the popupCommandGroup to set

setStatusBar

public void setStatusBar(StatusBar statusBar)
Set the status bar associated with this table. If non-null, then any time the final event list on this table changes, then the status bar will be updated with the current object counts.

Parameters:
statusBar - to update

getModelId

public String getModelId()
Returns:
the modelId

init

protected void init()
Initialize our internal values.


createControl

protected JComponent createControl()
Description copied from class: AbstractControlFactory
Subclasses must override this method to create a new instance of the control that this factory produces.

Specified by:
createControl in class AbstractControlFactory
Returns:
The newly created control, never null.

configureTable

protected void configureTable(JTable table)
Configure the newly created table as needed. Install any needed column sizes, renderers, and comparators. The default implementation does nothing.

Parameters:
table - The table to configure

getDefaultInitialData

protected abstract Object[] getDefaultInitialData()
Get the default set of objects for this table.

Returns:
Array of data for the table

getTable

protected JTable getTable()
Returns the created JTable.


createTableSorter

protected ca.odell.glazedlists.gui.AbstractTableComparatorChooser createTableSorter(JTable table,
                                                                                    ca.odell.glazedlists.SortedList sortedList)

isMultipleColumnSort

protected boolean isMultipleColumnSort()

onDoubleClick

protected void onDoubleClick()
Handle a double click on a row of the table. The row will already be selected.


createTableModel

protected GlazedTableModel createTableModel(ca.odell.glazedlists.EventList eventList)
Construct the table model for this table. The default implementation of this creates a GlazedTableModel using an Advanced format.

Parameters:
eventList - on which to build the model
Returns:
table model

shouldHandleEvent

protected boolean shouldHandleEvent(ApplicationEvent event)
Determine if the event should be handled on this table. If true is returned (the default), then the list holding the table data will be scanned for the object and updated appropriately depending on then event type.

Parameters:
event - to inspect
Returns:
boolean true if the object should be handled, false otherwise
See Also:
handleDeletedObject(Object), handleNewObject(Object), handleUpdatedObject(Object)

createPopupContextMenu

protected JPopupMenu createPopupContextMenu()
Create the context popup menu, if any, for this table. The default operation is to create the popup from the command group if one has been specified. If not, then null is returned.

Returns:
popup menu to show, or null if none

createPopupContextMenu

protected JPopupMenu createPopupContextMenu(MouseEvent e)
Create the context popup menu, if any, for this table. The default operation is to create the popup from the command group if one has been specified. If not, then null is returned.

Parameters:
e - the event which contains information about the current context.
Returns:
popup menu to show, or null if none

getInitialSortColumn

protected int getInitialSortColumn()
Get the default sort column. Defaults to 0.

Returns:
column to sort on

getSelectionModel

public ListSelectionModel getSelectionModel()
Get the selection model.

Returns:
selection model

runWithWriteLock

protected void runWithWriteLock(Runnable runnable)
Executes the runnable with a write lock on the event list.

Parameters:
runnable - its run method is executed while holding a write lock for the event list.
See Also:
getFinalEventList()

runWithReadLock

protected void runWithReadLock(Runnable runnable)
Executes the runnable with a read lock on the event list.

Parameters:
runnable - its run method is executed while holding a read lock for the event list.
See Also:
getFinalEventList()

handleNewObject

protected void handleNewObject(Object object)
Handle the creation of a new object.

Parameters:
object - New object to handle

handleUpdatedObject

protected void handleUpdatedObject(Object object)
Handle an updated object in this table. Locate the existing entry (by equals) and replace it in the underlying list.

Parameters:
object - Updated object to handle

handleDeletedObject

protected void handleDeletedObject(Object object)
Handle the deletion of an object in this table. Locate this entry (by equals) and delete it.

Parameters:
object - Updated object being deleted

updateStatusBar

protected void updateStatusBar()
Update the status bar with the current display counts.


onApplicationEvent

public void onApplicationEvent(ApplicationEvent e)
Handle an application event. This will notify us of object adds, deletes, and modifications. Update our table model accordingly.

Specified by:
onApplicationEvent in interface ApplicationListener
Parameters:
e - event to process


Copyright © 2004-2009 The Spring Framework. All Rights Reserved.