summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2015-04-21 17:06:50 +0300
committerPekka Hyvönen <pekka@vaadin.com>2015-04-24 10:11:03 +0000
commit0435a27fc9ed0e04f33d7b046e66f571ab4b09e0 (patch)
tree268a57284da15b1177108f8980c666dd1844df14 /client
parentec4e470e401a1a8f55b427b04dee08c39ed63d8b (diff)
downloadvaadin-framework-0435a27fc9ed0e04f33d7b046e66f571ab4b09e0.tar.gz
vaadin-framework-0435a27fc9ed0e04f33d7b046e66f571ab4b09e0.zip
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
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/widgets/Grid.java54
1 files changed, 51 insertions, 3 deletions
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<T> 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<T> extends ResizeComposite implements
private void updateTogglesOrder() {
if (!hidingColumn) {
+ int lastIndex = 0;
for (Column<?, T> 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<T> 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 <code>true</code> if the sidebar is open; <code>false</code> 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
+ * <code>true</code> to open the sidebar; <code>false</code> to
+ * close it
+ */
+ public void setSidebarOpen(boolean sidebarOpen) {
+ if (sidebarOpen) {
+ sidebar.open();
+ } else {
+ sidebar.close();
+ }
+ }
}