package com.smartgwt.sample.showcase.client.dataintegration.java.transactions; import com.google.gwt.i18n.client.NumberFormat; import com.google.gwt.user.client.Timer; import com.smartgwt.client.types.ListGridEditEvent; import com.smartgwt.client.types.ListGridFieldType; import com.smartgwt.client.types.RowEndEditAction; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.IButton; import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.layout.Layout; import com.smartgwt.client.widgets.layout.VLayout; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.grid.CellFormatter; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.grid.ListGridRecord; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.rpc.RPCRequest; import com.smartgwt.client.rpc.RPCManager; import com.smartgwt.client.rpc.QueueSentCallback; import com.smartgwt.sample.showcase.client.PanelFactory; import com.smartgwt.sample.showcase.client.ShowcasePanel; public class GridMassUpdateSample implements EntryPoint { public void onModuleLoad() { Layout layout = new VLayout(15); layout.setAutoHeight(); DataSource countryDS = DataSource.get("countryDS"); final ListGrid countryGrid = new ListGrid(); countryGrid.setWidth(500); countryGrid.setHeight(224); countryGrid.setAlternateRecordStyles(true); countryGrid.setCellHeight(22); countryGrid.setDataSource(countryDS); ListGridField nameField = new ListGridField("countryName", "Country"); ListGridField continentField = new ListGridField("continent", "Continent"); ListGridField memberG8Field = new ListGridField("member_g8", "Member G8"); ListGridField populationField = new ListGridField("population", "Population"); populationField.setType(ListGridFieldType.INTEGER); populationField.setCellFormatter(new CellFormatter() { public String format(Object value, ListGridRecord record, int rowNum, int colNum) { if(value == null) { return null; } NumberFormat nf = NumberFormat.getFormat("0,000"); try { return nf.format(((Number) value).longValue()); } catch (Exception e) { return value.toString(); } } }); ListGridField independenceField = new ListGridField("independence", "Independence"); countryGrid.setFields(nameField,continentField, memberG8Field, populationField, independenceField); countryGrid.setAutoFetchData(true); countryGrid.setCanEdit(true); countryGrid.setModalEditing(true); countryGrid.setEditEvent(ListGridEditEvent.CLICK); countryGrid.setListEndEditAction(RowEndEditAction.NEXT); countryGrid.setAutoSaveEdits(false); layout.addMember(countryGrid); HLayout hLayout = new HLayout(15); IButton editButton = new IButton("Edit New"); editButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { countryGrid.startEditingNew(); } }); hLayout.addMember(editButton); IButton saveButton = new IButton("Save"); saveButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { countryGrid.saveAllEdits(); } }); hLayout.addMember(saveButton); IButton discardButton = new IButton("Discard"); discardButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { countryGrid.discardAllEdits(); } }); hLayout.addMember(discardButton); layout.addMember(hLayout); final ServerCountLabel serverCountLabel = new ServerCountLabel(); layout.addMember(serverCountLabel); RPCManager.setQueueSentCallback(new QueueSentCallback() { public void queueSent(RPCRequest[] requests) { serverCountLabel.incrementAndUpdate(requests); //flash the label serverCountLabel.setBackgroundColor("ffff77"); new Timer() { public void run() { serverCountLabel.setBackgroundColor("ffffff"); } }.schedule(500); } }); layout.draw(); } class ServerCountLabel extends Label { private int count = 0; ServerCountLabel() { setPadding(10); setWidth(300); setHeight(40); setBorder("1px solid grey"); setContents("
Number of server trips: 0
No queues sent
"); } public void incrementAndUpdate(RPCRequest[] requests) { count++; setContents("
Number of server trips: " + count + "
Last queue contained: " + requests.length + " request(s)
"); } } }