| 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.FocusWidget; |
| 19 | |
| 20 | /** |
| 21 | * FocusWidgetModel |
| 22 | * |
| 23 | * @author Steve McDuff |
| 24 | * |
| 25 | */ |
| 26 | public abstract class FocusWidgetModel extends WidgetModel |
| 27 | { |
| 28 | /** |
| 29 | * serialVersionUID |
| 30 | */ |
| 31 | private static final long serialVersionUID = -4141904578169609000L; |
| 32 | |
| 33 | /** |
| 34 | * is the widget enabled |
| 35 | */ |
| 36 | private boolean enabled; |
| 37 | |
| 38 | /** |
| 39 | * get Focus Widget |
| 40 | * |
| 41 | * @return the focus widget |
| 42 | */ |
| 43 | public FocusWidget getFocusWidget() |
| 44 | { |
| 45 | return (FocusWidget) getUIObject(); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * (non-JSDoc) |
| 50 | * |
| 51 | * @see org.deduced.viewer.web.shared.UserInterfaceModel#internalSynchronizeWithUI() |
| 52 | */ |
| 53 | @Override |
| 54 | public void internalSynchronizeWithUI() |
| 55 | { |
| 56 | super.internalSynchronizeWithUI(); |
| 57 | FocusWidget focusWidget = getFocusWidget(); |
| 58 | focusWidget.setEnabled(isEnabled()); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * (non-JSDoc) |
| 63 | * |
| 64 | * @see org.deduced.viewer.web.shared.UserInterfaceModel#propertyChanged(org.deduced.viewer.web.shared.ChangeEvent) |
| 65 | */ |
| 66 | @Override |
| 67 | public void propertyChanged( |
| 68 | ChangeEvent event) |
| 69 | { |
| 70 | if (Utilities.equals(event.getName(), "enabled")) |
| 71 | { |
| 72 | setEnabled(((Boolean) event.getSerializableValue()).booleanValue()); |
| 73 | synchronizeWithUI(); |
| 74 | } |
| 75 | else |
| 76 | { |
| 77 | super.propertyChanged(event); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * @param setEnabled is the widget enabled |
| 83 | */ |
| 84 | public void setEnabled( |
| 85 | boolean setEnabled) |
| 86 | { |
| 87 | enabled = setEnabled; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * @return true if the widget is enabled |
| 92 | */ |
| 93 | public boolean isEnabled() |
| 94 | { |
| 95 | return enabled; |
| 96 | } |
| 97 | } |