Re: GWT Simple Pager Help
Hi Noor, Heres an example of a Celltable (using a DataProvider): public class TestTable implements EntryPoint { private GreetingServiceAsync gService; private CellTableMyStat table; /** * This is the entry point method. */ public void onModuleLoad() { // Create a CellTable. table = new CellTableMyStat(); // Create name column. gService = GWT.create(GreetingService.class); TextColumnMyStat mIdColumn = new TextColumnMyStat() { public String getValue(MyStat stat) { return +stat.getId(); } }; // Create address column. ColumnMyStat, String machIdColumn = new ColumnMyStat, String(new EditTextCell()) { @Override public String getValue(MyStat stat) { return stat.getMachineId(); } }; machIdColumn.setFieldUpdater(new FieldUpdaterMyStat, String() { @Override public void update(int index, MyStat object, String value) { object.setMachineId(value); Window.alert(value); } }); TextColumnMyStat msisdnColumn = new TextColumnMyStat() { public String getValue(MyStat stat) { return stat.getMsisdn(); } }; ColumnMyStat, String bCol = new ColumnMyStat, String(new ButtonCell()){ @Override public String getValue(MyStat myDto) { return OK; } }; bCol.setFieldUpdater(new FieldUpdaterMyStat, String() { @Override public void update(int index, MyStat object, String value) { Window.alert(testing); } }); // SelectionCell. final ListString options = new ArrayListString(); options.add(Opt1); options.add(Opt2); options.add(Opt3); options.add(Opt4); options.add(Opt5); options.add(Opt6); options.add(Opt7); options.add(Opt8); ColumnMyStat, String colMe = new ColumnMyStat, String(new SelectionCell(options)) { @Override public String getValue(MyStat object) { return options.get(object.getOptId()); } }; colMe.setFieldUpdater(new FieldUpdaterMyStat, String() { @Override public void update(int index, MyStat object, String value) { int i = 0; for (String category : options) { if (category.equals(value)) { object.setOptId(i); break; } i++; } } }); // Create a data provider. MyDataProvider dataProvider = new MyDataProvider(); // Add the cellList to the dataProvider. dataProvider.addDataDisplay(table); // Add the columns. table.addColumn(mIdColumn, ID); table.addColumn(machIdColumn, MachineId); table.addColumn(bCol, Report); table.addColumn(msisdnColumn, Msisdn); table.addColumn(colMe, Country); // Set the total row count. This isn't strictly necessary, but it affects // paging calculations, so its good habit to keep the row count up to date. table.setRowCount(10, false); NoSelectionModelMyStat selectionModel = new NoSelectionModelMyStat(); table.setSelectionModel(selectionModel); SimplePager pager = new SimplePager(); pager.setDisplay(table); RootPanel.get().add(table); RootPanel.get().add(pager); } class MyDataProvider extends AsyncDataProviderMyStat { /** * {...@link #onRangeChanged(HasData)} is called when the table requests a new * range of data. You can push data back to the displays using * {...@link #updateRowData(int, List)}. */ @Override protected void onRangeChanged(HasDataMyStat display) { // Get the new range. final Range range = display.getVisibleRange(); /* * Query the data asynchronously. If you
Re: Events from SelectionCell in CellTable - GWT 2.1 M1
The setFieldUpdater proved to be a better solution, thanks :-) For some reason InternetExplorer does not send change events when changing the value of the selectionCell. Is this a known bug in GWT 2.1 M1 ? On Jun 27, 2:59 pm, Paul Stockley pstockl...@gmail.com wrote: use the setFieldUpdater(fieldUpdater) on the Column class On Jun 27, 6:28 am, saklig d3andr...@gmail.com wrote: Which class has the addValueUpdateHandler ? On Jun 25, 4:08 pm, Paul Stockley pstockl...@gmail.com wrote: Can't you just add a ValueUpdater handler to see when the selection changes? On Jun 25, 4:27 am, saklig d3andr...@gmail.com wrote: After a couple of tries Ive managed to write something that gets the job done. My example: ListString opts = new ArrayListString(); opts.add(Enabled); opts.add(Disabled); table.addColumn(new IdentityColumnMyData(new ActiveSelectionCell(opts)), Active); private class ActiveSelectionCell implements CellMyData{ private HashMapString, Integer indexForOption = new HashMapString, Integer(); private final ListString options; public ActiveSelectionCell(ListString options) { this.options = new ArrayListString(options); int index = 0; for (String option : options) { indexForOption.put(option, index++); } } @Override public boolean consumesEvents() { return false; } @Override public boolean dependsOnSelection() { return false; } private int getSelectedIndex(String value) { Integer index = indexForOption.get(value); if (index == null) { return -1; } return index.intValue(); } @Override public void setValue(Element parent, MyData value, Object viewData) { StringBuilder sb = new StringBuilder(); render(value, viewData, sb); parent.setInnerHTML(sb.toString()); } @Override public Object onBrowserEvent(Element parent, MyData value, Object viewData, NativeEvent event, ValueUpdaterMyData valueUpdater) { String type = event.getType(); if (change.equals(type)) { SelectElement select = parent.getFirstChild().cast(); if( options.get(select.getSelectedIndex()).equalsIgnoreCase(Enabled)) value.setActive(1); else value.setActive(0); System.out.println(value.getName() + - + options.get(select.getSelectedIndex())); // valueUpdater.update(value); } return viewData; } @Override public void render(MyData value, Object viewData, StringBuilder sb) { int selectedIndex = 0; if(value.getActive().equalsIgnoreCase(1)){ selectedIndex = getSelectedIndex(Enabled); }else{ selectedIndex = getSelectedIndex(Disabled); } sb.append(select); int index = 0; for (String option : options) { if (index++ == selectedIndex) { sb.append(option selected='selected'); } else { sb.append(option); } sb.append(option); sb.append(/option); } sb.append(/select); } } If you think this was the wrong/not the best way to get an event from a cell, pleas give me a comment. On Jun 22, 1:25 pm, saklig d3andr...@gmail.com wrote: Hi, How does one handle events from cells in a CellTable( specifically a SelectionCell ) ? -- 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-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more
Re: Events from SelectionCell in CellTable - GWT 2.1 M1
Which class has the addValueUpdateHandler ? On Jun 25, 4:08 pm, Paul Stockley pstockl...@gmail.com wrote: Can't you just add a ValueUpdater handler to see when the selection changes? On Jun 25, 4:27 am, saklig d3andr...@gmail.com wrote: After a couple of tries Ive managed to write something that gets the job done. My example: ListString opts = new ArrayListString(); opts.add(Enabled); opts.add(Disabled); table.addColumn(new IdentityColumnMyData(new ActiveSelectionCell(opts)), Active); private class ActiveSelectionCell implements CellMyData{ private HashMapString, Integer indexForOption = new HashMapString, Integer(); private final ListString options; public ActiveSelectionCell(ListString options) { this.options = new ArrayListString(options); int index = 0; for (String option : options) { indexForOption.put(option, index++); } } @Override public boolean consumesEvents() { return false; } @Override public boolean dependsOnSelection() { return false; } private int getSelectedIndex(String value) { Integer index = indexForOption.get(value); if (index == null) { return -1; } return index.intValue(); } @Override public void setValue(Element parent, MyData value, Object viewData) { StringBuilder sb = new StringBuilder(); render(value, viewData, sb); parent.setInnerHTML(sb.toString()); } @Override public Object onBrowserEvent(Element parent, MyData value, Object viewData, NativeEvent event, ValueUpdaterMyData valueUpdater) { String type = event.getType(); if (change.equals(type)) { SelectElement select = parent.getFirstChild().cast(); if( options.get(select.getSelectedIndex()).equalsIgnoreCase(Enabled)) value.setActive(1); else value.setActive(0); System.out.println(value.getName() + - + options.get(select.getSelectedIndex())); // valueUpdater.update(value); } return viewData; } @Override public void render(MyData value, Object viewData, StringBuilder sb) { int selectedIndex = 0; if(value.getActive().equalsIgnoreCase(1)){ selectedIndex = getSelectedIndex(Enabled); }else{ selectedIndex = getSelectedIndex(Disabled); } sb.append(select); int index = 0; for (String option : options) { if (index++ == selectedIndex) { sb.append(option selected='selected'); } else { sb.append(option); } sb.append(option); sb.append(/option); } sb.append(/select); } } If you think this was the wrong/not the best way to get an event from a cell, pleas give me a comment. On Jun 22, 1:25 pm, saklig d3andr...@gmail.com wrote: Hi, How does one handle events from cells in a CellTable( specifically a SelectionCell ) ? -- 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-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
Re: Events from SelectionCell in CellTable - GWT 2.1 M1
After a couple of tries Ive managed to write something that gets the job done. My example: ListString opts = new ArrayListString(); opts.add(Enabled); opts.add(Disabled); table.addColumn(new IdentityColumnMyData(new ActiveSelectionCell(opts)), Active); private class ActiveSelectionCell implements CellMyData{ private HashMapString, Integer indexForOption = new HashMapString, Integer(); private final ListString options; public ActiveSelectionCell(ListString options) { this.options = new ArrayListString(options); int index = 0; for (String option : options) { indexForOption.put(option, index++); } } @Override public boolean consumesEvents() { return false; } @Override public boolean dependsOnSelection() { return false; } private int getSelectedIndex(String value) { Integer index = indexForOption.get(value); if (index == null) { return -1; } return index.intValue(); } @Override public void setValue(Element parent, MyData value, Object viewData) { StringBuilder sb = new StringBuilder(); render(value, viewData, sb); parent.setInnerHTML(sb.toString()); } @Override public Object onBrowserEvent(Element parent, MyData value, Object viewData, NativeEvent event, ValueUpdaterMyData valueUpdater) { String type = event.getType(); if (change.equals(type)) { SelectElement select = parent.getFirstChild().cast(); if( options.get(select.getSelectedIndex()).equalsIgnoreCase(Enabled)) value.setActive(1); else value.setActive(0); System.out.println(value.getName() + - + options.get(select.getSelectedIndex())); //valueUpdater.update(value); } return viewData; } @Override public void render(MyData value, Object viewData, StringBuilder sb) { int selectedIndex = 0; if(value.getActive().equalsIgnoreCase(1)){ selectedIndex = getSelectedIndex(Enabled); }else{ selectedIndex = getSelectedIndex(Disabled); } sb.append(select); int index = 0; for (String option : options) { if (index++ == selectedIndex) { sb.append(option selected='selected'); } else { sb.append(option); } sb.append(option); sb.append(/option); } sb.append(/select); } } If you think this was the wrong/not the best way to get an event from a cell, pleas give me a comment. On Jun 22, 1:25 pm, saklig d3andr...@gmail.com wrote: Hi, How does one handle events from cells in a CellTable( specifically a SelectionCell ) ? -- 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-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
Events from SelectionCell in CellTable - GWT 2.1 M1
Hi, How does one handle events from cells in a CellTable( specifically a SelectionCell ) ? -- 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-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
Re: Simple working example of the Data Presentation Widget CellTable
This helped me a lot :-) Thanks guys! On Jun 3, 2:14 pm, Paul Stockley pstockl...@gmail.com wrote: Sorry my message got truncated: Your over complicating it. You should just subclass AsyncListViewAdapter such as: protected class residentAsyncAdapter extends AsyncListViewAdapterResidentListDO{ @Override protected void onRangeChanged(ListViewResidentListDO view) { Range newRange = view.getRange(); updateViewData(newRange.getStart(), newRange.getLength(), a list of data for the requested range); } } Then add the table as a view of the adapter CellTableResidentListDO residentTable = new CellTableResidentListDO(5); ColumnResidentListDO, String unitColumn = new ColumnResidentListDO, String(new TextCell()) { @Override public String getValue(ResidentListDO object) { return object.getUnit(); } }; residentTable.addColumn(unitColumn, Unit); SimplePagerResidentListDO thePager = new SimplePagerResidentListDO(residentTable); residentTable.setPager(thePager); mainGridContainer.add(residentTable); pagerContainer.add(thePager); residentAsyncAdapter residentTableAdapter = new residentAsyncAdapter(); residentTableAdapter.addView(view.residentTable); residentTableAdapter.updateDataSize(size of data set, true); If you have a list on the client already for the data set it is even easier. Instead of using AsyncListViewAdapter use ListViewAdapter as follows: ListResidentListDO ourList = new ArrayListResidentListDO(); ListViewAdapterResidentListDO residentTableAdapter = new ListViewAdapterResidentListDO(ourList ); residentTableAdapter.addView(view.residentTable); //No need to call updateDataSize On Jun 3, 7:52 am, Paul Stockley pstockl...@gmail.com wrote: Your making it overly complicated: For the case where you have all the data in a list already: ColumnResidentListDO, String unitColumn = new ColumnResidentListDO, String(new TextCell()) { @Override public String getValue(ResidentListDO object) { return object.getUnit(); } }; ColumnResidentListDO, String nameColumn = new ColumnResidentListDO, String(new TextCell()) { @Override public String getValue(ResidentListDO object) { return object.getName(); } }; residentTable.addColumn(unitColumn, Unit); residentTable.addColumn(nameColumn, Name); SimplePagerResidentListDO thePager = new SimplePagerResidentListDO(residentTable); residentTable.setPager(thePager); mainGridContainer.add(residentTable); pagerContainer.add(thePager); residentTableAdapter = new residentAsyncAdapter(); On Jun 2, 11:18 pm, Andrew yenchu.chen...@gmail.com wrote: The following code is what I'm woking on, hope it can help you: protected void init() { VerticalPanel container = new VerticalPanel(); initWidget(container); int pageSize = 10; CellTableUser cellTable = new CellTableUser(pageSize); setColumns(cellTable); setSelectionModel(cellTable); setDataSize(cellTable); int pageStart = 0; loadData(pageStart, pageSize, cellTable); SimplePagerUser pager = createPager(cellTable); container.add(cellTable); container.add(pager); } private SimplePagerUser createPager(final CellTableUser cellTable) { SimplePagerUser pager = new SimplePagerUser(cellTable, SimplePager.TextLocation.CENTER) { public void onRangeOrSizeChanged(PagingListViewUser listView) { loadData(listView.getPageStart(), listView.getPageSize(), listView); super.onRangeOrSizeChanged(listView); } }; return pager; } private void setColumns(CellTableUser cellTable) { cellTable.addColumn(new TextColumnUser() { @Override public String getValue(User user) { return user.getName(); } }, new TextHeader(Name)); cellTable.addColumn(new TextColumnUser() { @Override public String getValue(User
Simple working example of the Data Presentation Widget CellTable
Hi, I want to create a working example of the CellTable widget that was recently released in GWT 2.1 M1. I'm having a hard time finding documentation for this widget, as apparently it has not been written yet :-/ What I've tried so far: ListMyCellData dataList = new ArrayListMyCellData(); dataList.add(Pizza, 15); dataList.add(Car, 4); ListViewAdapterMyCellData adapter = new ListViewAdapterMyCellData(); CellTableMyCellData view = new CellTableMyCellData(5); adapter.addView(view); RootPanel.get(cellTableDiv).add(view); view.setData(0, stringList.size(), dataList); adapter.refresh(); private class MyCellData{ private String name; private int numberOfSomething; public MyCellData(String name, int numberOfSomething){ this.name = name; this.numberOfSomething = numberOfSomething; } public String getName(){ return name; } public int getNumberOfSomething(){ return numberOfSomething; } } I'm not sure what to insert as parameter in the view.setData . Could someone pleas give me a pointer or a map :-) Thanks! -- 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-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.