package com.smartgwt.sample.client;
/*
 * 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.google.gwt.core.client.EntryPoint;
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.widgets.layout.VLayout;

public class DeleteRecordExample implements EntryPoint {

    public void onModuleLoad() {
    	
    	VLayout layout = new VLayout(15);
    	layout.setHeight(1200);
        final ListGrid countryGrid = new ListGrid();
        countryGrid.setWidth(500);
        countryGrid.setHeight(224);
        countryGrid.setShowAllRecords(true);
        countryGrid.setCanRemoveRecords(true);
        countryGrid.setDeferRemoval(true);
        ListGridField countryCodeField = new ListGridField("countryCode", "Code");
        ListGridField nameField = new ListGridField("countryName", "Country");

        countryGrid.setFields(new ListGridField[] {countryCodeField, nameField});
        countryGrid.setData(createRecords());

        layout.addMember(countryGrid);
        layout.draw();
    }
    
    private MyRecord[] createRecords()
    {
    	return new MyRecord[]{
    		new MyRecord("USA", "AMERICA"),
    		new MyRecord("UK", "UNITED KINGDOM"),
    		new MyRecord("GM", "GERMANY"),
    		new MyRecord("SP", "SPAIN"),
    		new MyRecord("FR", "FRANCE")
    	};
    }
    
    
    class MyRecord extends ListGridRecord{
    	
    	public MyRecord(String code, String name)
    	{
    		setCountryCode(code);
    		setCountryName(name);
    	}

		private void setCountryName(String name)
		{
			 setAttribute("countryName", name);
		}

		private void setCountryCode(String code) 
		{
			setAttribute("countryCode", code);   
		}
    	
	    public String getCountryName() 
	    {   
	        return getAttributeAsString("countryName");   
	    }   
	  
	    public String getCountryCode() 
	    {   
	        return getAttributeAsString("countryCode");   
	    }  
    }

}
 
