View Javadoc
1 /* 2 * Scope: a generic MVC framework. 3 * Copyright (c) 2000-2002, The Scope team 4 * All rights reserved. 5 * 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 14 * Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * Neither the name "Scope" nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 * 35 * 36 * $Id: PersonModel.java,v 1.3 2002/09/05 15:41:50 ludovicc Exp $ 37 */ 38 package samples.swing.timesheet.model; 39 40 import java.util.List; 41 import org.scopemvc.core.ControlException; 42 43 import org.scopemvc.core.Selector; 44 import org.scopemvc.model.basic.BasicModel; 45 import org.scopemvc.model.collection.ListModel; 46 47 /*** 48 * <p> 49 * 50 * Simple Person model which allows them to enter a name</p> 51 * 52 * @author <a href="mailto:steve.jones@netdecisions.co.uk>;Steve Jones</a> 53 * @created 05 September 2002 54 * @since Scope0.8 v1.0 55 * @version $Revision: 1.3 $ $Date: 2002/09/05 15:41:50 $ 56 */ 57 public class PersonModel extends BasicModel { 58 59 /*** 60 * TODO: describe of the Field 61 */ 62 public final static Selector NAME = Selector.fromString("name"); 63 /*** 64 * TODO: describe of the Field 65 */ 66 public final static Selector PROJECTS = Selector.fromString("projects"); 67 /*** 68 * TODO: describe of the Field 69 */ 70 public final static Selector TIMESHEET = Selector.fromString("timesheet"); 71 72 private String name; 73 private List projects; 74 private TimesheetModel timesheet; 75 76 77 /*** 78 * Constructor for the PersonModel object 79 */ 80 public PersonModel() { 81 name = "Steve"; 82 projects = new ListModel(); 83 timesheet = new TimesheetModel(); 84 85 listenNewSubmodel(PROJECTS); 86 listenNewSubmodel(TIMESHEET); 87 } 88 89 90 /*** 91 * Gets the name 92 * 93 * @return The name value 94 */ 95 public String getName() { 96 return name; 97 } 98 99 /*** 100 * Gets the projects 101 * 102 * @return The projects value 103 */ 104 public List getProjects() { 105 return projects; 106 } 107 108 /*** 109 * Gets the timesheet 110 * 111 * @return The timesheet value 112 */ 113 public TimesheetModel getTimesheet() { 114 return timesheet; 115 } 116 117 118 /*** 119 * Sets the name 120 * 121 * @param inName The new name value 122 */ 123 public void setName(String inName) { 124 name = inName; 125 fireModelChange(VALUE_CHANGED, NAME); 126 } 127 128 129 /*** 130 * TODO: document the method 131 */ 132 public void clearProjects() { 133 projects.clear(); 134 } 135 136 137 /*** 138 * Adds an element to the Project attribute of the PersonModel object 139 * 140 * @param inProject The element to be added to the Project attribute 141 * @throws ControlException TODO: Describe the Exception 142 */ 143 public void addProject(String inProject) throws ControlException { 144 // check that it isn't already in there 145 if (projects.contains(inProject)) { 146 throw new ControlException(inProject + " already exists"); 147 } else if (inProject == null || inProject.trim().length() == 0) { 148 throw new ControlException("A project must have a name"); 149 } 150 projects.add(inProject); 151 } 152 153 154 /*** 155 * TODO: document the method 156 * 157 * @param inProject TODO: Describe the Parameter 158 */ 159 public void removeProject(String inProject) { 160 if (inProject == null) { 161 throw new IllegalArgumentException("null project"); 162 } 163 projects.remove(inProject); 164 } 165 166 }

This page was automatically generated by Maven