package com.hp.isomorphic.client.issues;

import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.types.ExpansionComponentPoolingMode;
import com.smartgwt.client.types.ExpansionMode;
import com.smartgwt.client.types.FetchMode;
import com.smartgwt.client.types.SelectionStyle;
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.grid.ListGridRecord;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;

public class EditHilitesDialogHasScrollbar extends VLayout{
	private ListGrid grid;
	
	public EditHilitesDialogHasScrollbar() {
		
		ListGridRecord[] recordList = GridData.createRecordList(10);
		DataSource ds = new ClientDataSource(recordList);
		
		grid = new ListGrid();
		grid.setDataSource(ds);
		grid.setAutoFetchData(true);
		grid.setDataFetchMode(FetchMode.LOCAL);
		grid.setShowAllRecords(true);
		grid.setExpansionMode(ExpansionMode.RELATED);
		grid.setExpansionComponentPoolingMode(ExpansionComponentPoolingMode.DESTROY);
		grid.setCanExpandMultipleRecords(false);
		grid.setCanExpandRecords(true);
		grid.setSelectionType(SelectionStyle.SINGLE);
		
		grid.setHiliteIcons(); /* Could this be the cause of the mysterious scroll bars? */
        
		addMember(grid);
		
		HLayout buttonBar = new HLayout();
		buttonBar.setAutoHeight();
		buttonBar.setAutoWidth();
		
		Button button = new Button("Edit Hilites");
		button.setWidth(150);
		button.setHeight(40);
		button.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				grid.editHilites();
			}
		});
	
		buttonBar.addMember(button);
		addMember(buttonBar);
		
		
	}

	@Override
	public void destroy() {
		if (grid != null) {
			DataSource dataSource = grid.getDataSource();
			if (dataSource != null) {
				dataSource.destroy();
			}
		}
		super.destroy();
	}
}
