| 1 | /** |
| 2 | * Copyright 2005-2011 Steve McDuff d-duff@users.sourceforge.net |
| 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.deduced.viewer.web.shared; |
| 17 | |
| 18 | import java.util.ArrayList; |
| 19 | |
| 20 | /** |
| 21 | * |
| 22 | * String List Model |
| 23 | * |
| 24 | * @author Steve McDuff |
| 25 | * |
| 26 | */ |
| 27 | public class StringListModel extends Model |
| 28 | { |
| 29 | |
| 30 | /** |
| 31 | * serialVersionUID |
| 32 | */ |
| 33 | private static final long serialVersionUID = 2149042601867247028L; |
| 34 | /** |
| 35 | * the list of model |
| 36 | */ |
| 37 | private ArrayList<String> list = new ArrayList<String>(); |
| 38 | |
| 39 | /** |
| 40 | * |
| 41 | * ListModel constructor |
| 42 | */ |
| 43 | public StringListModel() |
| 44 | { |
| 45 | |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * (non-JSDoc) |
| 50 | * |
| 51 | * @see org.deduced.viewer.web.shared.Model#propertyChanged(org.deduced.viewer.web.shared.ChangeEvent) |
| 52 | */ |
| 53 | @SuppressWarnings("unchecked") |
| 54 | @Override |
| 55 | public void propertyChanged( |
| 56 | ChangeEvent event) |
| 57 | { |
| 58 | if (isEventAdd(event)) |
| 59 | { |
| 60 | String modelToAdd = null; |
| 61 | |
| 62 | modelToAdd = (String) event.getSerializableValue(); |
| 63 | |
| 64 | add(modelToAdd); |
| 65 | } |
| 66 | else if (isEventRemove(event)) |
| 67 | { |
| 68 | handleRemoveEvent(event); |
| 69 | } |
| 70 | else |
| 71 | { |
| 72 | super.propertyChanged(event); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * handle Remove Event |
| 78 | * |
| 79 | * @param event the remove event |
| 80 | */ |
| 81 | @SuppressWarnings("unchecked") |
| 82 | public void handleRemoveEvent( |
| 83 | ChangeEvent event) |
| 84 | { |
| 85 | remove((String) event.getSerializableValue()); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * remove a model from the list |
| 90 | * |
| 91 | * @param modelToRemove model to remove from the list |
| 92 | */ |
| 93 | public void remove( |
| 94 | String modelToRemove) |
| 95 | { |
| 96 | getList().remove(modelToRemove); |
| 97 | notifyParentThatModelChanged(); |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * add a model to the list |
| 102 | * |
| 103 | * @param newModel the model to add |
| 104 | */ |
| 105 | public void add( |
| 106 | String newModel) |
| 107 | { |
| 108 | getList().add(newModel); |
| 109 | notifyParentThatModelChanged(); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * (non-JSDoc) |
| 114 | * |
| 115 | * @see org.deduced.viewer.web.shared.Model#deleteChildModels() |
| 116 | */ |
| 117 | @Override |
| 118 | protected void deleteChildModels() |
| 119 | { |
| 120 | getList().clear(); |
| 121 | super.deleteChildModels(); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * @return the list |
| 126 | */ |
| 127 | public ArrayList<String> getList() |
| 128 | { |
| 129 | return list; |
| 130 | } |
| 131 | |
| 132 | } |