From 0435a27fc9ed0e04f33d7b046e66f571ab4b09e0 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 21 Apr 2015 17:06:50 +0300 Subject: Add support for custom Grid sidebar items (#17569) The current implementation does not in all cases enforce that visibility toggles are always before any custom items. The JavaDoc warns about this and the order is also restored whenever a visibility toggle is added or removed. Change-Id: I7160a04d6c96b2d6d821b13e420172e6115bc072 --- client/src/com/vaadin/client/widgets/Grid.java | 54 ++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) (limited to 'client/src') diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index 65d1173ee4..005532a849 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -3012,12 +3012,13 @@ public class Grid extends ResizeComposite implements menuBar = new MenuBar(true) { @Override - public MenuItem addItem(MenuItem item) { + public MenuItem insertItem(MenuItem item, int beforeIndex) + throws IndexOutOfBoundsException { if (getParent() == null) { content.insert(this, 0); updateVisibility(); } - return super.addItem(item); + return super.insertItem(item, beforeIndex); } @Override @@ -3273,12 +3274,13 @@ public class Grid extends ResizeComposite implements private void updateTogglesOrder() { if (!hidingColumn) { + int lastIndex = 0; for (Column column : getColumns()) { if (column.isHidable()) { final MenuItem menuItem = columnToHidingToggleMap .get(column); sidebar.menuBar.removeItem(menuItem); - sidebar.menuBar.addItem(menuItem); + sidebar.menuBar.insertItem(menuItem, lastIndex++); } } } @@ -7710,4 +7712,50 @@ public class Grid extends ResizeComposite implements private Sidebar getSidebar() { return sidebar; } + + /** + * Gets the customizable menu bar that is by default used for toggling + * column hidability. The application developer is allowed to add their + * custom items to the end of the menu, but should try to avoid modifying + * the items in the beginning of the menu that control the column hiding if + * any columns are marked as hidable. A toggle for opening the menu will be + * displayed whenever the menu contains at least one item. + * + * @since 7.5.0 + * @return the menu bar + */ + public MenuBar getSidebarMenu() { + return sidebar.menuBar; + } + + /** + * Tests whether the sidebar menu is currently open. + * + * @since 7.5.0 + * @see #getSidebarMenu() + * @return true if the sidebar is open; false if + * it is closed + */ + public boolean isSidebarOpen() { + return sidebar.isOpen(); + } + + /** + * Sets whether the sidebar menu is open. + * + * + * @since 7.5.0 + * @see #getSidebarMenu() + * @see #isSidebarOpen() + * @param sidebarOpen + * true to open the sidebar; false to + * close it + */ + public void setSidebarOpen(boolean sidebarOpen) { + if (sidebarOpen) { + sidebar.open(); + } else { + sidebar.close(); + } + } } -- cgit v1.2.3