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);
}
}
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);
}
}
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;
}
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));
}
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);
}
Aggregations