Skip to content

Commit

Permalink
Use the right amount of closing tags in AjaxTree when showRoot is false
Browse files Browse the repository at this point in the history
  • Loading branch information
lbane authored and Pascal Robert committed Mar 16, 2012
1 parent 4fa2304 commit 4ffe13a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Frameworks/Ajax/Ajax/Components/AjaxTree.wo/AjaxTree.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
<webobject name = "IsExpandedConditional"><webobject name = "NodeItem"/><webobject name = "CollapseAction"><webobject name = "ExpandedImage"/></webobject><webobject name = "TreeNodeRenderer"/><webobject name = "OpenUL"/></webobject>
</webobject>
</webobject>
<webobject name = "CloseCountRepetition"><webobject name = "CloseULLI"/></webobject>
<webobject name = "LastCloseCountRepetition"><webobject name = "CloseULLI"/></webobject>
</webobject>
4 changes: 4 additions & 0 deletions Frameworks/Ajax/Ajax/Components/AjaxTree.wo/AjaxTree.wod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ CloseCountRepetition : WORepetition {
count = closeCount;
}

LastCloseCountRepetition: WORepetition {
count = lastCloseCount;
}

TreeNodeRepetition : WORepetition {
list = nodes;
item = item;
Expand Down
24 changes: 24 additions & 0 deletions Frameworks/Ajax/Ajax/Sources/er/ajax/AjaxTree.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package er.ajax;

import org.apache.log4j.Logger;

import com.webobjects.appserver.WOActionResults;
import com.webobjects.appserver.WOComponent;
import com.webobjects.appserver.WOContext;
Expand Down Expand Up @@ -44,6 +46,7 @@
* @author mschrag
*/
public class AjaxTree extends WOComponent {
private static final Logger log = Logger.getLogger(AjaxTree.class);
private AjaxTreeModel _treeModel;

private NSArray _nodes;
Expand Down Expand Up @@ -150,6 +153,7 @@ else if (parent != _lastParent) {
else {
level = _level;
}

if (_level > level) {
_closeCount = (_level - level);
}
Expand All @@ -159,6 +163,9 @@ else if (parent != _lastParent) {
_lastParent = parent;
_level = level;
_item = item;
if (log.isDebugEnabled()) {
log.debug("AjaxTree item at level "+_level+" with close count "+_closeCount+": "+_item);
}
setValueForBinding(item, "item");
}
}
Expand All @@ -178,6 +185,23 @@ public boolean isExpanded() {
public int _closeCount() {
return _closeCount;
}

/**
* Count of /ul /li close elements at the end of the tree.
* If showRoot is "false" all displayed nodes have an internal "level" one greater than is really displayed,
* e.g. the first level after the root has a level of "1", but is displayed at level "0". CloseCount is used
* to close any open elements. When showRoot is "false" the jump from level 1 to level 0 at the end would compute
* to a closeCount of 1, but the last close is not necessary (as we are really displaying at level 0) and must be
* avoided.
* @return the last close count
*/
public int lastCloseCount() {
if (AjaxUtils.booleanValueForBinding("showRoot", true, _keyAssociations, parent()) || _closeCount < 1) {
return _closeCount;
}

return _closeCount - 1;
}

public void setTreeModel(AjaxTreeModel treeModel) {
_treeModel = treeModel;
Expand Down

0 comments on commit 4ffe13a

Please sign in to comment.