ini.trakem2.tree
Class TemplateThing

java.lang.Object
  extended by ini.trakem2.persistence.DBObject
      extended by ini.trakem2.tree.TemplateThing
All Implemented Interfaces:
Thing

public final class TemplateThing
extends DBObject
implements Thing


Field Summary
 
Fields inherited from class ini.trakem2.persistence.DBObject
id, project
 
Constructor Summary
TemplateThing(java.lang.String type)
          Create a new non-database-stored TemplateThing.
TemplateThing(java.lang.String type, Project project)
          Create a new database-stored TemplateThing.
TemplateThing(java.lang.String type, Project project, long id)
          Reconstruct a TemplateThing from the database.
 
Method Summary
 boolean addChild(Thing child)
           
 void addToDatabase(Project project)
          Recursive into children! Will add the attributes as well and grab an id for this instance.
 boolean canHaveAsChild(Thing thing)
           
 TemplateThing clone(Project pr, boolean copy_id)
          Recursive into children: clones the whole tree from this node downward.
 java.util.ArrayList<TemplateThing> collectAllChildren(java.util.ArrayList<TemplateThing> al)
          Recursive into children.
 java.util.HashSet<TemplateThing> collectSimilarThings(TemplateThing tt, java.util.HashSet<TemplateThing> hs)
          Recursive into children, find those of the given type that have the same immediate parent type as the given TemplateThing.
 java.util.HashSet<TemplateThing> collectSimilarThings2(TemplateThing tt, java.util.HashSet<TemplateThing> hs)
          Recursive into children, find those of the same type as the given TemplateThing and whose number of children is the same to those of the given TemplateThing (to exclude nested types).
 java.util.HashSet<TemplateThing> collectThingsOfEqualType(TemplateThing tt, java.util.HashSet<TemplateThing> hs)
          Find things of the same type, even if their parents are different, recusively into children.
 void debug(java.lang.String indent)
           
 void exportDTD(java.lang.StringBuilder sb_header, java.util.HashSet<java.lang.String> hs, java.lang.String indent)
          Only the header !ELEMENT and !ATTLIST.
 void exportXMLTemplate(java.lang.StringBuffer sb_header, java.lang.StringBuffer sb_body, java.util.HashSet<java.lang.String> hs, java.lang.String indent)
           
 Thing findChild(java.lang.Object ob)
          Ah, we love interfaces don't we.
 java.util.ArrayList<TemplateThing> getChildren()
           
 TemplateThing getChildTemplate(java.lang.String type)
           
 java.lang.String getInfo()
          Return information on this node and its object.
 java.lang.Object getObject()
          Returns null always, for TemplateThings don't hold any real object.
 Thing getParent()
           
protected  java.util.ArrayList<TemplateThing> getTemplatePathTo(java.lang.String type, java.util.ArrayList<TemplateThing> al)
          Returns the list of parents to reach a particular child, starting at this, and including the child.
 java.lang.String getType()
           
 java.util.HashMap<java.lang.String,TemplateThing> getUniqueTypes(java.util.HashMap<java.lang.String,TemplateThing> ht)
          Recursive into children.
 java.lang.String getValue()
           
 boolean hasChildren()
           
 boolean isExpanded()
           
 boolean isNested()
          Determine whether this instance is nested inside the tree of an instance of the same type (for example, a neurite_branch inside another neurite_branch)
 boolean remove(boolean check)
          Subclasses can override this method to perform other tasks before removing itself from the database.
 boolean removeChild(TemplateThing child)
           
protected  void rename(java.lang.String new_name)
          Change the type to new_name.
 void setParent(Thing parent)
           
 void setup(java.util.ArrayList<TemplateThing> al_children)
          For reconstruction purposes.
 void setValue(java.lang.String value)
           
 Thing shallowCopy()
          A new copy with same type, same project, same id, but no parent and no children.
 java.lang.String toString()
           
 boolean uniquePathExists(java.lang.String type)
          Check if a unique path exists through the child trees until reaching a Thing of the given type.
 
Methods inherited from class ini.trakem2.persistence.DBObject
addToDatabase, exportXML, getId, getProject, getShortTitle, getTitle, getUniqueIdentifier, removeFromDatabase, updateInDatabase, updateInDatabase
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ini.trakem2.tree.Thing
getTitle
 

Constructor Detail

TemplateThing

public TemplateThing(java.lang.String type)
Create a new non-database-stored TemplateThing.


TemplateThing

public TemplateThing(java.lang.String type,
                     Project project)
Create a new database-stored TemplateThing.


TemplateThing

public TemplateThing(java.lang.String type,
                     Project project,
                     long id)
Reconstruct a TemplateThing from the database.

