newbie: Events in subclasses

2 views
Skip to first unread message

jen

unread,
Feb 28, 2007, 6:50:08 PM2/28/07
to Google Web Toolkit
Hello,

I am having some problems with events in a subclass of a widget.
I have a SortableCheckBox class below:
--------------------------------------------------------------------------------------------------------
import com.google.gwt.user.client.ui.CheckBox;

public class SortableCheckBox extends CheckBox implements Comparable
{
public SortableCheckBox()
{
super();
}

public SortableCheckBox(String label)
{
super(label);
}

public SortableCheckBox(String label, boolean asHTML)
{
super(label, asHTML);
}

public int compareTo(Object arg0)
{
return 0;
}
}
---------------------------------------------------------------------------------------------

I have add this checkbox to a sortable table:

sortableTable.addValue(0, 1, sortableCheckBox);

When I deploy this and check the checkbox,

sortableCheckBox.isChecked() returns false

It's as if the sortableCheckBox never gets the event that the CheckBox
is checked.
Am i missing something in the subclass implementation?
Any ideas??

Thanks!
Jen.

Ian Petersen

unread,
Feb 28, 2007, 7:00:12 PM2/28/07
to Google-We...@googlegroups.com
Hi Jen,

Can you avoid the problem by using Comparator? Instead of using a
subclass CheckBox that implements Comparable, why not use CheckBox and
an instance of Comparator? It should be just as "sortable", but
without the problems you've run into.

Ian

--
Tired of pop-ups, security holes, and spyware?
Try Firefox: http://www.getfirefox.com

jen

unread,
Feb 28, 2007, 7:14:03 PM2/28/07
to Google Web Toolkit
Hi Ian,

Thanks for the reply.
The reason I'm implementing Comparable is because i'm using a sortable
table I got here:
http://psthapar.googlepages.com/simplesortabletable

this requires that entries that i want to be sorted implement
Comparable.
any suggestions around this?

Thanks!
Jen.

Ian Petersen

unread,
Mar 1, 2007, 8:02:33 AM3/1/07
to Google-We...@googlegroups.com
> this requires that entries that i want to be sorted implement
> Comparable.
> any suggestions around this?

It looks to me like the code you linked to doesn't do what you want.
When it renders the table, it assumes that the values you've added to
the table can all be drawn with "toString()". This assumption is
false for widgets, including CheckBox. Even if you could solve your
event problem, you'll run into issues when you add a SortableCheckBox
to a SortableTable.

You'll either have to change the code (it's under the LGPL, so that

Ian Petersen

unread,
Mar 1, 2007, 8:04:39 AM3/1/07
to Google-We...@googlegroups.com
Sorry Jen, GMail flubbed and my post got truncated... Here's the rest
of what I had to say:

> You'll either have to change the code (it's under the LGPL, so that

may mean distributing your changes, depending on your circumstances),
ask the original author to change the code, or find another way to do
what you want.

Ian

Reply all
Reply to author
Forward
0 new messages