barcodefontsoft.com

Add a private method to redraw the entire table when we change the sort order. in Java Generating Code 128C in Java Add a private method to redraw the entire table when we change the sort order.

6. Add a private method to redraw the entire table when we change the sort order. using jvm toattach code-128c in asp.net web,windows application PLANET private vo Code 128C for Java id redrawTable() { int row = 1; for (Iterator iter = sortColumnValues.iterator(); iter.hasNext();) { String key = (String) iter.

next(); CustomerData custData = (CustomerData) dataBucket.get(key); [ 75 ]. Interactiv e Forms sortableTable.setText(row, sortableTable.setText(row, sortableTable.

setText(row, sortableTable.setText(row, row++; } } 0, 1, 2, 3, custData.getFirstName()); custData.

getLastName()); custData.getCity()); custData.getCountry());.

7. Add a p jar Code 128 Code Set C rivate method that can sort the data in an ascending or descending way and redraw the table with the sorted rows. We are using the sort method provided by the Collections class to sort the data, but can also modify this to use the Comparator class to compare two pieces of data, and then use that for sorting.

. public voi d sortTable(int row, int cell) { dataBucket.clear(); sortColumnValues.clear(); for (int i = 1; i < customerData.

size() + 1; i++) { dataBucket.put(sortableTable.getText(i, cell), new CustomerData( sortableTable.

getText(i, 0), sortableTable.getText(i, 1), sortableTable.getText(i, 2), sortableTable.

getText (i, 3))); sortColumnValues.add(sortableTable.getText(i, cell)); } if (sortDirection == 0) { sortDirection = 1; Collections.

sort(sortColumnValues); } else { sortDirection = 0; Collections.reverse(sortColumnValues); } redrawColumnHeader(cell); resetColumnHeaders(cell); redrawTable(); }. [ 76 ]. 4 . Here is a Code 128 for Java screenshot of the application. You can click on any of the column headers to sort the data..

What Just Happened We create USS Code 128 for Java a CustomerData class to represent each row in a FlexTable. We then create some customer data and store it in an ArrayList..

customerDa ta.add(new CustomerData("Rahul", "Dravid", "Bangalore", "India"));. Data from jdk barcode standards 128 this list is added to the table. We need to specify the row number and column number in order to add an element to the table..

CustomerDa ta element = (CustomerData) iter.next(); sortableTable.setText(row, 0, element.

getFirstName()); sortableTable.setText(row, 1, element.getLastName()); sortableTable.

setText(row, 2, element.getCity()); sortableTable.setText(row, 3, element.

getCountry());. [ 77 ]. Interactive Forms The column code128b for Java headers are contained in row zero and the table data starts from row 1. We add the column header by setting the HTML for that particular cell like this:. sortableTa ble.setHTML(0, 0, columnHeaders[0] + "  <img border="0" src="images/blank.gif"/>");.

This enabl Code 128 for Java es us to add a snippet of HTML to the cell instead of setting just plain text. We add the text for the column header along with an img tag with a blank image file. A column header without an image next to the text visually indicates to the user that there is no sort order specified for that particular column.

When we click on a column header, we will be modifying this image to use either an ascending or descending icon. An event handler is registered to listen for clicks on the table. GWT does not contain a mechanism to register a handler when someone clicks on a specific cell, so we use the general table click listener and check to see if the click was on row zero, which is the row that contains the column headers.

If the user did click on the column header, we go ahead and sort the table. The real magic happens in the sortTable() method. A temporary HashMap named dataBucket is created to store the rows from the table, with each row keyed by the value in the column whose header was clicked, along with a temporary ArrayList named sortColumnValues that stores the column values in the column whose header was clicked.

This means that the sortColumnValues list contains values that are keys in the dataBucket map.. for (int i = 1; i < customerData.size() + 1; i++) { dataBucket.put(sortableTable.

getText(i, cell), new CustomerData( sortableTable.getText(i, 0), sortableTable.getText(i, 1), sortableTable.

getText(i, 2), sortableTable.getText(i, 3))); sortColumnValues.add(sortableTable.

getText(i, cell)); }. We check t applet Code 128C he value of the sortDirection variable and, based on the value, sort the sortColumnValues list either ascending or descending to contain the column values in the right order. The built-in sort() and reverseSort() methods of the Collections class are used to provide the sorting mechanism..

if (sortDi rection == 0) { sortDirection = 1; Collections.sort(sortColumnValues); } else { sortDirection = 0; Collections.reverse(sortColumnValues); } [ 78 ].

Copyright © barcodefontsoft.com . All rights reserved.