package com.sample.client.treegrid;

import java.util.ArrayList;
import java.util.List;

import com.smartgwt.client.widgets.tree.TreeNode;

public class TreeGridSampleDataprovider{


	static final String ID_FIELD 			= "ID_FIELD";
	static final String PARENT_ID_FIELD 	= "PARENT_ID_FIELD";
	static final String ROOT_ID_FIELD 		= "ROOT_ID_FIELD";
	static final String IS_FOLDER 			= "IS_FOLDER";

	// grid columns
	static final String COL_1 	= "COL_1";
	static final String COL_2	= "COL_2";
	static final String COL_3	= "COL_3"; 
	static final String	COL_4	= "COL_4";
	static final String COL_5 	= "COL_5";
	static final String COL_6	= "COL_6";
	static final String COL_7 	= "COL_7";
	static final String COL_8	= "COL_8";
	static final String COL_9	= "COL_9";
	static final String COL_10 	= "COL_10";
	static final String COL_11 	= "COL_11";
	static final String COL_12	= "COL_12";
	static final String COL_13 	= "COL_13";
	static final String COL_14	= "COL_14";
	static final String COL_15 	= "COL_15";
	static final String COL_16 	= "COL_16";
	static final String COL_17 	= "COL_17";
	static final String COL_18	= "COL_18";
	static final String COL_19	= "COL_19";
	static final String COL_20	= "COL_20";
	static final String COL_21 	= "COL_21";
	static final String COL_22	= "COL_22";

	List<TreeNode> listTreeNodes = new ArrayList<TreeNode>();

	private TreeNode addTreeRecord(String IDField, String parentID, String mtNo, String mtItm, String mtSItm, String source, String departure, String destination, String arrival, String contact, 
			String totalWgt, String dlvryMthd, String carrier, String voyage, String COL_REF_STR, String COL_PPCS_STR, 
			String balToPlan, String parentMT, String directShip, String status, String instructions) {
		TreeNode record = new TreeNode();

		record.setAttribute(ID_FIELD, IDField);
		record.setAttribute(PARENT_ID_FIELD, parentID);		
		if ( parentID.length() == 0  ) {
			record.setAttribute(IS_FOLDER, false);
			record.setAttribute(COL_1, mtNo);
		}
		else {
			record.setAttribute(IS_FOLDER, true);
			record.setAttribute(COL_1, "");
		}

		record.setAttribute(COL_15, contact);
		record.setAttribute(COL_17, dlvryMthd);

		record.setAttribute(COL_18, carrier);

		record.setAttribute(COL_20, voyage);

		record.setAttribute(COL_21, directShip);
		record.setAttribute(COL_22, instructions);



		// Pieces and weight
		record.setAttribute(COL_5, IDField);
		record.setAttribute(COL_6, parentID);
		record.setAttribute(COL_7, mtNo);
		record.setAttribute(COL_8, mtItm);
		record.setAttribute(COL_13, mtSItm);
		record.setAttribute(COL_14, IDField);
		record.setAttribute(COL_11, parentID);
		record.setAttribute(COL_12, mtNo);
		record.setAttribute(COL_9, mtItm);
		record.setAttribute(COL_10, mtNo);


		return (record);

	}

