1 /******************************************************************************* 2 * Copyright 2011 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 package org.universAAL.ui.handler.gui.swing.model.FormControl; 17 18 import org.universAAL.middleware.rdf.TypeMapper; 19 import org.universAAL.middleware.ui.rdf.FormControl; 20 import org.universAAL.middleware.ui.rdf.Group; 21 import org.universAAL.middleware.ui.rdf.Repeat; 22 import org.universAAL.middleware.ui.rdf.SubdialogTrigger; 23 import org.universAAL.middleware.ui.rdf.Submit; 24 import org.universAAL.ui.handler.gui.swing.Renderer; 25 26 /** 27 * @author <a href="mailto:amedrano@lst.tfo.upm.es">amedrano</a> 28 * @see Repeat 29 */ 30 public abstract class RepeatModel extends GroupModel { 31 32 /** 33 * Place holder for tables 34 */ 35 protected RepeatModelTable table; 36 37 /** 38 * Place holder for grids 39 */ 40 protected RepeatModelGrid grid; 41 42 /** 43 * Constructor 44 * @param control the {@link Repeat} which to model. 45 */ 46 public RepeatModel(Repeat control, Renderer render) { 47 super(control, render); 48 } 49 50 /** 51 * get the java {@link Class} of the children. 52 * @return 53 * {@link Class} of the 1st child. 54 */ 55 protected Class getChildrenType() { 56 FormControl[] children = ((Repeat) fc).getChildren(); 57 if (children != null && children.length > 0) { 58 return TypeMapper.getJavaClass(children[0].getTypeURI()); 59 } 60 return null; 61 } 62 63 /** 64 * check if the {@link Repeat} {@link FormControl} models a table. 65 * @return 66 * <code>true</code> is it does model a table. 67 * <code>false</code> otherwise. 68 */ 69 protected boolean isATable() { 70 /* 71 * Check that the children type is Group 72 */ 73 // if (getChildrenType() != null 74 // && getChildrenType().equals(Group.class)) { 75 // FormControl[] child = ((Repeat) fc).getChildren(); 76 // int i = 0; 77 // LevelRating complexity = LevelRating.none; 78 // Class last = child[0].getClass(); 79 // while (i < child.length 80 // && child[i].getClass() == last 81 // && complexity == ((Group) child[i]).getComplexity()) 82 // { i++; } 83 // return i == child.length; 84 // } 85 // else { 86 // return false; 87 // } 88 FormControl[] chd = ((Repeat) fc).getChildren(); 89 return chd.length > 0 && chd[0] instanceof Group; 90 } 91 92 93 /** 94 * Overriding update from {@link GroupModel} 95 */ 96 public void update() { 97 if (table != null){ 98 table.update(); 99 needsLabel = table.needsLabel; 100 } 101 else if (grid != null){ 102 grid.update(); 103 needsLabel = grid.needsLabel; 104 } 105 super.update(); 106 } 107 108 /** 109 * Tells whether this repeat has or not {@link Submit}s (or {@link SubdialogTrigger}s). 110 * @return true iff there is a {@link Submit} (or subclass of) as child. 111 */ 112 public boolean containsSubmits() { 113 boolean contains = false; 114 FormControl[] fcs = ((Repeat)fc).getChildren(); 115 for (int i = 0; i < fcs.length; i++) { 116 if (fcs[i] instanceof Submit){ 117 contains = true; 118 return contains; 119 } 120 } 121 return contains; 122 } 123 }