Package net.carchrae.smartgwt.client

Source Code of net.carchrae.smartgwt.client.Example

package net.carchrae.smartgwt.client;

import net.carchrae.smartgwt.client.datasource.DataSourceLoader;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.layout.VLayout;

public class Example implements EntryPoint {

  @Override
  public void onModuleLoad() {
    String className = "Sample";
    AsyncCallback<DataSource> callback = new AsyncCallback<DataSource>() {

      @Override
      public void onSuccess(DataSource dataSource) {
        showListGrid(dataSource);
      }

      @Override
      public void onFailure(Throwable caught) {
        SC.say("Failed to load datasource : " + caught.getMessage());
      }
    };
    DataSourceLoader.loadDataSource(className, callback);
  }

  protected void showListGrid(DataSource dataSource) {
    final ListGrid listGrid = new ListGrid();
    listGrid.setDataSource(dataSource);
    listGrid.setAutoFetchData(true);
    listGrid.setCanEdit(true);
    listGrid.setCanRemoveRecords(true);

    Button button = new Button("Add a New Record");
    button.setAutoFit(true);
    button.addClickHandler(new ClickHandler() {
      @Override
      public void onClick(ClickEvent event) {
        listGrid.startEditingNew();
      }
    });

    VLayout vLayout = new VLayout();
    vLayout.addMember(button);
    vLayout.addMember(listGrid);
    vLayout.setWidth100();
    vLayout.setHeight100();
    vLayout.show();
  }
}
TOP

Related Classes of net.carchrae.smartgwt.client.Example

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.