* @return tree for selection the transformation target.
*/
private JTree createTree() {
DefaultTreeModel treeModel = new DefaultTreeModel(
new DefaultMutableTreeNode("root"));
JTree result = new JTree(treeModel);
result.addTreeSelectionListener(this);
result.setCellRenderer(new TreeRenderer());
result.getSelectionModel().setSelectionMode(
TreeSelectionModel.SINGLE_TREE_SELECTION);
HashMap lang2list = new HashMap();
TransformTarget[] available = (TransformTarget[]) XslTransformer
.getTransformTargets().toArray(new TransformTarget[0]);
Arrays.sort(available, new LangTypeComp());
for (int i = 0; i < available.length; i++) {
String lang = available[i].getLanguage();
ArrayList list = (ArrayList) lang2list.get(lang);
if (list == null) {
list = new ArrayList();
lang2list.put(lang, list);
}
list.add(available[i]);
}
String[] languages = (String[]) lang2list.keySet().toArray(
new String[0]);
Arrays.sort(languages);
TreePath tp = null;
for (int i = 0; i < languages.length; i++) {
DefaultMutableTreeNode langNode = new DefaultMutableTreeNode(
languages[i]);
((DefaultMutableTreeNode) result.getModel().getRoot())
.add(langNode);
langNode.setAllowsChildren(true);
TransformTarget[] targets = (TransformTarget[]) ((ArrayList) lang2list
.get(languages[i])).toArray(new TransformTarget[0]);
Arrays.sort(targets);
for (int j = 0; j < targets.length; j++) {
DefaultMutableTreeNode tt = new DefaultMutableTreeNode(
targets[j]);
langNode.add(tt);
if (targets[j].equals(transformTask.getConfiguration()
.getTransformTarget())) {
tp = new TreePath(new Object[] {
result.getModel().getRoot(), langNode, tt });
}
}
}
result.setRootVisible(false);
if (tp != null) {
result.setSelectionPath(tp);
} else {
result.expandPath(new TreePath(result.getModel().getRoot()));
}
return result;
}