// default content repository.
ContentRepositoryRegistry registry =
ContentRepositoryRegistry.getInstance();
ContentRepository repo = registry.getRepository(session);
try {
ContentCollection sysCollection = repo.getSystemRoot();
ContentCollection userCollection =
(ContentCollection) repo.getRoot().getChild("users");
jtree.addTreeRoot(BUNDLE.getString("System"), sysCollection);
jtree.addTreeRoot(BUNDLE.getString("Users"), userCollection);
factoryMap.put(sysCollection, new ContentRepoNodeURIFactory());
factoryMap.put(userCollection, new ContentRepoNodeURIFactory());
} catch (ContentRepositoryException excp) {
logger.log(Level.WARNING, "Unable to create roots", excp);
}
// Formulate the "home" path as /Users/<login name>
try {
homePath = "/Users/" + repo.getUserRoot().getName();
} catch (ContentRepositoryException excp) {
logger.log(Level.WARNING, "Unable to find user's home", excp);
}
// Add the Module tree root, using a wrapper for the content repo to
// present the modules properly
try {
ContentCollection moduleCollection =
new ModuleRootContentCollection(repo);
jtree.addTreeRoot(BUNDLE.getString("Modules"), moduleCollection);
factoryMap.put(moduleCollection, new ModuleNodeURIFactory());
} catch (ContentRepositoryException excp) {
logger.log(Level.WARNING, "Unable to create module root", excp);
}
// Create a new table to display a particular directory. We use an
// AsynchronousJTable so that the entries are loaded asychronously in
// case a network call is required to load the children.
jtable = new AsynchronousJTable();
JScrollPane tableScrollPane = new JScrollPane();
tableScrollPane.setViewportView(jtable);
tablePanel.add(tableScrollPane);
// Listen for selections on the tree and update the right-hand table
// with the children for the currently selected node.
jtree.addAsyncTreeSelectionListener(new AsyncTreeSelectionListener() {
public void treeSelectionChanged(ContentNode node) {
treeSelectedNode = node;
if (node == null) {
jtable.setContentCollection(null);
} else if (node instanceof ContentCollection) {
jtable.setContentCollection((ContentCollection) node);
}
}
});
// Listen for when a new directory/file is selected in the list of
// files in a content repository. Update the state of the buttons
jtable.addAsyncTableSelectionListener(new AsyncTableSelectionListener() {
public void tableSelectionChanged(
ContentNode node, boolean changeTo) {
// If we select a node that isn't been selected then update
// the table with the new selection.
if (tableSelectedNode != node) {
tableSelectedNode = node;
changeTableSelection(node);
}
// If this selection was really a double-click to open a
// directory, then update the tree selection too. We know that
// the parent of the selected node in the table is the currently
// selected node in the tree. We use this to form the path to
// the newly selected node to expand
if (changeTo == true) {
jtree.expandAndSelectChild(node.getName());
}
}
});
// When the Cancel button is pressed, fire off events to the listeners
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(false);
dispose();
for (ContentBrowserListener l : listenerSet) {
l.cancelAction();
}
}
});
// When the Ok button is pressed, fire off events to the listeners,
// passing them the URI of the selected item
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(false);
dispose();
for (ContentBrowserListener l : listenerSet) {
// We need to get the URI of the selection. We first need a
// factory to generate the URI for us, based upon the root
// of the selected node. We ask the JTree for this.
ContentCollection c = jtree.getSelectedRootCollection();
if (c == null) {
logger.warning("Unable to find selected root");
l.cancelAction();
}