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

Quick Search    Search Deep

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


1   /*
2    * WXOutlineEntry.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 com.webobjects.appserver.*;
11  import com.webobjects.foundation.*;
12  import com.webobjects.eocontrol.*;
13  
14  public class WXOutlineEntry extends WOComponent {
15      protected int _nestingLevel;
16  
17      public WXOutlineEntry(WOContext aContext)  {
18          super(aContext);
19      }
20  
21      /////////////
22      // No-Sync
23      ////////////
24      public boolean synchronizesVariablesWithBindings() {
25          return false;
26      }
27  
28      public void awake() {
29          super.awake();
30          Object nestLevelBinding = _WOJExtensionsUtil.valueForBindingOrNull("nestingLevel",this);
31          if (nestLevelBinding instanceof Number) {
32              _nestingLevel = ((Number)nestLevelBinding).intValue();
33              return;
34          }
35  
36          if ((nestLevelBinding == null) || nestLevelBinding.equals("")) {
37              _nestingLevel = 0;
38              return;
39          }
40          try {
41              _nestingLevel = Integer.parseInt(nestLevelBinding.toString());
42          } catch (NumberFormatException e) {
43              throw new IllegalStateException("WXOutLineEntry - problem parsing int from nestingLevel binding "+e);
44          }
45      }
46  
47      public int nestingLevel() {
48          return _nestingLevel;
49      }
50  
51      public boolean isExpanded() {
52          Object currentItem = valueForBinding("item");
53          NSArray selectionPath = (NSArray)_WOJExtensionsUtil.valueForBindingOrNull("selectionPath",this);
54          return (_nestingLevel < selectionPath.count())
55              && selectionPath.objectAtIndex(_nestingLevel).equals(currentItem);
56      }
57  
58      public int nestingLevelForChildren() {
59          return _nestingLevel+1;
60      }
61  
62      public WOComponent toggleExpansion() {
63          NSArray selectionPath = (NSArray)_WOJExtensionsUtil.valueForBindingOrNull("selectionPath",this);
64  
65          selectionPath = selectionPath.subarrayWithRange(new NSRange(0, _nestingLevel));
66  
67          if (!isExpanded()) {
68              Object currentItem = valueForBinding("item");
69      //        NSLog(@"*** currentItem=%@", currentItem);
70              selectionPath = selectionPath.arrayByAddingObject(currentItem);
71          }
72  
73          setValueForBinding(selectionPath, "selectionPath");
74          return null;
75      }
76  
77      public boolean hasChildren() {
78          return ((Boolean)valueForBinding("hasChildren")).booleanValue();
79      }
80  
81  
82      public void takeValuesFromRequest(WORequest aRequest, WOContext aContext) {
83          session().setObjectForKey(this, "_outlineEntry");
84          super.takeValuesFromRequest(aRequest, aContext);
85      }
86  
87      public WOActionResults invokeAction(WORequest aRequest, WOContext aContext) {
88          WOActionResults returnElement;
89          session().setObjectForKey(this, "_outlineEntry");
90          returnElement = super.invokeAction(aRequest, aContext);
91          return returnElement;
92      }
93  
94      public void appendToResponse(WOResponse aResponse, WOContext aContext) {
95          session().setObjectForKey(this, "_outlineEntry");
96          super.appendToResponse(aResponse, aContext);
97      }
98  }