|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JTable
com.nqadmin.swingSet.SSDataGrid
public class SSDataGrid
SSDataGrid.java
SwingSet - Open Toolkit For Making Swing Controls Database-Aware
SSDataGrid provides a way to display information from a database in a table
format (aka "spreadsheet" or "datasheet" view). The SSDataGrid takes a SSRowSet
as a source of data. It also provides different cell renderers including a
comboboxes renderer and a date renderer.
SSDataGrid internally uses the SSTableModel to display the information in a
table format. SSDataGrid also provides an easy means for displaying headers.
Columns can be hidden or made uneditable. In addition, it provides much finer
control over which cells can be edited and which cells can't be edited. It
uses the SSCellEditing interface for achieving this. The implementation of
this interface also provides a way to specify what kind of information is valid
for each cell.
SSDataGrid uses the isCellEditable() method in SSCellEditing to determine if a
cell is editable or not. The cellUpdateRequested() method of SSCellEditing is
used to notify a user program when an update is requested. While doing so it
provides the present value in the cell and also the new value. Based on this
information the new value can be rejected or accepted by the program.
SSDataGrid also provides an "extra" row to facilitate the addition of rows to
the table. Default values for various columns can be set programmatically. A
programmer can also specify which column is the primary key column for the
underlying SSRowSet and supply a primary key for that column when a new row is
being added.
While using the headers always set them before you set the SSRowSet.
Otherwise the headers will not appear.
Also if you are using column names rather than column numbers for different function
you have to call them only after setting the SSRowSet. Because SSDataGrid uses the
SSRowSet to convert the column names to column numbers. If you specify the column
numbers you can do before or after setting the SSRowSet, it does not matter.
You can simply remember this order
1.Set the headers
2.Set the SSRowSet
3.Any other function calls.
Simple Example:
// SET THE HEADER BEFORE SETTING THE SSROWSET
dataGrid.setHeaders(new String[]{"Part Name", "Color Code", " Weight", "City"});
dataGrid.setSSRowSet(ssRowSet);
// HIDE THE PART ID COLUMN
// THIS SETS THE WIDTH OF THE COLUMN TO 0
//dataGrid.setHiddenColumns(new String[]{"part_id"});
dataGrid.setHiddenColumns(new String[]{"part_id"});
dataGrid.setMessageWindow(this);
dataGrid.setUneditableColumns(new String[]{"part_id"});
dataGrid.setComboRenderer("color_code",new String[]{"Red","Green","Blue"},
new Integer[]{new Integer(0),new Integer(1),new Integer(2)});
dataGrid.setDefaultValues(new int[]{1,2,3},new Object[]{new Integer(0),
new Integer(20),new String("New Orleans")});
dataGrid.setPrimaryColumn("part_id");
dataGrid.setSSDataValue(new SSDataValue(){
public Object getPrimaryColumnValue(){
// YOUR PRIMARY KEY VALUE GENERATION GOES HERE
// IF ITS SOME THING USER ENTERS THEN NO PROBLEM
// IF ITS AN AUTO INCREMENT FIELD THEN IT DEPENDS ON
// THE DATABASE DRIVER YOU ARE USING.
// IF THE UPDATEROW CAN RETRIEVE THE VALUES FOR THE ROW
// WITH OUT KNOWING THE PRIMARY KEY VALUE ITS FINE
// BUT POSTGRES CAN'T UPDATE ROW WITH OUT THE PRIMARY
// COLUMN.
// YOUR PRIMARY KEY VALUE GENERATION GOES HERE.
........
........
........
}
});
Also See Examples 5, 6, 7 in the samples.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class javax.swing.JTable |
|---|
javax.swing.JTable.PrintMode |
| Nested classes/interfaces inherited from class javax.swing.JComponent |
|---|
javax.swing.JComponent.AccessibleJComponent |
| 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 |
| Fields inherited from class javax.swing.JComponent |
|---|
TOOL_TIP_TEXT_KEY, 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 | |
|---|---|
SSDataGrid()
Constructs an empty data grid. |
|
SSDataGrid(SSRowSet _sSRowSet)
Constructs a data grid with the data source set to the given SSRowSet. |
|
| Method Summary | |
|---|---|
boolean |
getCallExecute()
Returns the callExecute property. |
int |
getColumnWidth()
Returns the minimum column width for the data grid. |
java.awt.Component |
getComponent()
Returns scroll pane with the JTable embedded in it. |
java.lang.Object |
getDefaultValue(int _columnNumber)
Returns the default value being used for the specified column. |
java.lang.Object |
getDefaultValue(java.lang.String _columnName)
Returns the default value being used for the specified column. |
boolean |
getInsertion()
Returns the allowInsertion property of the table. |
java.awt.Component |
getMessageWindow()
Returns the component on which error messages will be popped up. |
int |
getSelectedColumnCount()
Returns number of selected columns. |
int[] |
getSelectedColumns()
Returns the list of selected columns. |
SSRowSet |
getSSRowSet()
Returns the SSRowSet being used to get the values. |
void |
setCallExecute(boolean _callExecute)
Sets the callExecute property. |
void |
setCheckBoxRenderer(int _column)
Sets a check box renderer for the specified column. |
void |
setCheckBoxRenderer(java.lang.String _column)
Sets a check box renderer for the specified column. |
void |
setColumnWidth(int _columnWidth)
Sets the minimum column width for the data grid. |
void |
setComboRenderer(int _column,
java.lang.Object[] _displayItems,
java.lang.Object[] _underlyingValues)
Sets a combo box renderer for the specified column. |
void |
setComboRenderer(int _column,
java.lang.Object[] _displayItems,
java.lang.Object[] _underlyingValues,
int _columnWidth)
Sets a combo box renderer for the specified column. |
void |
setComboRenderer(java.lang.String _column,
java.lang.Object[] _displayItems,
java.lang.Object[] _underlyingValues)
Sets a combo box renderer for the specified column. |
void |
setComboRenderer(java.lang.String _column,
java.lang.Object[] _displayItems,
java.lang.Object[] _underlyingValues,
int _columnWidth)
Sets a combo box renderer for the specified column. |
void |
setDateRenderer(int _column)
Sets a date renderer for the specified column. |
void |
setDateRenderer(java.lang.String _column)
Sets a date renderer for the specified column. |
void |
setDefaultValues(int[] _columnNumbers,
java.lang.Object[] _values)
Sets the default values for different columns. |
void |
setDefaultValues(java.lang.String[] _columnNames,
java.lang.Object[] _values)
Sets the default values for different columns. |
void |
setHeaders(java.lang.String[] _headers)
Sets the header for the JTable. |
void |
setHiddenColumns(int[] _columnNumbers)
Sets the column numbers that should be hidden. |
void |
setHiddenColumns(java.lang.String[] _columnNames)
Sets the column numbers that should be hidden. |
void |
setInsertion(boolean _insertion)
Sets the allowInsertion property of the table. |
void |
setMessageWindow(java.awt.Component _messageWindow)
Sets the component on which error messages will be popped up. |
void |
setPrimaryColumn(int _columnNumber)
Sets the column number which is the primary column for the table. |
void |
setPrimaryColumn(java.lang.String _columnName)
Sets the column number which is the primary column for the table. |
void |
setRowSet(SSRowSet _sSRowSet)
Deprecated. |
void |
setSSCellEditing(SSCellEditing _cellEditing)
If the user has to decide on which cell has to be editable and which is not then SSCellEditable interface has to be implemented and set it for the SSTableModel. |
void |
setSSDataValue(SSDataValue _dataValue)
Sets the SSDataValue interface implemention. |
void |
setSSRowSet(SSRowSet _sSRowSet)
Binds the SSRowSet to the grid. |
void |
setUneditableColumns(int[] _columnNumbers)
Sets the uneditable columns. |
void |
setUneditableColumns(java.lang.String[] _columnNames)
Sets the uneditable columns. |
| Methods inherited from class javax.swing.JTable |
|---|
addColumn, addColumnSelectionInterval, addNotify, addRowSelectionInterval, changeSelection, clearSelection, columnAdded, columnAtPoint, columnMarginChanged, columnMoved, columnRemoved, columnSelectionChanged, convertColumnIndexToModel, convertColumnIndexToView, createDefaultColumnsFromModel, 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, getPrintable, getRowCount, getRowHeight, getRowHeight, getRowMargin, getRowSelectionAllowed, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedColumn, getSelectedRow, getSelectedRowCount, getSelectedRows, getSelectionBackground, getSelectionForeground, getSelectionModel, getShowHorizontalLines, getShowVerticalLines, getSurrendersFocusOnKeystroke, getTableHeader, getToolTipText, getUI, getUIClassID, getValueAt, isCellEditable, isCellSelected, isColumnSelected, isEditing, isRowSelected, moveColumn, prepareEditor, prepareRenderer, print, print, print, print, removeColumn, removeColumnSelectionInterval, removeEditor, removeNotify, removeRowSelectionInterval, 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, updateUI, valueChanged |
| Methods inherited from class javax.swing.JComponent |
|---|
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, 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, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, 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, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update |
| Methods inherited from class java.awt.Container |
|---|
add, add, add, add, add, addContainerListener, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate |
| Methods inherited from class java.awt.Component |
|---|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, 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, 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 |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public SSDataGrid(SSRowSet _sSRowSet)
_sSRowSet - SSRowSet from which values have to be retrieved.public SSDataGrid()
| Method Detail |
|---|
public void setColumnWidth(int _columnWidth)
_columnWidth - minimum column width of the each columnpublic int getColumnWidth()
public void setMessageWindow(java.awt.Component _messageWindow)
_messageWindow - the component that should be used when displaying error messagespublic java.awt.Component getMessageWindow()
public void setCallExecute(boolean _callExecute)
_callExecute - true if execute function call has to be skipped else falsepublic boolean getCallExecute()
public void setInsertion(boolean _insertion)
_insertion - true if new rows can be added else false.public boolean getInsertion()
public int[] getSelectedColumns()
getSelectedColumns in class javax.swing.JTablepublic int getSelectedColumnCount()
getSelectedColumnCount in class javax.swing.JTablepublic void setSSRowSet(SSRowSet _sSRowSet)
_sSRowSet - the SSRowSet which acts as the data source.public SSRowSet getSSRowSet()
public java.awt.Component getComponent()
public void setDefaultValues(int[] _columnNumbers,
java.lang.Object[] _values)
_columnNumbers - array containing the column numbers for which the
defaults apply._values - the values for the column numbers specified in _columnNumbers.
public void setDefaultValues(java.lang.String[] _columnNames,
java.lang.Object[] _values)
throws java.sql.SQLException
_columnNames - array containing the column names for which the
defaults apply._values - the values for the column names specified in _columnNames.
java.sql.SQLException - is the specified column name is not present in the SSRowSetpublic java.lang.Object getDefaultValue(int _columnNumber)
_columnNumber - the column number for which default value is to be returned.
public java.lang.Object getDefaultValue(java.lang.String _columnName)
throws java.sql.SQLException
_columnName - the column name for which default value is to be returned.
java.sql.SQLException - is the specified column name is not present in the SSRowSetpublic void setPrimaryColumn(int _columnNumber)
_columnNumber - the column which is the primary column.
public void setPrimaryColumn(java.lang.String _columnName)
throws java.sql.SQLException
_columnName - the column which is the primary column.
java.sql.SQLExceptionpublic void setSSDataValue(SSDataValue _dataValue)
_dataValue - implementation of SSDataValuepublic void setDateRenderer(int _column)
_column - column number for which a date renderer is needed.
public void setDateRenderer(java.lang.String _column)
throws java.sql.SQLException
_column - column name for which a date renderer is needed.
java.sql.SQLException
public void setComboRenderer(int _column,
java.lang.Object[] _displayItems,
java.lang.Object[] _underlyingValues)
_column - column number for which combo renderer is to be provided._displayItems - the actual Objects to be displayed in the combo box._underlyingValues - the values that have to be written to the database when an
item in the combo box is selected.
public void setComboRenderer(int _column,
java.lang.Object[] _displayItems,
java.lang.Object[] _underlyingValues,
int _columnWidth)
_column - column number for which combo renderer is to be provided._displayItems - the actual Objects to be displayed in the combo box._underlyingValues - the values that have to be written to the database when an
item in the combo box is selected.
public void setComboRenderer(java.lang.String _column,
java.lang.Object[] _displayItems,
java.lang.Object[] _underlyingValues)
throws java.sql.SQLException
_column - column name for which combo renderer is to be provided._displayItems - the actual Objects to be displayed in the combo box._underlyingValues - the values that have to be written to the database when an
item in the combo box is selected.
java.sql.SQLException
public void setComboRenderer(java.lang.String _column,
java.lang.Object[] _displayItems,
java.lang.Object[] _underlyingValues,
int _columnWidth)
throws java.sql.SQLException
_column - column name for which combo renderer is to be provided._displayItems - the actual Objects to be displayed in the combo box._underlyingValues - the values that have to be written to the database when an
item in the combo box is selected._columnWidth - required minimum width for this column
java.sql.SQLException
public void setCheckBoxRenderer(java.lang.String _column)
throws java.sql.SQLException
_column - - name ofthe column for which check box rendering is needed.
java.sql.SQLException
public void setCheckBoxRenderer(int _column)
throws java.sql.SQLException
_column - - column number for which check box rendering is needed.
java.sql.SQLExceptionpublic void setHeaders(java.lang.String[] _headers)
_headers - array of string objects representing the header of each column.public void setUneditableColumns(int[] _columnNumbers)
_columnNumbers - array specifying the column numbers which should be
uneditable.
public void setUneditableColumns(java.lang.String[] _columnNames)
throws java.sql.SQLException
_columnNames - array specifying the column names which should be
uneditable.
java.sql.SQLExceptionpublic void setHiddenColumns(int[] _columnNumbers)
_columnNumbers - array specifying the column numbers which should be
hidden
public void setHiddenColumns(java.lang.String[] _columnNames)
throws java.sql.SQLException
_columnNames - array specifying the column names which should be
hidden
java.sql.SQLExceptionpublic void setSSCellEditing(SSCellEditing _cellEditing)
_cellEditing - implementation of SSCellEditable interface.public void setRowSet(SSRowSet _sSRowSet)
_sSRowSet - SSRowSet to which the combo has to update values.setSSRowSet(com.nqadmin.swingSet.datasources.SSRowSet)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||