Documentum Docbase Swing Tree
Aug 30th 2007alexander.zubanDocumentum & Java

Do you like trees? I do, I like to spend time in forest, take a walk, listen trees.
Small article how to present Documentum docbase structure using the Swing tree. Example quite simple, but easy to understand and provide some basic functionality.
Well, Documentum structure has two types of object’s Folders(dm_folder) and Documents(dm_document). Folder may include other folders or documents. In the root of the structure always represented as Cabinet(dm_cabinet) which is subclass of the folder.
Here is a basic class diagram which will define the tree model structure:
DocumentumNode is an abstract class which is require to implement the following functions and do almost all Documentum stuff
protected abstract String getChildrenDocuType();
protected abstract String getWherePart();
DocbaseNode return as a children type dm_cabinet, FolderNode return dm_sysobject which is base type for dm_folder and dm_document and DocumentNode return null because it can’t have children(well, it is not really so, because document can be a virtual document, and you may extend it if you need this functionality)
DocumentumNode build children list after the first request, so the tree will fetch children in a lazy style. The following function do the job
private void initializeChildren() {
initialized = true;
IDfSession session = null;
IDfCollection collection = null;
try {
session = manager.getSession(docbase);
IDfQuery query = new DfQuery();
query.setDQL("select r_object_id,r_object_type,object_name from "
+ getChildrenDocuType() + " where 1=1 " + getWherePart());
collection = query.execute(session, IDfQuery.DF_READ_QUERY);
while (collection.next()) {
String objectId = collection.getString("r_object_id");
String objectName = collection.getString("object_name");
DocumentumNode child = factory.create(manager, docbase, objectId, objectName, this);
if (child != null) {
add(child);
}
}
} catch (DfException e) {
} finally {
FinallyClose.close(collection);
FinallyClose.close(session);
}
}
Nothing special, right? The FinallyClose class care about collections and sessions resource leak.
public class FinallyClose {
public static void close(IDfSession session) {
if (session != null) {
session.getSessionManager().release(session);
}
}
public static void close(IDfCollection collection) {
try {
if (collection != null) {
collection.close();
}
} catch (DfException ignore) {
}
}
}
Finally, here is an example which is show how to see this Docbase tree in a work. Note, that it will show documents under folders, if you don’t need it, just change model.setShowDocuments(false) and tree will display only folder structure.
IDfSessionManager manager = new DfClient().newSessionManager();
manager.setIdentity(docbase, login);
JFrame frame = new JFrame();
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
System.exit(0);
}
});
Container panel = frame.getContentPane();
panel.setLayout(new BorderLayout());
DocumentumTreeModel model = new DocumentumTreeModel(manager,docbase);
model.setShowDocuments(true);
panel.add(new JScrollPane(new JTree(model)),BorderLayout.CENTER);
panel.setPreferredSize(new Dimension(300,500));
frame.pack();
frame.setVisible(true);

You may download packages with all sources for the Documentum Swing Tree from here.