/* * 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.smartgwt.client.data.Criteria; import com.smartgwt.client.data.DataSource; import com.smartgwt.client.types.DragDataAction; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.TransferImgButton; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.form.DynamicForm; 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.grid.ListGrid; import com.smartgwt.client.widgets.grid.ListGridField; import com.smartgwt.client.widgets.layout.HStack; import com.smartgwt.client.widgets.layout.LayoutSpacer; import com.smartgwt.client.widgets.layout.VStack; import com.smartgwt.sample.showcase.client.data.EmployeeXmlDS; import com.smartgwt.sample.showcase.client.data.TeamMembersXmlDS; import com.google.gwt.core.client.EntryPoint; public class GridDataBoundDragDropSample implements EntryPoint { @Override protected boolean isTopIntro() { return true; } public void onModuleLoad() { String[] projects = new String[] { "New Costing System", "Warehousing Improvements", "Evaluate AJAX Frameworks", "Upgrade Postgres", "Online Billing" }; DataSource employeesDS = EmployeeXmlDS.getInstance(); final ListGrid employeesGrid = new ListGrid(); employeesGrid.setWidth(320); employeesGrid.setHeight(224); employeesGrid.setDataSource(employeesDS); employeesGrid.setCanDragRecordsOut(true); employeesGrid.setDragDataAction(DragDataAction.COPY); employeesGrid.setAutoFetchData(false); ListGridField employeeIdField = new ListGridField("EmployeeId"); employeeIdField.setWidth("35%"); ListGridField nameField = new ListGridField("Name"); employeesGrid.setFields(employeeIdField, nameField); DataSource teamMembersDS = TeamMembersXmlDS.getInstance(); final ListGrid projectGrid = new ListGrid(); projectGrid.setWidth(400); projectGrid.setHeight(264); projectGrid.setDataSource(teamMembersDS); projectGrid.setCanAcceptDroppedRecords(true); projectGrid.setCanRemoveRecords(true); projectGrid.setAutoFetchData(false); projectGrid.setPreventDuplicates(true); ListGridField employeeIdField2 = new ListGridField("employeeId"); employeeIdField2.setWidth("30%"); ListGridField employeeNameField2 = new ListGridField("employeeName"); employeeNameField2.setWidth("35%"); ListGridField projectCodeField2 = new ListGridField("projectCode"); projectGrid.setFields(employeeIdField2, employeeNameField2, projectCodeField2); HStack hStack = new HStack(10); hStack.setHeight(160); VStack vStack = new VStack(); LayoutSpacer spacer = new LayoutSpacer(); spacer.setHeight(30); vStack.addMember(spacer); vStack.addMember(employeesGrid); hStack.addMember(vStack); TransferImgButton arrowImg = new TransferImgButton(TransferImgButton.RIGHT); arrowImg.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { projectGrid.transferSelectedData(employeesGrid); } }); hStack.addMember(arrowImg); VStack vStack2 = new VStack(); final DynamicForm projectSelectorForm = new DynamicForm(); projectSelectorForm.setWidth(300); projectSelectorForm.setHeight(30); SelectItem selectItem = new SelectItem("projectCode", "Team for Project"); selectItem.setDefaultValue(projects[0]); selectItem.setValueMap(projects); selectItem.addChangedHandler(new ChangedHandler() { public void onChanged(ChangedEvent event) { Criteria criteria = projectSelectorForm.getValuesAsCriteria(); projectGrid.fetchData(criteria); } }); projectSelectorForm.setFields(selectItem); vStack2.addMember(projectSelectorForm); vStack2.addMember(projectGrid); hStack.addMember(vStack2); projectGrid.fetchData(projectSelectorForm.getValuesAsCriteria()); employeesGrid.fetchData(); hStack.draw(); } }