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.component;
20
21 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFComponent;
22 import org.apache.myfaces.trinidad.model.CollectionModel;
23 import org.apache.myfaces.trinidad.model.MenuModel;
24 import org.apache.myfaces.trinidad.model.ModelUtils;
25
26
27 /**
28 * Base class for the Navigation component.
29 * <p>
30 * Work on modeling navigation continues and it is very possible that this class
31 * will change in a future release.
32 */
33 // TODO these base classes need to be completely refactored
34 @JSFComponent
35 abstract public class UIXNavigationHierarchy extends UIXHierarchy
36 {
37
38 /**
39 * Create a Page component with the given render-type
40 */
41 protected UIXNavigationHierarchy(String rendererType)
42 {
43 super(rendererType);
44 }
45
46 protected UIXNavigationHierarchy()
47 {
48 this(null);
49 }
50
51 @Override
52 public CollectionModel createCollectionModel(CollectionModel current, Object value)
53 {
54 MenuModel model = ModelUtils.toMenuModel(value);
55 model.setRowKey(null);
56 return model;
57 }
58
59
60
61 /**
62 * gets the MenuModel that this page is displaying.
63 */
64 protected MenuModel getMenuModel()
65 {
66 return (MenuModel)getCollectionModel();
67 }
68
69 /**
70 * Gets the focus row for the current viewId.
71 * @see MenuModel#getFocusRowKey
72 * @return the focus rowKey for the current viewId
73 */
74 @Override
75 public Object getFocusRowKey()
76 {
77 MenuModel model = getMenuModel();
78 if (model != null)
79 {
80 Object currPath = model.getRowKey();
81 Object focusPath = model.getFocusRowKey();
82
83 // The row key should not change as a result of calling getFocusRowKey()
84 assert(((currPath == null) && (model.getRowKey() == null)) ||
85 ((currPath != null) && currPath.equals(model.getRowKey())));
86 return focusPath;
87 }
88
89 return null;
90 }
91
92 }