/* * Smart GWT (GWT for SmartClient) * Copyright 2008 and beyond, Isomorphic Software, Inc. * * Smart GWT is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3 * as published by the Free Software Foundation. Smart GWT is also * available under typical commercial license terms - see * http://smartclient.com/license * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ import com.smartgwt.client.data.Record; import com.smartgwt.client.types.Autofit; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.grid.ListGridRecord; import com.google.gwt.core.client.EntryPoint; public class FieldPickerSample implements EntryPoint { private ListGridField[] createFields(int fieldCount) { ListGridField[] fields = new ListGridField[fieldCount]; for (int i = 0; i < fields.length; i++) { fields[i]= new ListGridField("field" + (i+1), "Field " + (i+1)); } return fields; } private ListGridRecord[] createRecords(int recordCount, ListGridField[] fields) { ListGridRecord[] records = new ListGridRecord[recordCount]; for (int i =0; i < recordCount; i++) { ListGridRecord record = new ListGridRecord(); for (int j = 0; j < fields.length; j++) { record.setAttribute("field" + (j+1), "Row " + i + ", Value " + (j+1)); } records[i] = record; } return records; } private ListGridField[] getOrderedFields(ListGridField[] fields) { ListGridField[] orderedFields = new ListGridField[fields.length]; int initialFieldIndices[] = { 20, 5, 197, 59, 17, 120, 152, 91, 37, 101, 40, 9, 174, 29, 163 }; int oldIndex, newIndex; for (newIndex = 0; newIndex < initialFieldIndices.length; newIndex++) { int fieldIndex = initialFieldIndices[newIndex] - 1; orderedFields[newIndex] = fields[fieldIndex]; fields[fieldIndex] = null; } for (oldIndex = 0; oldIndex < fields.length; oldIndex++) { ListGridField field = fields[oldIndex]; if (field != null) { orderedFields[newIndex++] = field; field.setHidden(true); } } return orderedFields; } public class MyListGrid extends ListGrid { public MyListGrid() { super(); setID("pickableFields"); setCanEditTitles(true); setAutoFitData(Autofit.BOTH); setAutoFitMaxColumns(8); setAutoFitMaxRecords(20); setAutoFitFieldWidths(true); setUseAdvancedFieldPicker(true); setFieldPickerFieldProperties("frozen"); ListGridField[] fields = createFields(200); setFields(getOrderedFields(fields)); setData(createRecords(20, fields)); } protected String getBaseStyle(ListGridRecord record, int rowNum, int colNum) { return colNum % 2 == 0 ? "myEvenGridCell" : "myOddGridCell"; } } public void onModuleLoad() { MyListGrid grid = new MyListGrid(); Canvas canvas = new Canvas(); canvas.addChild(grid); canvas.draw(); grid.editFields(); canvas.draw(); } }