package com.dws.managemymanifest.client; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.event.shared.HandlerManager; import com.smartgwt.client.data.Criterion; import com.smartgwt.client.data.DSCallback; import com.smartgwt.client.data.DSRequest; import com.smartgwt.client.data.DSResponse; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.data.Record; import com.smartgwt.client.types.Alignment; import com.smartgwt.client.types.OperatorId; import com.smartgwt.client.types.SelectionAppearance; import com.smartgwt.client.types.SelectionStyle; import com.smartgwt.client.widgets.Window; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.fields.ButtonItem; import com.smartgwt.client.widgets.form.fields.DateItem; import com.smartgwt.client.widgets.form.fields.SelectItem; import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; import com.smartgwt.client.widgets.form.fields.events.ClickEvent; import com.smartgwt.client.widgets.form.fields.events.ClickHandler; 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; /** * Entry point classes define onModuleLoad(). */ public class TestBed implements EntryPoint { private HandlerManager eventBus; private VLayout main; final DataSource employeesDS = DataSource.get("Employees"); final DataSource manifestDS = DataSource.get("Manifest"); final DataSource projectsDS = DataSource.get("Projects"); public void onModuleLoad(){ final Window form = new Window(); form.setTitle("Add To Manifest"); form.setWidth(800); form.setHeight(400); form.setShowMinimizeButton(false); form.setShowCloseButton(true); form.setIsModal(true); form.setShowModalMask(true); form.setHeaderIcon("icons/16/person.png"); form.centerInPage(); final DynamicForm addUserForm = new DynamicForm(); addUserForm.setAutoFocus(true); addUserForm.setNumCols(4); addUserForm.setDataSource(manifestDS); addUserForm.setAddOperation("add_manifest"); addUserForm.setUseAllDataSourceFields(false); addUserForm.setPadding(0); final DateItem embD = new DateItem("EmbarkDate"); embD.setUseTextField(true); embD.setUseMask(true); embD.setRequired(true); final DateItem debD = new DateItem("DisembarkDate"); debD.setUseTextField(true); debD.setUseMask(true); debD.setRequired(true); ButtonItem newButton = new ButtonItem("addManifest"); newButton.setTitle("Add To Manifest"); newButton.setAlign(Alignment.CENTER); newButton.setWidth(150); newButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { ListGridRecord [] records= employeeName.getSelectedRecords(); for(int i = 0; i < records.length; i++) { System.out.println(records[i].getAttribute("FirstName")); } } }); DynamicForm projectForm = new DynamicForm(); projectForm.setDataSource(projectsDS); SelectItem project = new SelectItem("ProjectId"); project.setDisplayField("ProjectName"); project.setValueField("ProjectId"); project.addChangedHandler(new ChangedHandler(){ public void onChanged(ChangedEvent event) { int projectId = ((Integer)event.getValue()).intValue(); projectsDS.fetchData(new Criterion("ProjectId", OperatorId.EQUALS, projectId), new DSCallback(){ @Override public void execute(DSResponse response, Object rawData, DSRequest request) { // TODO Auto-generated method stub Record p = response.getData()[0]; System.out.println(p.getAttributeAsDate("StartDate")); DateItem embark = new DateItem("EmbarkDate"); embark.setUseTextField(true); embark.setUseMask(true); embark.setDefaultChooserDate(p.getAttributeAsDate("StartDate")); addUserForm.getItem("EmbarkDate").setEditorType(embark); DateItem debark = new DateItem("EmbarkDate"); debark.setUseTextField(true); debark.setUseMask(true); debark.setDefaultChooserDate(p.getAttributeAsDate("StartDate")); addUserForm.getItem("EmbarkDate").setEditorType(debark); } }); } }); projectForm.setFields(project); addUserForm.setFields(embD, debD, newButton); VLayout formLayout = new VLayout(); formLayout.setAlign(Alignment.CENTER); formLayout.addMember(projectForm); formLayout.addMember(addUserForm); form.addItem(formLayout); form.draw(); } }