SilverStream
Application Server 3.5

com.sssw.rt.jform
Class AgcJTable

java.lang.Object
 |
 +--java.awt.Component
       |
       +--java.awt.Container
             |
             +--javax.swing.JComponent
                   |
                   +--javax.swing.JTable
                         |
                         +--com.sssw.rt.jform.AgcJTable
All Implemented Interfaces:
Accessible, AgiHelpInfo, AgiRowSetManager, CellEditorListener, EventListener, ImageObserver, ListSelectionListener, MenuContainer, Scrollable, Serializable, TableColumnModelListener, TableModelListener

public class AgcJTable
extends JTable
implements AgiRowSetManager, ListSelectionListener, AgiHelpInfo

A lightweight component that displays rows and columns of data. It's easy to set up a table with data by retrieving data with an AgcData control and putting the data in the table with AgcJTable.loadFromRowCursor( AgiRowCursor, int[], int[], int).

The table can be bound to a database column. When you load the table data with loadFromRowCursor(), you specify a value column, which provides the storage values for the table. The value column doesn't have to be displayed. When any cell in a particular row is selected, the data in the value column is passed to the database when you call updateRows() the form.

To build a table model that that binds every table column to a database column and is updatable, see AgoRowCursorTableModel.

In addition to being data-bound, the control is a data-loaded control in which loadFromRowCursor() provides data from a database table or other data source. You can use methods of AgiRowSetManager to navigate the data. However, changes to the table data do not affect the underlying data; therefore, calling updateRows() for the control is not allowed. If you call it, updateRows() throws AgoUnsupportedOperationException.

AgcJTable uses a data model. You can call the inherited method JTable.getModel() to get the model and manipulate the data.

You can enable editing by calling AgcJTable.setEditable(boolean). You can call methods inherited from JTable to customize the table appearance and behavior.

For an example of using a table control, see Using the Swing Table Control in the online book Application Techniques.

Properties:
Background Color, Column Margin, Control Type, Editable, Enabled, Font Name, Font Size, Font Style, Foreground Color, Height, Help Page, Left, Name, Row Height, Row Margin, Selection, Shadow Color, Show Grid, Tool Tip, Top, Visible, Width
Events:
focusGained, focusLost, keyPressed, keyReleased, keyTyped, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased
See Also:
Serialized Form

Inner classes inherited from class javax.swing.JTable
JTable.AccessibleJTable
 
Inner classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
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
 
Constructor Summary
AgcJTable()
          Constructs a default table control which is initialized with a default data model, a default column model, and a default selection model.
AgcJTable(int numRows, int numColumns)
          Constructs a table control with the specified number of rows and columns filled with empty cells using the DefaultTableModel.
AgcJTable(Object[][] rowData, Object[] columnNames)
          Constructs a table control that displays the specified data values with the specified column names.
AgcJTable(TableModel dm)
          Constructs a table control which is initialized with the specified data model, a default column model, and a default selection model.
AgcJTable(TableModel dm, TableColumnModel cm)
          Constructs a table control which is initialized with the specified data model and column model, and a default selection model.
AgcJTable(TableModel dm, TableColumnModel cm, ListSelectionModel sm)
          Constructs a table control which is initialized with the specified data model, column model, and selection model.
AgcJTable(Vector rowData, Vector columnNames)
          Constructs a table control that displays the specified data values with the specified column names.
 
Method Summary
 Object getValue()
          Gets the value of the selected row.
 boolean isEditable()
          Finds out whether any cells in the table are editable.
 void loadFromRowCursor(AgiRowCursor rc, int[] displaycols, int[] editablecols, int valuecol)
          Creates rows of table data from an AgiRowCursor data source.
 void loadFromRowCursor(AgiRowCursor rc, int[] displaycols, int[] editablecols, int valuecol, String[] columnnames)
          Creates rows of table data from an AgiRowCursor data source.
 void setEditable(boolean editable)
          Specifies whether any cells in the table are editable.
 void setValue(Object value)
          Selects the row where the data in the value column is equal to the specified value.
 
