Monday, February 28, 2011

SelectionCell on a Celltable with values

Hello,

I'm new on this, and i'm having some problems...I'd like to create a
celltable with selectioncells. I'll get the data shown on the
selectioncell from a RPC call, but i don´t know how to do this, as I'm
not able to give the selectioncells values after the creation of the
table.
Could you PLEASE give some help???? I've trying this for days with no
results. :(
Thank you in advance...

My code:


class SearchUI extends SimplePanel {
private Grid pT = new Grid(5,1); //Main table
private Grid botones = new Grid(1,4); //Buttons table
private Grid check = new Grid(1,2); //Buttons table
private ListBox domains = new ListBox(); //Domains
private Button del = new Button(); //Buttons
private Button add = new Button();
private String domain = ""; //Selected domain
private final static String use = "Use Inference";
private CellTable<Row> table = new CellTable<Row>();;
private SingleSelectionModel<Row> selectionModel = null;
private ListDataProvider<Row> dataProvider = null;


private Column<Row,String> firstColumn = null;
List<String> subjects = new ArrayList<String>();

public SearchUI(){

createView();

}

private void createListeners(){

del.addClickHandler(new ClickHandler(){
public void onClick(ClickEvent event){
//TODO
Row selected = selectionModel.getSelectedObject();
if (selected != null) {
dataProvider.getList().remove(selected);
}else{
MessageBox.alert("ERROR:", "You need to choose a row to
delete!", null);
}
}

});

add.addClickHandler(new ClickHandler(){
public void onClick(ClickEvent event){
if("".equals(domain))
MessageBox.alert("ERROR:", "You need to choose a domain first!",
null);
else{
add.setEnabled(false);
getFields(domain);
}
}
});

}

private void createView(){

subjects.add("subject1");
subjects.add("subject2");
subjects.add("subject3");

final SelectionCell subjectsCell = new SelectionCell(subjects);

firstColumn = new Column<SearchUI.Row,String>(subjectsCell) {
@Override
public String getValue(Row object) {
return object.firstColumn;
}
};
table.addColumn(firstColumn, "Subject");

List<String> prods = new ArrayList<String>();
prods.add("prod1");
prods.add("prod2");
prods.add("prod3");

final SelectionCell prodsCell = new SelectionCell(prods);

Column<Row, String> secondColumn = new
Column<SearchUI.Row,String>(prodsCell) {

@Override
public String getValue(Row object) {
return object.secondColumn;
}
};
table.addColumn(secondColumn, "Prod");

List<String> objs = new ArrayList<String>();
objs.add("obj1");
objs.add("obj2");
objs.add("obj3");

final SelectionCell objsCell = new SelectionCell(objs);

Column<Row,String> thirdColumn = new
Column<SearchUI.Row,String>(objsCell) {

@Override
public String getValue(Row object) {
return object.thirdColumn;
}
};
table.addColumn(thirdColumn, "Object");

selectionModel = new SingleSelectionModel<SearchUI.Row>();
table.setSelectionModel(selectionModel);

...

//Listeners
createListeners();

pT.setSize("100%", "100%");

add(pT);
}


private void getFields(OntologyNode result){
if(table.getRowCount()==0){
table.setRowCount(getList().size());
dataProvider = new ListDataProvider<SearchUI.Row>(getList());
dataProvider.addDataDisplay(table);
}else if(table.getRowCount()>0){
table.setRowCount(table.getRowCount()+1);
dataProvider.getList().add(new Row("first", "entry", "foo"));
}
add.setEnabled(true);

}

private class Row {

private String firstColumn;
private String secondColumn;
private String thirdColumn;


public Row(String firstColumn, String secondColumn, String
thirdColumn) {
this.firstColumn = firstColumn;
this.secondColumn = secondColumn;
this.thirdColumn = thirdColumn;
}

}

private LinkedList<Row> getList() {
LinkedList<Row> list = new LinkedList<Row>();
list.add(new Row("first", "entry", "foo"));
return list;
}
}

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment