Mercurial > hg > Members > shoshi > TreeCMSv1
changeset 8:8fbe7ba1d820
added EditableNodeAPI
author | shoshi |
---|---|
date | Sat, 28 Aug 2010 17:34:57 +0900 |
parents | 18f696e9fc1e |
children | 79592d69632e |
files | src/treecms/proto/edit/EditableNodeAPITreeBuilder.java src/treecms/proto/simple/SimpleNodeAPI.java src/treecms/proto/simple/SimpleNodeAPITreeBuilder.java src/treecms/proto/test/Test1.java src/treecms/proto/test/Test2.java |
diffstat | 5 files changed, 107 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/treecms/proto/edit/EditableNodeAPITreeBuilder.java Sat Aug 28 15:43:18 2010 +0900 +++ b/src/treecms/proto/edit/EditableNodeAPITreeBuilder.java Sat Aug 28 17:34:57 2010 +0900 @@ -1,25 +1,69 @@ package treecms.proto.edit; +import java.util.List; +import java.util.UUID; + import treecms.proto.api.NodeAPI; import treecms.proto.api.NodeAPITreeBuilder; public class EditableNodeAPITreeBuilder implements NodeAPITreeBuilder { - public EditableNodeAPITreeBuilder() + private NodeAPI m_root; + private NodeAPI m_clone; + + public EditableNodeAPITreeBuilder(NodeAPI _root) + { + m_root = _root; + m_clone = clone(_root); + } + + private NodeAPI clone(NodeAPI _orig) { + EditableNodeAPI clone = new EditableNodeAPI(generateUUID()); + clone.setClassName(_orig.getClassName()); + clone.setTitle(_orig.getTitle()); + clone.setOriginal(_orig); + + List<NodeAPI> children = _orig.getChildList(); + for(NodeAPI child : children){ + //System.out.println(child.getTitle()); + clone.addChild(clone(child)); + } + return clone; } - + + public void discard() + { + //discard changes. + m_clone = clone(m_root); + } + + public void commit() + { + //commit changes + } + + public void push() + { + //push changes + } + + public String generateUUID() + { + return UUID.randomUUID().toString(); + } + @Override public NodeAPI getContents() { // TODO Auto-generated method stub - return null; + return this.m_clone; } @Override public NodeAPI createNode() { // TODO Auto-generated method stub - return null; + return new EditableNodeAPI(generateUUID()); } }
--- a/src/treecms/proto/simple/SimpleNodeAPI.java Sat Aug 28 15:43:18 2010 +0900 +++ b/src/treecms/proto/simple/SimpleNodeAPI.java Sat Aug 28 17:34:57 2010 +0900 @@ -6,7 +6,7 @@ import treecms.proto.api.NodeAPI; -class SimpleNodeAPI implements NodeAPI +public class SimpleNodeAPI implements NodeAPI { private LinkedList<NodeAPI> m_childs;
--- a/src/treecms/proto/simple/SimpleNodeAPITreeBuilder.java Sat Aug 28 15:43:18 2010 +0900 +++ b/src/treecms/proto/simple/SimpleNodeAPITreeBuilder.java Sat Aug 28 17:34:57 2010 +0900 @@ -6,14 +6,17 @@ public class SimpleNodeAPITreeBuilder implements NodeAPITreeBuilder { + private NodeAPI m_root; + public SimpleNodeAPITreeBuilder() { + m_root = new SimpleNodeAPI(generateUUID()); return; } public NodeAPI getContents() { - return new SimpleNodeAPI(generateUUID()); + return m_root; } public NodeAPI createNode()
--- a/src/treecms/proto/test/Test1.java Sat Aug 28 15:43:18 2010 +0900 +++ b/src/treecms/proto/test/Test1.java Sat Aug 28 17:34:57 2010 +0900 @@ -52,6 +52,5 @@ NodeAPI node = itr.next(); System.out.println(node.getTitle()); } - } }
--- a/src/treecms/proto/test/Test2.java Sat Aug 28 15:43:18 2010 +0900 +++ b/src/treecms/proto/test/Test2.java Sat Aug 28 17:34:57 2010 +0900 @@ -1,7 +1,58 @@ package treecms.proto.test; -import junit.framework.TestCase; +import java.util.Iterator; + +import treecms.proto.api.*; +import treecms.proto.simple.*; +import treecms.proto.edit.*; -public class Test2 extends TestCase { - +public class Test2 +{ + public static void main(String _arg[]) + { + NodeAPITreeBuilder builder = new SimpleNodeAPITreeBuilder(); + NodeAPI root = builder.getContents(); + root.setTitle("root"); + + NodeAPI child1 = builder.createNode(); + child1.setTitle("child1"); + NodeAPI child2 = builder.createNode(); + child2.setTitle("child2"); + + root.addChild(child1); + root.addChild(child2); + + NodeAPI child11 = builder.createNode(); + child11.setTitle("child11"); + NodeAPI child12 = builder.createNode(); + child12.setTitle("child12"); + NodeAPI child13 = builder.createNode(); + child13.setTitle("child13"); + + child1.addChild(child11); + child1.addChild(child12); + child1.addChild(child13); + + NodeAPI child21 = builder.createNode(); + child21.setTitle("child21"); + + child2.addChild(child21); + + NodeAPI child211 = builder.createNode(); + child211.setTitle("child211"); + NodeAPI child212 = builder.createNode(); + child212.setTitle("child212"); + + child21.addChild(child211); + child21.addChild(child212); + + + NodeAPITreeBuilder builder1 = new EditableNodeAPITreeBuilder(root); + PreOrderTreeWalker walker = new PreOrderTreeWalker(builder1.getContents()); + Iterator<NodeAPI> itr = walker.iterator(); + while(itr.hasNext()){ + NodeAPI node = itr.next(); + System.out.println(node.getTitle()); + } + } }