aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/itmill/toolkit/tests/TestForTablesInitialColumnWidthLogicRendering.java
blob: 1d33986bf6c1726199ac074b4b136a62ac37d3cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package com.itmill.toolkit.tests;

import java.util.Vector;

import com.itmill.toolkit.ui.Button;
import com.itmill.toolkit.ui.CustomComponent;
import com.itmill.toolkit.ui.Label;
import com.itmill.toolkit.ui.OrderedLayout;
import com.itmill.toolkit.ui.Table;

/**
 * 
 * This Component contains some simple test to see that component updates its
 * contents propertly.
 * 
 * @author IT Mill Ltd.
 */
public class TestForTablesInitialColumnWidthLogicRendering extends
		CustomComponent {

	private OrderedLayout main = new OrderedLayout();

	public TestForTablesInitialColumnWidthLogicRendering() {

		setCompositionRoot(main);
		createNewView();
	}

	public void createNewView() {
		main.removeAllComponents();
		main
				.addComponent(new Label(
						"Below are same tables that all should render somewhat nice. Also when testing, you might want to try resizing window."));

		Table t;

		// t = new Table("Empty table");
		// main.addComponent(t);

		t = getTestTable(5, 0);
		t.setCaption("Table with only headers");
		// main.addComponent(t);

		t = getTestTable(5, 200);
		t.setCaption("Table with  some cols and lot of rows");
		main.addComponent(t);

		t = getTestTable(12, 4);
		t.setCaption("Table with  some rows and lot of columns");
		main.addComponent(t);

		t = getTestTable(3, 40);
		t
				.setCaption("Table with some columns and wide explicit width. (Ought to widen columns to use all space)");
		t.setWidth(1000);
		main.addComponent(t);

		t = getTestTable(12, 4);
		t.setCaption("Table with  some rows and lot of columns, width == 100%");
		t.setWidth(100);
		t.setWidthUnits(Table.UNITS_PERCENTAGE);
		main.addComponent(t);

		t = getTestTable(12, 100);
		t
				.setCaption("Table with  lot of rows and lot of columns, width == 50%");
		t.setWidth(50);
		t.setWidthUnits(Table.UNITS_PERCENTAGE);
		main.addComponent(t);

		t = getTestTable(5, 100);
		t.setCaption("Table with 40 rows");
		// main.addComponent(t);

		t = getTestTable(4, 4);
		t.setCaption("Table with some rows and width = 200px");

		t.setWidth(200);
		main.addComponent(t);

		Button b = new Button("refresh view", this, "createNewView");
		main.addComponent(b);

	}

	public static Table getTestTable(int cols, int rows) {
		Table t = new Table();
		t.setColumnCollapsingAllowed(true);
		for (int i = 0; i < cols; i++) {
			t.addContainerProperty(testString[i], String.class, "");
		}
		for (int i = 0; i < rows; i++) {
			Vector content = new Vector();
			for (int j = 0; j < cols; j++) {
				content.add(rndString());
			}
			t.addItem(content.toArray(), "" + i);
		}
		return t;
	}

	static String[] testString = new String[] { "DSFdsfs", "böö", "1",
			"sdf sdfsd fsdfsdf sdf", "SDF SADds FASDF dsaf", "foo", "VADSFA",
			"DSFSD FS", "whattaa", " sdf sdfsd ", "DSf sdf sdf", "foods f",
			"VADsd fSFA", "DSFsd fSD FS", "wha sdf ttaa", " sd sdff sdfsd ",
			"DSf sdf sdf", "SDFsd sd fadsfadfs" };

	public static String rndString() {
		return testString[(int) (Math.random() * testString.length)];
	}

}