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.serializer; |
17 | |
18 | import java.io.Serializable; |
19 | |
20 | import org.deduced.PropertyCollection; |
21 | import org.deduced.viewer.model.combobox.implementation.ComboBoxImplementation; |
22 | import org.deduced.viewer.model.implementation.FocusComponentImplementation; |
23 | import org.deduced.viewer.web.shared.ComboBoxModel; |
24 | import org.deduced.viewer.web.shared.Model; |
25 | import org.deduced.viewer.web.shared.OrderedComboBoxItemModel; |
26 | import org.deduced.viewer.web.shared.OrderedListModel; |
27 | |
28 | /** |
29 | * ComboBoxModel Serializer |
30 | * |
31 | * @author Steve McDuff |
32 | * |
33 | */ |
34 | public class ComboBoxModelSerializer extends WidgetModelSerializer |
35 | { |
36 | /** |
37 | * fill ComboBox Model |
38 | * |
39 | * @param model the model to serialize |
40 | * @param comboBoxModel the model to fill |
41 | * @param masterSerializer the master serializer used to serialize child |
42 | * objects |
43 | */ |
44 | @SuppressWarnings("unchecked") |
45 | public static void fillComboBoxModel( |
46 | PropertyCollection<?, ?> model, ComboBoxModel comboBoxModel, |
47 | MasterWebSerializer masterSerializer) |
48 | { |
49 | PropertyCollection<?, ?> widgetList = |
50 | ComboBoxImplementation.getOrderedComboBoxItemList(model); |
51 | |
52 | OrderedListModel<OrderedComboBoxItemModel> serializedList = |
53 | (OrderedListModel<OrderedComboBoxItemModel>) masterSerializer |
54 | .serialize(widgetList); |
55 | |
56 | comboBoxModel.setOrderedComboBoxItemList(serializedList); |
57 | |
58 | PropertyCollection selectedUserInterfaceElement = |
59 | ComboBoxImplementation.getSelection(model); |
60 | if (selectedUserInterfaceElement != null) |
61 | { |
62 | String selectedUserElementID = getID(selectedUserInterfaceElement); |
63 | comboBoxModel.setSelection(selectedUserElementID); |
64 | } |
65 | |
66 | comboBoxModel.setVisibleRowCount(ComboBoxImplementation |
67 | .getVisibleRowCount(model)); |
68 | |
69 | comboBoxModel.setEnabled(FocusComponentImplementation.isEnabled(model) |
70 | .booleanValue()); |
71 | } |
72 | |
73 | /** |
74 | * (non-JSDoc) |
75 | * |
76 | * @see org.deduced.viewer.web.serializer.WidgetModelSerializer#createSerializedObject(org.deduced.PropertyCollection) |
77 | */ |
78 | @Override |
79 | public Model createSerializedObject( |
80 | PropertyCollection<?, ?> collection) |
81 | { |
82 | return new ComboBoxModel(); |
83 | } |
84 | |
85 | /** |
86 | * (non-JSDoc) |
87 | * |
88 | * @see org.deduced.viewer.web.serializer.UserInterfaceModelSerializer#fillSerializedObject(java.io.Serializable, |
89 | * org.deduced.PropertyCollection, |
90 | * org.deduced.viewer.web.serializer.MasterWebSerializer) |
91 | */ |
92 | @Override |
93 | public void fillSerializedObject( |
94 | Serializable serializedObject, PropertyCollection<?, ?> collection, |
95 | MasterWebSerializer masterSerializer) |
96 | { |
97 | fillComboBoxModel(collection, (ComboBoxModel) serializedObject, |
98 | masterSerializer); |
99 | |
100 | super.fillSerializedObject(serializedObject, collection, |
101 | masterSerializer); |
102 | } |
103 | } |