Mercurial > hg > Members > shoshi > TreeCMS > TreeCMSPrototype1
changeset 11:bb802051dab3
added proxy based EditableNodeAPI
author | shoshi |
---|---|
date | Sat, 28 Aug 2010 20:39:41 +0900 |
parents | f5a4baf70bdf |
children | c8e31aaac297 |
files | src/treecms/proto/edit/EditableNodeAPI.java src/treecms/proto/edit/EditableNodeAPITreeBuilder.java src/treecms/proto/edit/type1/EditableNodeAPI.java src/treecms/proto/edit/type1/EditableNodeAPITreeBuilder.java src/treecms/proto/edit/type2/EditableNodeAPI.java src/treecms/proto/edit/type2/EditableNodeAPITreeBuilder.java src/treecms/proto/test/Test2.java |
diffstat | 7 files changed, 467 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/src/treecms/proto/edit/EditableNodeAPI.java Sat Aug 28 18:10:53 2010 +0900 +++ b/src/treecms/proto/edit/EditableNodeAPI.java Sat Aug 28 20:39:41 2010 +0900 @@ -10,7 +10,6 @@ { private boolean m_flagChanged; - private String m_uuid; private String m_class; private String m_title; @@ -18,15 +17,28 @@ private LinkedList<NodeAPI> m_children; - public EditableNodeAPI(String _uuid) + public EditableNodeAPI(NodeAPI _orig) { - m_uuid = _uuid; - m_flagChanged = false; + m_orig = _orig; + if(m_orig != null){ + m_flagChanged = false; + }else{ + m_flagChanged = true; + } + m_children = new LinkedList<NodeAPI>(); + m_class = ""; + m_title = ""; } - public boolean isChanged() + void _resetFlag() { + m_flagChanged = false; + } + + public synchronized boolean setandgetChanged(boolean _flag) + { + m_flagChanged = m_flagChanged | _flag; return m_flagChanged; } @@ -40,38 +52,39 @@ return m_orig; } - public String getUUID() - { - return m_uuid; - } - - @Override public List<NodeAPI> getChildList() { // TODO Auto-generated method stub - return m_children; + if(setandgetChanged(false)){ + return this.m_children; + } + return this.m_orig.getChildList(); } @Override public boolean isChild(NodeAPI _child) { // TODO Auto-generated method stub - return m_children.contains(_child); + if(setandgetChanged(false)){ + return m_children.contains(_child); + } + return m_orig.getChildList().contains(_child); } @Override public void addChild(NodeAPI _child) { // TODO Auto-generated method stub - m_children.add(_child); - m_flagChanged = true; + if(m_children.add(_child)){ + setandgetChanged(true); + } } @Override public void removeChild(NodeAPI _child) { // TODO Auto-generated method stub if(m_children.remove(_child)){ - m_flagChanged = true; + setandgetChanged(true); } } @@ -81,7 +94,7 @@ int curPos = m_children.indexOf(_child); if(curPos - 1 > 0){ m_children.add(curPos - 1,m_children.remove(curPos)); - m_flagChanged = true; + setandgetChanged(true); } } @@ -99,31 +112,40 @@ public void setClassName(String _class) { // TODO Auto-generated method stub this.m_class = _class; - m_flagChanged = true; + setandgetChanged(true); } @Override public void setTitle(String _title) { // TODO Auto-generated method stub this.m_title = _title; - m_flagChanged = true; + setandgetChanged(true); } @Override public String getClassName() { // TODO Auto-generated method stub - return this.m_class; + if(setandgetChanged(false)){ + return this.m_class; + } + return m_orig.getClassName(); } @Override public String getTitle() { // TODO Auto-generated method stub - return this.m_title; + if(setandgetChanged(false)){ + return this.m_title; + } + return m_orig.getClassName(); } @Override public Iterator<NodeAPI> iterator() { // TODO Auto-generated method stub - return m_children.iterator(); + if(setandgetChanged(false)){ + return m_children.iterator(); + } + return m_orig.iterator(); } }
--- a/src/treecms/proto/edit/EditableNodeAPITreeBuilder.java Sat Aug 28 18:10:53 2010 +0900 +++ b/src/treecms/proto/edit/EditableNodeAPITreeBuilder.java Sat Aug 28 20:39:41 2010 +0900 @@ -19,10 +19,7 @@ private NodeAPI clone(NodeAPI _orig) { - EditableNodeAPI clone = new EditableNodeAPI(generateUUID()); - clone.setClassName(_orig.getClassName()); - clone.setTitle(_orig.getTitle()); - clone.setOriginal(_orig); + EditableNodeAPI clone = new EditableNodeAPI(_orig); List<NodeAPI> children = _orig.getChildList(); for(NodeAPI child : children){ @@ -30,6 +27,7 @@ clone.addChild(clone(child)); } + clone._resetFlag(); return clone; } @@ -63,7 +61,7 @@ @Override public NodeAPI createNode() { // TODO Auto-generated method stub - return new EditableNodeAPI(generateUUID()); + return new EditableNodeAPI(null); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/treecms/proto/edit/type1/EditableNodeAPI.java Sat Aug 28 20:39:41 2010 +0900 @@ -0,0 +1,129 @@ +package treecms.proto.edit.type1; + +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import treecms.proto.api.NodeAPI; + +public class EditableNodeAPI implements NodeAPI +{ + private boolean m_flagChanged; + + private String m_uuid; + private String m_class; + private String m_title; + + private NodeAPI m_orig; + + private LinkedList<NodeAPI> m_children; + + public EditableNodeAPI(String _uuid) + { + m_uuid = _uuid; + m_flagChanged = false; + m_children = new LinkedList<NodeAPI>(); + } + + public boolean isChanged() + { + return m_flagChanged; + } + + public void setOriginal(NodeAPI _orig) + { + m_orig = _orig; + } + + public NodeAPI getOriginal() + { + return m_orig; + } + + public String getUUID() + { + return m_uuid; + } + + + @Override + public List<NodeAPI> getChildList() + { + // TODO Auto-generated method stub + return m_children; + } + + @Override + public boolean isChild(NodeAPI _child) + { + // TODO Auto-generated method stub + return m_children.contains(_child); + } + + @Override + public void addChild(NodeAPI _child) { + // TODO Auto-generated method stub + m_children.add(_child); + m_flagChanged = true; + } + + @Override + public void removeChild(NodeAPI _child) { + // TODO Auto-generated method stub + if(m_children.remove(_child)){ + m_flagChanged = true; + } + } + + @Override + public void up(NodeAPI _child) { + // TODO Auto-generated method stub + int curPos = m_children.indexOf(_child); + if(curPos - 1 > 0){ + m_children.add(curPos - 1,m_children.remove(curPos)); + m_flagChanged = true; + } + } + + @Override + public void down(NodeAPI _child) { + // TODO Auto-generated method stub + int curPos = m_children.indexOf(_child); + if(curPos + 1 < m_children.size()){ + m_children.add(curPos + 1,m_children.remove(curPos)); + m_flagChanged = true; + } + } + + @Override + public void setClassName(String _class) { + // TODO Auto-generated method stub + this.m_class = _class; + m_flagChanged = true; + } + + @Override + public void setTitle(String _title) { + // TODO Auto-generated method stub + this.m_title = _title; + m_flagChanged = true; + } + + @Override + public String getClassName() { + // TODO Auto-generated method stub + return this.m_class; + } + + @Override + public String getTitle() { + // TODO Auto-generated method stub + return this.m_title; + } + + @Override + public Iterator<NodeAPI> iterator() { + // TODO Auto-generated method stub + return m_children.iterator(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/treecms/proto/edit/type1/EditableNodeAPITreeBuilder.java Sat Aug 28 20:39:41 2010 +0900 @@ -0,0 +1,69 @@ +package treecms.proto.edit.type1; + +import java.util.List; +import java.util.UUID; + +import treecms.proto.api.NodeAPI; +import treecms.proto.api.NodeAPITreeBuilder; + +public class EditableNodeAPITreeBuilder implements NodeAPITreeBuilder +{ + 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 this.m_clone; + } + + @Override + public NodeAPI createNode() { + // TODO Auto-generated method stub + return new EditableNodeAPI(generateUUID()); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/treecms/proto/edit/type2/EditableNodeAPI.java Sat Aug 28 20:39:41 2010 +0900 @@ -0,0 +1,151 @@ +package treecms.proto.edit.type2; + +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import treecms.proto.api.NodeAPI; + +public class EditableNodeAPI implements NodeAPI +{ + private boolean m_flagChanged; + + private String m_class; + private String m_title; + + private NodeAPI m_orig; + + private LinkedList<NodeAPI> m_children; + + public EditableNodeAPI(NodeAPI _orig) + { + m_orig = _orig; + if(m_orig != null){ + m_flagChanged = false; + }else{ + m_flagChanged = true; + } + + m_children = new LinkedList<NodeAPI>(); + m_class = ""; + m_title = ""; + } + + void _resetFlag() + { + m_flagChanged = false; + } + + public synchronized boolean setandgetChanged(boolean _flag) + { + m_flagChanged = m_flagChanged | _flag; + return m_flagChanged; + } + + public void setOriginal(NodeAPI _orig) + { + m_orig = _orig; + } + + public NodeAPI getOriginal() + { + return m_orig; + } + + @Override + public List<NodeAPI> getChildList() + { + // TODO Auto-generated method stub + if(setandgetChanged(false)){ + return this.m_children; + } + return this.m_orig.getChildList(); + } + + @Override + public boolean isChild(NodeAPI _child) + { + // TODO Auto-generated method stub + if(setandgetChanged(false)){ + return m_children.contains(_child); + } + return m_orig.getChildList().contains(_child); + } + + @Override + public void addChild(NodeAPI _child) { + // TODO Auto-generated method stub + if(m_children.add(_child)){ + setandgetChanged(true); + } + } + + @Override + public void removeChild(NodeAPI _child) { + // TODO Auto-generated method stub + if(m_children.remove(_child)){ + setandgetChanged(true); + } + } + + @Override + public void up(NodeAPI _child) { + // TODO Auto-generated method stub + int curPos = m_children.indexOf(_child); + if(curPos - 1 > 0){ + m_children.add(curPos - 1,m_children.remove(curPos)); + setandgetChanged(true); + } + } + + @Override + public void down(NodeAPI _child) { + // TODO Auto-generated method stub + int curPos = m_children.indexOf(_child); + if(curPos + 1 < m_children.size()){ + m_children.add(curPos + 1,m_children.remove(curPos)); + m_flagChanged = true; + } + } + + @Override + public void setClassName(String _class) { + // TODO Auto-generated method stub + this.m_class = _class; + setandgetChanged(true); + } + + @Override + public void setTitle(String _title) { + // TODO Auto-generated method stub + this.m_title = _title; + setandgetChanged(true); + } + + @Override + public String getClassName() { + // TODO Auto-generated method stub + if(setandgetChanged(false)){ + return this.m_class; + } + return m_orig.getClassName(); + } + + @Override + public String getTitle() { + // TODO Auto-generated method stub + if(setandgetChanged(false)){ + return this.m_title; + } + return m_orig.getClassName(); + } + + @Override + public Iterator<NodeAPI> iterator() { + // TODO Auto-generated method stub + if(setandgetChanged(false)){ + return m_children.iterator(); + } + return m_orig.iterator(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/treecms/proto/edit/type2/EditableNodeAPITreeBuilder.java Sat Aug 28 20:39:41 2010 +0900 @@ -0,0 +1,67 @@ +package treecms.proto.edit.type2; + +import java.util.List; +import java.util.UUID; + +import treecms.proto.api.NodeAPI; +import treecms.proto.api.NodeAPITreeBuilder; + +public class EditableNodeAPITreeBuilder implements NodeAPITreeBuilder +{ + 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(_orig); + + List<NodeAPI> children = _orig.getChildList(); + for(NodeAPI child : children){ + //System.out.println(child.getTitle()); + clone.addChild(clone(child)); + } + + clone._resetFlag(); + 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 this.m_clone; + } + + @Override + public NodeAPI createNode() { + // TODO Auto-generated method stub + return new EditableNodeAPI(null); + } + +}
--- a/src/treecms/proto/test/Test2.java Sat Aug 28 18:10:53 2010 +0900 +++ b/src/treecms/proto/test/Test2.java Sat Aug 28 20:39:41 2010 +0900 @@ -6,6 +6,10 @@ import treecms.proto.simple.*; import treecms.proto.edit.*; +/* + * treecms.proto.edit Test + */ + public class Test2 { public static void main(String _arg[])