com.nqadmin.swingSet
Class SSComboBox

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JComboBox
                  extended by com.nqadmin.swingSet.SSComboBox
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.ItemSelectable, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.ListDataListener

public class SSComboBox
extends javax.swing.JComboBox

SSComboBox.java

SwingSet - Open Toolkit For Making Swing Controls Database-Aware

 Provides a way of displaying text corresponding to codes that are stored in
 the database. By default the codes start from zero. If you want to provide a
 different mapping for the items in the combobox then a string of integers
 containing the corresponding numeric values for each choice must be provided.

 Note that if you DO NOT want to use the default mappings, the custom
 mappings must be set before calling the bind() method to bind the
 combobox to a database column.

 Also, if changing both a sSRowSet and column name consider using the bind()
 method rather than individual setSSRowSet() and setColumName() calls. 

 e.g.
      SSComboBox combo = new SSComboBox();
      String[] options = {"111", "2222", "33333"};
      combo.setOptions(options);

      For the above items the combobox assumes that the values start from zero:
           "111" -> 0, "2222" -> 1, "33333" -> 2

      To give your own mappings  you can set the mappings separately or pass
      them along with the options:

      SSComboBox combo = new SSComboBox();
      String[] options = {"111", "2222", "33333"};
      int[] mappings = { 1,5,7 };
      combo.setOptions(options, mappings);

      // next line is assuming mysSRowSet has been initialized and my_column is a
      // column in mysSRowSet
      combo.bind(mysSRowSet,"my_column");

Version:
$Revision: 1.38 $
Author:
$Author: prasanth $
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComboBox
javax.swing.JComboBox.AccessibleJComboBox, javax.swing.JComboBox.KeySelectionManager
 
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.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  java.lang.String columnName
          SSRowSet column to which the component will be bound.
static int EXCLUDE
          Predefined "exclude" option.
static int FEMALE
          Predefined "female" option.
static int GENDER_OPTION
          Constant indicating that combo box should display predefined gender options.
static int INCLUDE
          Predefined "include" option.
static int INCLUDE_EXCLUDE_OPTION
          Constant indicating that combo box should display predefined include/exclude options.
static int MALE
          Predefined "male" option.
protected  int[] mappings
          Underlying values for each combo box choice if different from defaults of 0, 1, 2, 3, etc.
static int NO
          Predefined "no" option.
static int NON_SELECTED
          Value to represent that no item has been selected in the combo box.
protected  java.lang.String[] options
          Options to be displayed in combo box.
