net.xoetrope.swing
Class XTable

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JTable
                  extended by net.xoetrope.swing.XTable
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.CellEditorListener, javax.swing.event.ListSelectionListener, javax.swing.event.RowSorterListener, javax.swing.event.TableColumnModelListener, javax.swing.event.TableModelListener, javax.swing.Scrollable, XRowSelector, XListenerHelper, XStyleComponent, XAttributedComponent, XModelHolder
Direct Known Subclasses:
XTable2

public class XTable
extends javax.swing.JTable
implements XAttributedComponent, XModelHolder, XStyleComponent, XRowSelector, XListenerHelper, javax.swing.event.ListSelectionListener

Provides a wrapper for the JTable and offer some compatibility with the AWT version of the XTable.

Copyright (c) Xoetrope Ltd., 1998-2004
License: see license.txt $Revision: 2.12 $

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JTable
javax.swing.JTable.AccessibleJTable, javax.swing.JTable.DropLocation, javax.swing.JTable.PrintMode
 
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  XProject currentProject
           
protected  java.lang.String headerStyle
           
protected  XHandlerInvoker invoker
           
protected  XModel model
           
protected  int oldRowSelection
           
protected  boolean updateModelSelection
           
protected  boolean usesDatabase
           
 
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
XTable()
          Create a new table
 
Method Summary
 void addHandler(java.lang.Object page, java.lang.String handlerType, java.lang.String methodName)
          Add an event handler response method to a component such that the page's response method is invoked when the event occurs
 void clearSelection()
          Deselects all selected columns and rows.
protected  javax.swing.table.JTableHeader createDefaultTableHeader()
           
 void first()
          Move to the first row
 javax.swing.table.TableCellEditor getCellEditor(int row, int column)
          Retrieves the TableCellEditor for a cell if one has been specified with the "editor" attribute
 java.lang.String getFieldValue(int fieldIdx)
          Gets a field value as a string from the currently selected row
 java.lang.String getFieldValue(int rowIdx, int fieldIdx)
          Gets a field value as a string from the specified row
 java.lang.String getHeaderStyle()
          Retrieve the name of the header style
 boolean getScrollableTracksViewportHeight()
          Force the scroll pane to set the component size if there is no data - otherwise the table would have no height
 boolean getTranslated()
          Get the translateable state of the table
 java.lang.Object getValue(int fieldIdx)
          Gets a field value object from the currently selected row
 java.lang.Object getValue(int rowIdx, int fieldIdx)
          Gets a field value object from the specified row
 XModel getXModel()
          Get the underlying model.
 boolean isInteractiveTable()
          Check the if the table is interactive
 void last()
          Move to the last row
 void next()
          Move to the next row
 void prev()
          Move to the previous row
 int setAttribute(java.lang.String attribName, java.lang.Object attribValue)
          Set one or more attributes of the component.
 void setBorderStyle(java.lang.String style)
          Set the style of the border
 void setColWidth(int columnIdx, int width)
          Set the column width.
 void setHeaderStyle(java.lang.String style)
          Set the style of the header data
 void setInteractiveTable(boolean state)
          Set the user interaction state
 void setModel(XModel xmodel)
          Set the XModel which we will be generating the table from
 void setSelectedRow(int idx)
          Sets the indexof the selected row
 void setSelectedStyle(java.lang.String style)
          Set the style of the selected row
 void setSelectionMode(java.lang.String value)
          Set the table selection mode
 void setStyle(java.lang.String style)
          Set the general style of the XTable
 void setTranslated(boolean state)
          Set the translateable state of the model
 void setUpdateModelSelection(boolean doUpdate)
          Tie the model selection to this table's selection
 void setViewportBackground(java.awt.Color viewportBkColor)
          Set the background color of the table's viewport
 void update()
          The model is modified and the UI needs to be updated.
 void updateTable()
          Force the table to update itself
 void valueChanged(javax.swing.event.ListSelectionEvent le)
          The row selection has changes, update the model if required.
 
