ini.trakem2.tree
Class ProjectThing

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

public final class ProjectThing
extends DBObject
implements TitledThing


Nested Class Summary
 class ProjectThing.Profile_List
           
 
Field Summary
 
Fields inherited from class ini.trakem2.persistence.DBObject
id, project
 
Constructor Summary
ProjectThing(TemplateThing template, Project project, long id, java.lang.Object ob, java.util.ArrayList<ProjectThing> al_children)
          Reconstruct a ProjectThing from the database, used in combination with the 'setup' method.
ProjectThing(TemplateThing template, Project project, java.lang.Object ob)
          Create a new ProjectThing of the given type to contain the given Object.
 
Method Summary
 boolean addChild(ProjectThing child, int index)
          In addition, if the child contains an object of class ini.trakem2.display.Profile, reorders all children of the parent Thing by the Z of the layers of the profiles.
 boolean addChild(Thing child)
           
 boolean canHaveAsChild(java.lang.String type)
           
 boolean canHaveAsChild(Thing thing)
           
 java.util.HashSet<ProjectThing> collectSimilarThings(TemplateThing tt, java.util.HashSet<ProjectThing> hs)
          Recursive into children, find those of the given type that have the same parent chain as the given TemplateThing.
 ProjectThing createChild(java.lang.String type)
           
 java.util.ArrayList<ProjectThing> createChildren(java.lang.String type, int amount, boolean recursive)
          Creates one instance of the given type and if recursive, also of all possible children of it, and of them, and so on.
 ProjectThing createClonedChild(ProjectThing child)
          At the moment only for basic types, which by definition have no children.
 void debug(java.lang.String indent)
           
 ProjectThing deepClone(Project project, boolean copy_id)
          Clone this ProjectThing with its template and all its children and objects cloned, and return it.
 void exportSVG(java.lang.StringBuffer data, double z_scale, java.lang.String indent)
           
 void exportXML(java.lang.StringBuilder sb_body, java.lang.String indent, java.util.HashMap<? extends Thing,java.lang.Boolean> expanded_states)
           
 void exportXML(java.lang.StringBuilder sb_body, java.lang.String indent, java.lang.Object any)
          Expects a HashMap as @param any.
 java.util.HashSet<ProjectThing> findBasicTypeChildren()
          Recursive into children.
 java.util.HashSet<ProjectThing> findBasicTypeChildren(java.util.HashSet<ProjectThing> hs_basic, java.util.HashSet<ProjectThing> hs_visited)
          Recursive into children, and adds this instance as well if it's a basic type.
 ProjectThing findChild(long id)
          Recursive search for the thing of the given id.
 Thing findChild(java.lang.Object ob)
          Recursive search for the thing that contains the given object.
 void findChildren(java.util.ArrayList<ProjectThing> found, java.util.regex.Pattern pattern, java.util.regex.Pattern pattern_exclude, boolean shallow)
          Recursive into children, searches for things whose object.toString() matches the given regex pattern, and stores the found ProjectThing in the given ArrayList.
 java.util.ArrayList<ProjectThing> findChildren(java.lang.String regex, java.lang.String regex_exclude, boolean shallow)
          Recursive into children, searches for the things whose object.toString() matches the given regex, case insensitive.
<T> java.util.ArrayList<T>
findChildrenOfType(java.lang.Class<T> c)
          Check if this Thing directly contains any child of the given object class (including interfaces), and return them all.
 java.util.ArrayList<ProjectThing> findChildrenOfType(java.lang.String type)
          Check if this Thing directly contains any child of the given type, and return them all.
 java.util.List<ProjectThing> findChildrenOfTypeR(java.lang.Class<?> c)
          Finds them in order.
 java.util.HashSet<ProjectThing> findChildrenOfTypeR(java.util.HashSet<ProjectThing> hs, java.lang.String type)
          Recursive into children.
 java.util.List<ProjectThing> findChildrenOfTypeR(java.util.List<ProjectThing> list, java.lang.Class<?> c)
          Finds them in order.
 java.util.HashSet<ProjectThing> findChildrenOfTypeR(java.lang.String type)
          Recursive into children.
 DBObject findObject(long id)
          Recursive search for the object with the given id.