protected  int predefinedOptions
          Code representing of predefined options to be displayed in the combo box (e.g.
static int SEX_OPTION
          Deprecated.  
protected  SSRowSet sSRowSet
          SSRowSet from which component will get/set values.
protected  SSTextField textField
          Text field bound to the SSRowSet.
static int UNI_SEX
          Deprecated.  
static int UNISEX
          Predefined "unisex" option.
static int YES
          Predefined "yes" option.
static int YES_NO_OPTION
          Constant indicating that combo box should display predefined yes/no options.
 
Fields inherited from class javax.swing.JComboBox
actionCommand, dataModel, editor, isEditable, keySelectionManager, lightWeightPopupEnabled, maximumRowCount, renderer, selectedItemReminder
 
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
SSComboBox()
          Creates an object of SSComboBox.
 
Method Summary
protected  void bind()
          Method for handling binding of component to a SSRowSet column.
 void bind(SSRowSet _sSRowSet, java.lang.String _columnName)
          Sets the SSRowSet and column name to which the component is to be bound.
 java.lang.String getColumnName()
          Returns the column name to which the combo is bound.
 javax.swing.JComboBox getComboBox()
          Deprecated.  
 java.awt.Component getComponent()
          Deprecated.  
 int[] getMappings()
          Returns the underlying values for each of the items in the combo box (e.g.
 java.lang.String[] getOptions()
          Returns the items displayed in the combo box.
 int getPredefinedOptions()
          Returns the option code used to display predefined options in the combo box.
 int getSelectedValue()
          Returns the combo box value associated with the currently selected item.
 SSRowSet getSSRowSet()
          Returns the SSRowSet being used to get the values.
protected  void init()
          Initialization code.
 void setColumnName(java.lang.String _columnName)
          Sets the SSRowSet column name to which the component is bound.
 void setMappings(int[] _mappings)
          Sets the underlying values for each of the items in the combo box (e.g.
 void setMappingValues(int[] _mappings)
          Deprecated.  
 boolean setOption(int _option)
          Deprecated.  
 void setOption(int _options, int[] _mappings)
          Deprecated.  
 boolean setOption(java.lang.String[] _options)
          Deprecated.  
 boolean setOption(java.lang.String[] _options, int[] _mappings)
          Deprecated.  
 void setOptions(java.lang.String[] _options)
          Adds an array of strings as combo box items.
 boolean setOptions(java.lang.String[] _options, int[] _mappings)
          Sets the options to be displayed in the combo box and their corresponding values.
 boolean setPredefinedOptions(int _predefinedOptions)
          Sets the options to be displayed in the combo box based on common predefined options.
 void setSelectedValue(int _value)
          Sets the value stored in the component.
 void setSSRowSet(SSRowSet _sSRowSet)
          Sets the SSRowSet to which the component is bound.
protected  void updateDisplay()
          Updates the value displayed in the component based on the SSRowSet column binding.
protected  void updateDisplay(boolean useTextField)
          Updates the value displayed in the component based on the SSRowSet column binding.
 
Methods inherited from class javax.swing.JComboBox
actionPerformed, addActionListener, addItem, addItemListener, addPopupMenuListener, configureEditor, configurePropertiesFromAction, contentsChanged, createActionPropertyChangeListener, createDefaultKeySelectionManager, fireActionEvent, fireItemStateChanged, firePopupMenuCanceled, firePopupMenuWillBecomeInvisible, firePopupMenuWillBecomeVisible, getAccessibleContext, getAction, getActionCommand, getActionListeners, getEditor, getItemAt, getItemCount, getItemListeners, getKeySelectionManager, getMaximumRowCount, getModel, getPopupMenuListeners, getPrototypeDisplayValue, getRenderer, getSelectedIndex, getSelectedItem, getSelectedObjects, getUI, getUIClassID, hidePopup, insertItemAt, installAncestorListener, intervalAdded, intervalRemoved, isEditable, isLightWeightPopupEnabled, isPopupVisible, paramString, processKeyEvent, removeActionListener, removeAllItems, removeItem, removeItemAt, removeItemListener, removePopupMenuListener, selectedItemChanged, 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, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, 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, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, 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, 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, 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, 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
 

Field Detail

NON_SELECTED

public static final int NON_SELECTED
Value to represent that no item has been selected in the combo box.


textField

protected SSTextField textField
Text field bound to the SSRowSet.


mappings

protected int[] mappings
Underlying values for each combo box choice if different from defaults of 0, 1, 2, 3, etc.


sSRowSet

protected SSRowSet sSRowSet
SSRowSet from which component will get/set values.


columnName

protected java.lang.String columnName
SSRowSet column to which the component will be bound.


options

protected java.lang.String[] options
Options to be displayed in combo box.


predefinedOptions

protected int predefinedOptions
Code representing of predefined options to be displayed in the combo box (e.g. yes/no, exclude/include, etc.


YES_NO_OPTION

public static final int YES_NO_OPTION
Constant indicating that combo box should display predefined yes/no options.

See Also:
Constant Field Values

YES

public static final int YES
Predefined "yes" option.

See Also:
Constant Field Values

NO

public static final int NO
Predefined "no" option.

See Also:
Constant Field Values

GENDER_OPTION

public static final int GENDER_OPTION
Constant indicating that combo box should display predefined gender options.

See Also:
Constant Field Values

MALE

public static final int MALE
Predefined "male" option.

See Also:
Constant Field Values

FEMALE

public static final int FEMALE
Predefined "female" option.

See Also:
Constant Field Values

UNISEX

public static final int UNISEX
Predefined "unisex" option.

See Also:
Constant Field Values

INCLUDE_EXCLUDE_OPTION

public static final int INCLUDE_EXCLUDE_OPTION
Constant indicating that combo box should display predefined include/exclude options.

See Also:
Constant Field Values

EXCLUDE

public static final int EXCLUDE
Predefined "exclude" option.

See Also:
Constant Field Values

INCLUDE

public static final int INCLUDE
Predefined "include" option.

See Also:
Constant Field Values

SEX_OPTION

public static final int SEX_OPTION
Deprecated. 
Constant indicating that combo box should display predefined gender options.

See Also:
GENDER_OPTION, Constant Field Values

UNI_SEX

public static final int UNI_SEX
Deprecated. 
Predefined "unisex" option.

See Also:
UNISEX, Constant Field Values
Constructor Detail

SSComboBox

public SSComboBox()
Creates an object of SSComboBox.

Method Detail

setSelectedValue

public void setSelectedValue(int _value)
Sets the value stored in the component. Currently not a bean property since there is no associated variable.

Parameters:
_value - value to assign to combo box

getSelectedValue

public int getSelectedValue()
Returns the combo box value associated with the currently selected item. Currently not a bean property since there is no associated variable.

Returns:
returns the value associated with the selected item OR -1 if nothing is selected.

setColumnName

public void setColumnName(java.lang.String _columnName)
Sets the SSRowSet column name to which the component is bound.

Parameters:
_columnName - column name in the SSRowSet to which the component is bound

getColumnName

public java.lang.String getColumnName()
Returns the column name to which the combo is bound.

Returns:
returns the column name to which to combo box is bound.

setSSRowSet

public void setSSRowSet(SSRowSet _sSRowSet)
Sets the SSRowSet to which the component is bound.

Parameters:
_sSRowSet - SSRowSet to which the component is bound

getSSRowSet

public SSRowSet getSSRowSet()
Returns the SSRowSet being used to get the values.

Returns:
returns the SSRowSet being used.

setMappings

public void setMappings(int[] _mappings)
Sets the underlying values for each of the items in the combo box (e.g. the values that map to the items displayed in the combo box)

Parameters:
_mappings - an array of values that correspond to those in the combo box.

getMappings

public int[] getMappings()
Returns the underlying values for each of the items in the combo box (e.g. the values that map to the items displayed in the combo box)

Returns:
returns the underlying values for each of the items in the combo box

setOptions

public void setOptions(java.lang.String[] _options)
Adds an array of strings as combo box items.

Parameters:
_options - the list of options that you want to appear in the combo box.

getOptions

public java.lang.String[] getOptions()
Returns the items displayed in the combo box.

Returns:
returns the items displayed in the combo box

setOptions

public boolean setOptions(java.lang.String[] _options,
                          int[] _mappings)
Sets the options to be displayed in the combo box and their corresponding values.

Parameters:
_options - options to be displayed in the combo box.
_mappings - integer values that correspond to the options in the combo box.
Returns:
returns true if the options and mappings are set successfully - returns false if the size of arrays do not match or if the values could not be set

setPredefinedOptions

public boolean setPredefinedOptions(int _predefinedOptions)
Sets the options to be displayed in the combo box based on common predefined options.

Parameters:
_predefinedOptions - predefined options to be displayed in the combo box.

getPredefinedOptions

public int getPredefinedOptions()
Returns the option code used to display predefined options in the combo box.

Returns:
returns the predefined option code

bind

public void bind(SSRowSet _sSRowSet,
                 java.lang.String _columnName)
Sets the SSRowSet and column name to which the component is to be bound.

Parameters:
_sSRowSet - datasource to be used.
_columnName - Name of the column to which this check box should be bound

init

protected void init()
Initialization code.


bind

protected void bind()
             throws java.sql.SQLException
Method for handling binding of component to a SSRowSet column.

Throws:
java.sql.SQLException

updateDisplay

protected void updateDisplay()
                      throws java.sql.SQLException
Updates the value displayed in the component based on the SSRowSet column binding.

Throws:
java.sql.SQLException

updateDisplay

protected void updateDisplay(boolean useTextField)
                      throws java.sql.SQLException
Updates the value displayed in the component based on the SSRowSet column binding.

Throws:
java.sql.SQLException

getComboBox

public javax.swing.JComboBox getComboBox()
Deprecated. 

returns the combo box that has to be displayed on screen.

Returns:
returns the combo box that displays the items.

getComponent

public java.awt.Component getComponent()
Deprecated. 

Returns the combo box to be displayed on the screen.

Returns:
returns the combo box that displays the items.

setOption

public boolean setOption(java.lang.String[] _options)
Deprecated. 

Adds an array of strings as combo box items.

Parameters:
_options - the list of options that you want to appear in the combo box.
Returns:
returns true if the options and mappings are set successfully - returns false if the size of arrays do not match or if the values could not be set
See Also:
setOptions(java.lang.String[])

setOption

public boolean setOption(java.lang.String[] _options,
                         int[] _mappings)
Deprecated. 

Sets the options to be displayed in the combo box and their corresponding values.

Parameters:
_options - options to be displayed in the combo box.
_mappings - integer values that correspond to the options in the combo box.
Returns:
returns true if the options and mappings are set successfully - returns false if the size of arrays do not match or if the values could not be set
See Also:
setOptions(java.lang.String[])

setOption

public void setOption(int _options,
                      int[] _mappings)
               throws java.beans.PropertyVetoException
Deprecated. 

Sets the options to be displayed in the combo box and their corresponding values.

Parameters:
_options - predefined options to be displayed in the combo box.
_mappings - integer values that correspond to the options in the combo box.
Throws:
java.beans.PropertyVetoException
See Also:
setPredefinedOptions(int), setMappings(int[])

setOption

public boolean setOption(int _option)
Deprecated. 

Sets the options to be displayed in the combo box based on common predefined options.

Parameters:
_option - predefined options to be displayed in the combo box.
See Also:
setPredefinedOptions(int)

setMappingValues

public void setMappingValues(int[] _mappings)
Deprecated. 

Sets the underlying values for each of the items in the combo box (e.g. the values that map to the items displayed in the combo box)

Parameters:
_mappings - an array of values that correspond to those in the combo box.
See Also:
setMappings(int[])