Methods inherited from class javax.swing.JTable
addColumn, addColumnSelectionInterval, addNotify, addRowSelectionInterval, clearSelection, columnAdded, columnAtPoint, columnMarginChanged, columnMoved, columnRemoved, columnSelectionChanged, configureEnclosingScrollPane, convertColumnIndexToModel, convertColumnIndexToView, createDefaultColumnModel, createDefaultColumnsFromModel, createDefaultDataModel, createDefaultEditors, createDefaultRenderers, createDefaultSelectionModel, createDefaultTableHeader, createScrollPaneForTable, editCellAt, editCellAt, editingCanceled, editingStopped, getAccessibleContext, getAutoCreateColumnsFromModel, getAutoResizeMode, getCellEditor, getCellEditor, getCellRect, getCellRenderer, getCellSelectionEnabled, getColumn, getColumnClass, getColumnCount, getColumnModel, getColumnName, getColumnSelectionAllowed, getDefaultEditor, getDefaultRenderer, getEditingColumn, getEditingRow, getEditorComponent, getGridColor, getIntercellSpacing, getModel, getPreferredScrollableViewportSize, getRowCount, getRowHeight, getRowMargin, getRowSelectionAllowed, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedColumn, getSelectedColumnCount, getSelectedColumns, getSelectedRow, getSelectedRowCount, getSelectedRows, getSelectionBackground, getSelectionForeground, getSelectionModel, getShowHorizontalLines, getShowVerticalLines, getTableHeader, getToolTipText, getUI, getUIClassID, getValueAt, initializeLocalVars, isCellEditable, isCellSelected, isColumnSelected, isEditing, isManagingFocus, isRowSelected, moveColumn, paramString, prepareEditor, prepareRenderer, removeColumn, removeColumnSelectionInterval, removeEditor, removeRowSelectionInterval, reshape, resizeAndRepaint, rowAtPoint, selectAll, setAutoCreateColumnsFromModel, setAutoResizeMode, setCellEditor, setCellSelectionEnabled, setColumnModel, setColumnSelectionAllowed, setColumnSelectionInterval, setDefaultEditor, setDefaultRenderer, setEditingColumn, setEditingRow, setGridColor, setIntercellSpacing, setModel, setPreferredScrollableViewportSize, setRowHeight, setRowMargin, setRowSelectionAllowed, setRowSelectionInterval, setSelectionBackground, setSelectionForeground, setSelectionMode, setSelectionModel, setShowGrid, setShowHorizontalLines, setShowVerticalLines, setTableHeader, setUI, setValueAt, sizeColumnsToFit, sizeColumnsToFit, tableChanged, updateUI, valueChanged
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInsets, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, processComponentKeyEvent, processFocusEvent, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, revalidate, scrollRectToVisible, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setCursor, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hide, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods implemented from interface com.sssw.rt.form.AgiHelpInfo
getHelpInfo, setHelpInfo
 
Methods implemented from interface com.sssw.rt.util.AgiRowSetManager
clearRows, haveRowsChanged, query, query, refreshRows, updateRows
 

Constructor Detail

AgcJTable

public AgcJTable()
Constructs a default table control which is initialized with a default data model, a default column model, and a default selection model.

AgcJTable

public AgcJTable(int numRows,
                 int numColumns)
Constructs a table control with the specified number of rows and columns filled with empty cells using the DefaultTableModel. The columns will be named alphabetically with "A", "B", "C", etc.
Parameters:
numRows - the number of rows in the table
numColumns - the number of columns in the table

AgcJTable

public AgcJTable(Object[][] rowData,
                 Object[] columnNames)
Constructs a table control that displays the specified data values with the specified column names.
Parameters:
rowData - a two-dimensional array of data for the new table. All rows must be of the same length as the columnNames array.
columnNames - a 1-dimensional array containing the names of the columns
Usage:
rowData is an array of arrays. For example, the value that will be in the cell at row 1, column 5 can be obtained with the following code:
  rowData[1][5]; 
 

AgcJTable

public AgcJTable(TableModel dm)
Constructs a table control which is initialized with the specified data model, a default column model, and a default selection model.
Parameters:
dm - the data model for the table

AgcJTable

public AgcJTable(TableModel dm,
                 TableColumnModel cm)
Constructs a table control which is initialized with the specified data model and column model, and a default selection model.
Parameters:
dm - the data model for the table
cm - the column model for the table

AgcJTable

public AgcJTable(TableModel dm,
                 TableColumnModel cm,
                 ListSelectionModel sm)
Constructs a table control which is initialized with the specified data model, column model, and selection model. If any of the parameters are null this method will initialize the table with the corresponding default model. The autoCreateColumnsFromModel flag is set to false if the column model is non-null, otherwise it is set to true and the column model is populated with suitable TableColumns for the columns in the data model.
Parameters:
dm - the data model for the table
cm - the column model for the table
sm - the row selection model for the table

AgcJTable

public AgcJTable(Vector rowData,
                 Vector columnNames)
Constructs a table control that displays the specified data values with the specified column names. The data is provided as a Vector of Vectors.
Parameters:
rowData - the data for the new table. There must be the same number of elements in each row vector as in the columnNames array.
columnNames - names of each column
Usage:
Each Vector contained in the rowData Vector contain the values for that row. For example, the value that will be in the cell at row 1, column 5 can be obtained with the following code:
   ((Vector)rowData.elementAt(1)).elementAt(5);
 
Method Detail

isEditable

