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

Quick Search    Search Deep

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


1   /*
2    * WOCollapsibleComponentContent.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  
12  public class WOCollapsibleComponentContent extends WOComponent
13  {
14      protected boolean _isVisible;
15      protected boolean _isVisibleSet;
16      protected String _openedImageFileName;
17      protected String _closedImageFileName;
18      protected String _submitActionName;
19      protected String  _framework;
20      protected boolean _isFrameworkSet;
21      protected int _anchor;
22  
23      protected static String _undefinedMarker="UNDEFINED";
24      protected static int _counter = 0;
25      
26      public WOCollapsibleComponentContent(WOContext aContext)  {
27          super(aContext);
28          _isVisibleSet = false;
29          _submitActionName=_undefinedMarker;
30          _isFrameworkSet = false;
31  
32          // just a hack to get a unique anchor in a thread safe manner.
33          synchronized(_undefinedMarker) {
34              _counter++;
35              _anchor = _counter;
36          }
37      }
38  
39      public boolean synchronizesVariablesWithBindings() {
40          return false;
41      }
42  
43      public boolean isVisible()  {
44          if (!_isVisibleSet) {
45              _isVisible = (valueForBinding("condition")!=null) ? true : false;
46  
47              Object _conditionObj = valueForBinding("condition");
48              if (_conditionObj instanceof Boolean) {
49                  _isVisible = ((Boolean)_conditionObj).booleanValue();
50              } else if (_conditionObj instanceof Number) {
51                  _isVisible = ((Number)_conditionObj).intValue() != 0;
52              }
53              _isVisibleSet = true;
54          }
55          return _isVisible;
56      }
57  
58      public WOComponent toggleVisibilityClicked()  {
59          _isVisible = isVisible() ? false : true;
60          if (canSetValueForBinding("visibility")) {
61              if (_isVisible) {
62                  setValueForBinding(new Integer(1), "visibility");
63              } else {
64                  setValueForBinding(new Integer(0), "visibility");
65              }
66          }
67          
68          if (hasSubmitAction()) {
69              performParentAction(submitActionName());
70          }
71          return null;
72      }
73  
74      public String openedImageFileName()  {
75          if (_openedImageFileName==null) {
76              if (hasBinding("openedImageFileName")) {
77                  _openedImageFileName = (String) _WOJExtensionsUtil.valueForBindingOrNull("openedImageFileName",this);
78              } else {
79                  _openedImageFileName = "DownTriangle.gif";
80              }
81          }
82          return _openedImageFileName;
83      }
84  
85      public String closedImageFileName()  {
86          if (_closedImageFileName==null) {
87              if (hasBinding("closedImageFileName")) {
88                  _closedImageFileName = (String) _WOJExtensionsUtil.valueForBindingOrNull("closedImageFileName",this);
89              } else {
90                  _closedImageFileName = "RightTriangle.gif";
91              }
92          }
93          return _closedImageFileName;
94      }
95  
96      public String currentArrowImageName()  {
97          String aCurrentArrowImageName = null;
98          if (isVisible()) {
99              aCurrentArrowImageName = openedImageFileName();
100         } else {
101             aCurrentArrowImageName = closedImageFileName();
102         }
103         return aCurrentArrowImageName;
104     }
105 
106     public String label()  {
107         String aLabel = null;
108         if (isVisible()) {
109             aLabel = (String)_WOJExtensionsUtil.valueForBindingOrNull("openedLabel",this);
110         } else {
111             aLabel = (String)_WOJExtensionsUtil.valueForBindingOrNull("closedLabel",this);
112         }
113 
114         return aLabel;
115     }
116 
117     public String helpString()  {
118         String aHelpString = null;
119         if (isVisible()) {
120             aHelpString = (String)_WOJExtensionsUtil.valueForBindingOrNull("Click to collapse",this);
121         } else {
122             aHelpString = (String)_WOJExtensionsUtil.valueForBindingOrNull("Click to expand",this);
123         }
124         return aHelpString;
125     }
126 
127     public String framework() {
128         if (!_isFrameworkSet) {
129             _isFrameworkSet = true;
130             _framework = hasBinding("framework") ? (String) _WOJExtensionsUtil.valueForBindingOrNull("framework",this) : "JavaWOExtensions";
131             if ((_framework!=null) && _framework.equalsIgnoreCase("app"))
132                 _framework=null;
133         }
134         return _framework;
135     }
136 
137 
138     public String submitActionName() {
139         if (_submitActionName==_undefinedMarker) {
140             if (hasBinding("submitActionName")) {
141                 Object value = valueForBinding("submitActionName");
142                 // if the value of the binding in the wod file is 'null' the association treats it as
143                 // a Boolean whose string value is "false". We need to check for this
144                 if (value instanceof String) {
145                     _submitActionName= value.toString();
146                 } else {
147                     _submitActionName=null;
148                 }
149             }
150             else
151                 _submitActionName=null;
152         }
153         return _submitActionName;
154     }
155 
156     public boolean hasSubmitAction() {
157         return (submitActionName()!=null);
158     }
159 
160     public String anchor() {
161         return "" + _anchor;
162     }
163 
164 
165 }