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 | /** |
19 | * Ordered Tree Item Model is used by ordered tree item lists to store the |
20 | * ordering information and a link to the tree item itself. |
21 | * |
22 | * @author Steve McDuff |
23 | * |
24 | */ |
25 | public class OrderedComboBoxItemModel extends OrderedModel implements |
26 | ModelContainer |
27 | { |
28 | |
29 | /** |
30 | * serialVersionUID |
31 | */ |
32 | private static final long serialVersionUID = -8918806048071335745L; |
33 | |
34 | /** |
35 | * the ordered combo box item model |
36 | */ |
37 | private ComboBoxItemModel comboBoxItem; |
38 | |
39 | /** |
40 | * |
41 | * OrderedComboBoxItemModel constructor |
42 | */ |
43 | public OrderedComboBoxItemModel() |
44 | { |
45 | |
46 | } |
47 | |
48 | /** |
49 | * (non-JSDoc) |
50 | * |
51 | * @see org.deduced.viewer.web.shared.Model#registerChildModels() |
52 | */ |
53 | @Override |
54 | protected void registerChildModels() |
55 | { |
56 | registerChildModel(getComboBoxItem(), this); |
57 | super.registerChildModels(); |
58 | } |
59 | |
60 | /** |
61 | * (non-JSDoc) |
62 | * |
63 | * @see org.deduced.viewer.web.shared.OrderedModel#propertyChanged(org.deduced.viewer.web.shared.ChangeEvent) |
64 | */ |
65 | @Override |
66 | public void propertyChanged( |
67 | ChangeEvent event) |
68 | { |
69 | if (Utilities.equals(event.getName(), "combo box item")) |
70 | { |
71 | ComboBoxItemModel newComboBoxItem = |
72 | (ComboBoxItemModel) event.getSerializableValue(); |
73 | |
74 | updateComboBoxItem(newComboBoxItem); |
75 | } |
76 | else |
77 | { |
78 | super.propertyChanged(event); |
79 | } |
80 | } |
81 | |
82 | /** |
83 | * update Tree Item |
84 | * |
85 | * @param newComboBoxItem the new tree item |
86 | */ |
87 | public void updateComboBoxItem( |
88 | ComboBoxItemModel newComboBoxItem) |
89 | { |
90 | setComboBoxItem(updateModel(newComboBoxItem, getComboBoxItem(), this)); |
91 | notifyParentThatModelChanged(); |
92 | } |
93 | |
94 | /** |
95 | * set the Tree Item |
96 | * |
97 | * @param newComboBoxItem the ordered tree item |
98 | */ |
99 | public void setComboBoxItem( |
100 | ComboBoxItemModel newComboBoxItem) |
101 | { |
102 | comboBoxItem = newComboBoxItem; |
103 | } |
104 | |
105 | /** |
106 | * delete the Tree Item |
107 | */ |
108 | private void deleteComboBoxItem() |
109 | { |
110 | if (getComboBoxItem() != null) |
111 | { |
112 | getComboBoxItem().delete(); |
113 | setComboBoxItem(null); |
114 | } |
115 | } |
116 | |
117 | /** |
118 | * (non-JSDoc) |
119 | * |
120 | * @see org.deduced.viewer.web.shared.Model#deleteChildModels() |
121 | */ |
122 | @Override |
123 | protected void deleteChildModels() |
124 | { |
125 | deleteComboBoxItem(); |
126 | super.deleteChildModels(); |
127 | } |
128 | |
129 | /** |
130 | * @return the treeItem |
131 | */ |
132 | public ComboBoxItemModel getComboBoxItem() |
133 | { |
134 | return comboBoxItem; |
135 | } |
136 | |
137 | /** |
138 | * (non-JSDoc) |
139 | * |
140 | * @see org.deduced.viewer.web.shared.OrderedModel#getOrderedValue() |
141 | */ |
142 | @Override |
143 | public Object getOrderedValue() |
144 | { |
145 | return comboBoxItem; |
146 | } |
147 | |
148 | /** |
149 | * (non-JSDoc) |
150 | * |
151 | * @see org.deduced.viewer.web.shared.ModelContainer#modelChanged(org.deduced.viewer.web.shared.Model) |
152 | */ |
153 | @Override |
154 | public void modelChanged( |
155 | Model model) |
156 | { |
157 | notifyParentThatModelChanged(); |
158 | } |
159 | |
160 | } |