Update of /var/cvs/applications/taglib/src/org/mmbase/bridge/jsp/taglib/tree
In directory james.mmbase.org:/tmp/cvs-serv21305/tree

Modified Files:
        TreeTag.java 
Log Message:
 MMB-1611


See also: 
http://cvs.mmbase.org/viewcvs/applications/taglib/src/org/mmbase/bridge/jsp/taglib/tree
See also: http://www.mmbase.org/jira/browse/MMB-1611


Index: TreeTag.java
===================================================================
RCS file: 
/var/cvs/applications/taglib/src/org/mmbase/bridge/jsp/taglib/tree/TreeTag.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- TreeTag.java        23 Feb 2008 15:55:15 -0000      1.24
+++ TreeTag.java        28 Feb 2008 12:22:59 -0000      1.25
@@ -11,6 +11,7 @@
 
 import javax.servlet.jsp.JspTagException;
 import javax.servlet.jsp.PageContext;
+import javax.servlet.jsp.jstl.core.*;
 
 import java.io.IOException;
 import java.util.Stack;
@@ -47,7 +48,7 @@
 </pre>
  * @author Michiel Meeuwissen
  * @since MMBase-1.7
- * @version $Id: TreeTag.java,v 1.24 2008/02/23 15:55:15 michiel Exp $
+ * @version $Id: TreeTag.java,v 1.25 2008/02/28 12:22:59 michiel Exp $
  */
 public class TreeTag extends AbstractNodeProviderTag implements TreeProvider, 
QueryContainerReferrer  {
     private static final Logger log = Logging.getLoggerInstance(TreeTag.class);
@@ -64,6 +65,7 @@
     private int index;
 
     private Node nextNode;
+    private BranchLoopStatus nextBranchStatus;
 
     private Object prevDepthProvider;
     private Object prevTreeProvider;
@@ -84,6 +86,14 @@
     protected Attribute directions  = Attribute.NULL;
     protected Attribute max         = Attribute.NULL;
 
+    protected Attribute varStatus = Attribute.NULL;
+    protected String varStatusName = null;
+
+    protected Attribute varBranchStatus = Attribute.NULL;
+    protected String varBranchStatusName = null;
+
+
+
     public void setContainer(String c) throws JspTagException {
         container = getAttribute(c);
     }
@@ -164,6 +174,20 @@
         return nextDepth;
     }
 
+    /**
+     * @since MMBase-1.8.6
+     */
+    public void setVarStatus(String s) throws JspTagException {
+        varStatus = getAttribute(s);
+    }
+    /**
+     * @since MMBase-1.8.6
+     */
+    public void setVarBranchStatus(String s) throws JspTagException {
+        varBranchStatus = getAttribute(s);
+    }
+
+
     public void setAdd(String c) throws JspTagException {
         throw new UnsupportedOperationException();
     }
@@ -174,7 +198,6 @@
         throw new UnsupportedOperationException();
     }
 
-
     protected void noSpecification() throws JspTagException {
         if (nodeManager != Attribute.NULL) {
             throw new JspTagException("'type' attribute does not make sense 
with 'referid' attribute");
@@ -199,6 +222,9 @@
         pageContext.setAttribute(DepthProvider.KEY, this, 
PageContext.REQUEST_SCOPE);
         pageContext.setAttribute(TreeProvider.KEY, this, 
PageContext.REQUEST_SCOPE);
 
+        varStatusName = (String) varStatus.getValue(this);
+        varBranchStatusName = (String) varBranchStatus.getValue(this);
+
         // serve parent timer tag:
         TimerTag t = findParentTag(TimerTag.class, null, false);
         if (t != null) {
@@ -264,9 +290,21 @@
             setNodeVar(node);
             fillVars();
             depth         = iterator.currentDepth();
+          if (varStatusName != null) {
+                org.mmbase.bridge.jsp.taglib.util.ContextContainer cc = 
getContextProvider().getContextContainer();
+                cc.register(varStatusName, getLoopStatus());
+            }
+            if (varBranchStatusName != null) {
+                org.mmbase.bridge.jsp.taglib.util.ContextContainer cc = 
getContextProvider().getContextContainer();
+                cc.register(varBranchStatusName, new BranchLoopStatus(node, 
iterator.getSiblings()));
+            }
 
             if (iterator.hasNext()) {
                 nextNode  = iterator.nextNode();
+                if (varBranchStatusName != null) {
+                    org.mmbase.bridge.jsp.taglib.util.ContextContainer cc = 
getContextProvider().getContextContainer();
+                    nextBranchStatus = new BranchLoopStatus(nextNode, 
iterator.getSiblings());
+                }
                 nextDepth = iterator.currentDepth();
                 log.debug("hasnext " + nextDepth);
             } else {
@@ -293,6 +331,9 @@
         if (getId() != null) {
             getContextProvider().getContextContainer().unRegister(getId());
         }
+        if (varStatusName != null) {
+            
getContextProvider().getContextContainer().unRegister(varStatusName);
+        }
 
         collector.doAfterBody();
 
@@ -300,11 +341,23 @@
             log.debug("using next-node");
             setNodeVar(nextNode);
             fillVars();
+            if (varStatusName != null) {
+                org.mmbase.bridge.jsp.taglib.util.ContextContainer cc = 
getContextProvider().getContextContainer();
+                cc.reregister(varStatusName, new 
ListProviderLoopTagStatus(this));
+            }
+            if (varBranchStatusName != null) {
+                org.mmbase.bridge.jsp.taglib.util.ContextContainer cc = 
getContextProvider().getContextContainer();
+                cc.reregister(varBranchStatusName, nextBranchStatus);
+            }
             previousDepth = depth;
             depth         = nextDepth;
 
             if (iterator.hasNext()) {
                 nextNode  = iterator.nextNode();
+                if (varBranchStatusName != null) {
+                    org.mmbase.bridge.jsp.taglib.util.ContextContainer cc = 
getContextProvider().getContextContainer();
+                    nextBranchStatus = new BranchLoopStatus(nextNode, 
iterator.getSiblings());
+                }
                 nextDepth = iterator.currentDepth();
                 log.debug("has next " + nextDepth);
             } else {
@@ -357,6 +410,48 @@
     }
 
 
+    /**
+     * @since MMBase-1.8.6
+     */
+    class BranchLoopStatus implements LoopTagStatus {
+        private final Node current;
+        private final NodeList siblings;
+        public BranchLoopStatus(Node c, NodeList s) {
+            current = c;
+            siblings = s;
+        }
+        public Object getCurrent() {
+            return current;
+        }
+        public int getIndex() {
+            return siblings.indexOf(current);
+        }
+
+        public int getCount() {
+            return siblings.size();
+        }
+
+        public boolean isFirst() {
+            return getIndex() == 0;
+        }
+        public boolean isLast() {
+            return getCount() == getIndex() + 1;
+        }
+        public Integer getBegin() {
+            return null;
+        }
+        public Integer getEnd() {
+            return null;
+        }
+        public Integer getStep() {
+            return null;
+        }
+    }
+
+
+
+
+
 
 
 }
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to