diff options
author | Denis <denis@vaadin.com> | 2016-12-15 12:40:54 +0200 |
---|---|---|
committer | Pekka Hyvönen <pekka@vaadin.com> | 2016-12-15 12:40:54 +0200 |
commit | 809a486c60a680d31308ffd078e6f8036252a990 (patch) | |
tree | 75a3d7481a12d042606316fad190130ada181b62 /client | |
parent | 616e1f8ce5e544693268f54a2ac4cec2158d4a19 (diff) | |
download | vaadin-framework-809a486c60a680d31308ffd078e6f8036252a990.tar.gz vaadin-framework-809a486c60a680d31308ffd078e6f8036252a990.zip |
Migrate 7.7.5 branch patches to v8. (#7969)
* Prevent adding several scrollbar handlers (#19189).
Change-Id: Ib0cc6c6835aab6d263f153362a328bcf2be7bc5c
* Prevent adding several scrollbar handlers (#19189).
* Keep expand ratio for last row/column when reducing grid layout size (#20297)
Change-Id: Iff53a803596f4fc1eae8e4bfa307b9c1f4df961a
* Fixed drag and drop failure when message dragged from email client (#20451)
When dragging message form email client on Windows, item.webkitGetAsEntry()
might return null creating NPE on the client side. Added additional checks
for this situation.
Change-Id: I569f7e6d0d7b137f24be53d1fbce384695ae8c73
* Change expected pre-release version number pattern in publish report
Change-Id: Icdacecc490d2490ea9e262f5c5736c1dece2a89d
* Mark TextField/TextArea as busy when a text change event is pending
(#20469)
Change-Id: I404985ae0be1e7dc65171b610032f8649e700f50
# Conflicts:
# client/src/main/java/com/vaadin/client/ui/VTextField.java
# uitest/src/main/java/com/vaadin/tests/components/textfield/TextChangeEvents.java
* Fixed touch scrolling issue in Surface and WP devices (#18737)
Fixed by using pointerevents instead of touchevents when the browser is
IE11,
or Edge. Also added touch-action: none; css rules into escalator.css to
prevent
default touch behaviour on IE11 and Edge. Does not affect IE8 to IE10
browsers,
behaviour on those will stay the same as before the fix.
No new unit tests since we do not have automatic touch testing
possibilities yet.
Please test manually with Surface: IE11 and Edge, use for example
uitest:
com.vaadin.tests.components.grid.basics.GridBasicsomponents.grid.basics.GridBasics
Change-Id: Iddbf1852e6ffafc855f749d6f4ebb235ed0f5703
* Add lazy/simple resize mode to Grid (#20108)
Change-Id: I47427efc28c350382dba8c1f50fd332a3f4585e4
# Conflicts:
# client/src/main/java/com/vaadin/client/connectors/GridConnector.java
# client/src/main/java/com/vaadin/client/widgets/Grid.java
# server/src/main/java/com/vaadin/ui/Grid.java
# shared/src/main/java/com/vaadin/shared/ui/grid/GridState.java
# themes/src/main/themes/VAADIN/themes/base/grid/grid.scss
# uitest/src/main/java/com/vaadin/tests/components/grid/basicfeatures/GridBasicFeatures.java
Change-Id: Ieca56121875198ed559a41c143b28926e2695433
* Fix NPE in case some items don't contain all properties of Grid.
This could occur in when parent is a different entity than its children
in hierarchical data.
Change-Id: Icd53b5b5e5544a3680d0cd99702ab78224b2dc08
# Conflicts:
# server/src/main/java/com/vaadin/data/fieldgroup/FieldGroup.java
# server/src/main/java/com/vaadin/ui/Grid.java
* Mark TextField/TextArea as busy when a text change event is pending
(#20469)
Change-Id: I404985ae0be1e7dc65171b610032f8649e700f50
# Conflicts:
# client/src/main/java/com/vaadin/client/ui/VTextField.java
# uitest/src/test/java/com/vaadin/tests/components/textfield/TextChangeEventsTest.java
* Add lazy/simple resize mode to Grid (#20108)
Change-Id: I47427efc28c350382dba8c1f50fd332a3f4585e4
* Removed V8 VTextField unused import, forgotten @RunLocally.
* Don't rely on selenium "sendKeys" behavior.
* Revert "Change expected pre-release version number pattern in publish report"
This reverts commit 8df27b952dddb691aead6a633c5b3724c98bf343.
* Migrate TextField/TextArea patch from 7.7 to master (modern components)
Mark TextField/TextArea as busy when a text change event is pending
(#20469)
Change-Id: I404985ae0be1e7dc65171b610032f8649e700f50
Diffstat (limited to 'client')
7 files changed, 346 insertions, 78 deletions
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java index 7d906fc4af..828c795777 100644 --- a/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java +++ b/client/src/main/java/com/vaadin/client/connectors/grid/GridConnector.java @@ -53,9 +53,7 @@ import com.vaadin.client.widget.grid.sort.SortEvent; import com.vaadin.client.widget.grid.sort.SortOrder; import com.vaadin.client.widgets.Grid; import com.vaadin.client.widgets.Grid.Column; -import com.vaadin.client.widgets.Grid.FooterCell; import com.vaadin.client.widgets.Grid.FooterRow; -import com.vaadin.client.widgets.Grid.HeaderCell; import com.vaadin.client.widgets.Grid.HeaderRow; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.data.sort.SortDirection; @@ -212,6 +210,11 @@ public class GridConnector extends AbstractListingConnector .map(this::getColumn).toArray(size -> new Column[size])); } + @OnStateChange("columnResizeMode") + void updateColumnResizeMode() { + getWidget().setColumnResizeMode(getState().columnResizeMode); + } + /** * Updates the grid header section on state change. */ @@ -235,18 +238,21 @@ public class GridConnector extends AbstractListingConnector } } - private void updateStaticRow(RowState rowState, Grid.StaticSection.StaticRow row) { + private void updateStaticRow(RowState rowState, + Grid.StaticSection.StaticRow row) { rowState.cells.forEach((columnId, cellState) -> { updateStaticCellFromState(row.getCell(getColumn(columnId)), cellState); }); - for (Map.Entry<CellState, Set<String>> cellGroupEntry : rowState.cellGroups.entrySet()) { + for (Map.Entry<CellState, Set<String>> cellGroupEntry : rowState.cellGroups + .entrySet()) { Set<String> group = cellGroupEntry.getValue(); - Grid.Column<?, ?>[] columns = - group.stream().map(idToColumn::get).toArray(size->new Grid.Column<?, ?>[size]); + Grid.Column<?, ?>[] columns = group.stream().map(idToColumn::get) + .toArray(size -> new Grid.Column<?, ?>[size]); // Set state to be the same as first in group. - updateStaticCellFromState(row.join(columns), cellGroupEntry.getKey()); + updateStaticCellFromState(row.join(columns), + cellGroupEntry.getKey()); } } diff --git a/client/src/main/java/com/vaadin/client/ui/VTextField.java b/client/src/main/java/com/vaadin/client/ui/VTextField.java index 1eb499505a..1ed84ab274 100644 --- a/client/src/main/java/com/vaadin/client/ui/VTextField.java +++ b/client/src/main/java/com/vaadin/client/ui/VTextField.java @@ -72,4 +72,5 @@ public class VTextField extends TextBoxBase public void onFocus(FocusEvent event) { addStyleDependentName(CLASSNAME_FOCUS); } + } diff --git a/client/src/main/java/com/vaadin/client/ui/dd/DragHandle.java b/client/src/main/java/com/vaadin/client/ui/dd/DragHandle.java index b800c5e53b..c5a9475d39 100644 --- a/client/src/main/java/com/vaadin/client/ui/dd/DragHandle.java +++ b/client/src/main/java/com/vaadin/client/ui/dd/DragHandle.java @@ -37,14 +37,14 @@ import com.vaadin.client.ui.dd.DragAndDropHandler.DragAndDropCallback; public class DragHandle { /** - * Callback interface for the DragHandle event life cycle + * Callback interface for the DragHandle event life cycle. */ public interface DragHandleCallback { /** - * Called when dragging starts + * Called when dragging starts. */ - public void onStart(); + void onStart(); /** * Called when the drag handle has moved. @@ -54,18 +54,18 @@ public class DragHandle { * @param deltaY * change in Y direction since start */ - public void onUpdate(double deltaX, double deltaY); + void onUpdate(double deltaX, double deltaY); /** * Called when the drag operation has been cancelled (usually by - * pressing ESC) + * pressing ESC). */ - public void onCancel(); + void onCancel(); /** - * Called when the drag operation completes successfully + * Called when the drag operation completes successfully. */ - public void onComplete(); + void onComplete(); } @@ -87,6 +87,20 @@ public class DragHandle { * later) both to provide the "-dragged" style and to make sure * that the drag handle can be properly styled (it's otherwise * invisible) + */ + public DragHandle(String baseName) { + this(baseName, null); + } + + /** + * Creates a new DragHandle. + * + * @param baseName + * CSS style name to use for this DragHandle element. This + * parameter is supplied to the constructor (rather than added + * later) both to provide the "-dragged" style and to make sure + * that the drag handle can be properly styled (it's otherwise + * invisible) * @param callback * Callback object allows hooking up the drag handle to the rest * of the program logic @@ -106,22 +120,28 @@ public class DragHandle { @Override public void onDrop() { removeDraggingStyle(); - userCallback.onComplete(); + if (userCallback != null) { + userCallback.onComplete(); + } } @Override public void onDragUpdate(Event e) { - double dx = WidgetUtil.getTouchOrMouseClientX(e) - startX; - double dy = WidgetUtil.getTouchOrMouseClientY(e) - startY; - userCallback.onUpdate(dx, dy); + if (userCallback != null) { + double dx = WidgetUtil.getTouchOrMouseClientX(e) - startX; + double dy = WidgetUtil.getTouchOrMouseClientY(e) - startY; + userCallback.onUpdate(dx, dy); + } } @Override public boolean onDragStart(Event e) { addDraggingStyle(); - startX = WidgetUtil.getTouchOrMouseClientX(e); - startY = WidgetUtil.getTouchOrMouseClientY(e); - userCallback.onStart(); + if (userCallback != null) { + startX = WidgetUtil.getTouchOrMouseClientX(e); + startY = WidgetUtil.getTouchOrMouseClientY(e); + userCallback.onStart(); + } return true; } @@ -133,7 +153,9 @@ public class DragHandle { @Override public void onDragCancel() { removeDraggingStyle(); - userCallback.onCancel(); + if (userCallback != null) { + userCallback.onCancel(); + } } private void addDraggingStyle() { @@ -157,6 +179,18 @@ public class DragHandle { } /** + * Sets the user-facing drag handle callback method. This allows code using + * the DragHandle to react to the situations where a drag handle first + * touched, when it's moved and when it's released. + * + * @param dragHandleCallback + * the callback object to use (can be null) + */ + public void setCallback(DragHandleCallback dragHandleCallback) { + userCallback = dragHandleCallback; + } + + /** * Returns the current parent element for this drag handle. May be null. * * @return an Element or null diff --git a/client/src/main/java/com/vaadin/client/ui/dd/VHtml5DragEvent.java b/client/src/main/java/com/vaadin/client/ui/dd/VHtml5DragEvent.java index 581d9263ac..830f668a00 100644 --- a/client/src/main/java/com/vaadin/client/ui/dd/VHtml5DragEvent.java +++ b/client/src/main/java/com/vaadin/client/ui/dd/VHtml5DragEvent.java @@ -90,8 +90,11 @@ public class VHtml5DragEvent extends NativeEvent { // Chrome >= v21 and Opera >= v? if (this.dataTransfer.items) { var item = this.dataTransfer.items[fileIndex]; - if (item.webkitGetAsEntry) { - return item.webkitGetAsEntry().isFile; + if (typeof item.webkitGetAsEntry == "function") { + var entry = item.webkitGetAsEntry(); + if (typeof entry !== "undefined" && entry !== null) { + return entry.isFile; + } } } diff --git a/client/src/main/java/com/vaadin/client/widget/escalator/ScrollbarBundle.java b/client/src/main/java/com/vaadin/client/widget/escalator/ScrollbarBundle.java index 2b615ebdb7..ed8d3cd57b 100644 --- a/client/src/main/java/com/vaadin/client/widget/escalator/ScrollbarBundle.java +++ b/client/src/main/java/com/vaadin/client/widget/escalator/ScrollbarBundle.java @@ -436,6 +436,9 @@ public abstract class ScrollbarBundle implements DeferredWorker { boolean offsetSizeBecomesGreaterThanScrollSize = showsScrollHandle() && newOffsetSizeIsGreaterThanScrollSize; if (offsetSizeBecomesGreaterThanScrollSize && getScrollPos() != 0) { + if (offsetSizeTemporaryScrollHandler != null) { + offsetSizeTemporaryScrollHandler.removeHandler(); + } // must be a field because Java insists. offsetSizeTemporaryScrollHandler = addScrollHandler( new ScrollHandler() { @@ -661,6 +664,9 @@ public abstract class ScrollbarBundle implements DeferredWorker { */ boolean delayedSizeSet = !BrowserInfo.get().isFirefox(); if (delayedSizeSet) { + if (scrollSizeTemporaryScrollHandler != null) { + scrollSizeTemporaryScrollHandler.removeHandler(); + } scrollSizeTemporaryScrollHandler = addScrollHandler( new ScrollHandler() { @Override diff --git a/client/src/main/java/com/vaadin/client/widgets/Escalator.java b/client/src/main/java/com/vaadin/client/widgets/Escalator.java index e3e0dfa0e4..e3953b436a 100644 --- a/client/src/main/java/com/vaadin/client/widgets/Escalator.java +++ b/client/src/main/java/com/vaadin/client/widgets/Escalator.java @@ -307,6 +307,8 @@ public class Escalator extends Widget static class JsniUtil { public static class TouchHandlerBundle { + public static final String POINTER_EVENT_TYPE_TOUCH = "touch"; + /** * A <a href= * "http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsOverlay.html" @@ -339,6 +341,11 @@ public class Escalator extends Widget /*-{ return this.targetTouches[0].pageY; }-*/; + + public native String getPointerType() + /*-{ + return this.pointerType; + }-*/; } private final Escalator escalator; @@ -456,6 +463,15 @@ public class Escalator extends Widget } int pagePosition(CustomTouchEvent event) { + // Use native event's screen x and y for IE11 and Edge + // since there is no touches for these browsers (#18737) + if (isCurrentBrowserIE11OrEdge()) { + return vertical + ? event.getNativeEvent().getClientY() + + Window.getScrollTop() + : event.getNativeEvent().getClientX() + + Window.getScrollLeft(); + } JsArray<Touch> a = event.getNativeEvent().getTouches(); return vertical ? a.get(0).getPageY() : a.get(0).getPageX(); } @@ -495,7 +511,7 @@ public class Escalator extends Widget }; public void touchStart(final CustomTouchEvent event) { - if (event.getNativeEvent().getTouches().length() == 1) { + if (allowTouch(event)) { if (yMov == null) { yMov = new Movement(true); xMov = new Movement(false); @@ -543,6 +559,18 @@ public class Escalator extends Widget } } + // Allow touchStart for IE11 and Edge even though there is no touch + // (#18737), + // otherwise allow touch only if there is a single touch in the + // event + private boolean allowTouch(final TouchHandlerBundle.CustomTouchEvent event) { + if (isCurrentBrowserIE11OrEdge()) { + return (POINTER_EVENT_TYPE_TOUCH.equals(event.getPointerType())); + } else { + return (event.getNativeEvent().getTouches().length() == 1); + } + } + private double easingInOutCos(double val, double max) { return 0.5 - 0.5 * Math.cos(Math.PI * Math.signum(val) * Math.min(Math.abs(val), max) / max); @@ -881,7 +909,7 @@ public class Escalator extends Widget public native void detachScrollListener(Element element) /* - * Attaching events with JSNI instead of the GWT event mechanism because + * Detaching events with JSNI instead of the GWT event mechanism because * GWT didn't provide enough details in events, or triggering the event * handlers with GWT bindings was unsuccessful. Maybe, with more time * and skill, it could be done with better success. JavaScript overlay @@ -958,6 +986,50 @@ public class Escalator extends Widget element.removeEventListener("touchcancel", this.@com.vaadin.client.widgets.JsniWorkaround::touchEndFunction); }-*/; + /** + * Using pointerdown, pointermove, pointerup, and pointercancel for IE11 and Edge instead of + * touch* listeners (#18737) + * + * @param element + */ + public native void attachPointerEventListeners(Element element) + /* + * Attaching events with JSNI instead of the GWT event mechanism because + * GWT didn't provide enough details in events, or triggering the event + * handlers with GWT bindings was unsuccessful. Maybe, with more time + * and skill, it could be done with better success. JavaScript overlay + * types might work. This might also get rid of the JsniWorkaround + * class. + */ + /*-{ + element.addEventListener("pointerdown", this.@com.vaadin.client.widgets.JsniWorkaround::touchStartFunction); + element.addEventListener("pointermove", this.@com.vaadin.client.widgets.JsniWorkaround::touchMoveFunction); + element.addEventListener("pointerup", this.@com.vaadin.client.widgets.JsniWorkaround::touchEndFunction); + element.addEventListener("pointercancel", this.@com.vaadin.client.widgets.JsniWorkaround::touchEndFunction); + }-*/; + + /** + * Using pointerdown, pointermove, pointerup, and pointercancel for IE11 and Edge instead of + * touch* listeners (#18737) + * + * @param element + */ + public native void detachPointerEventListeners(Element element) + /* + * Detaching events with JSNI instead of the GWT event mechanism because + * GWT didn't provide enough details in events, or triggering the event + * handlers with GWT bindings was unsuccessful. Maybe, with more time + * and skill, it could be done with better success. JavaScript overlay + * types might work. This might also get rid of the JsniWorkaround + * class. + */ + /*-{ + element.removeEventListener("pointerdown", this.@com.vaadin.client.widgets.JsniWorkaround::touchStartFunction); + element.removeEventListener("pointermove", this.@com.vaadin.client.widgets.JsniWorkaround::touchMoveFunction); + element.removeEventListener("pointerup", this.@com.vaadin.client.widgets.JsniWorkaround::touchEndFunction); + element.removeEventListener("pointercancel", this.@com.vaadin.client.widgets.JsniWorkaround::touchEndFunction); + }-*/; + public void scrollToColumn(final int columnIndex, final ScrollDestination destination, final int padding) { assert columnIndex >= columnConfiguration.frozenColumns : "Can't scroll to a frozen column"; @@ -5717,7 +5789,13 @@ public class Escalator extends Widget scroller.attachScrollListener(verticalScrollbar.getElement()); scroller.attachScrollListener(horizontalScrollbar.getElement()); scroller.attachMousewheelListener(getElement()); - scroller.attachTouchListeners(getElement()); + + if (isCurrentBrowserIE11OrEdge()) { + // Touch listeners doesn't work for IE11 and Edge (#18737) + scroller.attachPointerEventListeners(getElement()); + } else { + scroller.attachTouchListeners(getElement()); + } } @Override @@ -5726,7 +5804,13 @@ public class Escalator extends Widget scroller.detachScrollListener(verticalScrollbar.getElement()); scroller.detachScrollListener(horizontalScrollbar.getElement()); scroller.detachMousewheelListener(getElement()); - scroller.detachTouchListeners(getElement()); + + if (isCurrentBrowserIE11OrEdge()) { + // Touch listeners doesn't work for IE11 and Edge (#18737) + scroller.detachPointerEventListeners(getElement()); + } else { + scroller.detachTouchListeners(getElement()); + } /* * We can call paintRemoveRows here, because static ranges are simple to @@ -6772,4 +6856,12 @@ public class Escalator extends Widget double getMinCellWidth(int colIndex) { return columnConfiguration.getMinCellWidth(colIndex); } + + /** + * Internal method for checking whether the browser is IE11 or Edge + * @return true only if the current browser is IE11, or Edge + */ + private static boolean isCurrentBrowserIE11OrEdge() { + return BrowserInfo.get().isIE11() || BrowserInfo.get().isEdge(); + } } diff --git a/client/src/main/java/com/vaadin/client/widgets/Grid.java b/client/src/main/java/com/vaadin/client/widgets/Grid.java index 368ad8693b..1ffda08ef7 100644 --- a/client/src/main/java/com/vaadin/client/widgets/Grid.java +++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java @@ -37,6 +37,7 @@ import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.core.shared.GWT; import com.google.gwt.dom.client.BrowserEvents; import com.google.gwt.dom.client.DivElement; +import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.EventTarget; import com.google.gwt.dom.client.NativeEvent; @@ -174,6 +175,7 @@ import com.vaadin.client.widgets.Grid.StaticSection.StaticRow; import com.vaadin.shared.Range; import com.vaadin.shared.Registration; import com.vaadin.shared.data.sort.SortDirection; +import com.vaadin.shared.ui.grid.ColumnResizeMode; import com.vaadin.shared.ui.grid.GridConstants; import com.vaadin.shared.ui.grid.GridConstants.Section; import com.vaadin.shared.ui.grid.GridStaticCellType; @@ -4140,6 +4142,8 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, private AutoScroller autoScroller = new AutoScroller(this); + private ColumnResizeMode columnResizeMode = ColumnResizeMode.ANIMATED; + private DragAndDropHandler.DragAndDropCallback headerCellDndCallback = new DragAndDropCallback() { private final AutoScrollerCallback autoScrollerCallback = new AutoScrollerCallback() { @@ -5684,63 +5688,164 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, && staticRow instanceof HeaderRow && ((HeaderRow) staticRow).isDefault()) { + final DivElement resizeElement = Document.get() + .createDivElement(); + resizeElement.addClassName(getStylePrimaryName() + + "-column-resize-simple-indicator"); + final int column = cell.getColumn(); - DragHandle dragger = new DragHandle( - getStylePrimaryName() + "-column-resize-handle", - new DragHandleCallback() { - - private Column<?, T> col = getVisibleColumn( - column); - private double initialWidth = 0; - private double minCellWidth; - - @Override - public void onUpdate(double deltaX, - double deltaY) { - col.setWidth(Math.max(minCellWidth, - initialWidth + deltaX)); - } + final DragHandle dragger = new DragHandle( + getStylePrimaryName() + "-column-resize-handle"); + dragger.addTo(td); - @Override - public void onStart() { - initialWidth = col.getWidthActual(); - - minCellWidth = escalator.getMinCellWidth( - getVisibleColumns().indexOf(col)); - for (Column<?, T> c : getVisibleColumns()) { - if (selectionColumn == c) { - // Don't modify selection column. - continue; - } - - if (c.getWidth() < 0) { - c.setWidth(c.getWidthActual()); - fireEvent( - new ColumnResizeEvent<>(c)); - } - } + // Common functionality for drag handle callback + // implementations + abstract class AbstractDHCallback + implements DragHandleCallback { + protected Column<?, T> col = getVisibleColumn(column); + protected double initialWidth = 0; + protected double minCellWidth; + protected double width; + + protected void dragStarted() { + initialWidth = col.getWidthActual(); + width = initialWidth; + + minCellWidth = escalator.getMinCellWidth( + getVisibleColumns().indexOf(col)); + for (Column<?, T> c : getVisibleColumns()) { + if (selectionColumn == c) { + // Don't modify selection column. + continue; + } - WidgetUtil.setTextSelectionEnabled( - getElement(), false); + if (c.getWidth() < 0) { + c.setWidth(c.getWidthActual()); + fireEvent(new ColumnResizeEvent<>(c)); } + } - @Override - public void onComplete() { - fireEvent(new ColumnResizeEvent<>(col)); + WidgetUtil.setTextSelectionEnabled(getElement(), + false); + } - WidgetUtil.setTextSelectionEnabled( - getElement(), true); - } + protected void dragEnded() { + WidgetUtil.setTextSelectionEnabled(getElement(), + true); + } + } - @Override - public void onCancel() { - col.setWidth(initialWidth); + final DragHandleCallback simpleResizeMode = new AbstractDHCallback() { + @Override + protected void dragEnded() { + super.dragEnded(); + dragger.getElement().removeChild(resizeElement); + } - WidgetUtil.setTextSelectionEnabled( - getElement(), true); - } - }); - dragger.addTo(td); + @Override + public void onStart() { + dragStarted(); + dragger.getElement().appendChild(resizeElement); + resizeElement.getStyle().setLeft( + (dragger.getElement().getOffsetWidth() + - resizeElement.getOffsetWidth()) + * .5, + Unit.PX); + resizeElement.getStyle().setHeight( + col.grid.getOffsetHeight(), Unit.PX); + } + + @Override + public void onUpdate(double deltaX, double deltaY) { + width = Math.max(minCellWidth, + initialWidth + deltaX); + resizeElement.getStyle().setLeft( + (dragger.getElement().getOffsetWidth() + - resizeElement.getOffsetWidth()) + * .5 + (width - initialWidth), + Unit.PX); + } + + @Override + public void onCancel() { + dragEnded(); + } + + @Override + public void onComplete() { + dragEnded(); + + col.setWidth(width); + fireEvent(new ColumnResizeEvent<>(col)); + } + }; + + final DragHandleCallback animatedResizeMode = new AbstractDHCallback() { + @Override + public void onStart() { + dragStarted(); + } + + @Override + public void onUpdate(double deltaX, double deltaY) { + width = Math.max(minCellWidth, + initialWidth + deltaX); + col.setWidth(width); + } + + @Override + public void onCancel() { + dragEnded(); + col.setWidth(initialWidth); + } + + @Override + public void onComplete() { + dragEnded(); + col.setWidth(width); + fireEvent(new ColumnResizeEvent<>(col)); + } + }; + + // DragHandle gets assigned a 'master callback' that + // delegates + // functionality to the correct case-specific implementation + dragger.setCallback(new DragHandleCallback() { + + private DragHandleCallback currentCallback; + + @Override + public void onStart() { + switch (getColumnResizeMode()) { + case SIMPLE: + currentCallback = simpleResizeMode; + break; + case ANIMATED: + currentCallback = animatedResizeMode; + break; + default: + throw new UnsupportedOperationException( + "Support for current column resize mode is not yet implemented"); + } + + currentCallback.onStart(); + } + + @Override + public void onUpdate(double deltaX, double deltaY) { + currentCallback.onUpdate(deltaX, deltaY); + } + + @Override + public void onCancel() { + currentCallback.onCancel(); + } + + @Override + public void onComplete() { + currentCallback.onComplete(); + } + }); } cellFocusHandler.updateFocusedCellStyle(cell, container); @@ -5996,6 +6101,27 @@ public class Grid<T> extends ResizeComposite implements HasSelectionHandlers<T>, fireEvent(new GridEnabledEvent(enabled)); } + /** + * Sets the column resize mode to use. The default mode is + * {@link ColumnResizeMode.ANIMATED}. + * + * @param mode + * a ColumnResizeMode value + */ + public void setColumnResizeMode(ColumnResizeMode mode) { + columnResizeMode = mode; + } + + /** + * Returns the current column resize mode. The default mode is + * {@link ColumnResizeMode.ANIMATED}. + * + * @return a ColumnResizeMode value + */ + public ColumnResizeMode getColumnResizeMode() { + return columnResizeMode; + } + @Override public void setStylePrimaryName(String style) { super.setStylePrimaryName(style); |