]> source.dussan.org Git - vaadin-framework.git/commitdiff
Table: Make some columns uncollapsable (#7495)
authorLeif Åstrand <leif@vaadin.com>
Wed, 23 May 2012 08:06:06 +0000 (08:06 +0000)
committerLeif Åstrand <leif@vaadin.com>
Wed, 23 May 2012 08:06:06 +0000 (08:06 +0000)
svn changeset:23811/svn branch:6.8

src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java
src/com/vaadin/ui/Table.java
tests/testbench/com/vaadin/tests/components/table/TableWithNoncollapsibleColumns.html [new file with mode: 0644]
tests/testbench/com/vaadin/tests/components/table/TableWithNoncollapsibleColumns.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/components/table/Tables.java

index 39492d873125cfcc4a69b53078ef24187abe654c..c5ca16925b523a443c4554ed1a30165d136e0156 100644 (file)
@@ -214,6 +214,8 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler,
             .isTouchDevice()
             && !BrowserInfo.get().requiresTouchScrollDelegate();
 
+    private Set<String> 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("<span class=\"");
                 if (collapsed) {
-                    buf.append("<span class=\"v-off\">");
+                    buf.append("v-off");
                 } else {
-                    buf.append("<span class=\"v-on\">");
+                    buf.append("v-on");
+                }
+                if (noncollapsible) {
+                    buf.append(" v-disabled");
                 }
+                buf.append("\">");
+
                 buf.append(super.getHTML());
                 buf.append("</span>");
 
@@ -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;
index db0809fbd558010ffcb3902d088ae1c0141e9851..a2db89cabbd0413514aa02a0ce02361f66a5b89a 100644 (file)
@@ -229,6 +229,11 @@ public class Table extends AbstractSelect implements Action.Container,
      */
     private LinkedList<Object> visibleColumns = new LinkedList<Object>();
 
+    /**
+     * Holds noncollapsible columns.
+     */
+    private HashSet<Object> noncollapsibleColumns = new HashSet<Object>();
+
     /**
      * 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<Action> 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 (file)
index 0000000..e3c9a84
--- /dev/null
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>TableWithNoncollapsibleColumns</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">TableWithNoncollapsibleColumns</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/com.vaadin.tests.components.table.TableWithNoncollapsibleColumns?restartApplication</td>
+       <td></td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableWithNoncollapsibleColumns::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>column-3-collapsed</td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableWithNoncollapsibleColumns::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[4]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>column-3-noncollapsible</td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableWithNoncollapsibleColumns::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableWithNoncollapsibleColumns::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[2]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableWithNoncollapsibleColumns::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableWithNoncollapsibleColumns::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[0]/domChild[1]</td>
+       <td>9,7</td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>column-menu-after-collapsing-all-columns</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableWithNoncollapsibleColumns::Root/VContextMenu[0]#option2</td>
+       <td>93,4</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstableTableWithNoncollapsibleColumns::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[0]/VScrollTable[0]/domChild[0]/domChild[1]</td>
+       <td>7,10</td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td>column-menu-after-expanding-column-2</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
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 (file)
index 0000000..9e8c201
--- /dev/null
@@ -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;
+    }
+
+}
index 3f37a178b6c08d7c3f095f05aea2f7fb2ba02195..5c55ea87b2ca633e855219330a159ec2f93b9a1a 100644 (file)
@@ -73,6 +73,14 @@ public class Tables<T extends Table> extends AbstractSelectTestCase<T>
         }
     };
 
+    private Command<T, Boolean> columnNonCollapsibleCommand = new Command<T, Boolean>() {
+
+        public void execute(T c, Boolean noncollapsible, Object propertyId) {
+            c.setColumnNoncollapsible(propertyId, noncollapsible);
+
+        }
+    };
+
     protected Command<T, Boolean> columnResizeListenerCommand = new Command<T, Boolean>() {
 
         public void execute(Table c, Boolean value, Object data) {
@@ -644,6 +652,9 @@ public class Tables<T extends Table> extends AbstractSelectTestCase<T>
         createSelectAction("Expand ratio", category, expandOptions,
                 "- remove -", columnExpandRatioCommand, propertyId);
         t.log("Expand");
+        createBooleanAction("Noncollapsible", category, false,
+                columnNonCollapsibleCommand, propertyId);
+
         // Footer text (move)
         // Header text (move)