Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/webobjects/woextensions/WOCheckboxMatrix.java


1   /*
2    * WOCheckboxMatrix.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  // ** This uses a technique of having the WORepetition compute the form values for us.  This is a bit strange to have the Repetition having form values.  It may well be clearer to simply use takeValuesFromRequest... in here and not use this trick.  The ability to ask an element for its elementID seems logical and useful (as we use it for the umbrealla name here).  Of course, we could have this on the component just as easily, and this may be clearer.  However, if there is a repetition with a repetition in it, then the component's elementID isn't enough.
11  
12  import com.webobjects.appserver.*;
13  
14  import com.webobjects.foundation.*;
15  import java.util.*;
16  
17  public class WOCheckboxMatrix extends WOComponent {
18  
19      public Object currentItem;
20      public int index;
21      public String wrapperElementID;
22      protected NSArray _selections = null;
23  
24      public WOCheckboxMatrix(WOContext aContext) {
25          super(aContext);
26      }
27      
28      public boolean isStateless() {
29          return true;
30      }
31  
32      public void setCurrentItem(Object anItem) {
33          currentItem = anItem;
34          setValueForBinding(currentItem, "item");
35      }
36  
37      public NSArray selections() {
38          if (_selections == null) {
39              _selections = (NSArray)_WOJExtensionsUtil.valueForBindingOrNull("selections",this);
40              if (_selections == null) {
41                  _selections = NSArray.EmptyArray;
42              }
43          }
44          return _selections;
45      }
46  
47      public void setSelections(NSArray aFormValuesArray) {
48          // ** This is where we accept the formValues.  Kind of weird.
49          NSMutableArray aSelectionsArray = new NSMutableArray();
50          if (aFormValuesArray != null) {
51              Number anIndex = null;
52              Enumeration anIndexEnumerator = aFormValuesArray.objectEnumerator();
53              NSArray anItemList = (NSArray)_WOJExtensionsUtil.valueForBindingOrNull("list",this);
54              if (anItemList == null) {
55                  anItemList = NSArray.EmptyArray;
56              }
57              int anItemCount = anItemList.count();
58              while (anIndexEnumerator.hasMoreElements()) {
59                  anIndex = new Integer((String)anIndexEnumerator.nextElement());
60                  int i = anIndex.intValue();
61                  if (i < anItemCount) {
62                      Object anObject = anItemList.objectAtIndex(i);
63                      aSelectionsArray.addObject(anObject);
64                  } else {
65                      // ** serious problem here. Raise an exception?
66                  }
67              }
68          }
69          setValueForBinding(aSelectionsArray, "selections");
70          _selections = null;
71      }
72  
73      public String isCurrentItemChecked() {
74          if ((selections() != null) && selections().containsObject(currentItem)) {
75              return "checked";
76          }
77          return null;
78      }
79  
80  
81      protected void _invalidateCaches() {
82          _selections=null;
83          currentItem = null;
84      }
85  
86      public void reset()  {
87          _invalidateCaches();
88      }
89  }