public boolean isEditable()
Finds out whether any cells in the table are editable.
Returns:
a boolean specifying the editable value for this table. The default value is false.
See Also:
AgcJTable.setEditable(boolean)

setEditable

public void setEditable(boolean editable)
Specifies whether any cells in the table are editable.
Parameters:
editable - a boolean value specifying whether any of the table is editable. Values are:
  • false - none of the cells in this table are editable.
  • true - some or all of the cells may be editable, as determined by the current TableModel.
Usage:
In the DefaultTableModel, all cells are editable. So if your table uses the DefaultTableModel, then the cells will be editable if and only if setEditable is true.
See Also:
AgcJTable.isEditable()

getValue

public Object getValue()
Gets the value of the selected row.
Returns:
an Object that is the data in the row's value column
See Also:
AgcJTable.setValue(Object)

setValue

public void setValue(Object value)
Selects the row where the data in the value column is equal to the specified value.
Parameters:
value - an Object whose value is meant to match a row in the table
See Also:
AgcJTable.getValue()

loadFromRowCursor

public void loadFromRowCursor(AgiRowCursor rc,
                              int[] displaycols,
                              int[] editablecols,
                              int valuecol)
                       throws AgoSecurityException,
                              AgoTransientSystemException,
                              AgoUnrecoverableSystemException
Creates rows of table data from an AgiRowCursor data source. Each database row becomes a table row. Column titles are the same as the property names in AgiRowCursor. All column numbers are zero-based. Column numbers for displaycols specify columns in the row cursor. For editablecols and valuecol, column numbers are the columns as they appear in the table control.
Parameters:
rc - the AgiRowCursor object whose data you want to display in the table
displaycols[] - an array of ints specifying column numbers in the AgiRowCursor. Those columns become the columns in the table.
editablecols[] - an array of ints specifying which JTable column numbers are editable
valuecol - an int specifying the JTable column whose values will be storage values. When the table control is bound to a database column, the storage value of the selected row is the value updated in the database.
Example:
See AgcJTable.loadFromRowCursor( AgiRowCursor rc, int[] displaycols, int[] editablecols, int valuecol, String[] columnnames )
See Also:
AgiRowCursor, AgcData

loadFromRowCursor

public void loadFromRowCursor(AgiRowCursor rc,
                              int[] displaycols,
                              int[] editablecols,
                              int valuecol,
                              String[] columnnames)
                       throws AgoSecurityException,
                              AgoTransientSystemException,
                              AgoUnrecoverableSystemException
Creates rows of table data from an AgiRowCursor data source. Each database row becomes a table row. With this syntax, you can specify titles for the display columns. All column numbers are zero-based. Column numbers for displaycols specify columns in the row cursor. For editablecols and valuecol, column numbers are the columns as they appear in the table control.
Parameters:
rc - the AgiRowCursor object whose data you want to display in the table
displaycols[] - an array of ints specifying column numbers in the AgiRowCursor. Those columns become the columns in the table.
editablecols[] - an array of ints specifying which JTable column numbers are editable
valuecol - an int specifying the JTable column whose values will be storage values. When the table control is bound to a database column, the storage value of the selected row is the value updated in the database.
columnnames[] - an array of Strings specifying the column titles. The columnnames and displaycols arrays must be the same length.
Example:
This code illustrates how to use column numbers in loadFromRowCursor().
   int[] displaycols = { 2, 7 }; // Columns 2 and 7 of the row cursor
   int[] editablecols = { 1 };   // JTable column 1 is row cursor column 7
   int valuecol = 0;             // JTable column 0 is row cursor column 2
   String[] columnnames = { "Two", "Seven" };  // JTable column names
   table.loadFromRowCursor(rc, 
      displaycols, editablecols, valuecol, columnnames);
 
This code loads the table control from the primary database table for the form.
   // use first and last 2 columns from agData with 8 columns
   int[] displaycols = {0, 1, 6, 7 };
 
   // make the last 3 columns editable
   int[] editablecols = {1, 2, 3};
 
   // storage values are in the first column 
   int valuecol = 0;
 
   // create some column titles from agData property names
   String[] displayTitles = new String[4];
   for (int i = 0; i < displaycols.length; i++) {
  // the table name "Terms." is dropped from 
  // the property name to create the display title
  displayTitles[i] = agData.getPropertyName(displaycols[i]).substring(6);
   }
 
   try{
 	 // load the data
 	 Table1.loadFromRowCursor( (AgiRowCursor) agData, 
        displaycols, editablecols, valuecol, displayTitles);
   } catch (Exception e) {
  System.out.println("loadFromRowCursor error: " + e);
   }
 
See Also:
AgiRowCursor, AgcData, AgoRowCursorTableModel

SilverStream
Application Server 3.5