try {
TreePath path = mainTree.getSelectionPath();
Object treeItem = (path == null) ? null : path.getLastPathComponent();
if (treeItem != null &&
treeItem instanceof DirectoryTextTemplateTreeItem) {
DirectoryTextTemplateTreeItem item = (DirectoryTextTemplateTreeItem) treeItem;
DirectoryTextTemplate dir = (DirectoryTextTemplate) DirectoryLocator.getDirectory(DirectoryTextTemplate.class, false);
List<DirectoryTextTemplateItem> list = dir.getItems(item);
if (list.size() > 0) {
throw new ClipsException("Сначала удалите все шаблоны из группы");
}
//remove from DB
DirectoryTextTemplateTreeItem parent = item.getParent();
if (parent != null) {
parent.getItems().remove(item);
} else {
DirectoryTextTemplateTree treedir = (DirectoryTextTemplateTree) DirectoryLocator.getDirectory(DirectoryTextTemplateTree.class, false);
treedir.getItems().remove(item);
}
//updating structure