ggeorg / gwt-mosaic

Automatically exported from code.google.com/p/gwt-mosaic
1 stars 0 forks source link

ComboBox.setSelectedIndex causes a ClassCastException when an item of any type other than String is selected #38

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a org.gwt.mosaic.ui.client.ComboBox<T> instance such that T is
some class other than String
2. Insert an item of type T into the ComboBox instance at index 0
("insertItem(<item>, 0)")
3. Call "setSelectedIndex(0)" on the instance

What is the expected output? What do you see instead?
This should have selected the item inserted at index 0. Instead, an
exception was thrown. Here is the relevant section of the stack trace:

"java.lang.ClassCastException: ...
    at org.gwt.mosaic.ui.client.ComboBox$3.onChange(ComboBox.java:78)
    at
com.google.gwt.user.client.ui.ChangeListenerCollection.fireChange(ChangeListener
Collection.java:34)
    at org.gwt.mosaic.ui.client.ListBox$3.onRowsSelected(ListBox.java:290)
    at
com.google.gwt.widgetideas.table.client.TableSelectionListenerCollection.fireRow
sSelected(TableSelectionListenerCollection.java:105)
    at
com.google.gwt.widgetideas.table.client.SelectionGrid.selectRow(SelectionGrid.ja
va:713)
    at
com.google.gwt.widgetideas.table.client.SelectionGrid.selectRow(SelectionGrid.ja
va:443)
    at org.gwt.mosaic.ui.client.ListBox.setSelectedIndex(ListBox.java:821)
    at org.gwt.mosaic.ui.client.ComboBox.setSelectedIndex(ComboBox.java:226)
..."

What version of the product are you using? On what operating system?
0.1.7 on Windows XP

Please provide any additional information below.
This exception will occur whenever the an instance of ComboBox is typed for
something other than String, due to a listener that ComboBox attaches in
its constructor. This listener is notified whenever an item is selected and
attempts to cast the item as a string. It is not possible to correct this
behavior by overriding the constructor as the "listBox" member variable is
private and final, and therefore cannot be set without using the
constructor that causes the problem.

Excerpt from source code for org.gwt.mosaic.ui.client.ComboBox:
"listBox.addChangeListener(new ChangeListener() {
      public void onChange(Widget sender) {
        setText((String)listBox.getItem(listBox.getSelectedIndex()));
        hidePopup();
      }
    });"

Original issue reported on code.google.com by jason.se...@issinc.com on 30 Jan 2009 at 2:21

GoogleCodeExporter commented 9 years ago
ComboBox is not ready yet this is why there is no demo in Showcase. Sorry for 
any
trouble. I will try to fix that after 0.1.8 next Saturday.

Kind Regards,
George.

Original comment by georgopo...@gmail.com on 31 Jan 2009 at 9:10

GoogleCodeExporter commented 9 years ago
Ok, thanks for the information. I spent some time experimenting with the 
existing
implementation, and I have a few other requests and suggestions based on what I
found. I'll list them them in case they're useful. Please let me know if you'd 
like
assistance with implementation or testing of this control once you get the 
chance to
start working on it.

1. When scrollbars are active on the popup panel, the space they take up isn't
accounted for properly by the ColumnWidget - this causes the space allowed for 
each
"column" item on the panel to shrink a little more each time it's opened until 
the
minimum size (1) is reached. The starting column width (80) also doesn't seem 
to make
much sense - it should probably be equal to the width of the input control (or 
the
input control plus the dropdown arrow button).

2. It would be best if the CellRenderer could control the rendering of the 
ComboBox's
"input" field as well as the popup panel items (so if the items on the popup 
panel
are complex widgets instead of just text, the currently selected item can look 
the
same). This would make the behavior more consistent with the CellRenderer of the
equivalent Swing class.

3. The dropdown arrow button doesn't seem to be sizing itself properly - it's 
taking
up about half the space allocated to the control instead of a small, fixed 
section on
the right side.

Original comment by jason.se...@issinc.com on 2 Feb 2009 at 5:30

GoogleCodeExporter commented 9 years ago

Original comment by georgopo...@gmail.com on 11 Jul 2009 at 7:44