Methods inherited from class javax.swing.JTable
addColumn, addColumnSelectionInterval, addNotify, addRowSelectionInterval, changeSelection, columnAdded, columnAtPoint, columnMarginChanged, columnMoved, columnRemoved, columnSelectionChanged, configureEnclosingScrollPane, convertColumnIndexToModel, convertColumnIndexToView, convertRowIndexToModel, convertRowIndexToView, createDefaultColumnModel, createDefaultColumnsFromModel, createDefaultDataModel, createDefaultEditors, createDefaultRenderers, createDefaultSelectionModel, createScrollPaneForTable, doLayout, editCellAt, editCellAt, editingCanceled, editingStopped, getAccessibleContext, getAutoCreateColumnsFromModel, getAutoCreateRowSorter, getAutoResizeMode, getCellEditor, getCellRect, getCellRenderer, getCellSelectionEnabled, getColumn, getColumnClass, getColumnCount, getColumnModel, getColumnName, getColumnSelectionAllowed, getDefaultEditor, getDefaultRenderer, getDragEnabled, getDropLocation, getDropMode, getEditingColumn, getEditingRow, getEditorComponent, getFillsViewportHeight, getGridColor, getIntercellSpacing, getModel, getPreferredScrollableViewportSize, getPrintable, getRowCount, getRowHeight, getRowHeight, getRowMargin, getRowSelectionAllowed, getRowSorter, getScrollableBlockIncrement, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedColumn, getSelectedColumnCount, getSelectedColumns, getSelectedRow, getSelectedRowCount, getSelectedRows, getSelectionBackground, getSelectionForeground, getSelectionModel, getShowHorizontalLines, getShowVerticalLines, getSurrendersFocusOnKeystroke, getTableHeader, getToolTipText, getUI, getUIClassID, getUpdateSelectionOnSort, getValueAt, initializeLocalVars, isCellEditable, isCellSelected, isColumnSelected, isEditing, isRowSelected, moveColumn, paramString, prepareEditor, prepareRenderer, print, print, print, print, print, processKeyBinding, removeColumn, removeColumnSelectionInterval, removeEditor, removeNotify, removeRowSelectionInterval, resizeAndRepaint, rowAtPoint, selectAll, setAutoCreateColumnsFromModel, setAutoCreateRowSorter, setAutoResizeMode, setCellEditor, setCellSelectionEnabled, setColumnModel, setColumnSelectionAllowed, setColumnSelectionInterval, setDefaultEditor, setDefaultRenderer, setDragEnabled, setDropMode, setEditingColumn, setEditingRow, setFillsViewportHeight, setGridColor, setIntercellSpacing, setModel, setPreferredScrollableViewportSize, setRowHeight, setRowHeight, setRowMargin, setRowSelectionAllowed, setRowSelectionInterval, setRowSorter, setSelectionBackground, setSelectionForeground, setSelectionMode, setSelectionModel, setShowGrid, setShowHorizontalLines, setShowVerticalLines, setSurrendersFocusOnKeystroke, setTableHeader, setUI, setUpdateSelectionOnSort, setValueAt, sizeColumnsToFit, sizeColumnsToFit, sorterChanged, tableChanged, unconfigureEnclosingScrollPane, 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, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, 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, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, 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, 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
 
Methods inherited from interface net.xoetrope.xui.data.XRowSelector
getSelectedRow
 

Field Detail

currentProject

protected XProject currentProject

model

protected XModel model

updateModelSelection

protected boolean updateModelSelection

invoker

protected XHandlerInvoker invoker

oldRowSelection

protected int oldRowSelection

usesDatabase

protected boolean usesDatabase

headerStyle

protected java.lang.String headerStyle
Constructor Detail

XTable

public XTable()
Create a new table

Method Detail

createDefaultTableHeader

protected javax.swing.table.JTableHeader createDefaultTableHeader()
Overrides:
createDefaultTableHeader in class javax.swing.JTable

update

public void update()
Description copied from interface: XModelHolder
The model is modified and the UI needs to be updated.

Specified by:
update in interface XModelHolder

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Force the scroll pane to set the component size if there is no data - otherwise the table would have no height

Specified by:
getScrollableTracksViewportHeight in interface javax.swing.Scrollable
Overrides:
getScrollableTracksViewportHeight in class javax.swing.JTable

updateTable

public void updateTable()
Force the table to update itself


addHandler

public void addHandler(java.lang.Object page,
                       java.lang.String handlerType,
                       java.lang.String methodName)
                throws java.lang.NoSuchMethodException
Add an event handler response method to a component such that the page's response method is invoked when the event occurs

Specified by:
addHandler in interface XListenerHelper
Parameters:
page - the page containing the method
handlerType - the type of event handler
methodName - the method to invoke
Throws:
java.lang.NoSuchMethodException - cannot add the handler

valueChanged

public void valueChanged(javax.swing.event.ListSelectionEvent le)
The row selection has changes, update the model if required.

