package e4s.tutorial; import e4s.util.E4ID; import e4s.html.*; import e4s.html.list.E4SortedList; import e4s.html.list.E4SortedListElement; import e4s.html.list.E4SortedList_Intf; import e4s.html.list.E4SortedListItem; import e4s.servlet.*; /** * Create a table with dynamic sorting capabilities. * * {@tutorial Example_SortedList} */ public class Example_SortedList extends E4ModuleImplementation { public static E4Method startList = null; public void startList( HTML html ) { String countries[] = { "France", "Germany", "Germany", "Germany", "Germany", "Austria", "Austria", "Italy" }; String cities[] = { "Paris", "Berlin", "Cologne", "Munich", "Hamburg", "Vienna", "Klosterneuburg", "Rome" }; String wind[] = { "NE", "N", "N", null, "N", "SO", "SO", "SW" }; float temperature[] = { 30f, 31.5f, 29.8f, 34f, 32f, 32.5f, 30.8f, 37.6f }; // create the "list". This is the base object that handles // all the functionality and will be stored persistant // in a session object while needed. The list must be unique // identified by it's ID which is "EXAMPLE_LIST" E4SortedList exampleList = new E4SortedList( E4ID(), "EXAMPLE_LIST",getServlet()); // exampleList.setEnableColumnChange(false); exampleList.setBorder(); exampleList.setCellspacing(0,0); // now we need the HTML element representing the list. This is done // by a call to html.SortedListElement() which now joins the // list to the HTML output E4SortedListElement exampleListElement = html.SortedListElement(exampleList); // let's define some header columns for the list now exampleList.defineColumn(Align.LEFT,E4LabelNone("Country")); exampleList.defineColumn(Align.LEFT,E4LabelNone("City")); exampleList.defineColumn(Align.CENTER,E4LabelNone("Wind")); exampleList.defineColumn(Align.RIGHT,E4LabelNone("Temp.")); // define a row for the average temperature. This row is used // in the header and will not be part of the sort E4SortedListItem bootomRow = new E4SortedListItem(4); bootomRow.setPrimarySort(E4SortedList_Intf.PRIMARY_SORT_BOTTOM); bootomRow.setBgColor(E4Color.LIGHT_BLUE); exampleList.addElement(bootomRow); float sum = 0.0f; for( int i = 0; i < countries.length; i++ ) { // create a data row and append it to the list E4SortedListItem row = new E4SortedListItem(4); row.set(0,countries[i]); row.set(1,cities[i]); row.set(2,wind[i]); row.set(3,temperature[i]); exampleList.addElement(row); sum += temperature[i]; } bootomRow.set(0,"Average"); bootomRow.set(3,sum / countries.length); } }