|
||||||||||
| 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.JComboBox
com.nqadmin.swingSet.SSDBComboBox
public class SSDBComboBox
SSDBComboBox.java
SwingSet - Open Toolkit For Making Swing Controls Database-Aware
Similar to the SSComboBox, but used when both the 'bound' values and the
'display' values are pulled from a database table. Generally the bound
value represents a foreign key to another table, and the combobox needs to
diplay a list of one (or more) columns from the other table.
Note, if changing both a sSRowSet and column name consider using the bind()
method rather than individual setSSRowSet() and setColumName() calls.
e.g.
Consider two tables:
1. part_data (part_id, part_name, ...)
2. shipment_data (shipment_id, part_id, quantity, ...)
Assume you would like to develop a screen for the shipment table and you
want to have a screen with a combobox where the user can choose a
part and a textbox where the user can specify a quantity.
In the combobox you would want to display the part name rather than
part_id so that it is easier for the user to choose. At the same time you
want to store the id of the part chosen by the user in the shipment
table.
SSConnection connection = null;
SSJdbcRowSetImpl sSRowSet = null;
SSDataNavigator navigator = null;
SSDBComboBox combo = null;
try {
// CREATE A DATABASE CONNECTION OBJECT
SSConnection connection = new SSConnection(........);
// CREATE AN INSTANCE OF SSJDBCROWSETIMPL
SSJdbcRowsetImpl sSRowSet = new SSJdbcRowsetImpl(connection);
sSRowSet.setCommand("SELECT * FROM shipment_data;");
// DATA NAVIGATOR CALLS THE EXECUTE AND NEXT FUNCTIONS ON THE SSROWSET.
// IF YOU ARE NOT USING THE DATA NAVIGATOR YOU HAVE TO INCLUDE THOSE.
// sSRowSet.execute();
// sSRowSet.next();
SSDataNavigator navigator = new SSDataNavigator(sSRowSet);
// QUERY FOR THE COMBOBOX.
String query = "SELECT * FROM part_data;";
// CREATE AN INSTANCE OF THE SSDBCOMBOBOX WITH THE CONNECTION OBJECT
// QUERY AND COLUMN NAMES
combo = new SSDBComboBox(connection,query,"part_id","part_name");
// THIS BASICALLY SPECIFIES THE COLUMN AND THE SSROWSET WHERE UPDATES HAVE
// TO BE MADE.
combo.bind(sSRowSet,"part_id");
combo.execute();
// CREATE A TEXTFIELD
JTextField myText = new JTextField();
myText.setDocument(new SSTextDocument(sSRowSet, "quantity");
} catch(Exception e) {
// EXCEPTION HANDLER HERE...
}
// ADD THE SSDBCOMBOBOX TO THE JFRAME
getContentPane().add(combo.getComboBox());
// ADD THE JTEXTFIELD TO THE JFRAME
getContentPane().add(myText);
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class javax.swing.JComboBox |
|---|
javax.swing.JComboBox.KeySelectionManager |
| Nested classes/interfaces inherited from class javax.swing.JComponent |
|---|
javax.swing.JComponent.AccessibleJComponent |
| Field Summary |
|---|
| 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 | |
|---|---|
SSDBComboBox()
Creates an object of the SSDBComboBox. |
|
SSDBComboBox(SSConnection _sSConnection,
java.lang.String _query,
java.lang.String _primaryKeyColumnName,
java.lang.String _displayColumnName)
Constructs a SSDBComboBox with the given parameters. |
|
SSDBComboBox(SSConnection _sSConnection,
java.lang.String _query,
java.lang.String _primaryKeyColumnName,
java.lang.String _displayColumnName,
javax.swing.JTextField _textField)
Deprecated. |
|
| Method Summary | |
|---|---|
void |
addItem(java.lang.String _name,
long _value)
Adds an item to the existing list of items in the combo box. |
void |
addStringItem(java.lang.String _name,
java.lang.String _value)
Adds an item to the existing list of items in the combo box. |
void |
bind(SSRowSet _sSRowSet,
java.lang.String _columnName)
Sets the SSRowSet and column name to which the component is to be bound. |
boolean |
deleteItem(long _value)
Deletes the item which has value equal to _value. |
boolean |
deleteItem(java.lang.String _name)
Deprecated. |
boolean |
deleteItem(java.lang.String _name,
long _value)
Deprecated. |
boolean |
deleteStringItem(java.lang.String _value)
Deletes the item which has value equal to _value. |
void |
execute()
Executes the query and adds items to the combo box based on the values retrieved from the database. |
java.lang.String |
getColumnName()
Returns the column name to which the combo is bound. |
javax.swing.JComboBox |
getComboBox()
Deprecated. |
java.awt.Component |
getComponent()
Deprecated. |
SSConnection |
getConnection()
Deprecated. |
java.lang.String |
getDateFormat()
Returns the pattern in which dates have to be displayed |
java.lang.String |
getDisplayColumnName()
Returns the column name whose values are displayed in the combo box. |
int |
getNumberOfItems()
Returns the number of items present in the combo box. |
java.lang.String |
getQuery()
Returns the query used to retrieve values from database for the combo box. |
java.lang.String |
getSecondDisplayColumnName()
Returns the second column name whose values are also displayed in the combo box. |
java.lang.String |
getSelectedStringValue()
Returns the value of the selected item. |
long |
getSelectedValue()
Returns the value of the selected item. |
java.lang.String |
getSeperator()
Returns the seperator used when multiple columns are displayed |
SSConnection |
getSSConnection()
Returns connection object used to get values from database. |
SSRowSet |
getSSRowSet()
Returns the SSRowSet being used to get the values. |
javax.swing.JTextField |
getTextField()
Deprecated. |
void |
setColumnName(java.lang.String _columnName)
Sets the column name for the combo box |
void |
setConnection(SSConnection _sSConnection)
Deprecated. |
void |
setDateFormat(java.lang.String _dateFormat)
When a display column is of type date you can choose the format in which it has to be displayed. |
void |
setDisplayColumnName(java.lang.String _displayColumnName)
Sets the column name whose values have to be displayed in combo box. |
void |
setPrimaryKeyColumnName(java.lang.String _primaryKeyColumnName)
|
void |
setQuery(java.lang.String _query)
Sets the query used to display items in the combo box. |
void |
setRowSet(SSRowSet _sSRowSet)
Deprecated. |
void |
setSecondDisplayColumnName(java.lang.String _secondDisplayColumnName)
Sets the second display name. |
void |
setSelectedStringValue(java.lang.String _value)
Sets the currently selected value Currently not a bean property since there is no associated variable. |
void |
setSelectedValue(long _value)
Sets the currently selected value Currently not a bean property since there is no associated variable. |
void |
setSeperator(java.lang.String _seperator)
Set the seperator to be used when multiple columns are displayed |
void |
setSSConnection(SSConnection _sSConnection)
Sets the connection object to be used. |
void |
setSSRowSet(SSRowSet _sSRowSet)
Sets the new SSRowSet for the combo box. |
void |
setTextField(javax.swing.JTextField _textField)
Deprecated. |
boolean |
updateItem(long _value,
java.lang.String _name)
Updates the string thats being displayed. |
boolean |
updateStringItem(java.lang.String _value,
java.lang.String _name)
Updates the string thats being displayed. |
| Methods inherited from class javax.swing.JComboBox |
|---|
actionPerformed, addActionListener, addItem, addItemListener, addPopupMenuListener, configureEditor, contentsChanged, firePopupMenuCanceled, firePopupMenuWillBecomeInvisible, firePopupMenuWillBecomeVisible, getAccessibleContext, getAction, getActionCommand, getActionListeners, getEditor, getItemAt, getItemCount, getItemListeners, getKeySelectionManager, getMaximumRowCount, getModel, getPopupMenuListeners, getPrototypeDisplayValue, getRenderer, getSelectedIndex, getSelectedItem, getSelectedObjects, getUI, getUIClassID, hidePopup, insertItemAt, intervalAdded, intervalRemoved, isEditable, isLightWeightPopupEnabled, isPopupVisible, processKeyEvent, removeActionListener, removeAllItems, removeItem, removeItemAt, removeItemListener, removePopupMenuListener, selectWithKeyChar, setAction, setActionCommand, setEditable, setEditor, setEnabled, setKeySelectionManager, setLightWeightPopupEnabled, setMaximumRowCount, setModel, setPopupVisible, setPrototypeDisplayValue, setRenderer, setSelectedIndex, setSelectedItem, setUI, showPopup, updateUI |
| Methods inherited from class javax.swing.JComponent |
|---|
addAncestorListener, addNotify, 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, 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, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, 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, doLayout, 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 SSDBComboBox()
public SSDBComboBox(SSConnection _sSConnection,
java.lang.String _query,
java.lang.String _primaryKeyColumnName,
java.lang.String _displayColumnName)
_sSConnection - database connection to be used._query - query to be used to retrieve the values from the database._primaryKeyColumnName - column name whose value has to be stored._displayColumnName - column name whose values are displayed in the combo box.
public SSDBComboBox(SSConnection _sSConnection,
java.lang.String _query,
java.lang.String _primaryKeyColumnName,
java.lang.String _displayColumnName,
javax.swing.JTextField _textField)
_sSConnection - database connection to be used._query - query to be used to retrieve the values from the database._primaryKeyColumnName - column name whose value has to be stored._displayColumnName - column name whose values are displayed in the combo box._textField - a text field to which the combo box has to be synchronized| Method Detail |
|---|
public void setSSRowSet(SSRowSet _sSRowSet)
_sSRowSet - SSRowSet to which the combo has to update values.public SSRowSet getSSRowSet()
public void setSSConnection(SSConnection _sSConnection)
_sSConnection - connection object used for database.public SSConnection getSSConnection()
public void setQuery(java.lang.String _query)
_query - query to be used to get values from database (to display combo box items)public java.lang.String getQuery()
public void setColumnName(java.lang.String _columnName)
_columnName - name of columnpublic java.lang.String getColumnName()
public void setDisplayColumnName(java.lang.String _displayColumnName)
_displayColumnName - column name whose values have to be displayed.public java.lang.String getDisplayColumnName()
public void setPrimaryKeyColumnName(java.lang.String _primaryKeyColumnName)
public void setDateFormat(java.lang.String _dateFormat)
_dateFormat - pattern in which dates have to be displayedpublic java.lang.String getDateFormat()
public void setSecondDisplayColumnName(java.lang.String _secondDisplayColumnName)
_secondDisplayColumnName - column name whose values have to be
displayed in the combo in addition to the first column name.public java.lang.String getSecondDisplayColumnName()
public void setSeperator(java.lang.String _seperator)
_seperator - seperator to be used.public java.lang.String getSeperator()
public int getNumberOfItems()
public void setSelectedValue(long _value)
_value - value to set as currently selected.public long getSelectedValue()
public void setSelectedStringValue(java.lang.String _value)
_value - value to set as currently selected.public java.lang.String getSelectedStringValue()
public void execute()
throws java.sql.SQLException,
java.lang.Exception
java.sql.SQLException
java.lang.Exception
public void bind(SSRowSet _sSRowSet,
java.lang.String _columnName)
_sSRowSet - datasource to be used._columnName - Name of the column to which this check box should be bound
public void addItem(java.lang.String _name,
long _value)
_name - name that should be displayed in the combo_value - value corresponding the the name
public void addStringItem(java.lang.String _name,
java.lang.String _value)
_name - name that should be displayed in the combo_value - value corresponding the the namepublic boolean deleteItem(long _value)
_value - value of the item to be deleted.
public boolean deleteStringItem(java.lang.String _value)
_value - value of the item to be deleted.
public boolean updateItem(long _value,
java.lang.String _name)
_value - the value corresponding to the item in combo to be updated._name - the new name that replace old one.
public boolean updateStringItem(java.lang.String _value,
java.lang.String _name)
_value - the value corresponding to the item in combo to be updated._name - the new name that replace old one.
public void setConnection(SSConnection _sSConnection)
_sSConnection - connection object used for database.setSSConnection(com.nqadmin.swingSet.datasources.SSConnection)public void setRowSet(SSRowSet _sSRowSet)
_sSRowSet - SSRowSet to which the combo has to update values.setSSRowSet(com.nqadmin.swingSet.datasources.SSRowSet)public void setTextField(javax.swing.JTextField _textField)
_textField - text field to which the selected item value has to
be written.public SSConnection getConnection()
getSSConnection()public javax.swing.JTextField getTextField()
public javax.swing.JComboBox getComboBox()
public java.awt.Component getComponent()
public boolean deleteItem(java.lang.String _name)
_name - value of the item to be deleted.
public boolean deleteItem(java.lang.String _name,
long _value)
_name - name of item to be deleted_value - value of the item to be deleted.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||