Mercurial > hg > Members > shoshi > TreeCMS > TreeCMSPrototype1
changeset 15:6b8f33b7e09f
added Test3 , EditableTreeBuilder
author | shoshi |
---|---|
date | Sun, 29 Aug 2010 23:08:47 +0900 |
parents | ce6e4523b284 |
children | 36d4445b349d |
files | src/treecms/proto/edit/EditableNodeAPI.java src/treecms/proto/edit/EditableNodeAPITreeBuilder.java src/treecms/proto/test/Test3.java |
diffstat | 3 files changed, 80 insertions(+), 80 deletions(-) [+] |
line wrap: on
line diff
--- a/src/treecms/proto/edit/EditableNodeAPI.java Sun Aug 29 20:46:21 2010 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +0,0 @@ -package treecms.proto.edit; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import treecms.proto.api.NodeAPI; - -public class EditableNodeAPI implements NodeAPI -{ - - @Override - public Iterator<NodeAPI> iterator() { - // TODO Auto-generated method stub - return null; - } - - @Override - public List<NodeAPI> getChildList() { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean isChild(NodeAPI _child) { - // TODO Auto-generated method stub - return false; - } - - @Override - public void addChild(NodeAPI _child) { - // TODO Auto-generated method stub - - } - - @Override - public void removeChild(NodeAPI _child) { - // TODO Auto-generated method stub - - } - - @Override - public void up(NodeAPI _child) { - // TODO Auto-generated method stub - - } - - @Override - public void down(NodeAPI _child) { - // TODO Auto-generated method stub - - } - - @Override - public void setClassName(String _class) { - // TODO Auto-generated method stub - - } - - @Override - public void setTitle(String _title) { - // TODO Auto-generated method stub - - } - - @Override - public String getClassName() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getTitle() { - // TODO Auto-generated method stub - return null; - } -} \ No newline at end of file
--- a/src/treecms/proto/edit/EditableNodeAPITreeBuilder.java Sun Aug 29 20:46:21 2010 +0900 +++ b/src/treecms/proto/edit/EditableNodeAPITreeBuilder.java Sun Aug 29 23:08:47 2010 +0900 @@ -17,7 +17,6 @@ public EditableNodeAPITreeBuilder(NodeAPI _target,NodeAPITreeBuilder _builder) { m_builder = _builder; - m_newRoot = m_builder.createNode(); //search path m_oldRoot = _builder.getContents(); @@ -36,20 +35,38 @@ target = node; } } + path.addFirst(m_oldRoot); + LinkedList<NodeAPI> copyList = new LinkedList<NodeAPI>(); + for(NodeAPI node : path){ + System.out.println(node.getTitle()); + + NodeAPI copy = m_builder.createNode(); + copy.setTitle(node.getTitle() + " copied"); + for(NodeAPI child : node.getChildList()){ + copy.addChild(child); + } + if(!copyList.isEmpty()){ + List<NodeAPI> childList = copyList.getLast().getChildList(); + childList.add(childList.indexOf(node),copy); + childList.remove(node); + } + copyList.add(copy); + } + m_newRoot = copyList.getFirst(); } @Override public NodeAPI getContents() { // TODO Auto-generated method stub - return null; + return m_newRoot; } @Override public NodeAPI createNode() { // TODO Auto-generated method stub - return null; + return m_builder.createNode(); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/treecms/proto/test/Test3.java Sun Aug 29 23:08:47 2010 +0900 @@ -0,0 +1,60 @@ +package treecms.proto.test; + +import java.util.Iterator; + +import treecms.proto.edit.*; +import treecms.proto.api.*; +import treecms.proto.simple.*; + +public class Test3 +{ + 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); + + EditableNodeAPITreeBuilder builder2 = new EditableNodeAPITreeBuilder(child212,builder); + + System.out.println("-----------------------------"); + + PreOrderTreeWalkerRecursive walker = new PreOrderTreeWalkerRecursive(builder2.getContents()); + Iterator<NodeAPI> itr = walker.iterator(); + while(itr.hasNext()){ + NodeAPI node = itr.next(); + System.out.println(node.getTitle()); + } + } +}