com.taursys.swing
Class MTable

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JTable
                  extended bycom.taursys.swing.MTable
All Implemented Interfaces:
javax.accessibility.Accessible, javax.swing.event.CellEditorListener, java.util.EventListener, java.awt.image.ImageObserver, javax.swing.event.ListSelectionListener, java.awt.MenuContainer, javax.swing.Scrollable, java.io.Serializable, javax.swing.event.TableColumnModelListener, javax.swing.event.TableModelListener

public class MTable
extends javax.swing.JTable

MTable is an extension of the JTable which binds to data in a ListValueHolder. When you create a new MTable, it creates all the required internal subcomponents needed to be fully functional. You can change any of these subcomponents as needed. Typically, you will create this MTable, set its listValueHolder property, and indicate which properties to display by setting the columnNames property.

There are two ways to setup the columns to display. The first is by simply setting the columnNames property to a String array of property names. This will use default formatting, widths and column titles. Below is an example of this approach:

 private MTable holdersTable = new MTable();
 private VOListValueHolder holder = new VOListValueHolder();
 ...
 private void jbInit() throws Exception {
   holder.setValueObjectClass(com.taursys.tools.ValueHolderInfo.class);
   holdersTable.setListValueHolder(holder);
   holdersTable.setColumnNames(new String[] {
       "holderName","holderAlias",});
 ...
 
The second method gives you much more control over presentation. In this approach, you create an MTableColumn for each column and set its properties. You then add this column to the MTable using the addColumn method. Below is an example of this approach:
 private MTable holdersTable = new MTable();
 private VOListValueHolder holder = new VOListValueHolder();
 private MTableColumn holderNameColumn = new MTableColumn();
 private MTableColumn holderAliasColumn = new MTableColumn();
 ...
 private void jbInit() throws Exception {
   holder.setValueObjectClass(com.taursys.tools.ValueHolderInfo.class);
   holdersTable.setListValueHolder(holder);
   holderNameColumn.setPreferredWidth(80);
   holderNameColumn.setDisplayHeading("Name");
   holderNameColumn.setPropertyName("holderName");
   holderNameColumn.setValueHolder(holder);
   holderNameColumn.setHeaderValue("Holder Name");
   holdersTable.addColumn(holderNameColumn);
   holderAliasColumn.setDisplayHeading("Alias");
   holderAliasColumn.setPropertyName("holderAlias");
   holdersTable.addColumn(holderAliasColumn);
 ...
 
The MTable will display the 2 listed properties for every object in the holder. You can add or remove any object from the holder and the changes will be displayed in the table. Further, if the class which is contained in the VOListValueHolder implements the BoundValueObject interface, any changes to the values will be immediately displayed in the table.

The MTable uses a MTableModel which extends the of the AbstractTableModel. The MTableModel uses a ListValueHolder to contain the actual data for this table. The MTableModel uses a ListSelectionBinder to synchronize the position in this table and the ListValueHolder.

Version:
1.0
Author:
Marty Phelan
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JTable
javax.swing.JTable.AccessibleJTable
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JTable
AUTO_RESIZE_ALL_COLUMNS, AUTO_RESIZE_LAST_COLUMN, AUTO_RESIZE_NEXT_COLUMN, AUTO_RESIZE_OFF, AUTO_RESIZE_SUBSEQUENT_COLUMNS, autoCreateColumnsFromModel, autoResizeMode, cellEditor, cellSelectionEnabled, columnModel, dataModel, defaultEditorsByColumnClass, defaultRenderersByColumnClass, editingColumn, editingRow, editorComp, gridColor, preferredViewportSize, rowHeight, rowMargin, rowSelectionAllowed, selectionBackground, selectionForeground, selectionModel, showHorizontalLines, showVerticalLines, tableHeader
 
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
MTable()
          Construct a new MTable.
 
Method Summary
 void addColumn(javax.swing.table.TableColumn newColumn)
          Add column to ColumnModel for this table (and possibly to MTableModel).
protected  javax.swing.table.TableModel createDefaultDataModel()
          Create a TableModel to be used by this MTable.
 java.lang.String[] getColumnNames()
          Get which columnNames (property names) to display in this MTable.
 java.util.List getList()
          Gets the List that the internal ListValueHolder will use.
 ListValueHolder getListValueHolder()
          Get the ListValueHolder used by the MTableModel
protected  MTableModel getMTableModel()
          Get the current MTableModel for this MTable.
 java.lang.Class getValueObjectClass()
          Get the class of the value object.
 void setColumnNames(java.lang.String[] newColumnNames)
          Set which columnNames (property names) to display in this MTable.
 void setList(java.util.List newList)
          Set the List that the internal ListValueHolder will use.
 void setListValueHolder(ListValueHolder newListValueHolder)
          Set the ListValueHolder used by the MTableModel.
 void setValueObjectClass(java.lang.Class newValueObjectClass)
          Set the class of the value object.
 
Methods inherited from class javax.swing.JTable
addColumnSelectionInterval, addNotify, addRowSelectionInterval, changeSelection, clearSelection, columnAdded, columnAtPoint, columnMarginChanged, columnMoved, columnRemoved, columnSelectionChanged, configureEnclosingScrollPane, convertColumnIndexToModel, convertColumnIndexToView, createDefaultColumnModel, createDefaultColumnsFromModel, createDefaultEditors, createDefaultRenderers, createDefaultSelectionModel, createDefaultTableHeader, createScrollPaneForTable, doLayout, editCellAt, editCellAt, editingCanceled, editingStopped, getAccessibleContext, getAutoCreateColumnsFromModel, getAutoResizeMode, getCellEditor, getCellEditor, getCellRect, getCellRenderer, getCellSelectionEnabled, getColumn, getColumnClass, getColumnCount, getColumnModel, getColumnName, getColumnSelectionAllowed, getDefaultEditor, getDefaultRenderer, getDragEnabled, getEditingColumn, getEditingRow, getEditorComponent, getGridColor, getIntercellSpacing, getModel, getPreferredScrollableViewportSize, getRowCount, getRowHeight, getRowHeight, getRowMargin, getRowSelectionAllowed, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedColumn, getSelectedColumnCount, getSelectedColumns, getSelectedRow, getSelectedRowCount, getSelectedRows, getSelectionBackground, getSelectionForeground, getSelectionModel, getShowHorizontalLines, getShowVerticalLines, getSurrendersFocusOnKeystroke, getTableHeader, getToolTipText, getUI, getUIClassID, getValueAt, initializeLocalVars, isCellEditable, isCellSelected, isColumnSelected, isEditing, isRowSelected, moveColumn, paramString, prepareEditor, prepareRenderer, processKeyBinding, removeColumn, removeColumnSelectionInterval, removeEditor, removeNotify, removeRowSelectionInterval, resizeAndRepaint, rowAtPoint, selectAll, setAutoCreateColumnsFromModel, setAutoResizeMode, setCellEditor, setCellSelectionEnabled, setColumnModel, setColumnSelectionAllowed, setColumnSelectionInterval, setDefaultEditor, setDefaultRenderer, setDragEnabled, setEditingColumn, setEditingRow, setGridColor, setIntercellSpacing, setModel, setPreferredScrollableViewportSize, setRowHeight, setRowHeight, setRowMargin, setRowSelectionAllowed, setRowSelectionInterval, setSelectionBackground, setSelectionForeground, setSelectionMode, setSelectionModel, setShowGrid, setShowHorizontalLines, setShowVerticalLines, setSurrendersFocusOnKeystroke, setTableHeader, setUI, setValueAt, sizeColumnsToFit, sizeColumnsToFit, tableChanged, unconfigureEnclosingScrollPane, updateUI, valueChanged
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, 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
 

Constructor Detail

MTable

public MTable()
Construct a new MTable.

Method Detail

createDefaultDataModel

protected javax.swing.table.TableModel createDefaultDataModel()
Create a TableModel to be used by this MTable. By default, this method returns a MTableModel. It also sets the MTableModel's listSelectionModel to this MTable's listSelectionModel.

Returns:
a TableModel to be used by this MTable.

setValueObjectClass

public void setValueObjectClass(java.lang.Class newValueObjectClass)
Set the class of the value object. Only needed if the valueObject itself can be null. If set, this takes presidence over the actual class of the valueObject. This property is only effective if the internal ListValueHolder is an instanceof VOListValueHolder (which is the default).


getValueObjectClass

public java.lang.Class getValueObjectClass()
Get the class of the value object. Only needed if the valueObject itself can be null. If set, this takes presidence over the actual class of the valueObject. This property is only effective if the internal ListValueHolder is an instanceof VOListValueHolder (which is the default).


setList

public void setList(java.util.List newList)
Set the List that the internal ListValueHolder will use. This property is only effective if the internal ListValueHolder is an instanceof VOListValueHolder (which is the default).


getList

public java.util.List getList()
Gets the List that the internal ListValueHolder will use. This property is only effective if the internal ListValueHolder is an instanceof VOListValueHolder (which is the default).


getMTableModel

protected MTableModel getMTableModel()
Get the current MTableModel for this MTable.

Returns:
the current MTableModel for this MTable.
Throws:
java.lang.ClassCastException - if the internal model does not subclass MTableModel.

getListValueHolder

public ListValueHolder getListValueHolder()
Get the ListValueHolder used by the MTableModel

Returns:
the ListValueHolder used by the MTableModel

setListValueHolder

public void setListValueHolder(ListValueHolder newListValueHolder)
Set the ListValueHolder used by the MTableModel. This method also binds the

Parameters:
newListValueHolder - the ListValueHolder used by the MTableModel

setColumnNames

public void setColumnNames(java.lang.String[] newColumnNames)
Set which columnNames (property names) to display in this MTable.

Parameters:
newColumnNames - a String array of which columnNames (property names) to display in this MTable.

getColumnNames

public java.lang.String[] getColumnNames()
Get which columnNames (property names) to display in this MTable.

Returns:
a String array of which columnNames (property names) to display in this MTable.

addColumn

public void addColumn(javax.swing.table.TableColumn newColumn)
Add column to ColumnModel for this table (and possibly to MTableModel). If the given column is a MTableColumn, additional operations are performed. It will try to set the modelIndex of the MTableColumn based on the MTableColumn's propertyName property. If the propertyName is null or blank, no action will occur. It will attempt to determine the modelIndex by looking up the propertyName in the MTableModel. If not found, it will add the propertyName to the MTableModel. It will then set the MTableColumn's modelIndex to the index in the MTableModel. It will also set the MTableColumn's valueHolder to the MTableModel's valueHolder.



Copyright © 2007 Martin T Phelan. All Rights Reserved.