Source code: com/webobjects/woextensions/WOBatchNavigationBar.java
1 /*
2 * WOBatchNavigationBar.java
3 * © Copyright 2001 Apple Computer, Inc. All rights reserved.
4 * This a modified version.
5 * Original license: http://www.opensource.apple.com/apsl/
6 */
7
8 package com.webobjects.woextensions;
9
10 import java.util.*;
11 import com.webobjects.appserver.*;
12 import com.webobjects.foundation.*;
13
14 public class WOBatchNavigationBar extends WOComponent {
15
16 public WOBatchNavigationBar(WOContext aContext) {
17 super(aContext);
18 }
19
20 public boolean isStateless() {
21 return true;
22 }
23
24 public boolean hasObjectName() {
25 return hasBinding("objectName");
26 }
27
28 public boolean hasSortKeyList() {
29 return hasBinding("sortKeyList");
30 }
31
32 public int numberOfObjectsPerBatch() {
33
34 return ((WODisplayGroup)valueForBinding("displayGroup")).numberOfObjectsPerBatch();
35 }
36
37 public void setNumberOfObjectsPerBatch(Integer number) {
38 int _number;
39
40 //If a negative number is provided we default the number
41 //of objects per batch to 0.
42 _number = ((number != null) && (number.intValue() > 0)) ? number.intValue() : 0;
43
44 ((WODisplayGroup)valueForBinding("displayGroup")).setNumberOfObjectsPerBatch(_number);
45 }
46
47 public int batchIndex() {
48 return ((WODisplayGroup)valueForBinding("displayGroup")).currentBatchIndex();
49 }
50
51 public void setBatchIndex(Integer index) {
52 int _batchIndex;
53
54 //Treat a null index as a 0 index. Negative numbers are handled
55 //by the display group.
56 _batchIndex = (index != null) ? index.intValue() : 0;
57
58 ((WODisplayGroup)valueForBinding("displayGroup")).setCurrentBatchIndex(_batchIndex);
59 }
60
61 protected String _singularName() {
62 String name = (String) valueForBinding("objectName");
63 if (name == null || name.length() == 0) {
64 name = "item";
65 }
66 return name;
67 }
68
69 protected String _pluralName() {
70 String name = (String) valueForBinding("pluralName");
71 if (name == null || name.length() == 0) {
72 name = _singularName() + "s";
73 }
74 return name;
75 }
76
77 public String entityLabel() {
78 WODisplayGroup dg = (WODisplayGroup)valueForBinding("displayGroup");
79 if (dg.allObjects().count() == 1) {
80 return _singularName();
81 } else {
82 return _pluralName();
83 }
84 }
85 }