	public TreeNode[]  getRecords() {

		listTreeNodes.add(addTreeRecord("40000",    "",  "400",  "0", "0",  "Acme Export", "Jul 4", "", "", "John Smith", "10", "QC","(1060 Acme Truck)","","","","","","", "Open", "Call first"));
		listTreeNodes.add(addTreeRecord("40010", "40000", "400",  "1", "0",             "", "", "Port Storage", "Jul 7th", "Cart Helper", "10", "","","","","","","","", "", ""));

		listTreeNodes.add(addTreeRecord("40100",    "",  "401",  "0",  "0", "Port Storage", "Jul 8", "", "", "John Smith", "10", "QC","(1060 Acme Truck)","","","","","","", "Open", "Call first"));
		listTreeNodes.add(addTreeRecord("40110", "40100", "401",  "1", "0",             "", "", "NY Port", "Jul 20th", "Cart Herber",  "10", "","","","","","","","", "", ""));

		listTreeNodes.add(addTreeRecord("40200", 	  "", "402",  "0",  "0", "NY Port Storage", "Jul 21", "", "", "John Smith", "10", "QC","(1060 Acme Truck)","","","","","","", "Open", "Call first"));

		listTreeNodes.add(addTreeRecord("50000",    "",  "500",  "0", "0",  "Acme Export", "Jul 4", "", "", "John Smith", "10", "QC","(1060 Acme Truck)","","","","","","", "Open", "Call first"));
		listTreeNodes.add(addTreeRecord("50010", "50000", "500",  "1", "0",             "", "", "Port Storage", "Jul 7th", "Cart Helper",  "10", "","","","","","","","", "", ""));

		listTreeNodes.add(addTreeRecord("50100",    "",  "501",  "0",  "0", "Port Storage", "Jul 8", "", "", "John Smith", "10", "QC","(1060 Acme Truck)","","","","","","", "Open", "Call first"));
		listTreeNodes.add(addTreeRecord("50110", "50100", "501",  "1", "0",             "", "", "NY Port", "Jul 20th", "Cart Herber",  "10", "","","","","","","","", "", ""));


		listTreeNodes.add(addTreeRecord("50200", 	  "", "502",  "0",  "0", "NY Port Storage", "Jul 21", "", "", "John Smith", "10", "QC","(1060 Acme Truck)","","","","","","", "Open", "Call first"));
		listTreeNodes.add(addTreeRecord("50210",  "50200", "502",  "1", "0",             "", "", "CHI Wharehouse", "Jul 23", "Cart Helper", "10", "","","","","","","","", "", ""));
		listTreeNodes.add(addTreeRecord("50220",  "50200", "502",  "2", "0",             "", "", "StelcoCorp", "Jul 23", "Cart Helper", "10", "","","","","","","","", "", ""));


		listTreeNodes.add(addTreeRecord("60000",    "",  "600",  "0", "0",  "Acme Export", "Jul 4", "", "", "John Smith", "10", "QC","(1060 Acme Truck)","","","","","","", "Open", "Call first"));
		listTreeNodes.add(addTreeRecord("60010", "60000", "600",  "1", "0",             "", "", "Port Storage", "Jul 7th", "Cart Helper", "10", "","","","","","","","", "", ""));

		listTreeNodes.add(addTreeRecord("60100",    "",  "601",  "0",  "0", "Port Storage", "Jul 8", "", "", "John Smith", "10", "QC","(1060 Acme Truck)","","","","","","", "Open", "Call first"));
		listTreeNodes.add(addTreeRecord("60110", "60100", "601",  "1", "0",             "", "", "NY Port", "Jul 20th", "Cart Herber", "10", "","","","","","","","", "", ""));

		listTreeNodes.add(addTreeRecord("60200", 	  "", "602",  "0",  "0", "NY Port Storage", "Jul 21", "", "", "John Smith", "10", "QC","(1060 Acme Truck)","","","","","","", "Open", "Call first"));
		listTreeNodes.add(addTreeRecord("60210",  "60200", "602",  "1", "0",             "", "", "CHI Wharehouse", "Jul 23", "Cart Helper", "10", "","","","","","","","", "", ""));
		listTreeNodes.add(addTreeRecord("60220",  "60200", "602",  "2", "0",             "", "", "StelcoCorp", "Jul 23", "Cart Helper", "10", "","","","","","","","", "", ""));


		listTreeNodes.add(addTreeRecord("70000",    "",  "700",  "0", "0",  "Acme Export", "Jul 4", "", "", "John Smith", "10", "QC","(1060 Acme Truck)","","","","","","", "Open", "Call first"));
		listTreeNodes.add(addTreeRecord("70010", "70000", "700",  "1", "0",             "", "", "Port Storage", "Jul 7th", "Cart Helper", "10", "","","","","","","","", "", ""));			
		listTreeNodes.add(addTreeRecord("70100",    "",  "701",  "0",  "0", "Port Storage", "Jul 8", "", "", "John Smith", "10", "QC","(1060 Acme Truck)","","","","","","", "Open", "Call first"));
		listTreeNodes.add(addTreeRecord("70110", "70100", "701",  "1", "0",             "", "", "NY Port", "Jul 20th", "Cart Herber", "10", "","","","","","","","", "", ""));
		listTreeNodes.add(addTreeRecord("70200", 	  "", "702",  "0",  "0", "NY Port Storage", "Jul 21", "", "", "John Smith", "10", "QC","(1060 Acme Truck)","","","","","","", "Open", "Call first"));
		listTreeNodes.add(addTreeRecord("70210",  "70200",  "702",  "1", "0",             "", "", "CHI Wharehouse", "Jul 23", "Cart Helper", "10", "","","","","","","","", "", ""));
		listTreeNodes.add(addTreeRecord("70220",  "70200", "702",  "2", "0",             "", "", "StelcoCorp", "Jul 23", "Cart Helper", "10", "","","","","","","","", "", ""));

		return listTreeNodes.toArray(new TreeNode[listTreeNodes.size()]);
	}


	public TreeNode[]  getSubRecords() {
		List<TreeNode> listTreeNodes = new ArrayList<TreeNode>();
		listTreeNodes.add(addTreeRecord("40210",  "40200", "402",  "1", "0",             "", "", "CHI Wharehouse", "Jul 23", "Cart Helperrrrrrrrrrrrrrrrrrr", "10", "","","","","","","","", "", ""));				
		listTreeNodes.add(addTreeRecord("40220",  "40200", "402",  "2", "0",             "", "", "StelcoCorp", "Jul 23", "Cart Helperrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr", "10", "","","","","","","","", "", ""));
		listTreeNodes.add(addTreeRecord("40230",  "40200", "402",  "1", "0",             "", "", "CHI Wharehouse", "Jul 23", "Cart Helperrrrrrrrrrrrrrrrrrr", "10", "","","","","","","","", "", ""));				
		listTreeNodes.add(addTreeRecord("40240",  "40200", "402",  "2", "0",             "", "", "StelcoCorp", "Jul 23", "Cart Helperrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr", "10", "","","","","","","","", "", ""));

		return listTreeNodes.toArray(new TreeNode[listTreeNodes.size()]);
	}

}