com.nqadmin.swingSet
Class SSDBComboBox

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.SSDBComboBox
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 SSDBComboBox
extends javax.swing.JComboBox

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);

Version:
$Revision: 1.32 $
See Also:
Serialized Form

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

SSDBComboBox

public SSDBComboBox()
Creates an object of the SSDBComboBox.


SSDBComboBox

public SSDBComboBox(SSConnection _sSConnection,
                    java.lang.String _query,
                    java.lang.String _primaryKeyColumnName,
                    java.lang.String _displayColumnName)
Constructs a SSDBComboBox with the given parameters.

Parameters:
_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.

SSDBComboBox

public SSDBComboBox(SSConnection _sSConnection,
                    java.lang.String _query,
                    java.lang.String _primaryKeyColumnName,
                    java.lang.String _displayColumnName,
                    javax.swing.JTextField _textField)
Deprecated. 

Constructs a SSDBComboBox with the given parameters.

Parameters:
_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

setSSRowSet

public void setSSRowSet(SSRowSet _sSRowSet)
Sets the new SSRowSet for the combo box.

Parameters:
_sSRowSet - SSRowSet to which the combo has to update values.

getSSRowSet

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

Returns:
returns the SSRowSet being used.

setSSConnection

public void setSSConnection(SSConnection _sSConnection)
Sets the connection object to be used.

Parameters:
_sSConnection - connection object used for database.

getSSConnection

public SSConnection getSSConnection()
Returns connection object used to get values from database.

Returns:
returns a SSConnection object.

setQuery

public void setQuery(java.lang.String _query)
Sets the query used to display items in the combo box.

Parameters:
_query - query to be used to get values from database (to display combo box items)

getQuery

public java.lang.String getQuery()
Returns the query used to retrieve values from database for the combo box.

Returns:
returns the query used.

setColumnName

public void setColumnName(java.lang.String _columnName)
Sets the column name for the combo box

Parameters:
_columnName - name of column

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.

setDisplayColumnName

public void setDisplayColumnName(java.lang.String _displayColumnName)
Sets the column name whose values have to be displayed in combo box.

Parameters:
_displayColumnName - column name whose values have to be displayed.

getDisplayColumnName

public java.lang.String getDisplayColumnName()
Returns the column name whose values are displayed in the combo box.

Returns:
returns the name of the column used to get values for combo box items.

setPrimaryKeyColumnName

public void setPrimaryKeyColumnName(java.lang.String _primaryKeyColumnName)

setDateFormat

public 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. For the pattern refer SimpleDateFormat in java.text package.

Parameters:
_dateFormat - pattern in which dates have to be displayed

getDateFormat

public java.lang.String getDateFormat()
Returns the pattern in which dates have to be displayed

Returns:
returns the pattern in which dates have to be displayed

setSecondDisplayColumnName

public void setSecondDisplayColumnName(java.lang.String _secondDisplayColumnName)
Sets the second display name. If more than one column have to displayed then use this. For the parts example given above. If you have a part description in part table. Then you can display both part name and part description.

Parameters:
_secondDisplayColumnName - column name whose values have to be displayed in the combo in addition to the first column name.

getSecondDisplayColumnName

public java.lang.String getSecondDisplayColumnName()
Returns the second column name whose values are also displayed in the combo box.

Returns:
returns the name of the column used to get values for combo box items. returns NULL if the second display column is not provided.

setSeperator

public void setSeperator(java.lang.String _seperator)
Set the seperator to be used when multiple columns are displayed

Parameters:
_seperator - seperator to be used.

getSeperator

public java.lang.String getSeperator()
Returns the seperator used when multiple columns are displayed

Returns:
seperator used.

getNumberOfItems

public int getNumberOfItems()
Returns the number of items present in the combo box. This is a read-only bean property.

Returns:
returns the number of items present in the combo box.

setSelectedValue

public void setSelectedValue(long _value)
Sets the currently selected value Currently not a bean property since there is no associated variable.

Parameters:
_value - value to set as currently selected.

getSelectedValue

public long getSelectedValue()
Returns the value of the selected item. Currently not a bean property since there is no associated variable.

Returns:
value corresponding to the selected item in the combo. return -1 if no item is selected.

setSelectedStringValue

public void setSelectedStringValue(java.lang.String _value)
Sets the currently selected value Currently not a bean property since there is no associated variable.

Parameters:
_value - value to set as currently selected.

getSelectedStringValue