<T> java.util.List<T>
findObjects(java.lang.Class<T> c)
          Find objects of the given class, as determined by c.isInstance(this.object).
 boolean fixZOrdering()
          If this is of type profile_list, order all children Profile by their layer's Z coordinate, ascending.
 java.util.HashMap<java.lang.String,java.util.ArrayList<ProjectThing>> getByType()
          Recursively browse all children to classify all nodes by type.
 java.util.ArrayList<ProjectThing> getChildren()
           
 TemplateThing getChildTemplate(java.lang.String type)
           
 java.lang.String getInfo()
          Return information on this node and its object, and also on all the children, recursively.
 java.lang.String getNodeInfo()
          Return information on this node and its object.
 java.lang.Object getObject()
           
 Thing getParent()
           
 javax.swing.JMenuItem[] getPopupItems(java.awt.event.ActionListener listener)
           
 ProjectThing getRootParent()
          Crawl up until finding a parent that has no parent: the root.
 TemplateThing getTemplate()
           
 java.util.ArrayList<TemplateThing> getTemplatePathTo(java.lang.String type)
          Returns a list of parent types (String), in order, for the given Thing if it exists as a child in the traversed trees.
 java.lang.String getTitle()
          Sublcasses can override this method to provide a proper String, otherwise calls toString()
 java.lang.String getType()
           
 boolean hasChildren()
           
 boolean hasParent(java.lang.String type)
          Check if this or any of its parents are of the given type.
 boolean isExpanded()
           
 void measure()
          Measure each node, recursively into children, and at the end display all the result tables, one for each data type.
 java.util.HashMap<java.lang.Class<?>,ij.measure.ResultsTable> measure(java.util.HashMap<java.lang.Class<?>,ij.measure.ResultsTable> ht)
          Call on children things, and on itself if it contains a basic data type directly.
 boolean move(int inc)
          Moves this ProjectThing up and down the parent's children list.
 boolean remove(boolean check)
          Subclasses can override this method to perform other tasks before removing itself from the database.
