View Javadoc

1   /*******************************************************************************
2    * Copyright 2013 Universidad Politécnica de Madrid - Life Supporting Technologies
3    * Copyright 2013 Fraunhofer-Gesellschaft - Institute for Computer Graphics Research
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   ******************************************************************************/
17  
18  package org.universAAL.ui.ui.handler.web.html.model;
19  
20  import java.util.Iterator;
21  import java.util.List;
22  import java.util.Properties;
23  
24  import org.universAAL.middleware.ui.rdf.Form;
25  import org.universAAL.middleware.ui.rdf.FormControl;
26  import org.universAAL.middleware.ui.rdf.Group;
27  import org.universAAL.middleware.ui.rdf.Repeat;
28  import org.universAAL.ui.ui.handler.web.html.HTMLUserGenerator;
29  
30  /**
31   * @author amedrano
32   * 
33   */
34  public class RepeatModel extends GroupModel {
35  
36  	/**
37  	 * @param fe
38  	 * @param render
39  	 */
40  	public RepeatModel(Repeat fe, HTMLUserGenerator render) {
41  		super(fe, render);
42  	}
43  
44  	/** {@ inheritDoc} */
45  	public StringBuffer generateHTML() {
46  		List Vforms = ((Repeat) fe).virtualFormExpansion();
47  		int i = 0;
48  		StringBuffer table = new StringBuffer();
49  			FormControl[] headFCs = ((Repeat) fe).getChildren();
50  			if (headFCs[0] instanceof Group){
51  				headFCs = ((Group) headFCs[0]).getChildren();
52  			}
53  		StringBuffer title = getLabelModel().getImgText();
54  		if (title.length() > 0){
55  			//  add label (spanning first row)
56  			Properties head = new Properties();
57  			head.put("class", "repeatLabel");
58  			if (headFCs.length > 1)
59  				head.put("colspan", Integer.toString(headFCs.length));
60  			table.append(tag("tr", tag("th", title, head), null));
61  		}
62  		// and row headers
63  		StringBuffer th = new StringBuffer();
64  		for (int j = 0; j < headFCs.length; j++) {
65  			FormControlModel fcm = (FormControlModel) getRenderer().getModelMapper().getModelFor(headFCs[j]);
66  			StringBuffer label = fcm.getLabelModel().getImgText();
67  			Properties lp = new Properties();
68  			lp.put("class", "repeatColLabel");
69  			th.append(tag("th", label, lp));
70  		}
71  		table.append(tag("tr", th, null));
72  		for (Iterator it = Vforms.iterator(); it.hasNext();) {
73  			Form f = (Form) it.next();
74  			StringBuffer rowHTML = new StringBuffer();
75  			FormControl[] fcs = f.getIOControls().getChildren();
76  			for (int col = 0; col < fcs.length; col++) {
77  				rowHTML.append(tag("td",
78  				// don't add labels on cells
79  						((FormControlModel) getModelFor(fcs[col]))
80  								.generateHTMLWithoutLabel(), null));
81  			}
82  			table.append(tag("tr", rowHTML, null));
83  			i++;
84  		}
85  		fcProps.put("class", "repeat");
86  		return tag("table", table, fcProps);
87  	}
88  
89  }