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.PopupPanel; |
19 | import com.google.gwt.user.client.ui.UIObject; |
20 | |
21 | /** |
22 | * Panel Model |
23 | * |
24 | * @author Steve McDuff |
25 | * |
26 | */ |
27 | public class PopupPanelModel extends SimplePanelModel |
28 | { |
29 | |
30 | /** |
31 | * serialVersionUID |
32 | */ |
33 | private static final long serialVersionUID = -2313259052846810682L; |
34 | |
35 | /** |
36 | * is auto hide enabled |
37 | */ |
38 | private boolean isAutoHideEnabled = false; |
39 | |
40 | /** |
41 | * is modal |
42 | */ |
43 | private boolean isModal = false; |
44 | |
45 | /** |
46 | * get the Pop up Panel |
47 | * |
48 | * @return the Pop up panel |
49 | */ |
50 | public PopupPanel getPopupPanel() |
51 | { |
52 | return (PopupPanel) getUIObject(); |
53 | } |
54 | |
55 | /** |
56 | * (non-JSDoc) |
57 | * |
58 | * @see org.deduced.viewer.web.shared.SimplePanelModel#deleteChildModels() |
59 | */ |
60 | @Override |
61 | protected void deleteChildModels() |
62 | { |
63 | PopupPanel popupPanel = getPopupPanel(); |
64 | if (popupPanel != null) |
65 | { |
66 | popupPanel.hide(); |
67 | } |
68 | |
69 | super.deleteChildModels(); |
70 | } |
71 | |
72 | /** |
73 | * (non-JSDoc) |
74 | * |
75 | * @see org.deduced.viewer.web.shared.SimplePanelModel#createUIObject() |
76 | */ |
77 | @Override |
78 | public UIObject createUIObject() |
79 | { |
80 | return new PopupPanel(); |
81 | } |
82 | |
83 | /** |
84 | * is Auto Hide Enabled |
85 | * |
86 | * @return true if automatic hide is enabled |
87 | */ |
88 | public boolean isAutoHideEnabled() |
89 | { |
90 | return isAutoHideEnabled; |
91 | } |
92 | |
93 | /** |
94 | * set Auto Hide Enabled |
95 | * |
96 | * @param setIsAutoHideEnabled new auto hide enabled flag |
97 | */ |
98 | public void setIsAutoHideEnabled( |
99 | boolean setIsAutoHideEnabled) |
100 | { |
101 | isAutoHideEnabled = setIsAutoHideEnabled; |
102 | } |
103 | |
104 | /** |
105 | * is Modal |
106 | * |
107 | * @return true if the dialog is modal |
108 | */ |
109 | public boolean isModal() |
110 | { |
111 | return isModal; |
112 | } |
113 | |
114 | /** |
115 | * set Modal |
116 | * |
117 | * @param setIsModal new modal flag |
118 | */ |
119 | public void setIsModal( |
120 | boolean setIsModal) |
121 | { |
122 | isModal = setIsModal; |
123 | } |
124 | |
125 | /** |
126 | * (non-JSDoc) |
127 | * |
128 | * @see org.deduced.viewer.web.shared.UserInterfaceModel#propertyChanged(org.deduced.viewer.web.shared.ChangeEvent) |
129 | */ |
130 | @SuppressWarnings("boxing") |
131 | @Override |
132 | public void propertyChanged( |
133 | ChangeEvent event) |
134 | { |
135 | if (Utilities.equals(event.getName(), "is auto hide enabled")) |
136 | { |
137 | setIsAutoHideEnabled((Boolean) event.getSerializableValue()); |
138 | synchronizeWithUI(); |
139 | } |
140 | else if (Utilities.equals(event.getName(), "is modal")) |
141 | { |
142 | setIsModal((Boolean) event.getSerializableValue()); |
143 | synchronizeWithUI(); |
144 | } |
145 | else |
146 | { |
147 | super.propertyChanged(event); |
148 | } |
149 | } |
150 | |
151 | /** |
152 | * (non-JSDoc) |
153 | * |
154 | * @see org.deduced.viewer.web.shared.SimplePanelModel#internalSynchronizeWithUI() |
155 | */ |
156 | @Override |
157 | public void internalSynchronizeWithUI() |
158 | { |
159 | PopupPanel popupPanel = getPopupPanel(); |
160 | |
161 | popupPanel.setModal(isModal()); |
162 | popupPanel.setAutoHideEnabled(isAutoHideEnabled()); |
163 | |
164 | if (isVisible()) |
165 | { |
166 | popupPanel.show(); |
167 | } |
168 | else |
169 | { |
170 | popupPanel.hide(); |
171 | } |
172 | |
173 | super.internalSynchronizeWithUI(); |
174 | } |
175 | } |