public java.lang.String getSelectedStringValue()
Returns the value of the selected item. Currently not a bean property since there is no associated variable.

Returns:
value corresponding to the selected item in the combo. return null if no item is selected.

execute

public void execute()
             throws java.sql.SQLException,
                    java.lang.Exception
Executes the query and adds items to the combo box based on the values retrieved from the database.

Throws:
java.sql.SQLException
java.lang.Exception

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

addItem

public void addItem(java.lang.String _name,
                    long _value)
Adds an item to the existing list of items in the combo box.

Parameters:
_name - name that should be displayed in the combo
_value - value corresponding the the name

addStringItem

public void addStringItem(java.lang.String _name,
                          java.lang.String _value)
Adds an item to the existing list of items in the combo box.

Parameters:
_name - name that should be displayed in the combo
_value - value corresponding the the name

deleteItem

public boolean deleteItem(long _value)
Deletes the item which has value equal to _value. If more than one item is present in the combo for that value the first one is changed.

Parameters:
_value - value of the item to be deleted.
Returns:
returns true on successful deletion else returns false.

deleteStringItem

public boolean deleteStringItem(java.lang.String _value)
Deletes the item which has value equal to _value. If more than one item is present in the combo for that value the first one is changed.

Parameters:
_value - value of the item to be deleted.
Returns:
returns true on successful deletion else returns false.

updateItem

public boolean updateItem(long _value,
                          java.lang.String _name)
Updates the string thats being displayed. If more than one item is present in the combo for that value the first one is changed. NOTE: To retain changes made to current SSRowSet call updateRow before calling the updateItem on SSDBComboBox. (Only if you are using the SSDBComboBox and SSDataNavigator for navigation in the screen. If you are not using the SSDBComboBox for navigation then no need to call updateRow on the SSRowSet. Also if you are using only SSDBComboBox for navigation you need not call the updateRow.)

Parameters:
_value - the value corresponding to the item in combo to be updated.
_name - the new name that replace old one.
Returns:
returns true if successful else false.

updateStringItem

public boolean updateStringItem(java.lang.String _value,
                                java.lang.String _name)
Updates the string thats being displayed. If more than one item is present in the combo for that value the first one is changed. NOTE: To retain changes made to current SSRowSet call updateRow before calling the updateItem on SSDBComboBox. (Only if you are using the SSDBComboBox and SSDataNavigator for navigation in the screen. If you are not using the SSDBComboBox for navigation then no need to call updateRow on the SSRowSet. Also if you are using only SSDBComboBox for navigation you need not call the updateRow.)

Parameters:
_value - the value corresponding to the item in combo to be updated.
_name - the new name that replace old one.
Returns:
returns true if successful else false.

setConnection

public void setConnection(SSConnection _sSConnection)
Deprecated. 

Sets the connection object to be used.

Parameters:
_sSConnection - connection object used for database.
See Also:
setSSConnection(com.nqadmin.swingSet.datasources.SSConnection)

setRowSet

public void setRowSet(SSRowSet _sSRowSet)
Deprecated. 

Sets the new SSRowSet for the combo box.

Parameters:
_sSRowSet - SSRowSet to which the combo has to update values.
See Also:
setSSRowSet(com.nqadmin.swingSet.datasources.SSRowSet)

setTextField

public void setTextField(javax.swing.JTextField _textField)
Deprecated. 

Sets the text field to which the underlying value is written to.

Parameters:
_textField - text field to which the selected item value has to be written.

getConnection

public SSConnection getConnection()
Deprecated. 

Returns connection object used to get values from database.

Returns:
returns a SSConnection object.
See Also:
getSSConnection()

getTextField

public javax.swing.JTextField getTextField()
Deprecated. 

Returns the text field used to synchronize with the SSRowSet.

Returns:
returns the text field used to synchronize with the SSRowSet.

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.

deleteItem

public boolean deleteItem(java.lang.String _name)
Deprecated. 

Deletes the item which has name equal to _name. If there are more than one item with the same name then the first occurance is deleted.

Parameters:
_name - value of the item to be deleted.
Returns:
returns true on successful deletion else returns false.

deleteItem

public boolean deleteItem(java.lang.String _name,
                          long _value)
Deprecated. 

Deletes the item which has display name equal to _name and corresponding value as _value. If there is more than one item with same name and value then the first occurance is deleted.

Parameters:
_name - name of item to be deleted
_value - value of the item to be deleted.
Returns:
returns true on successful deletion else returns false.