| 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.io.Serializable; |
| 19 | |
| 20 | /** |
| 21 | * View Model |
| 22 | * |
| 23 | * @author Steve McDuff |
| 24 | * |
| 25 | */ |
| 26 | public class ViewModel extends Model implements ModelContainer, Serializable |
| 27 | { |
| 28 | |
| 29 | /** |
| 30 | * serialVersionUID |
| 31 | */ |
| 32 | private static final long serialVersionUID = -3960040177369494395L; |
| 33 | |
| 34 | /** |
| 35 | * popup panel list |
| 36 | */ |
| 37 | private ModelListModel<PopupPanelModel> popupPanelList = |
| 38 | new ModelListModel<PopupPanelModel>(); |
| 39 | |
| 40 | /** |
| 41 | * root component |
| 42 | */ |
| 43 | private WidgetModel rootComponent; |
| 44 | |
| 45 | /** |
| 46 | * root widget control |
| 47 | */ |
| 48 | private transient RootWidgetControl rootWidgetControl; |
| 49 | |
| 50 | /** |
| 51 | * name |
| 52 | */ |
| 53 | private String name; |
| 54 | |
| 55 | /** |
| 56 | * |
| 57 | * ScrollPanelModel constructor |
| 58 | */ |
| 59 | public ViewModel() |
| 60 | { |
| 61 | popupPanelList.setParent(this); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * get Name |
| 66 | * |
| 67 | * @return the name |
| 68 | */ |
| 69 | public String getName() |
| 70 | { |
| 71 | return name; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * set Name |
| 76 | * |
| 77 | * @param setName new name |
| 78 | */ |
| 79 | public void setName( |
| 80 | String setName) |
| 81 | { |
| 82 | name = setName; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * (non-JSDoc) |
| 87 | * |
| 88 | * @see org.deduced.viewer.web.shared.Model#propertyChanged(org.deduced.viewer.web.shared.ChangeEvent) |
| 89 | */ |
| 90 | @Override |
| 91 | public void propertyChanged( |
| 92 | ChangeEvent event) |
| 93 | { |
| 94 | if (Utilities.equals(event.getName(), "popup panel list")) |
| 95 | { |
| 96 | @SuppressWarnings("unchecked") |
| 97 | ModelListModel<PopupPanelModel> newList = |
| 98 | (ModelListModel<PopupPanelModel>) event.getSerializableValue(); |
| 99 | |
| 100 | popupListChanged(newList); |
| 101 | } |
| 102 | else if (Utilities.equals(event.getName(), "root component")) |
| 103 | { |
| 104 | WidgetModel newModel = (WidgetModel) event.getSerializableValue(); |
| 105 | WidgetModel currentRoot = getRootComponent(); |
| 106 | WidgetModel updateModel = updateModel(newModel, currentRoot, this); |
| 107 | setRootComponent(updateModel); |
| 108 | synchronizeWithUI(); |
| 109 | } |
| 110 | else if (Utilities.equals(event.getName(), "name")) |
| 111 | { |
| 112 | setName((String) event.getSerializableValue()); |
| 113 | synchronizeWithUI(); |
| 114 | } |
| 115 | else |
| 116 | { |
| 117 | super.propertyChanged(event); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * popup List Changed |
| 123 | * |
| 124 | * @param newList the new list |
| 125 | */ |
| 126 | private void popupListChanged( |
| 127 | ModelListModel<PopupPanelModel> newList) |
| 128 | { |
| 129 | ModelListModel<PopupPanelModel> currentPopupPanelList = |
| 130 | getPopupPanelList(); |
| 131 | ModelListModel<PopupPanelModel> updatedList = |
| 132 | updateModel(newList, currentPopupPanelList, this); |
| 133 | setPopupPanelList(updatedList); |
| 134 | |
| 135 | synchronizeWithUI(); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * synchronize With UI |
| 140 | */ |
| 141 | public void synchronizeWithUI() |
| 142 | { |
| 143 | if (rootWidgetControl != null) |
| 144 | { |
| 145 | rootWidgetControl.setRootWidget(rootComponent); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * get Popup Panel List |
| 151 | * |
| 152 | * @return Popup Panel List |
| 153 | */ |
| 154 | public ModelListModel<PopupPanelModel> getPopupPanelList() |
| 155 | { |
| 156 | return popupPanelList; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * set Popup Panel List |
| 161 | * |
| 162 | * @param setPopupPanelList Popup Panel List |
| 163 | */ |
| 164 | public void setPopupPanelList( |
| 165 | ModelListModel<PopupPanelModel> setPopupPanelList) |
| 166 | { |
| 167 | popupPanelList = setPopupPanelList; |
| 168 | if (popupPanelList != null) |
| 169 | { |
| 170 | popupPanelList.setParent(this); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * get Root Component |
| 176 | * |
| 177 | * @return Root Component |
| 178 | */ |
| 179 | public WidgetModel getRootComponent() |
| 180 | { |
| 181 | return rootComponent; |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * set Root Component |
| 186 | * |
| 187 | * @param setRootComponent Root Component |
| 188 | */ |
| 189 | public void setRootComponent( |
| 190 | WidgetModel setRootComponent) |
| 191 | { |
| 192 | rootComponent = setRootComponent; |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * get Root Widget Control |
| 197 | * |
| 198 | * @return Root Widget Control |
| 199 | */ |
| 200 | public RootWidgetControl getRootWidgetControl() |
| 201 | { |
| 202 | return rootWidgetControl; |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * set Root Widget Control |
| 207 | * |
| 208 | * @param setRootWidgetControl Root Widget Control |
| 209 | */ |
| 210 | public void setRootWidgetControl( |
| 211 | RootWidgetControl setRootWidgetControl) |
| 212 | { |
| 213 | rootWidgetControl = setRootWidgetControl; |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * (non-JSDoc) |
| 218 | * |
| 219 | * @see org.deduced.viewer.web.shared.ModelContainer#modelChanged(org.deduced.viewer.web.shared.Model) |
| 220 | */ |
| 221 | @Override |
| 222 | public void modelChanged( |
| 223 | Model model) |
| 224 | { |
| 225 | synchronizeWithUI(); |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * (non-JSDoc) |
| 230 | * |
| 231 | * @see org.deduced.viewer.web.shared.Model#deleteChildModels() |
| 232 | */ |
| 233 | @Override |
| 234 | protected void deleteChildModels() |
| 235 | { |
| 236 | deletePopupPanelList(); |
| 237 | deleteRootComponent(); |
| 238 | super.deleteChildModels(); |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * delete the popup panel list |
| 243 | */ |
| 244 | private void deletePopupPanelList() |
| 245 | { |
| 246 | deleteChildModel(getPopupPanelList()); |
| 247 | setPopupPanelList(null); |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * delete the root component |
| 252 | */ |
| 253 | private void deleteRootComponent() |
| 254 | { |
| 255 | deleteChildModel(getRootComponent()); |
| 256 | setRootComponent(null); |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * (non-JSDoc) |
| 261 | * |
| 262 | * @see org.deduced.viewer.web.shared.Model#registerChildModels() |
| 263 | */ |
| 264 | @Override |
| 265 | protected void registerChildModels() |
| 266 | { |
| 267 | registerChildModel(getRootComponent(), this); |
| 268 | registerChildModel(getPopupPanelList(), this); |
| 269 | super.registerChildModels(); |
| 270 | } |
| 271 | |
| 272 | } |