You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2011/12/14 09:01:34 UTC
svn commit: r1214085 - in /myfaces/tobago/trunk/tobago-core/src:
main/java/org/apache/myfaces/tobago/internal/component/
main/java/org/apache/myfaces/tobago/model/
test/java/org/apache/myfaces/tobago/model/
Author: lofwyr
Date: Wed Dec 14 08:01:34 2011
New Revision: 1214085
URL: http://svn.apache.org/viewvc?rev=1214085&view=rev
Log:
TOBAGO-1049: Tree inside of the Sheet (aka TreeTable)
- preparation: simplify existing tree rendering
Modified:
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeNode.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/MixedTreeModel.java
myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/Node.java
myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/model/MixedTreeModelUnitTest.java
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeNode.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeNode.java?rev=1214085&r1=1214084&r2=1214085&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeNode.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITreeNode.java Wed Dec 14 08:01:34 2011
@@ -85,14 +85,6 @@ public abstract class AbstractUITreeNode
super.encodeBegin(context);
}
- @Override
- public void encodeEnd(FacesContext context) throws IOException {
- super.encodeEnd(context);
- AbstractUITree tree = ComponentUtils.findAncestor(this, AbstractUITree.class);
- MixedTreeModel mixedModel = tree.getModel();
- mixedModel.onEncodeEnd();
- }
-
private int computeDepth(UIComponent component) {
int depth = 0;
while (component != null) {
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/MixedTreeModel.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/MixedTreeModel.java?rev=1214085&r1=1214084&r2=1214085&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/MixedTreeModel.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/MixedTreeModel.java Wed Dec 14 08:01:34 2011
@@ -24,16 +24,12 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
-/**
- * Date: 23.04.2007 16:10:22
- */
public class MixedTreeModel {
private static final Logger LOG = LoggerFactory.getLogger(MixedTreeModel.class);
private Node root;
private Node current;
- private Integer nextChildIndex;
private Stack<Boolean> junctions = new Stack<Boolean>();
public void beginBuildNode() {
@@ -57,28 +53,26 @@ public class MixedTreeModel {
}
if (current == null) {
current = root;
+ junctions.push(hasCurrentNodeNextSibling());
} else {
- current = current.getChildAt(nextChildIndex);
+ if (current.getChildren().size() > 0) {
+ current = current.getChildAt(0); // first child
+ junctions.push(hasCurrentNodeNextSibling());
+ } else {
+ Node searchParent = current;
+ do {
+ junctions.pop();
+ Node nextSibling = searchParent.nextSibling();
+ if (nextSibling != null) {
+ current = nextSibling;
+ junctions.push(hasCurrentNodeNextSibling());
+ return;
+ }
+ searchParent = searchParent.getParent();
+ } while (searchParent != null);
+ current = null;
+ }
}
- nextChildIndex = 0;
-
- junctions.push(hasCurrentNodeNextSibling());
- }
-
- public void onEncodeEnd() {
- if (LOG.isDebugEnabled()) {
- LOG.debug("current=" + current);
- }
- Node parent = current.getParent();
- if (parent != null) {
- nextChildIndex = parent.getIndex(current) + 1;
- current = parent;
- } else {
- nextChildIndex = null;
- current = null;
- }
-
- junctions.pop();
}
public boolean hasCurrentNodeNextSibling() {
Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/Node.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/Node.java?rev=1214085&r1=1214084&r2=1214085&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/Node.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/model/Node.java Wed Dec 14 08:01:34 2011
@@ -72,6 +72,14 @@ public class Node {
return parent != null && parent.getIndex(this) + 1 < parent.getChildCount();
}
+ public Node nextSibling() {
+ if (parent == null) {
+ return null;
+ }
+ final int nextIndex = parent.getIndex(this) + 1;
+ return nextIndex < parent.getChildCount() ? parent.getChildAt(nextIndex) : null;
+ }
+
public TreePath getPath() {
List<Integer> result = new ArrayList<Integer>();
Node node = this;
Modified: myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/model/MixedTreeModelUnitTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/model/MixedTreeModelUnitTest.java?rev=1214085&r1=1214084&r2=1214085&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/model/MixedTreeModelUnitTest.java (original)
+++ myfaces/tobago/trunk/tobago-core/src/test/java/org/apache/myfaces/tobago/model/MixedTreeModelUnitTest.java Wed Dec 14 08:01:34 2011
@@ -18,7 +18,6 @@ package org.apache.myfaces.tobago.model;
*/
import org.apache.myfaces.tobago.component.UITreeData;
-import org.apache.myfaces.tobago.component.UITreeNode;
import org.junit.Assert;
import org.junit.Test;
@@ -36,7 +35,6 @@ public class MixedTreeModelUnitTest {
model.onEncodeBegin();
Assert.assertEquals(new TreePath(0), model.getPath());
- model.onEncodeEnd();
}
@Test
@@ -53,10 +51,7 @@ public class MixedTreeModelUnitTest {
model.onEncodeBegin();
model.onEncodeBegin();
- model.onEncodeEnd();
model.onEncodeBegin();
- model.onEncodeEnd();
- model.onEncodeEnd();
}
@Test
@@ -69,26 +64,20 @@ public class MixedTreeModelUnitTest {
UITreeData data = new UITreeData();
data.setValue(tree);
- UITreeNode node = new UITreeNode();
-// model.beginBuildNodeData(data);
model.beginBuildNode();
model.beginBuildNode();
model.endBuildNode();
model.beginBuildNode();
model.endBuildNode();
model.endBuildNode();
-// model.endBuildNodeData(data);
model.onEncodeBegin();
Assert.assertEquals(new TreePath(0), model.getPath());
model.onEncodeBegin();
Assert.assertEquals(new TreePath(0, 0), model.getPath());
- model.onEncodeEnd();
model.onEncodeBegin();
Assert.assertEquals(new TreePath(0, 1), model.getPath());
- model.onEncodeEnd();
- model.onEncodeEnd();
}
/**
@@ -108,22 +97,10 @@ public class MixedTreeModelUnitTest {
public void testLifecycleMixed() {
MixedTreeModel model = new MixedTreeModel();
- DefaultMutableTreeNode tree = new DefaultMutableTreeNode("root");
- tree.add(new DefaultMutableTreeNode("node1"));
- DefaultMutableTreeNode node2 = new DefaultMutableTreeNode("node2");
- node2.add(new DefaultMutableTreeNode("node3"));
- tree.add(node2);
-
- UITreeData data = new UITreeData();
- data.setValue(tree);
- UITreeNode root = new UITreeNode();
- UITreeNode individual = new UITreeNode();
- UITreeNode node = new UITreeNode();
model.beginBuildNode();
model.beginBuildNode();
model.endBuildNode();
-// model.beginBuildNodeData(data);
model.beginBuildNode();
model.beginBuildNode();
model.endBuildNode();
@@ -132,32 +109,24 @@ public class MixedTreeModelUnitTest {
model.endBuildNode();
model.endBuildNode();
model.endBuildNode();
-// model.endBuildNodeData(data);
+ model.beginBuildNode();
+ model.endBuildNode();
model.endBuildNode();
model.onEncodeBegin(); // root
Assert.assertEquals(new TreePath(0), model.getPath());
model.onEncodeBegin(); // individual
Assert.assertEquals(new TreePath(0, 0), model.getPath());
- model.onEncodeEnd(); // individual
- Assert.assertEquals(new TreePath(0), model.getPath());
model.onEncodeBegin(); // data root node
Assert.assertEquals(new TreePath(0, 1), model.getPath());
model.onEncodeBegin(); // data sub node 1
Assert.assertEquals(new TreePath(0, 1, 0), model.getPath());
- model.onEncodeEnd(); // data sub node 1
- Assert.assertEquals(new TreePath(0, 1), model.getPath());
model.onEncodeBegin(); // data sub node 2
Assert.assertEquals(new TreePath(0, 1, 1), model.getPath());
model.onEncodeBegin(); // data sub node 3
Assert.assertEquals(new TreePath(0, 1, 1, 0), model.getPath());
- model.onEncodeEnd(); // data sub node 3
- Assert.assertEquals(new TreePath(0, 1, 1), model.getPath());
- model.onEncodeEnd(); // data sub node 2
- Assert.assertEquals(new TreePath(0, 1), model.getPath());
- model.onEncodeEnd(); // data root node
- Assert.assertEquals(new TreePath(0), model.getPath());
- model.onEncodeEnd(); // root
+ model.onEncodeBegin();
+ Assert.assertEquals(new TreePath(0, 2), model.getPath());
}
}