/* * 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.widgets.IButton; import com.smartgwt.client.widgets.layout.VStack; import com.smartgwt.client.types.Alignment; import com.smartgwt.client.types.DragDataAction; import com.smartgwt.client.types.ListGridFieldType; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.layout.HStack; import com.smartgwt.client.widgets.TransferImgButton; import com.smartgwt.client.widgets.TransferImgButton.TransferImg; 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.ListGridField; import com.smartgwt.sample.showcase.client.data.CountrySampleData; import com.google.gwt.core.client.EntryPoint; public class TouchDragSample implements EntryPoint { private boolean hidden = false; public void onModuleLoad() { final DragHandlesGrid countryList1 = new DragHandlesGrid(); countryList1.setWidth(325); countryList1.setHeight(224); countryList1.setData(CountrySampleData.getRecords()); ListGridField countryCodeField1 = new ListGridField("countryCode", "Flag", 40); countryCodeField1.setAlign(Alignment.CENTER); countryCodeField1.setType(ListGridFieldType.IMAGE); countryCodeField1.setImageURLPrefix("flags/16/"); countryCodeField1.setImageURLSuffix(".png"); ListGridField nameField1 = new ListGridField("countryName", "Country"); ListGridField capitalField1 = new ListGridField("capital", "Capital"); countryList1.setFields(countryCodeField1, nameField1, capitalField1); final DragHandlesGrid countryList2 = new DragHandlesGrid(); countryList2.setWidth(225); countryList2.setHeight(224); ListGridField countryCodeField2 = new ListGridField("countryCode", "Flag", 40); countryCodeField2.setAlign(Alignment.CENTER); countryCodeField2.setType(ListGridFieldType.IMAGE); countryCodeField2.setImageURLPrefix("flags/16/"); countryCodeField2.setImageURLSuffix(".png"); ListGridField nameField2 = new ListGridField("countryName", "Country"); countryList2.setFields(countryCodeField2, nameField2); countryList2.setEmptyMessage("drop rows here"); VStack vStackButtons = new VStack(10); vStackButtons.setWidth(32); vStackButtons.setHeight(74); vStackButtons.setLayoutAlign(Alignment.CENTER); TransferImgButton rightImg = new TransferImgButton(new TransferImg("icons/32/arrow_right.png")); rightImg.setHeight(32); rightImg.setWidth(32); rightImg.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { countryList2.transferSelectedData(countryList1); } }); vStackButtons.addMember(rightImg); TransferImgButton leftImg = new TransferImgButton(new TransferImg("icons/32/arrow_left.png")); leftImg.setHeight(32); leftImg.setWidth(32); leftImg.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { countryList1.transferSelectedData(countryList2); } }); vStackButtons.addMember(leftImg); HStack hStack = new HStack(); hStack.setMembersMargin(10); hStack.setHeight(160); hStack.addMember(countryList1); hStack.addMember(vStackButtons); hStack.addMember(countryList2); final IButton button = new IButton(); button.setAutoFit(true); button.setTitle("Hide Drag Handles"); button.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { if (hidden) { countryList1.showDragHandles(); countryList2.showDragHandles(); button.setTitle("Hide Drag Handles"); } else { countryList1.hideDragHandles(); countryList2.hideDragHandles(); button.setTitle("Show Drag Handles"); } hidden = !hidden; } }); VStack vStack = new VStack(); vStack.setLayoutLeftMargin(20); vStack.setMembersMargin(20); vStack.addMember(hStack); vStack.addMember(button); vStack.draw(); } private class DragHandlesGrid extends ListGrid { public DragHandlesGrid() { setCanReorderRecords(true); setCanDragRecordsOut(true); setCanAcceptDroppedRecords(true); setShowInitialDragHandles(true); setDragDataAction(DragDataAction.MOVE); } } }