Method Detail

shallowCopy

public Thing shallowCopy()
A new copy with same type, same project, same id, but no parent and no children.

Specified by:
shallowCopy in interface Thing

setup

public void setup(java.util.ArrayList<TemplateThing> al_children)
For reconstruction purposes.


addToDatabase

public void addToDatabase(Project project)
Recursive into children! Will add the attributes as well and grab an id for this instance.


setValue

public void setValue(java.lang.String value)

getValue

public java.lang.String getValue()

setParent

public void setParent(Thing parent)
Specified by:
setParent in interface Thing

getParent

public Thing getParent()
Specified by:
getParent in interface Thing

toString

public java.lang.String toString()
Specified by:
toString in interface Thing
Overrides:
toString in class java.lang.Object

getType

public java.lang.String getType()
Specified by:
getType in interface Thing

getChildTemplate

public TemplateThing getChildTemplate(java.lang.String type)

addChild

public boolean addChild(Thing child)
Specified by:
addChild in interface Thing

getChildren

public java.util.ArrayList<TemplateThing> getChildren()
Specified by:
getChildren in interface Thing

hasChildren

public boolean hasChildren()
Specified by:
hasChildren in interface Thing

canHaveAsChild

public boolean canHaveAsChild(Thing thing)
Specified by:
canHaveAsChild in interface Thing

uniquePathExists

public boolean uniquePathExists(java.lang.String type)
Check if a unique path exists through the child trees until reaching a Thing of the given type. Does not look inside that found thing if any.


getTemplatePathTo

protected java.util.ArrayList<TemplateThing> getTemplatePathTo(java.lang.String type,
                                                               java.util.ArrayList<TemplateThing> al)
Returns the list of parents to reach a particular child, starting at this, and including the child. Only the first path is reported, others are ignored.


getObject

public java.lang.Object getObject()
Returns null always, for TemplateThings don't hold any real object.

Specified by:
getObject in interface Thing

findChild

public Thing findChild(java.lang.Object ob)
Ah, we love interfaces don't we. This method returns null.

Specified by:
findChild in interface Thing

getUniqueTypes

public java.util.HashMap<java.lang.String,TemplateThing> getUniqueTypes(java.util.HashMap<java.lang.String,TemplateThing> ht)
Recursive into children. The parent of each stored TemplateThing are not meaningful for a tree; only the children are meaningful.


collectAllChildren

public java.util.ArrayList<TemplateThing> collectAllChildren(java.util.ArrayList<TemplateThing> al)
Recursive into children.


rename

protected void rename(java.lang.String new_name)
Change the type to new_name.


remove

public boolean remove(boolean check)
Description copied from class: DBObject
Subclasses can override this method to perform other tasks before removing itself from the database.

Overrides:
remove in class DBObject

removeChild

public boolean removeChild(TemplateThing child)

collectSimilarThings

public java.util.HashSet<TemplateThing> collectSimilarThings(TemplateThing tt,
                                                             java.util.HashSet<TemplateThing> hs)
Recursive into children, find those of the given type that have the same immediate parent type as the given TemplateThing.


collectSimilarThings2

public java.util.HashSet<TemplateThing> collectSimilarThings2(TemplateThing tt,
                                                              java.util.HashSet<TemplateThing> hs)
Recursive into children, find those of the same type as the given TemplateThing and whose number of children is the same to those of the given TemplateThing (to exclude nested types).


collectThingsOfEqualType

public java.util.HashSet<TemplateThing> collectThingsOfEqualType(TemplateThing tt,
                                                                 java.util.HashSet<TemplateThing> hs)
Find things of the same type, even if their parents are different, recusively into children.


isNested

public boolean isNested()
Determine whether this instance is nested inside the tree of an instance of the same type (for example, a neurite_branch inside another neurite_branch)


exportDTD

public void exportDTD(java.lang.StringBuilder sb_header,
                      java.util.HashSet<java.lang.String> hs,
                      java.lang.String indent)
Only the header !ELEMENT and !ATTLIST.


exportXMLTemplate

public void exportXMLTemplate(java.lang.StringBuffer sb_header,
                              java.lang.StringBuffer sb_body,
                              java.util.HashSet<java.lang.String> hs,
                              java.lang.String indent)

debug

public void debug(java.lang.String indent)
Specified by:
debug in interface Thing

isExpanded

public boolean isExpanded()
Specified by:
isExpanded in interface Thing

getInfo

public java.lang.String getInfo()
Return information on this node and its object.

Specified by:
getInfo in interface Thing
Overrides:
getInfo in class DBObject

clone

public TemplateThing clone(Project pr,
                           boolean copy_id)
Recursive into children: clones the whole tree from this node downward.