1 /******************************************************************************* 2 * Copyright 2013 Universidad Politécnica de Madrid 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of 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, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 ******************************************************************************/ 16 17 package org.universAAL.ui.handler.gui.swing.model.FormControl.support; 18 19 import java.util.List; 20 21 import org.universAAL.middleware.ui.rdf.Form; 22 import org.universAAL.middleware.ui.rdf.FormControl; 23 import org.universAAL.middleware.ui.rdf.Group; 24 import org.universAAL.middleware.ui.rdf.Repeat; 25 26 /** 27 * This support class is used to generate a list of virtual forms (one per row) so each element of 28 * the repeat ({@link FormControl}) can be Modeled as the rest of {@link FormControl}. 29 * @author amedrano 30 * 31 */ 32 public class RepeatSubdivider { 33 34 /** 35 * {@link Repeat} object to be used. 36 */ 37 private Repeat repeat; 38 39 /** 40 * container for children of {@link #repeat} 41 */ 42 private FormControl[] elems; 43 44 /** 45 * Constructor 46 */ 47 public RepeatSubdivider(Repeat repeat) { 48 this.repeat = repeat; 49 elems = repeat.getChildren(); 50 if (elems == null || elems.length != 1) { 51 throw new IllegalArgumentException("Malformed argument!"); 52 } 53 if (elems[0] instanceof Group) { 54 elems = ((Group) elems[0]).getChildren(); 55 if (elems == null || elems.length == 0) 56 throw new IllegalArgumentException("Malformed argument!"); 57 } else if (elems[0] == null) 58 throw new IllegalArgumentException("Malformed argument!"); 59 60 } 61 62 public FormControl[] getElems(){ 63 return elems; 64 } 65 66 /** 67 * Generates a {@link List} of (virtual) {@link Form}s which each contains in its IOControls group 68 * the corresponding row of {@link FormControl}. 69 * This works because the dataRoot of each form is the corresponding for the row, so each {@link FormControl} 70 * can be modeled as usual. 71 * @return 72 */ 73 public List generateSubForms() { 74 return repeat.virtualFormExpansion(); 75 } 76 }