Bug 60462 - [CellEditors] applyEditorValueAndDeactivate() in ComboBoxCellEditor gets index exception.
Summary: [CellEditors] applyEditorValueAndDeactivate() in ComboBoxCellEditor gets inde...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.1.3   Edit
Hardware: PC Windows 2000
: P4 normal (vote)
Target Milestone: 3.2 M3   Edit
Assignee: Eric Moffatt CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
: 39826 67698 107930 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-04-29 13:02 EDT by San CLA
Modified: 2005-11-08 10:21 EST (History)
3 users (show)

See Also:


Attachments
Use the text from the edit control if the 'selection' index == -1 (1.46 KB, patch)
2005-07-20 10:55 EDT, Eric Moffatt CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description San CLA 2004-04-29 13:02:52 EDT
The problem is in this method. See line marked with "@ERROR" below.

private void applyEditorValueAndDeactivate() {
  selection = comboBox.getSelectionIndex();
  Object newValue = doGetValue();
  markDirty();
  boolean isValid = isCorrect(newValue);
  setValueValid(isValid);
  if (!isValid) {
    //@ERROR
    //THIS LINE CAUSES AN ERROR. IT ASSUMES SOMETHING IS SELECTED. IN EDIT
    //MODE, THIS IS NOT TRUE IF I JUST TYPE SOMETHING INTO THE CELL EDITOR.
    //IN THIS CASE, selection IS AN INVALID INDEX.
    setErrorMessage(
    MessageFormat.format(getErrorMessage(), new Object[] {items[selection]})); 
  }
  fireApplyEditorValue();
  deactivate();
}
Comment 1 Michael Mansell CLA 2004-05-26 21:01:01 EDT
The problem appears to lie in that the populateComboBoxItems() routine sets the 
selection in the ComboBoxCellEditor, but not in the contained CCombo. 
Therefore, the CCombo remains with a selection of -1. If some code happens to 
cause a deactivation (usually because of lost focus) before a call to doSetValue
(), then CCombo still returns a -1 which causes many problems, not just the one 
reported above. For example, if the ComboBoxCellEditor is being used by an EMF 
editor (ExtendedComboboxCellEditor) and the EMF model is a boolean, then when 
the code attempts to store the value (because of focus lost) you end up with a 
NullPointerException.

It would seem to me that the simplest solution would be to add a comboBox.select
(selection) call into populateComboBoxItems().
Comment 2 Majnoud Fatishi CLA 2005-03-17 04:09:11 EST
Hi Tod,

Since there was no activity in this bug since May 2004, I am assuming there
is some plausible workaround which would enable one to use the ComboBoxCellEditor 
without throwing an exception.  But I can't figure out how to do it (maybe there
is an alternative CellEditor somewhere?)  

Could you please point out how to work around this bug?

Thank you!
Comment 3 Tod Creasey CLA 2005-03-17 08:33:31 EST
We haven't had the resources to invetigate your case. The workaround is to only
return false for isValid when you want the error.

If you have a suggested patch we could look at it.
Comment 4 Nick Edgar CLA 2005-07-19 13:02:13 EDT
*** Bug 39826 has been marked as a duplicate of this bug. ***
Comment 5 Nick Edgar CLA 2005-07-19 13:02:43 EDT
Eric is in this area at the moment.  The fix should be simple.
Comment 6 Eric Moffatt CLA 2005-07-20 10:55:16 EDT
Created attachment 25045 [details]
Use the text from the edit control if the 'selection' index == -1


JUnit tests should come as part of fixing Bug 83559
Comment 7 Tod Creasey CLA 2005-08-12 13:48:11 EDT
Patch released to HEAD with Bug number removed.
Comment 8 Eric Moffatt CLA 2005-08-25 10:45:44 EDT
*** Bug 107930 has been marked as a duplicate of this bug. ***
Comment 9 Eric Moffatt CLA 2005-10-19 14:51:26 EDT
Test in M2...
Comment 10 Tod Creasey CLA 2005-10-19 14:57:02 EDT
M3...
Comment 11 Eric Moffatt CLA 2005-11-01 15:55:52 EST
Verified in >I20051101-0010.
Comment 12 Boris Bokowski CLA 2005-11-08 10:21:38 EST
*** Bug 67698 has been marked as a duplicate of this bug. ***