| 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 com.google.gwt.user.client.ui.SimplePanel; |
| 19 | import com.google.gwt.user.client.ui.UIObject; |
| 20 | import com.google.gwt.user.client.ui.Widget; |
| 21 | |
| 22 | /** |
| 23 | * SimplePanel Model |
| 24 | * |
| 25 | * @author Steve McDuff |
| 26 | * |
| 27 | */ |
| 28 | public class SimplePanelModel extends PanelModel |
| 29 | { |
| 30 | |
| 31 | /** |
| 32 | * serialVersionUID |
| 33 | */ |
| 34 | private static final long serialVersionUID = 1738021180710871458L; |
| 35 | |
| 36 | /** |
| 37 | * |
| 38 | * SimplePanelModel constructor |
| 39 | */ |
| 40 | public SimplePanelModel() |
| 41 | { |
| 42 | |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * (non-JSDoc) |
| 47 | * |
| 48 | * @see org.deduced.viewer.web.shared.WidgetModel#createUIObject() |
| 49 | */ |
| 50 | @Override |
| 51 | public UIObject createUIObject() |
| 52 | { |
| 53 | return new SimplePanel(); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * get Simple Panel |
| 58 | * |
| 59 | * @return the simple panel |
| 60 | */ |
| 61 | public SimplePanel getSimplePanel() |
| 62 | { |
| 63 | return (SimplePanel) getUIObject(); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * component model of the scroll panel |
| 68 | */ |
| 69 | private WidgetModel component; |
| 70 | |
| 71 | /** |
| 72 | * (non-JSDoc) |
| 73 | * |
| 74 | * @see org.deduced.viewer.web.shared.UserInterfaceModel#propertyChanged(org.deduced.viewer.web.shared.ChangeEvent) |
| 75 | */ |
| 76 | @Override |
| 77 | public void propertyChanged( |
| 78 | ChangeEvent event) |
| 79 | { |
| 80 | if (Utilities.equals(event.getName(), "component")) |
| 81 | { |
| 82 | WidgetModel newComponent = |
| 83 | (WidgetModel) event.getSerializableValue(); |
| 84 | |
| 85 | updateComponent(newComponent); |
| 86 | } |
| 87 | else |
| 88 | { |
| 89 | super.propertyChanged(event); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * update Component |
| 95 | * |
| 96 | * @param newComponent the new component widget to use |
| 97 | */ |
| 98 | public void updateComponent( |
| 99 | WidgetModel newComponent) |
| 100 | { |
| 101 | setComponent(updateModel(newComponent, getComponent(), this)); |
| 102 | synchronizeWithUI(); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * (non-JSDoc) |
| 107 | * |
| 108 | * @see org.deduced.viewer.web.shared.UserInterfaceModel#internalSynchronizeWithUI() |
| 109 | */ |
| 110 | @Override |
| 111 | public void internalSynchronizeWithUI() |
| 112 | { |
| 113 | SimplePanel simplePanel = getSimplePanel(); |
| 114 | Widget childWidget = simplePanel.getWidget(); |
| 115 | Widget newChild = null; |
| 116 | if (getComponent() != null) |
| 117 | { |
| 118 | newChild = getComponent().getWidget(); |
| 119 | } |
| 120 | |
| 121 | if (childWidget != newChild) |
| 122 | { |
| 123 | simplePanel.setWidget(newChild); |
| 124 | } |
| 125 | |
| 126 | super.internalSynchronizeWithUI(); |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * (non-JSDoc) |
| 131 | * |
| 132 | * @see org.deduced.viewer.web.shared.Model#deleteChildModels() |
| 133 | */ |
| 134 | @Override |
| 135 | protected void deleteChildModels() |
| 136 | { |
| 137 | deleteComponent(); |
| 138 | super.deleteChildModels(); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * delete the Component of the scroll panel |
| 143 | */ |
| 144 | private void deleteComponent() |
| 145 | { |
| 146 | if (getComponent() != null) |
| 147 | { |
| 148 | getComponent().delete(); |
| 149 | setComponent(null); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * (non-JSDoc) |
| 155 | * |
| 156 | * @see org.deduced.viewer.web.shared.Model#registerChildModels() |
| 157 | */ |
| 158 | @Override |
| 159 | protected void registerChildModels() |
| 160 | { |
| 161 | registerChildModel(getComponent(), this); |
| 162 | super.registerChildModels(); |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * @param setComponent the component to set |
| 167 | */ |
| 168 | public void setComponent( |
| 169 | WidgetModel setComponent) |
| 170 | { |
| 171 | component = setComponent; |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * @return the component |
| 176 | */ |
| 177 | public WidgetModel getComponent() |
| 178 | { |
| 179 | return component; |
| 180 | } |
| 181 | |
| 182 | } |