protected  boolean remove(boolean check, boolean remove_object)
           
 boolean removeChild(ProjectThing child)
           
 void setObject(java.lang.Object object)
          Used by the TMLHandler; can be used only once.
 void setParent(Thing parent)
           
 void setTitle(java.lang.String title)
           
 void setup()
           
 void setVisible(boolean b)
          Switch the visibility of the Displayable objects contained here or in the children.
 Thing shallowCopy()
          A new copy with same template, same object and cloned table of same attributes, but no parent and no children.
 ProjectThing subclone(Project pr)
          Implicit id copying; assumes the ids of the object are also the same in the given project; the object, if it is a DBObject, is retrieved from the given project by matching its id.
 java.lang.String toString()
           
 boolean uniquePathExists(java.lang.String type)
          Check if any of the possible children of this Thing can have the given Thing as child, or any of they children can, recursing down.
 void updateTitle()
          Recursive into children and object (to update it's DisplayablePanel title).
 void updateType(java.lang.String new_type, java.lang.String old_type)
          Recursive into children, changes the type column in the ab_things table.
 
Methods inherited from class ini.trakem2.persistence.DBObject
addToDatabase, getId, getProject, getShortTitle, getUniqueIdentifier, removeFromDatabase, updateInDatabase, updateInDatabase
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ProjectThing

public ProjectThing(TemplateThing template,
                    Project project,
                    java.lang.Object ob)
             throws java.lang.Exception
Create a new ProjectThing of the given type to contain the given Object. The object cannot be null.

Throws:
java.lang.Exception

ProjectThing

public ProjectThing(TemplateThing template,
                    Project project,
                    long id,
                    java.lang.Object ob,
                    java.util.ArrayList<ProjectThing> al_children)
Reconstruct a ProjectThing from the database, used in combination with the 'setup' method.

Method Detail

shallowCopy

public Thing shallowCopy()
A new copy with same template, same object and cloned table of same attributes, but no parent and no children.

Specified by:
shallowCopy in interface Thing

deepClone

public ProjectThing deepClone(Project project,
                              boolean copy_id)
                       throws java.lang.Exception
Clone this ProjectThing with its template and all its children and objects cloned, and return it. The templates are added to the project as unique types when not there yet. WARNING there isn't any conflict resolution between potentially different kinds of TemplateThing parent/child chains.

Throws:
java.lang.Exception

setObject

public void setObject(java.lang.Object object)
Used by the TMLHandler; can be used only once.


setup

public void setup()

toString

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

getTitle

public java.lang.String getTitle()
Description copied from class: DBObject
Sublcasses can override this method to provide a proper String, otherwise calls toString()

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

addChild

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

addChild

public boolean addChild(ProjectThing child,
                        int index)
In addition, if the child contains an object of class ini.trakem2.display.Profile, reorders all children of the parent Thing by the Z of the layers of the profiles.


getChildren

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

hasChildren

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

removeChild

public boolean removeChild(ProjectThing child)

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

remove

protected boolean remove(boolean check,
                         boolean remove_object)

setParent

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

getParent

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

getRootParent

public ProjectThing getRootParent()
Crawl up until finding a parent that has no parent: the root.


hasParent

public boolean hasParent(java.lang.String type)
Check if this or any of its parents are of the given type.


setTitle

public void setTitle(java.lang.String title)
Specified by:
setTitle in interface TitledThing

getObject

public java.lang.Object getObject()
Specified by:
getObject in interface Thing

getChildTemplate

public TemplateThing getChildTemplate(java.lang.String type)

canHaveAsChild

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

uniquePathExists

public boolean uniquePathExists(java.lang.String type)
Check if any of the possible children of this Thing can have the given Thing as child, or any of they children can, recursing down. Returns true only if one possibility exists.


getTemplatePathTo

public java.util.ArrayList<TemplateThing> getTemplatePathTo(java.lang.String type)
Returns a list of parent types (String), in order, for the given Thing if it exists as a child in the traversed trees. This method returns the first path that it finds, avoiding a check to uniquePathExists(type).


getType

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

getTemplate

public TemplateThing getTemplate()

getPopupItems

public javax.swing.JMenuItem[] getPopupItems(java.awt.event.ActionListener listener)

setVisible

public void setVisible(boolean b)
Switch the visibility of the Displayable objects contained here or in the children.


createChildren

public java.util.ArrayList<ProjectThing> createChildren(java.lang.String type,
                                                        int amount,
                                                        boolean recursive)
Creates one instance of the given type and if recursive, also of all possible children of it, and of them, and so on.

Returns:
all created nodes, or null if the given type cannot be contained here as a child.

canHaveAsChild

public boolean canHaveAsChild(java.lang.String type)

createChild

public ProjectThing createChild(java.lang.String type)

createClonedChild

public ProjectThing createClonedChild(ProjectThing child)
At the moment only for basic types, which by definition have no children.


findChildren

public java.util.ArrayList<ProjectThing> findChildren(java.lang.String regex,
                                                      java.lang.String regex_exclude,
                                                      boolean shallow)
Recursive into children, searches for the things whose object.toString() matches the given regex, case insensitive. If shallow, the recursive search does not look into the children of a parent that matches.


findChildren

public void findChildren(java.util.ArrayList<ProjectThing> found,
                         java.util.regex.Pattern pattern,
                         java.util.regex.Pattern pattern_exclude,
                         boolean shallow)
Recursive into children, searches for things whose object.toString() matches the given regex pattern, and stores the found ProjectThing in the given ArrayList. If shallow, the recursive search does not look into the children of a parent that matches.


findChild

public Thing findChild(java.lang.Object ob)
Recursive search for the thing that contains the given object.

Specified by:
findChild in interface Thing

findChild

public ProjectThing findChild(long id)
Recursive search for the thing of the given id.


findObject

public DBObject findObject(long id)
Recursive search for the object with the given id.


measure

public java.util.HashMap<java.lang.Class<?>,ij.measure.ResultsTable> measure(java.util.HashMap<java.lang.Class<?>,ij.measure.ResultsTable> ht)
Call on children things, and on itself if it contains a basic data type directly. All children of the same type report to the same table. Result tables are returned without ever displaying them.


measure

public void measure()
Measure each node, recursively into children, and at the end display all the result tables, one for each data type.


exportSVG

public void exportSVG(java.lang.StringBuffer data,
                      double z_scale,
                      java.lang.String indent)

findChildrenOfType

public java.util.ArrayList<ProjectThing> findChildrenOfType(java.lang.String type)
Check if this Thing directly contains any child of the given type, and return them all.


findChildrenOfType

public <T> java.util.ArrayList<T> findChildrenOfType(java.lang.Class<T> c)
Check if this Thing directly contains any child of the given object class (including interfaces), and return them all.


findChildrenOfTypeR

public java.util.HashSet<ProjectThing> findChildrenOfTypeR(java.lang.String type)
Recursive into children.


findChildrenOfTypeR

public java.util.HashSet<ProjectThing> findChildrenOfTypeR(java.util.HashSet<ProjectThing> hs,
                                                           java.lang.String type)
Recursive into children.


findChildrenOfTypeR

public java.util.List<ProjectThing> findChildrenOfTypeR(java.lang.Class<?> c)
Finds them in order. Recursive into children.


findChildrenOfTypeR

public java.util.List<ProjectThing> findChildrenOfTypeR(java.util.List<ProjectThing> list,
                                                        java.lang.Class<?> c)
Finds them in order. Recursive into children.


findObjects

public <T> java.util.List<T> findObjects(java.lang.Class<T> c)
Find objects of the given class, as determined by c.isInstance(this.object).


findBasicTypeChildren

public java.util.HashSet<ProjectThing> findBasicTypeChildren()
Recursive into children.


findBasicTypeChildren

public java.util.HashSet<ProjectThing> findBasicTypeChildren(java.util.HashSet<ProjectThing> hs_basic,
                                                             java.util.HashSet<ProjectThing> hs_visited)
Recursive into children, and adds this instance as well if it's a basic type.


updateTitle

public void updateTitle()
Recursive into children and object (to update it's DisplayablePanel title). Does not affect the database.


updateType

public void updateType(java.lang.String new_type,
                       java.lang.String old_type)
Recursive into children, changes the type column in the ab_things table. Only if the given 'type' is equal to this instance's template type, the type will be updated in the database and the title will be updated wherever it shows.


collectSimilarThings

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


exportXML

public void exportXML(java.lang.StringBuilder sb_body,
                      java.lang.String indent,
                      java.lang.Object any)
Expects a HashMap as @param any.

Overrides:
exportXML in class DBObject

exportXML

public void exportXML(java.lang.StringBuilder sb_body,
                      java.lang.String indent,
                      java.util.HashMap<? extends Thing,java.lang.Boolean> expanded_states)

debug

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

fixZOrdering

public boolean fixZOrdering()
If this is of type profile_list, order all children Profile by their layer's Z coordinate, ascending.


isExpanded

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

getNodeInfo

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


getInfo

public java.lang.String getInfo()
Return information on this node and its object, and also on all the children, recursively.

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

subclone

public ProjectThing subclone(Project pr)
Implicit id copying; assumes the ids of the object are also the same in the given project; the object, if it is a DBObject, is retrieved from the given project by matching its id.


move

public boolean move(int inc)
Moves this ProjectThing up and down the parent's children list. Returns false if no movement was done.


getByType

public java.util.HashMap<java.lang.String,java.util.ArrayList<ProjectThing>> getByType()
Recursively browse all children to classify all nodes by type. Returns a table of String types and ArrayList ProjectThing.