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 /**
23 * A base class which takes a TreeModel. Developers can extend this class and
24 * just override the getFocusRowKey() method.
25 *
26 */
27 public abstract class BaseMenuModel extends MenuModel
28 {
29
30 /**
31 *
32 * @param modelObject the treeModel to use, this object will be passed to
33 * {@link ModelUtils#toTreeModel}.
34 */
35 public BaseMenuModel(Object modelObject)
36 {
37 _treeModel = ModelUtils.toTreeModel(modelObject);
38 }
39
40 /**
41 * no-arg constructor needed for managed-bean support.
42 * {@link #setWrappedData} must be called soon after constructing this
43 * instance.
44 */
45 protected BaseMenuModel()
46 {
47 }
48
49 @Override
50 public Object getContainerRowKey(Object childKey)
51 {
52 return _treeModel.getContainerRowKey(childKey);
53 }
54
55 @Override
56 public void enterContainer()
57 {
58 _treeModel.enterContainer();
59 }
60
61 @Override
62 public void exitContainer()
63 {
64 _treeModel.exitContainer();
65 }
66
67 @Override
68 public int getRowCount()
69 {
70 return _treeModel.getRowCount();
71 }
72
73 @Override
74 public Object getRowData()
75 {
76 return _treeModel.getRowData();
77 }
78
79 @Override
80 public int getRowIndex()
81 {
82 return _treeModel.getRowIndex();
83 }
84
85 @Override
86 public Object getRowKey()
87 {
88 return _treeModel.getRowKey();
89 }
90
91 @Override
92 public Object getWrappedData()
93 {
94 // since we don't know how to adapt an ordinary POJO into a
95 // treeModel, the wrappedData itself is a treeModel. so just return it:
96 return _treeModel;
97 }
98
99 @Override
100 public boolean isContainer()
101 {
102 return _treeModel.isContainer();
103 }
104
105 @Override
106 public boolean isRowAvailable()
107 {
108 return _treeModel.isRowAvailable();
109 }
110
111 @Override
112 public void setRowIndex(int index)
113 {
114 _treeModel.setRowIndex(index);
115 }
116
117 @Override
118 public void setRowKey(Object key)
119 {
120 _treeModel.setRowKey(key);
121 }
122
123 @Override
124 public void setWrappedData(Object data)
125 {
126 // since we don't know how to adapt an ordinary POJO into a
127 // treeModel, the ModelUtils call is currently no-op:
128 _treeModel = ModelUtils.toTreeModel(data);
129 }
130
131 private TreeModel _treeModel = null;
132 }