Skip to main content
summaryrefslogtreecommitdiffstats
blob: a2912500dc12f5e1f19c9e655ab0f75c745a48d4 (plain) (blame)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/**
 * Copyright (c) 2011, 2014 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors: 
 * 		Florian Pirchner - Initial implementation
 */

package org.eclipse.osbp.runtime.web.ecview.presentation.vaadin.tests.ui.samples;

import org.eclipse.osbp.ecview.core.common.context.ContextException;
import org.eclipse.osbp.ecview.core.common.model.binding.YBindingSet;
import org.eclipse.osbp.ecview.core.common.model.core.YView;
import org.eclipse.osbp.ecview.core.extension.model.extension.YHorizontalLayout;
import org.eclipse.osbp.ecview.core.extension.model.extension.YLabel;
import org.eclipse.osbp.ecview.core.extension.model.extension.YSelectionType;
import org.eclipse.osbp.ecview.core.extension.model.extension.YTable;
import org.eclipse.osbp.ecview.core.extension.model.extension.YVerticalLayout;
import org.eclipse.osbp.ecview.core.extension.model.extension.util.SimpleExtensionModelFactory;
import org.eclipse.osbp.runtime.web.ecview.presentation.vaadin.VaadinRenderer;

import com.vaadin.ui.CssLayout;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Label;

public class TableSample extends CustomComponent {

	private final SimpleExtensionModelFactory factory = new SimpleExtensionModelFactory();

	private CssLayout layout;

	private YView yView;

	private YBindingSet yBindingSet;

	private YVerticalLayout yLayout;

	public TableSample() {
		layout = new CssLayout();
		setCompositionRoot(layout);

		init();
	}

	protected void init() {

		// TODO - fix me FP

		yView = factory.createView();
		yLayout = factory.createVerticalLayout();
		yView.setContent(yLayout);

		yBindingSet = yView.getOrCreateBindingSet();

		row1();

		row2();

		// render now, fill in values later
		// to avoid overwriting values with bindings to empty fields
		VaadinRenderer renderer = new VaadinRenderer();
		try {
			renderer.render(layout, yView, null);
		} catch (ContextException e) {
			layout.addComponent(new Label(e.toString()));
		}
	}

	// public void row2() {
	// // test row 2
	// YHorizontalLayout row2 = factory.createHorizontalLayout();
	// yLayout.addElement(row2);
	//
	// YTable yTable2_1 = factory.createTable();
	// yTable2_1.setLabel("minLength 3");
	// row2.addElement(yTable2_1);
	//
	// YTable yTable2_2 = factory.createTable();
	// yTable2_2.setLabel("maxLength 10:");
	// row2.addElement(yTable2_2);
	//
	// YTable yTable2_3 = factory.createTable();
	// yTable2_3.setLabel("regexp: \\d+");
	// row2.addElement(yTable2_3);
	// }

	public void row1() {
		// test row 1
		YHorizontalLayout row1 = factory.createHorizontalLayout();
		yLayout.addElement(row1);

		YLabel label = factory.createLabel();
		label.setLabel("SingleSelection");
		row1.addElement(label);
		YTable yTable1_1 = factory.createTable();
		yTable1_1.setId("Field1");
		yTable1_1.setLabel("Field1");
		yTable1_1.setType(Bean.class);
		YTable yTable1_2 = factory.createTable();
		yTable1_2.setId("Field2");
		yTable1_2.setLabel("Field2");
		yTable1_2.setType(Bean.class);
		row1.addElement(yTable1_1);
		row1.addElement(yTable1_2);

		yTable1_2.getCollection().add(new Bean("Sabrina"));
		yTable1_2.getCollection().add(new Bean("Klemens"));
		yTable1_2.getCollection().add(new Bean("Flo"));

		yBindingSet.addBinding(yTable1_1.createCollectionEndpoint(),
				yTable1_2.createCollectionEndpoint());
		yBindingSet.addBinding(yTable1_1.createSelectionEndpoint(),
				yTable1_2.createSelectionEndpoint());
	}

	public void row2() {
		// test row 2
		YHorizontalLayout row1 = factory.createHorizontalLayout();
		yLayout.addElement(row1);

		YLabel label = factory.createLabel();
		label.setLabel("Multi Selection");
		row1.addElement(label);
		YTable yTable1_1 = factory.createTable();
		yTable1_1.setId("Field3");
		yTable1_1.setLabel("Field3");
		yTable1_1.setType(Bean.class);
		yTable1_1.setSelectionType(YSelectionType.MULTI);
		YTable yTable1_2 = factory.createTable();
		yTable1_2.setId("Field4");
		yTable1_2.setLabel("Field4");
		yTable1_2.setType(Bean.class);
		yTable1_2.setSelectionType(YSelectionType.MULTI);
		row1.addElement(yTable1_1);
		row1.addElement(yTable1_2);

		yTable1_2.getCollection().add(new Bean("Sabrina"));
		yTable1_2.getCollection().add(new Bean("Klemens"));
		yTable1_2.getCollection().add(new Bean("Flo"));

		yBindingSet.addBinding(yTable1_1.createCollectionEndpoint(),
				yTable1_2.createCollectionEndpoint());
		yBindingSet.addBinding(yTable1_1.createMultiSelectionEndpoint(),
				yTable1_2.createMultiSelectionEndpoint());
	}

	public static final class Bean {
		private String name;

		public Bean(String name) {
			super();
			this.name = name;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

	}
}

Back to the top