Specified by:
valueChanged in interface javax.swing.event.ListSelectionListener
Overrides:
valueChanged in class javax.swing.JTable
Parameters:
le - the list selection event

setModel

public void setModel(XModel xmodel)
Set the XModel which we will be generating the table from

Specified by:
setModel in interface XModelHolder
Parameters:
xmodel - The XModel of data

getXModel

public XModel getXModel()
Get the underlying model.

Returns:
the model

setStyle

public void setStyle(java.lang.String style)
Set the general style of the XTable

Specified by:
setStyle in interface XStyleComponent
Parameters:
style - XStyle

setViewportBackground

public void setViewportBackground(java.awt.Color viewportBkColor)
Set the background color of the table's viewport

Parameters:
viewportBkColor - the viewport background color

setHeaderStyle

public void setHeaderStyle(java.lang.String style)
Set the style of the header data

Parameters:
style - XStyle

getHeaderStyle

public java.lang.String getHeaderStyle()
Retrieve the name of the header style

Returns:
the header style name;

setSelectedStyle

public void setSelectedStyle(java.lang.String style)
Set the style of the selected row

Parameters:
style - XStyle

setBorderStyle

public void setBorderStyle(java.lang.String style)
Set the style of the border

Parameters:
style - XStyle

isInteractiveTable

public boolean isInteractiveTable()
Check the if the table is interactive

Returns:
true if the table supports user interaction

setInteractiveTable

public void setInteractiveTable(boolean state)
Set the user interaction state

Parameters:
state - true for an user interactive table.

setSelectedRow

public void setSelectedRow(int idx)
Sets the indexof the selected row

Specified by:
setSelectedRow in interface XRowSelector
Parameters:
idx - the new selected row

clearSelection

public void clearSelection()
Deselects all selected columns and rows.

Overrides:
clearSelection in class javax.swing.JTable

setTranslated

public void setTranslated(boolean state)
Set the translateable state of the model

Parameters:
state - 'true' for a transalted table

getTranslated

public boolean getTranslated()
Get the translateable state of the table

Returns:
true if the table is translateable

first

public void first()
Move to the first row


prev

public void prev()
Move to the previous row


next

public void next()
Move to the next row


last

public void last()
Move to the last row


setUpdateModelSelection

public void setUpdateModelSelection(boolean doUpdate)
Tie the model selection to this table's selection

Parameters:
doUpdate - true to tie the selections together, false to ignore

setColWidth

public void setColWidth(int columnIdx,
                        int width)
Set the column width. Sets the maximum width as a workaround for a Swing problem

Parameters:
columnIdx - the column index
width - the new width

setAttribute

public int setAttribute(java.lang.String attribName,
                        java.lang.Object attribValue)
Set one or more attributes of the component. Currently this handles the attributes
  1. headingStyle, value=the table header style
  2. selectionStyle, value=the selected row style
  3. interactive, value=true|false
  4. updateModel, value=true|false update the underlying model selection (the selected row)

Specified by:
setAttribute in interface XAttributedComponent
Parameters:
attribName - the attribute name
attribValue - the attribute value
Returns:
0 for success, non zero for failure or to require some further action

setSelectionMode

public void setSelectionMode(java.lang.String value)
Set the table selection mode

Parameters:
value - 'multiple' for ListSelectionModel.MULTIPLE_INTERVAL_SELECTION, other wise ListSelectionModel.SINGLE_INTERVAL_SELECTION

getValue

public java.lang.Object getValue(int fieldIdx)
Gets a field value object from the currently selected row

Parameters:
fieldIdx - the field offset
Returns:
the value

getValue

public java.lang.Object getValue(int rowIdx,
                                 int fieldIdx)
Gets a field value object from the specified row

Parameters:
rowIdx - the row offset
fieldIdx - the field offset
Returns:
the value

getFieldValue

public java.lang.String getFieldValue(int fieldIdx)
Gets a field value as a string from the currently selected row

Parameters:
fieldIdx - the field offset
Returns:
the value

getFieldValue

public java.lang.String getFieldValue(int rowIdx,
                                      int fieldIdx)
Gets a field value as a string from the specified row

Parameters:
rowIdx - the row offset
fieldIdx - the field offset
Returns:
the value

getCellEditor

public javax.swing.table.TableCellEditor getCellEditor(int row,
                                                       int column)
Retrieves the TableCellEditor for a cell if one has been specified with the "editor" attribute

Overrides:
getCellEditor in class javax.swing.JTable
Parameters:
row - the row/record index (zero based)
column - the column/field index (zero based)