diff options
author | Henrik Paul <henrik@vaadin.com> | 2015-02-03 16:19:46 +0200 |
---|---|---|
committer | Henrik Paul <henrik@vaadin.com> | 2015-02-03 16:23:15 +0200 |
commit | bd8931f0cd8ed05c9891f4f5eb3646bc3d4bc989 (patch) | |
tree | afba841657349211f723180b0d22d880bba1dc12 | |
parent | 9cac6602821383dc2e03607066c0ea7ec7d01af7 (diff) | |
parent | 0dcaa660c5bd2c5c2bdea352c5141754a549b18c (diff) | |
download | vaadin-framework-bd8931f0cd8ed05c9891f4f5eb3646bc3d4bc989.tar.gz vaadin-framework-bd8931f0cd8ed05c9891f4f5eb3646bc3d4bc989.zip |
Merge branch 'grid'
Change-Id: I31da151c65ce307d6205905682c6f1e6bbbed258
6 files changed, 101 insertions, 12 deletions
diff --git a/client/src/com/vaadin/client/WidgetUtil.java b/client/src/com/vaadin/client/WidgetUtil.java index 96f161c4a8..eb6697dda0 100644 --- a/client/src/com/vaadin/client/WidgetUtil.java +++ b/client/src/com/vaadin/client/WidgetUtil.java @@ -21,6 +21,7 @@ import java.util.HashMap; import java.util.Map; import java.util.logging.Logger; +import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.dom.client.AnchorElement; @@ -1243,6 +1244,46 @@ public class WidgetUtil { return Math.abs(num1 - num2) <= PIXEL_EPSILON; } + public static native TextRectangle getBoundingClientRect(Element e) + /*-{ + return e.getBoundingClientRect(); + }-*/; + + public static final class TextRectangle extends JavaScriptObject { + protected TextRectangle() { + } + + public native double getBottom() + /*-{ + return this.bottom; + }-*/; + + public native double getHeight() + /*-{ + return this.height; + }-*/; + + public native double getLeft() + /*-{ + return this.left; + }-*/; + + public native double getRight() + /*-{ + return this.right; + }-*/; + + public native double getTop() + /*-{ + return this.top; + }-*/; + + public native double getWidth() + /*-{ + return this.width; + }-*/; + } + /** * Wrap a css size value and its unit and translate back and forth to the * string representation.<br/> diff --git a/client/src/com/vaadin/client/widget/escalator/RowContainer.java b/client/src/com/vaadin/client/widget/escalator/RowContainer.java index 2fe2070b0d..397336450e 100644 --- a/client/src/com/vaadin/client/widget/escalator/RowContainer.java +++ b/client/src/com/vaadin/client/widget/escalator/RowContainer.java @@ -18,7 +18,7 @@ package com.vaadin.client.widget.escalator; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.TableRowElement; -import com.vaadin.client.widgets.Escalator; +import com.google.gwt.dom.client.TableSectionElement; /** * A representation of the rows in each of the sections (header, body and @@ -192,5 +192,5 @@ public interface RowContainer { * * @return RowContainer root element */ - public Element getElement(); + public TableSectionElement getElement(); } diff --git a/client/src/com/vaadin/client/widgets/Escalator.java b/client/src/com/vaadin/client/widgets/Escalator.java index 4f853a928f..6a8fb311b1 100644 --- a/client/src/com/vaadin/client/widgets/Escalator.java +++ b/client/src/com/vaadin/client/widgets/Escalator.java @@ -1245,7 +1245,7 @@ public class Escalator extends Widget implements RequiresResize, DeferredWorker } @Override - public Element getElement() { + public TableSectionElement getElement() { return root; } diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index d6dfdee3b3..c8354dc5ce 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -39,6 +39,7 @@ import com.google.gwt.dom.client.Style; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.dom.client.TableCellElement; import com.google.gwt.dom.client.TableRowElement; +import com.google.gwt.dom.client.TableSectionElement; import com.google.gwt.dom.client.Touch; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; @@ -941,6 +942,9 @@ public class Grid<T> extends ResizeComposite implements */ protected static class Editor<T> { + private static final double BUTTON_HEIGHT = 25; + private static final double BUTTON_WIDTH = 50; + private static final double BUTTON_MARGIN = 5; public static final int KEYCODE_SHOW = KeyCodes.KEY_ENTER; public static final int KEYCODE_HIDE = KeyCodes.KEY_ESCAPE; @@ -1256,8 +1260,9 @@ public class Grid<T> extends ResizeComposite implements .getRequiredWidthBoundingClientRectDouble(tr); double height = WidgetUtil .getRequiredHeightBoundingClientRectDouble(tr); - setBounds(editorOverlay, tr.getOffsetLeft(), rowTop + bodyTop - - wrapperTop, width, height); + double overlayTop = rowTop + bodyTop - wrapperTop; + setBounds(editorOverlay, tr.getOffsetLeft(), overlayTop, width, + height); updateHorizontalScrollPosition(); @@ -1297,8 +1302,6 @@ public class Grid<T> extends ResizeComposite implements save(); } }); - setBounds(saveButton.getElement(), 0, tr.getOffsetHeight() + 5, 50, - 25); attachWidget(saveButton, editorOverlay); cancelButton = new Button(); @@ -1311,9 +1314,41 @@ public class Grid<T> extends ResizeComposite implements cancel(); } }); - setBounds(cancelButton.getElement(), 55, tr.getOffsetHeight() + 5, - 50, 25); attachWidget(cancelButton, editorOverlay); + + /* + * We can't use BUTTON_HEIGHT here, becuase it's ignored by at least + * Chrome and Firefox. So we measure it. + */ + double buttonTop = getButtonTop(tr, saveButton.getOffsetHeight()); + setBounds(saveButton.getElement(), 0, buttonTop, BUTTON_WIDTH, + BUTTON_HEIGHT); + setBounds(cancelButton.getElement(), BUTTON_WIDTH + BUTTON_MARGIN, + buttonTop, BUTTON_WIDTH, BUTTON_HEIGHT); + } + + private double getButtonTop(TableRowElement tr, int buttonHeight) { + boolean buttonsShouldBeRenderedBelow = buttonsShouldBeRenderedBelow( + tr, buttonHeight); + final double buttonTop; + if (buttonsShouldBeRenderedBelow) { + buttonTop = tr.getOffsetHeight() + BUTTON_MARGIN; + } else { + buttonTop = -(buttonHeight + BUTTON_MARGIN); + } + return buttonTop; + } + + private boolean buttonsShouldBeRenderedBelow(TableRowElement tr, + int buttonHeight) { + TableSectionElement tfoot = grid.escalator.getFooter().getElement(); + double tfootPageTop = WidgetUtil.getBoundingClientRect(tfoot) + .getTop(); + double trPageBottom = WidgetUtil.getBoundingClientRect(tr) + .getBottom(); + double bottomOfButtons = trPageBottom + buttonHeight + + BUTTON_MARGIN; + return bottomOfButtons < tfootPageTop; } protected void hideOverlay() { diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java index 0ba771b283..458522f58e 100644 --- a/server/src/com/vaadin/ui/Grid.java +++ b/server/src/com/vaadin/ui/Grid.java @@ -51,7 +51,6 @@ import com.vaadin.data.RpcDataProviderExtension.DataProviderKeyMapper; import com.vaadin.data.Validator.InvalidValueException; import com.vaadin.data.fieldgroup.DefaultFieldGroupFieldFactory; import com.vaadin.data.fieldgroup.FieldGroup; -import com.vaadin.data.fieldgroup.FieldGroup.BindException; import com.vaadin.data.fieldgroup.FieldGroup.CommitException; import com.vaadin.data.fieldgroup.FieldGroupFieldFactory; import com.vaadin.data.sort.Sort; @@ -4851,6 +4850,18 @@ public class Grid extends AbstractComponent implements SelectionNotifier, return editorErrorHandler; } + /** + * Gets the field factory for the {@link FieldGroup}. The field factory is + * only used when {@link FieldGroup} creates a new field. + * <p> + * <em>Note:</em> This is a pass-through call to the backing field group. + * + * @return The field factory in use + */ + public FieldGroupFieldFactory getEditorFieldFactory() { + return editorFieldGroup.getFieldFactory(); + } + @Override public void addItemClickListener(ItemClickListener listener) { addListener(GridConstants.ITEM_CLICK_EVENT_ID, ItemClickEvent.class, diff --git a/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java b/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java index 53bf96c587..29e56b1b8c 100644 --- a/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java +++ b/uitest/src/com/vaadin/tests/widgetset/client/grid/EscalatorProxy.java @@ -17,6 +17,7 @@ package com.vaadin.tests.widgetset.client.grid; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.TableRowElement; +import com.google.gwt.dom.client.TableSectionElement; import com.vaadin.client.widget.escalator.Cell; import com.vaadin.client.widget.escalator.ColumnConfiguration; import com.vaadin.client.widget.escalator.EscalatorUpdater; @@ -138,7 +139,8 @@ public class EscalatorProxy extends Escalator { } @Override - public void setDefaultRowHeight(double px) throws IllegalArgumentException { + public void setDefaultRowHeight(double px) + throws IllegalArgumentException { rowContainer.setDefaultRowHeight(px); } @@ -159,7 +161,7 @@ public class EscalatorProxy extends Escalator { } @Override - public Element getElement() { + public TableSectionElement getElement() { return rowContainer.getElement(); } |