1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.myfaces.trinidad.model;
20
21 /**
22 * A subclass of {@link ChildPropertyTreeModel} that supports row keys by creating
23 * {@link RowKeyPropertyModel}(s) for its child models.
24 *
25 * Ooverrides the protected createChildModel method in {@link ChildPropertyTreeModel} so that it can instantiate
26 * RowKeyPropertyModels as it encounters child data.
27 */
28 public class RowKeyPropertyTreeModel
29 extends ChildPropertyTreeModel
30 {
31
32 /**
33 * Creates a RowKeyPropertyTreeModel
34 *
35 * @param model The underlying model. This will be converted into a {@link DataModel} if necessary
36 * @param childProperty The property by which the child data can be accessed.
37 * @param rowKeyProperty The property by which the row key can be accessed.
38 */
39 public RowKeyPropertyTreeModel(Object model, String childProperty,
40 String rowKeyProperty)
41 {
42 super (new RowKeyPropertyModel(model, rowKeyProperty), childProperty);
43 _rowKeyProperty = rowKeyProperty;
44 }
45
46 /**
47 * No-arg constructor for use with managed-beans.
48 * Must call the {@link #setChildProperty},
49 * {@link #setWrappedData} and {@link #setRowKeyProperty} methods after constructing this instance.
50 */
51 public RowKeyPropertyTreeModel()
52 {
53 super();
54 }
55
56 /**
57 * Overrides ChildPropertyTreeModel.createChildModel().
58 * Converts childData into a RowKeyPropertyModel.
59 *
60 * @param childData the data to convert. This can be a List or array.
61 */
62 @Override
63 protected CollectionModel createChildModel(Object childData)
64 {
65 CollectionModel model =
66 new RowKeyPropertyModel(childData, _rowKeyProperty);
67 model.setRowIndex(-1);
68 return model;
69 }
70
71
72 /**
73 * Gets the row key property name for this model
74 * @return row key property name
75 */
76 public String getRowKeyProperty()
77 {
78 return _rowKeyProperty;
79 }
80
81 /**
82 * Sets the row key property for this model
83 * @param rowKeyProperty row key property to set
84 */
85 public void setRowKeyProperty(String rowKeyProperty)
86 {
87 _rowKeyProperty = rowKeyProperty;
88 }
89
90 private String _rowKeyProperty = null;
91
92 }