| 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 java.util.Collections; |
| 19 | |
| 20 | /** |
| 21 | * |
| 22 | * OrderedListModel is a type of model list that's expected to contain ordered |
| 23 | * models. The ordered list model will automatically sort itself as the list |
| 24 | * content changes. |
| 25 | * |
| 26 | * @author Steve McDuff |
| 27 | * |
| 28 | * @param <c> the type of ordered model contained in the list |
| 29 | */ |
| 30 | public class OrderedListModel<c extends OrderedModel> extends ModelListModel<c> |
| 31 | { |
| 32 | |
| 33 | /** |
| 34 | * serialVersionUID |
| 35 | */ |
| 36 | private static final long serialVersionUID = -2263808521309700570L; |
| 37 | |
| 38 | /** |
| 39 | * |
| 40 | * OrderedListModel constructor |
| 41 | */ |
| 42 | public OrderedListModel() |
| 43 | { |
| 44 | |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * (non-JSDoc) |
| 49 | * |
| 50 | * @see org.deduced.viewer.web.shared.Model#notifyParentThatModelChanged() |
| 51 | */ |
| 52 | @Override |
| 53 | public void notifyParentThatModelChanged() |
| 54 | { |
| 55 | sort(); |
| 56 | super.notifyParentThatModelChanged(); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * sort the contained list so that models end up in the right order when |
| 61 | * browsing the list. |
| 62 | */ |
| 63 | public void sort() |
| 64 | { |
| 65 | Collections.sort(getList()); |
| 66 | } |
| 67 | |
| 68 | } |