﻿public class Service extends SimpleModule {	
	@Override
	public Canvas getRootCanvas() {
		Canvas canvas = new Canvas();
		
		final DataSource serviceListGridDS = ServiceDS.getInstance("ListGrid"); 
		
		final DataSource dynamicFormDS = ServiceDS.getInstance("DynamicForm");
		
		// layout
		VLayout mainLayout = new VLayout(); 
		
		// button    
    final IButton queryButton = new IButton("Query");
        
    // service form
    final DynamicForm serviceForm = new DynamicForm();
    serviceForm.setDataSource(dynamicFormDS);
                    
    SelectItem product = new SelectItem("Product");
    product.setAutoFetchData(true);
  
    serviceForm.setFields(product);
    //-----------------------------
    
    // service list grid
    final ListGrid serviceListGrid = new ListGrid(); 
    serviceListGrid.setAutoFetchData(true);
    serviceListGrid.setAutoFetchAsFilter(true);
                 
    ListGridField productField = new ListGridField("Product");
    
    serviceListGrid.setFields(productField);
    //--------------------------------------
                            
    // handler       
    queryButton.addClickHandler(new ClickHandler() {
    	@Override
			public void onClick(ClickEvent event) {	
    		serviceListGrid.fetchData(serviceForm.getValuesAsCriteria());
			}
    });
    //-
         
    mainLayout.addMember(queryButton);
    mainLayout.addMember(serviceForm);
    mainLayout.addMember(serviceListGrid);
    
    canvas.addChild(mainLayout);
        
		return canvas;
	}
}

