Java tutorial
//This file is part of Moodle - http://moodle.org/ // //Moodle is free software: you can redistribute it and/or modify //it under the terms of the GNU General Public License as published by //the Free Software Foundation, either version 3 of the License, or //(at your option) any later version. // //Moodle 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 General Public License for more details. // //You should have received a copy of the GNU General Public License //along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * @package eMarking * @copyright 2013 Jorge Villaln <villalon@gmail.com> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ package cl.uai.client.toolbar.sortpages; import cl.uai.client.resources.Resources; import com.google.gwt.user.client.ui.AbsolutePanel; import com.google.gwt.user.client.ui.FlexTable; import com.google.gwt.user.client.ui.Widget; import com.allen_sauer.gwt.dnd.client.DragContext; import com.allen_sauer.gwt.dnd.client.PickupDragController; import com.allen_sauer.gwt.dnd.client.drop.BoundaryDropController; /** * Allows table rows to dragged by their handle. */ public final class FlexTableRowDragController extends PickupDragController { private FlexTable draggableTable; private int dragRow; public FlexTableRowDragController(AbsolutePanel boundaryPanel) { super(boundaryPanel, false); setBehaviorDragProxy(true); setBehaviorMultipleSelection(false); } @Override public void dragEnd() { super.dragEnd(); // cleanup draggableTable = null; } @Override public void setBehaviorDragProxy(boolean dragProxyEnabled) { if (!dragProxyEnabled) { throw new IllegalArgumentException(); } super.setBehaviorDragProxy(dragProxyEnabled); } @Override protected BoundaryDropController newBoundaryDropController(AbsolutePanel boundaryPanel, boolean allowDroppingOnBoundaryPanel) { if (allowDroppingOnBoundaryPanel) { throw new IllegalArgumentException(); } return super.newBoundaryDropController(boundaryPanel, allowDroppingOnBoundaryPanel); } @Override protected Widget newDragProxy(DragContext context) { FlexTable proxy; proxy = new FlexTable(); proxy.addStyleName(Resources.INSTANCE.css().sortpagestableproxy()); draggableTable = (FlexTable) context.draggable.getParent(); dragRow = getWidgetRow(context.draggable, draggableTable); FlexTableUtil.copyRow(draggableTable, proxy, dragRow, 0); return proxy; } FlexTable getDraggableTable() { return draggableTable; } int getDragRow() { return dragRow; } private int getWidgetRow(Widget widget, FlexTable table) { for (int row = 0; row < table.getRowCount(); row++) { for (int col = 0; col < table.getCellCount(row); col++) { Widget w = table.getWidget(row, col); if (w == widget) { return row; } } } throw new RuntimeException("Unable to determine widget row"); } }