Search in sources :

Example 1 with DBObject

use of ini.trakem2.persistence.DBObject in project TrakEM2 by trakem2.

the class DBLoader method unpack.

/**
 * Unpack all objects and accumulate them, tagged by their id.
 */
private void unpack(ProjectThing root, HashMap hs) {
    Object ob = root.getObject();
    if (null != ob && ob instanceof DBObject) {
        DBObject dbo = (DBObject) ob;
        hs.put(new Long(dbo.getId()), dbo);
    } else {
    // Utils.log("ProjectThing " + root + " has ob: " + ob);
    }
    if (null == root.getChildren())
        return;
    Iterator it = root.getChildren().iterator();
    while (it.hasNext()) {
        ProjectThing pt = (ProjectThing) it.next();
        unpack(pt, hs);
    }
}
Also used : Iterator(java.util.Iterator) ProjectThing(ini.trakem2.tree.ProjectThing)

Example 2 with DBObject

use of ini.trakem2.persistence.DBObject in project TrakEM2 by trakem2.

the class DBLoader method unpackLayers.

/**
 * Recursive. Place all Layer (but not LayerSet) objects with a key as Long(id).
 */
private void unpackLayers(LayerThing root, HashMap hs) {
    Object ob = root.getObject();
    if (ob instanceof Layer)
        hs.put(new Long(((DBObject) ob).getId()), ob);
    if (null == root.getChildren())
        return;
    Iterator it = root.getChildren().iterator();
    while (it.hasNext()) {
        LayerThing child = (LayerThing) it.next();
        unpackLayers(child, hs);
    }
}
Also used : LayerThing(ini.trakem2.tree.LayerThing) Iterator(java.util.Iterator) Layer(ini.trakem2.display.Layer)

Example 3 with DBObject

use of ini.trakem2.persistence.DBObject in project TrakEM2 by trakem2.

the class ProjectThing method createChild.

public ProjectThing createChild(String type) {
    // create the Displayable
    TemplateThing tt = template.getChildTemplate(type);
    if (null == tt) {
        Utils.log2("Can't create a child of type " + type);
        return null;
    }
    Object ob = project.makeObject(tt);
    Layer layer = null;
    if (ob instanceof Displayable) {
        // which layer to add it to? Get it from the front Display
        layer = Display.getFrontLayer(this.project);
        if (null == layer) {
            Utils.showMessage("Open a display first!");
            ((DBObject) ob).removeFromDatabase();
            return null;
        }
    }
    // wrap it in a new ProjectThing
    ProjectThing pt = null;
    try {
        pt = new ProjectThing(tt, project, ob);
    } catch (Exception e) {
        IJError.print(e);
        return null;
    }
    // add it here as child
    addChild(pt);
    // finally, add it to the layer if appropriate
    if (null != layer) {
        if (ob instanceof ZDisplayable) {
            layer.getParent().add((ZDisplayable) ob);
        } else {
            layer.add((Displayable) ob);
        }
    }
    // finally, return it to be added to the ProjectTree as a new node
    return pt;
}
Also used : ZDisplayable(ini.trakem2.display.ZDisplayable) ZDisplayable(ini.trakem2.display.ZDisplayable) Displayable(ini.trakem2.display.Displayable) DBObject(ini.trakem2.persistence.DBObject) Layer(ini.trakem2.display.Layer) DBObject(ini.trakem2.persistence.DBObject)

Example 4 with DBObject

use of ini.trakem2.persistence.DBObject in project TrakEM2 by trakem2.

the class ProjectTree method rename.

public void rename(final ProjectThing thing) {
    final Object ob = thing.getObject();
    final String old_title;
    if (null == ob)
        old_title = thing.getType();
    else if (ob instanceof DBObject)
        old_title = ((DBObject) ob).getTitle();
    else
        old_title = ob.toString();
    GenericDialog gd = ControlWindow.makeGenericDialog("New name");
    gd.addMessage("Old name: " + old_title);
    gd.addStringField("New name: ", old_title, 40);
    gd.showDialog();
    if (gd.wasCanceled())
        return;
    String title = gd.getNextString();
    if (null == title) {
        Utils.log("WARNING: avoided setting the title to null for " + thing);
        return;
    }
    // avoid XML problems - could also replace by double '', then replace again by " when reading.
    title = title.replace('"', '\'').trim();
    project.getRootLayerSet().addUndoStep(new RenameThingStep(thing));
    if (title.length() == 0) {
        // Set the title to the template type
        thing.setTitle(thing.getTemplate().getType());
        return;
    }
    thing.setTitle(title);
    this.updateUILater();
    project.getRootLayerSet().addUndoStep(new RenameThingStep(thing));
}
Also used : GenericDialog(ij.gui.GenericDialog) DBObject(ini.trakem2.persistence.DBObject) DBObject(ini.trakem2.persistence.DBObject)

Example 5 with DBObject

use of ini.trakem2.persistence.DBObject in project TrakEM2 by trakem2.

the class Project method findById.

public DBObject findById(final long id) {
    if (this.id == id)
        return this;
    DBObject dbo = layer_set.findById(id);
    if (null != dbo)
        return dbo;
    // could call findObject(id), but all objects must exist in layer sets anyway.
    dbo = root_pt.findChild(id);
    if (null != dbo)
        return dbo;
    return (DBObject) root_tt.findChild(id);
}
Also used : DBObject(ini.trakem2.persistence.DBObject)

Aggregations

DBObject (ini.trakem2.persistence.DBObject)9 Layer (ini.trakem2.display.Layer)6 LayerSet (ini.trakem2.display.LayerSet)4 Patch (ini.trakem2.display.Patch)4 Displayable (ini.trakem2.display.Displayable)3 ZDisplayable (ini.trakem2.display.ZDisplayable)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 GenericDialog (ij.gui.GenericDialog)2 AffineTransform (java.awt.geom.AffineTransform)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 TreePath (javax.swing.tree.TreePath)2 Project (ini.trakem2.Project)1 AreaList (ini.trakem2.display.AreaList)1 AreaTree (ini.trakem2.display.AreaTree)1 Coordinate (ini.trakem2.display.Coordinate)1