]> source.dussan.org Git - vaadin-framework.git/blob
28424b86d0387e7af7d0f8dc5cfcef908c2c4855
[vaadin-framework.git] /
1 /*
2  * Copyright 2000-2016 Vaadin Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 package com.vaadin.v7.tests.server.component.table;
17
18 import org.junit.Assert;
19 import org.junit.Test;
20
21 import com.vaadin.server.ExternalResource;
22 import com.vaadin.shared.ui.MultiSelectMode;
23 import com.vaadin.v7.ui.Table;
24 import com.vaadin.v7.ui.Table.Align;
25 import com.vaadin.v7.ui.Table.ColumnHeaderMode;
26 import com.vaadin.v7.ui.Table.RowHeaderMode;
27 import com.vaadin.v7.ui.Table.TableDragMode;
28
29 /**
30  * Test declarative support for {@link Table}.
31  *
32  * @since
33  * @author Vaadin Ltd
34  */
35 public class TableDeclarativeTest extends TableDeclarativeTestBase {
36
37     @Test
38     public void testBasicAttributes() {
39
40         String design = "<" + getTag()
41                 + " page-length=30 cache-rate=3 selectable editable "
42                 + "sortable=false sort-ascending=false sort-container-property-id=foo "
43                 + "drag-mode=row multi-select-mode=simple column-header-mode=id row-header-mode=id "
44                 + "column-reordering-allowed column-collapsing-allowed />";
45
46         Table table = getTable();
47         table.setPageLength(30);
48         table.setCacheRate(3);
49         table.setSelectable(true);
50         table.setEditable(true);
51
52         table.setSortEnabled(false);
53         table.setSortAscending(false);
54         table.setSortContainerPropertyId("foo");
55
56         table.setDragMode(TableDragMode.ROW);
57         table.setMultiSelectMode(MultiSelectMode.SIMPLE);
58         table.setColumnHeaderMode(ColumnHeaderMode.ID);
59         table.setRowHeaderMode(RowHeaderMode.ID);
60
61         table.setColumnReorderingAllowed(true);
62         table.setColumnCollapsingAllowed(true);
63
64         testRead(design, table);
65         testWrite(design, table);
66     }
67
68     @Test
69     public void testColumns() {
70         String design = "<" + getTag() + " column-collapsing-allowed>" //
71                 + "  <table>" //
72                 + "    <colgroup>" + "      <col property-id='foo' width=300>"
73                 + "      <col property-id='bar' center expand=1 collapsible=false>"
74                 + "      <col property-id='baz' right expand=2 collapsed>"
75                 + "    </colgroup>" //
76                 + "  </table>";
77
78         Table table = getTable();
79         table.setColumnCollapsingAllowed(true);
80
81         table.addContainerProperty("foo", String.class, null);
82         table.setColumnAlignment("foo", Align.LEFT);
83         table.setColumnWidth("foo", 300);
84
85         table.addContainerProperty("bar", String.class, null);
86         table.setColumnAlignment("bar", Align.CENTER);
87         table.setColumnExpandRatio("bar", 1);
88         table.setColumnCollapsible("bar", false);
89
90         table.addContainerProperty("baz", String.class, null);
91         table.setColumnAlignment("baz", Align.RIGHT);
92         table.setColumnExpandRatio("baz", 2);
93         table.setColumnCollapsed("baz", true);
94
95         testRead(design, table);
96         testWrite(design, table);
97     }
98
99     @Test
100     public void testHeadersFooters() {
101         String design = "<" + getTag() + ">" //
102                 + "  <table>" //
103                 + "    <colgroup><col property-id=foo><col property-id=bar></colgroup>" //
104                 + "    <thead>" //
105                 + "      <tr><th icon='http://example.com/icon.png'>FOO<th>BAR" //
106                 + "    </thead>" //
107                 + "    <tfoot>" //
108                 + "      <tr><td>foo<td>bar" //
109                 + "    </tfoot>" //
110                 + "  </table>";
111
112         Table table = getTable();
113         table.setFooterVisible(true);
114
115         table.addContainerProperty("foo", String.class, null);
116         table.setColumnHeader("foo", "FOO");
117         table.setColumnIcon("foo",
118                 new ExternalResource("http://example.com/icon.png"));
119         table.setColumnFooter("foo", "foo");
120
121         table.addContainerProperty("bar", String.class, null);
122         table.setColumnHeader("bar", "BAR");
123         table.setColumnFooter("bar", "bar");
124
125         testRead(design, table);
126         testWrite(design, table);
127     }
128
129     @Test
130     public void testInlineData() {
131         String design = "<" + getTag() + ">" //
132                 + "  <table>" //
133                 + "    <colgroup>" + "      <col property-id='foo' />"
134                 + "      <col property-id='bar' />"
135                 + "      <col property-id='baz' />" //
136                 + "    </colgroup>" + "    <thead>"
137                 + "      <tr><th>Description<th>Milestone<th>Status</tr>"
138                 + "    </thead>" + "    <tbody>"
139                 + "      <tr item-id=1><td>r1c1</td><td>r1c2</td><td>r1c3</td>" //
140                 + "      <tr item-id=2><td>r2c1</td><td>r2c2</td><td>r2c3</td>" //
141                 + "    </tbody>" //
142                 + "    <tfoot>" //
143                 + "      <tr><td>F1<td>F2<td>F3</tr>" //
144                 + "    </tfoot>" //
145                 + "  </table>";
146
147         Table table = getTable();
148         table.addContainerProperty("foo", String.class, null);
149         table.addContainerProperty("bar", String.class, null);
150         table.addContainerProperty("baz", String.class, null);
151         table.setColumnHeaders("Description", "Milestone", "Status");
152         table.setColumnFooter("foo", "F1");
153         table.setColumnFooter("bar", "F2");
154         table.setColumnFooter("baz", "F3");
155         table.addItem(new Object[] { "r1c1", "r1c2", "r1c3" }, "1");
156         table.addItem(new Object[] { "r2c1", "r2c2", "r2c3" }, "2");
157         table.setFooterVisible(true);
158
159         testRead(design, table);
160         testWrite(design, table, true);
161     }
162
163     @Test
164     public void testHtmlEntities() {
165         String design = "<vaadin7-table>" + "<table>" + "  <colgroup>"
166                 + "    <col property-id=\"test\"" + "  </colgroup>"
167                 + "  <thead>" + "    <tr><th>&amp; Test</th></tr>"
168                 + "  </thead>" + "  <tbody>"
169                 + "    <tr item-id=\"test\"><td>&amp; Test</tr>" + "  </tbody>"
170                 + "  <tfoot>" + "    <tr><td>&amp; Test</td></tr>"
171                 + "  </tfoot>" + "</table>" + "</vaadin7-table>";
172         Table read = read(design);
173
174         assertEquals("& Test",
175                 read.getContainerProperty("test", "test").getValue());
176         assertEquals("& Test", read.getColumnHeader("test"));
177         assertEquals("& Test", read.getColumnFooter("test"));
178     }
179 }