From e8a652c91e9e02079180a854789afd5accffce7b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Wed, 23 May 2012 08:06:06 +0000 Subject: [PATCH] Table: Make some columns uncollapsable (#7495) svn changeset:23811/svn branch:6.8 --- .../terminal/gwt/client/ui/VScrollTable.java | 27 +++++- src/com/vaadin/ui/Table.java | 46 ++++++++++ .../table/TableWithNoncollapsibleColumns.html | 82 ++++++++++++++++++ .../table/TableWithNoncollapsibleColumns.java | 83 +++++++++++++++++++ .../vaadin/tests/components/table/Tables.java | 11 +++ 5 files changed, 247 insertions(+), 2 deletions(-) create mode 100644 tests/testbench/com/vaadin/tests/components/table/TableWithNoncollapsibleColumns.html create mode 100644 tests/testbench/com/vaadin/tests/components/table/TableWithNoncollapsibleColumns.java diff --git a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java index 39492d8731..c5ca16925b 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java @@ -214,6 +214,8 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, .isTouchDevice() && !BrowserInfo.get().requiresTouchScrollDelegate(); + private Set noncollapsibleColumns; + /** * Represents a select range of rows */ @@ -1086,6 +1088,10 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, updateHeader(uidl.getStringArrayAttribute("vcolorder")); updateFooter(uidl.getStringArrayAttribute("vcolorder")); + if (uidl.hasVariable("noncollapsiblecolumns")) { + noncollapsibleColumns = uidl + .getStringArrayVariableAsSet("noncollapsiblecolumns"); + } } private void updateCollapsedColumns(UIDL uidl) { @@ -3244,6 +3250,7 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, String colKey; private boolean collapsed; + private boolean noncollapsible = false; private VScrollTableRow currentlyFocusedRow; public VisibleColumnAction(String colKey) { @@ -3255,6 +3262,9 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, @Override public void execute() { + if (noncollapsible) { + return; + } client.getContextMenu().hide(); // toggle selected column if (collapsedColumns.contains(colKey)) { @@ -3278,17 +3288,27 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, collapsed = b; } + public void setNoncollapsible(boolean b) { + noncollapsible = b; + } + /** * Override default method to distinguish on/off columns */ @Override public String getHTML() { final StringBuffer buf = new StringBuffer(); + buf.append(""); + buf.append("v-off"); } else { - buf.append(""); + buf.append("v-on"); + } + if (noncollapsible) { + buf.append(" v-disabled"); } + buf.append("\">"); + buf.append(super.getHTML()); buf.append(""); @@ -3330,6 +3350,9 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, if (!c.isEnabled()) { a.setCollapsed(true); } + if (noncollapsibleColumns.contains(cid)) { + a.setNoncollapsible(true); + } actions[i] = a; } return actions; diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java index db0809fbd5..a2db89cabb 100644 --- a/src/com/vaadin/ui/Table.java +++ b/src/com/vaadin/ui/Table.java @@ -229,6 +229,11 @@ public class Table extends AbstractSelect implements Action.Container, */ private LinkedList visibleColumns = new LinkedList(); + /** + * Holds noncollapsible columns. + */ + private HashSet noncollapsibleColumns = new HashSet(); + /** * Holds propertyIds of currently collapsed columns. */ @@ -1139,6 +1144,9 @@ public class Table extends AbstractSelect implements Action.Container, if (!isColumnCollapsingAllowed()) { throw new IllegalStateException("Column collapsing not allowed!"); } + if (collapsed && noncollapsibleColumns.contains(propertyId)) { + throw new IllegalStateException("The column is noncollapsible!"); + } if (collapsed) { collapsedColumns.add(propertyId); @@ -1177,6 +1185,34 @@ public class Table extends AbstractSelect implements Action.Container, refreshRenderedCells(); } + /** + * Sets whether a column can be collapsed or not. + * + * @param propertyId + * the propertyID identifying the column. + * @param collapsible + * the desired collapsibleness + */ + public void setColumnNoncollapsible(Object propertyId, + boolean noncollapsible) { + if (noncollapsible) { + noncollapsibleColumns.add(propertyId); + collapsedColumns.remove(propertyId); + } else { + noncollapsibleColumns.remove(propertyId); + } + refreshRowCache(); + } + + /** + * Checks if the column can be collapsed. + * + * @return true if the column can be collapsed; false otherwise. + */ + public boolean isColumnNoncollapsible(Object propertyId) { + return noncollapsibleColumns.contains(propertyId); + } + /** * Checks if column reordering is allowed. * @@ -2996,7 +3032,17 @@ public class Table extends AbstractSelect implements Action.Container, } } target.addVariable(this, "collapsedcolumns", collapsedKeys); + + final String[] noncollapsibleKeys = new String[noncollapsibleColumns + .size()]; + nextColumn = 0; + for (Object colId : noncollapsibleColumns) { + noncollapsibleKeys[nextColumn++] = columnIdMap.key(colId); + } + target.addVariable(this, "noncollapsiblecolumns", + noncollapsibleKeys); } + } private void paintActions(PaintTarget target, final Set actionSet) diff --git a/tests/testbench/com/vaadin/tests/components/table/TableWithNoncollapsibleColumns.html b/tests/testbench/com/vaadin/tests/components/table/TableWithNoncollapsibleColumns.html new file mode 100644 index 0000000000..e3c9a8423b --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/table/TableWithNoncollapsibleColumns.html @@ -0,0 +1,82 @@ + + + + + + +TableWithNoncollapsibleColumns + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TableWithNoncollapsibleColumns
open/run/com.vaadin.tests.components.table.TableWithNoncollapsibleColumns?restartApplication
clickvaadin=runcomvaadintestscomponentstableTableWithNoncollapsibleColumns::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]
screenCapturecolumn-3-collapsed
clickvaadin=runcomvaadintestscomponentstableTableWithNoncollapsibleColumns::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[4]/VButton[0]/domChild[0]/domChild[0]
screenCapturecolumn-3-noncollapsible
clickvaadin=runcomvaadintestscomponentstableTableWithNoncollapsibleColumns::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstableTableWithNoncollapsibleColumns::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[2]/VButton[0]/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentstableTableWithNoncollapsibleColumns::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]
mouseClickvaadin=runcomvaadintestscomponentstableTableWithNoncollapsibleColumns::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[0]/domChild[1]9,7
screenCapturecolumn-menu-after-collapsing-all-columns
mouseClickvaadin=runcomvaadintestscomponentstableTableWithNoncollapsibleColumns::Root/VContextMenu[0]#option293,4
mouseClickvaadin=runcomvaadintestscomponentstableTableWithNoncollapsibleColumns::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[0]/domChild[1]7,10
screenCapturecolumn-menu-after-expanding-column-2
+ + diff --git a/tests/testbench/com/vaadin/tests/components/table/TableWithNoncollapsibleColumns.java b/tests/testbench/com/vaadin/tests/components/table/TableWithNoncollapsibleColumns.java new file mode 100644 index 0000000000..9e8c201452 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/table/TableWithNoncollapsibleColumns.java @@ -0,0 +1,83 @@ +package com.vaadin.tests.components.table; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Table; +import com.vaadin.ui.VerticalLayout; + +public class TableWithNoncollapsibleColumns extends TestBase { + + @Override + protected void setup() { + VerticalLayout layout = new VerticalLayout(); + layout.setSizeFull(); + addComponent(layout); + + final Table table = new Table(); + table.setWidth("100%"); + table.setHeight("300px"); + table.setColumnCollapsingAllowed(true); + + table.addContainerProperty("Column 1 - noncollapsible", String.class, + null); + table.addContainerProperty("Column 2 - collapsible", String.class, null); + table.addContainerProperty("Column 3 - toggle collapsing", + String.class, null); + + table.setColumnNoncollapsible("Column 1 - noncollapsible", true); + layout.addComponent(table); + + final Button button1 = new Button("Column 1: collapse/show", + new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + table.setColumnCollapsed( + "Column 1 - noncollapsible", + !table.isColumnCollapsed("Column 1 - noncollapsible")); + } + }); + final Button button2 = new Button("Column 2: collapse/show", + new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + table.setColumnCollapsed( + "Column 2 - collapsible", + !table.isColumnCollapsed("Column 2 - collapsible")); + } + }); + + final Button button3 = new Button("Column 3: collapse/show", + new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + table.setColumnCollapsed( + "Column 3 - toggle collapsing", + !table.isColumnCollapsed("Column 3 - toggle collapsing")); + } + }); + final Button button4 = new Button( + "Column 3: make noncollapsible/collapsible", + new Button.ClickListener() { + public void buttonClick(ClickEvent event) { + table.setColumnNoncollapsible( + "Column 3 - toggle collapsing", + !table.isColumnNoncollapsible("Column 3 - toggle collapsing")); + } + }); + + layout.addComponent(button1); + layout.addComponent(button2); + layout.addComponent(button3); + layout.addComponent(button4); + + } + + @Override + protected String getDescription() { + return "Often a table has one column that identifies the row better than any other and it would not make sense to collapse that one. Make it possible from the server side api to disable collapsing for some properties. These properties could appear as grayed out in the collapse drop down menu."; + } + + @Override + protected Integer getTicketNumber() { + return 7495; + } + +} diff --git a/tests/testbench/com/vaadin/tests/components/table/Tables.java b/tests/testbench/com/vaadin/tests/components/table/Tables.java index 3f37a178b6..5c55ea87b2 100644 --- a/tests/testbench/com/vaadin/tests/components/table/Tables.java +++ b/tests/testbench/com/vaadin/tests/components/table/Tables.java @@ -73,6 +73,14 @@ public class Tables extends AbstractSelectTestCase } }; + private Command columnNonCollapsibleCommand = new Command() { + + public void execute(T c, Boolean noncollapsible, Object propertyId) { + c.setColumnNoncollapsible(propertyId, noncollapsible); + + } + }; + protected Command columnResizeListenerCommand = new Command() { public void execute(Table c, Boolean value, Object data) { @@ -644,6 +652,9 @@ public class Tables extends AbstractSelectTestCase createSelectAction("Expand ratio", category, expandOptions, "- remove -", columnExpandRatioCommand, propertyId); t.log("Expand"); + createBooleanAction("Noncollapsible", category, false, + columnNonCollapsibleCommand, propertyId); + // Footer text (move) // Header text (move) -- 2.39.5