diff options
author | Leif Åstrand <leif@vaadin.com> | 2015-09-18 14:26:50 +0300 |
---|---|---|
committer | Henri Sara <hesara@vaadin.com> | 2015-12-16 07:18:37 +0000 |
commit | 3aff803172dab49a6e0ac694b3b3d687dc7e976c (patch) | |
tree | 469ac91e564baf88852bb73460194b07cf381134 | |
parent | 61e83653330399f6ead49f74277410e43368a2cb (diff) | |
download | vaadin-framework-3aff803172dab49a6e0ac694b3b3d687dc7e976c.tar.gz vaadin-framework-3aff803172dab49a6e0ac694b3b3d687dc7e976c.zip |
Make it possible to only show collapsible columns in menu (#9811)
Change-Id: I52cd2648d305f44d5688e7a2fcd222e6b167b97b
9 files changed, 184 insertions, 5 deletions
diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index 5bd6ed390d..74966d6b26 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -104,6 +104,7 @@ import com.vaadin.client.ui.dd.VTransferable; import com.vaadin.shared.AbstractComponentState; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.ui.dd.VerticalDropLocation; +import com.vaadin.shared.ui.table.CollapseMenuContent; import com.vaadin.shared.ui.table.TableConstants; /** @@ -4018,10 +4019,17 @@ public class VScrollTable extends FlowPanel implements HasWidgets, cols[i++] = it.next(); } } - final Action[] actions = new Action[cols.length]; + List<Action> actions = new ArrayList<Action>(cols.length); for (int i = 0; i < cols.length; i++) { final String cid = (String) cols[i]; + boolean noncollapsible = noncollapsibleColumns.contains(cid); + + if (noncollapsible + && collapsibleMenuContent == CollapseMenuContent.COLLAPSIBLE_COLUMNS) { + continue; + } + final HeaderCell c = getHeaderCell(cid); final VisibleColumnAction a = new VisibleColumnAction( c.getColKey()); @@ -4029,12 +4037,12 @@ public class VScrollTable extends FlowPanel implements HasWidgets, if (!c.isEnabled()) { a.setCollapsed(true); } - if (noncollapsibleColumns.contains(cid)) { + if (noncollapsible) { a.setNoncollapsible(true); } - actions[i] = a; + actions.add(a); } - return actions; + return actions.toArray(new Action[actions.size()]); } @Override @@ -7205,6 +7213,9 @@ public class VScrollTable extends FlowPanel implements HasWidgets, /** For internal use only. May be removed or replaced in the future. */ public boolean multiselectPending; + /** For internal use only. May be removed or replaced in the future. */ + public CollapseMenuContent collapsibleMenuContent; + /** * @return border top + border bottom of the scrollable area of table */ diff --git a/client/src/com/vaadin/client/ui/table/TableConnector.java b/client/src/com/vaadin/client/ui/table/TableConnector.java index cdd9397976..a554b9335c 100644 --- a/client/src/com/vaadin/client/ui/table/TableConnector.java +++ b/client/src/com/vaadin/client/ui/table/TableConnector.java @@ -395,6 +395,7 @@ public class TableConnector extends AbstractFieldConnector implements getWidget().rendering = false; getWidget().headerChangedDuringUpdate = false; + getWidget().collapsibleMenuContent = getState().collapseMenuContent; } @Override diff --git a/server/src/com/vaadin/ui/Table.java b/server/src/com/vaadin/ui/Table.java index 3edfe7845f..fa7f6cfc01 100644 --- a/server/src/com/vaadin/ui/Table.java +++ b/server/src/com/vaadin/ui/Table.java @@ -65,6 +65,7 @@ import com.vaadin.server.PaintTarget; import com.vaadin.server.Resource; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.ui.MultiSelectMode; +import com.vaadin.shared.ui.table.CollapseMenuContent; import com.vaadin.shared.ui.table.TableConstants; import com.vaadin.shared.ui.table.TableConstants.Section; import com.vaadin.shared.ui.table.TableServerRpc; @@ -6469,7 +6470,12 @@ public class Table extends AbstractSelect implements Action.Container, @Override protected TableState getState() { - return (TableState) super.getState(); + return getState(true); + } + + @Override + protected TableState getState(boolean markAsDirty) { + return (TableState) super.getState(markAsDirty); } private final Logger getLogger() { @@ -6492,4 +6498,30 @@ public class Table extends AbstractSelect implements Action.Container, public ChildMeasurementHint getChildMeasurementHint() { return childMeasurementHint; } + + /** + * Sets whether only collapsible columns should be shown to the user in the + * column collapse menu. The default is + * {@link CollapseMenuContent#ALL_COLUMNS}. + * + * + * @since + * @param content + * the desired collapsible menu content setting + */ + public void setCollapseMenuContent(CollapseMenuContent content) { + getState().collapseMenuContent = content; + } + + /** + * Checks whether only collapsible columns are shown to the user in the + * column collapse menu. The default is + * {@link CollapseMenuContent#ALL_COLUMNS} . + * + * @since + * @return the current collapsible menu content setting + */ + public CollapseMenuContent getCollapseMenuContent() { + return getState(false).collapseMenuContent; + } } diff --git a/shared/src/com/vaadin/shared/ui/table/CollapseMenuContent.java b/shared/src/com/vaadin/shared/ui/table/CollapseMenuContent.java new file mode 100644 index 0000000000..22f28d193b --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/table/CollapseMenuContent.java @@ -0,0 +1,40 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.vaadin.shared.ui.table; + +/** + * Defines whether only collapsible columns should be shown to the user in the + * column collapse menu. + * + * @see com.vaadin.ui.Table#setCollapseMenuContent(CollapseMenuContent) + * + * @since + * @author Vaadin Ltd + */ +public enum CollapseMenuContent { + /** + * All columns are shown in the collapse menu. Columns that are not + * collapsible are shown as disabled in the menu. This is the default + * setting. + */ + ALL_COLUMNS, + + /** + * Only collapsible columns are shown in the collapse menu. + */ + COLLAPSIBLE_COLUMNS; +} diff --git a/shared/src/com/vaadin/shared/ui/table/TableConstants.java b/shared/src/com/vaadin/shared/ui/table/TableConstants.java index 3a11e0a69a..a90bb7208a 100644 --- a/shared/src/com/vaadin/shared/ui/table/TableConstants.java +++ b/shared/src/com/vaadin/shared/ui/table/TableConstants.java @@ -45,4 +45,11 @@ public class TableConstants implements Serializable { @Deprecated public static final String ATTRIBUTE_KEY_MAPPER_RESET = "clearKeyMap"; + /** + * Default value for {@link TableState#collapseMenuContent}. + * + * @since + */ + public static final CollapseMenuContent DEFAULT_COLLAPSE_MENU_CONTENT = CollapseMenuContent.ALL_COLUMNS; + } diff --git a/shared/src/com/vaadin/shared/ui/table/TableState.java b/shared/src/com/vaadin/shared/ui/table/TableState.java index 7c60a78f57..9e225846b8 100644 --- a/shared/src/com/vaadin/shared/ui/table/TableState.java +++ b/shared/src/com/vaadin/shared/ui/table/TableState.java @@ -26,4 +26,6 @@ public class TableState extends AbstractSelectState { { primaryStyleName = "v-table"; } + + public CollapseMenuContent collapseMenuContent = TableConstants.DEFAULT_COLLAPSE_MENU_CONTENT; } diff --git a/uitest/src/com/vaadin/tests/components/AbstractComponentTest.java b/uitest/src/com/vaadin/tests/components/AbstractComponentTest.java index aca617aa5a..d033443a2c 100644 --- a/uitest/src/com/vaadin/tests/components/AbstractComponentTest.java +++ b/uitest/src/com/vaadin/tests/components/AbstractComponentTest.java @@ -1,5 +1,6 @@ package com.vaadin.tests.components; +import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -603,6 +604,20 @@ public abstract class AbstractComponentTest<T extends AbstractComponent> } + protected <TYPE extends Enum<TYPE>> void createSelectAction( + String caption, + String category, + Class<TYPE> enumType, + TYPE initialValue, + com.vaadin.tests.components.ComponentTestCase.Command<T, TYPE> command) { + LinkedHashMap<String, TYPE> options = new LinkedHashMap<String, TYPE>(); + for (TYPE value : EnumSet.allOf(enumType)) { + options.put(value.toString(), value); + } + createSelectAction(caption, category, options, initialValue.toString(), + command); + } + protected <TYPE> void createMultiClickAction( String caption, String category, diff --git a/uitest/src/com/vaadin/tests/components/table/OnlyCollapsibleInMenu.java b/uitest/src/com/vaadin/tests/components/table/OnlyCollapsibleInMenu.java new file mode 100644 index 0000000000..2b053a6d1c --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/OnlyCollapsibleInMenu.java @@ -0,0 +1,54 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.components.table; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.shared.ui.table.CollapseMenuContent; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class OnlyCollapsibleInMenu extends SingleBrowserTest { + + @Override + protected Class<?> getUIClass() { + return Tables.class; + } + + @Test + public void testOnlyCollapsibleInMenu() { + openTestURL(); + CustomTableElement table = $(CustomTableElement.class).first(); + + selectMenuPath("Component", "Columns", "Property 3", "Collapsible"); + table.getCollapseMenuToggle().click(); + Assert.assertEquals("Property 3 should still be in the context menu", + "Property 3", table.getContextMenu().getItem(2).getText()); + + selectMenuPath("Component", "Features", "Collapsible menu content", + CollapseMenuContent.COLLAPSIBLE_COLUMNS.toString()); + table.getCollapseMenuToggle().click(); + Assert.assertEquals("Property 3 should not be in the context menu", + "Property 4", table.getContextMenu().getItem(2).getText()); + + selectMenuPath("Component", "Features", "Collapsible menu content", + CollapseMenuContent.ALL_COLUMNS.toString()); + table.getCollapseMenuToggle().click(); + Assert.assertEquals("Property 3 should again be in the context menu", + "Property 3", table.getContextMenu().getItem(2).getText()); + } + +} diff --git a/uitest/src/com/vaadin/tests/components/table/Tables.java b/uitest/src/com/vaadin/tests/components/table/Tables.java index c8d1061943..e82cb8321f 100644 --- a/uitest/src/com/vaadin/tests/components/table/Tables.java +++ b/uitest/src/com/vaadin/tests/components/table/Tables.java @@ -11,6 +11,8 @@ import com.vaadin.event.ItemClickEvent.ItemClickListener; import com.vaadin.server.Resource; import com.vaadin.shared.ui.MultiSelectMode; import com.vaadin.shared.ui.label.ContentMode; +import com.vaadin.shared.ui.table.CollapseMenuContent; +import com.vaadin.shared.ui.table.TableConstants; import com.vaadin.tests.components.select.AbstractSelectTestCase; import com.vaadin.ui.Button; import com.vaadin.ui.Label; @@ -443,6 +445,8 @@ public class Tables<T extends Table> extends AbstractSelectTestCase<T> createBooleanAction("Sort enabled", CATEGORY_FEATURES, true, setSortEnabledCommand); createColumnOptions(true); + + createCollapsibleMenuContentSelect(CATEGORY_FEATURES); } private void createAddGeneratedColumnAction(String categoryFeatures) { @@ -590,6 +594,19 @@ public class Tables<T extends Table> extends AbstractSelectTestCase<T> }); } + private void createCollapsibleMenuContentSelect(String category) { + createSelectAction("Collapsible menu content", category, + CollapseMenuContent.class, + TableConstants.DEFAULT_COLLAPSE_MENU_CONTENT, + new Command<T, CollapseMenuContent>() { + @Override + public void execute(T c, CollapseMenuContent value, + Object data) { + c.setCollapseMenuContent(value); + } + }); + } + private void createColumnOptions(boolean init) { if (!init && !hasCategory(CATEGORY_COLUMNS)) { return; |