use of com.intellij.util.ui.EditableTreeModel in project intellij-community by JetBrains.
the class TreeToolbarDecorator method createDefaultTreeActions.
private void createDefaultTreeActions() {
final EditableTreeModel model = (EditableTreeModel) myTree.getModel();
myAddAction = new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
final TreePath path = myTree.getSelectionPath();
final DefaultMutableTreeNode selected = path == null ? (DefaultMutableTreeNode) myTree.getModel().getRoot() : (DefaultMutableTreeNode) path.getLastPathComponent();
final Object selectedNode = selected.getUserObject();
myTree.stopEditing();
Object element;
if (model instanceof DefaultTreeModel && myProducer != null) {
element = myProducer.createElement();
if (element == null)
return;
} else {
element = null;
}
DefaultMutableTreeNode parent = selected;
if ((selectedNode instanceof SimpleNode && ((SimpleNode) selectedNode).isAlwaysLeaf()) || !selected.getAllowsChildren()) {
parent = (DefaultMutableTreeNode) selected.getParent();
}
if (parent != null) {
parent.insert(new DefaultMutableTreeNode(element), parent.getChildCount());
}
final TreePath createdPath = model.addNode(new TreePath(parent.getPath()));
if (path != null) {
TreeUtil.selectPath(myTree, createdPath);
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
IdeFocusManager.getGlobalInstance().requestFocus(myTree, true);
});
}
}
};
myRemoveAction = new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
myTree.stopEditing();
if (myTree.getSelectionModel().getSelectionMode() == TreeSelectionModel.SINGLE_TREE_SELECTION) {
final TreePath path = myTree.getSelectionPath();
if (path != null) {
model.removeNode(path);
}
} else {
final TreePath[] paths = myTree.getSelectionPaths();
if (paths != null && paths.length > 0) {
model.removeNodes(Arrays.asList(paths));
}
}
}
};
}
Aggregations