Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT Different column types in same column?

I'm working on a GWT app, and so far I'm loving the Java developer friendly UI framework!

So far I've been able to do pretty much anything with the widgets, but this one has me stumped. I have a cell table, that I use as a user input source. Its just a way for users to enter key-value pairs to call my service. User can dynamically add rows and delete rows.

Now the tricky part is I want to force the user to enter value for some keys. There are only certain 4-5 acceptable values for these keys so for those rows I would like to replace the editableTextCell with a selectionCell. Not sure how I can mix cell types within a table, given that the column cell type declaration is done while adding the column to the table.

Any input is appreciated!

Thanks

like image 689
theboot Avatar asked May 09 '11 14:05

theboot


1 Answers

You'll have to create a custom Cell that sometimes renders a <select> and sometimes renders an <input>. If you look at the code of EditableTextCell and SelectionCell you can get ideas about how to accomplish that. It may be pretty simple - you could compose one of each, and in your render function just pass the data to the appropriate cell.

Something like...

public class ChoosyCell extends AbstractCell<YourData> {
    SelectionCell selectCell = new SelectionCell<YourData>();
    EditableTextCell textCell = new EditableTextCell<YourData>();

    public void render(Context context, YourData data, SafeHtmlBuilder sb) {
        if (data.isTheLimitedType()) {
            selectCell.render(context, data, sb);
        } else {
            textCell.render(context,data, sb);
        }
     }
}

(untested code)

like image 97
Riley Lark Avatar answered Sep 25 '22 16:09

Riley Lark