IDEA-141247 Allow to remove multiple Annotation Profiles at once

This commit is contained in:
Eugene Zhuravlev
2015-06-10 14:11:13 +02:00
parent bdabf14d5d
commit 484038e916
3 changed files with 38 additions and 8 deletions
@@ -36,6 +36,7 @@ import com.intellij.ui.ToolbarDecorator;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.ui.components.JBList;
import com.intellij.ui.treeStructure.Tree;
import com.intellij.util.SmartList;
import com.intellij.util.ui.EditableTreeModel;
import com.intellij.util.ui.tree.TreeUtil;
import org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile;
@@ -270,14 +271,29 @@ public class AnnotationProcessorsPanel extends JPanel {
@Override
public void removeNode(TreePath nodePath) {
Object node = nodePath.getLastPathComponent();
if (node instanceof ProfileNode) {
final ProcessorConfigProfile nodeProfile = ((ProfileNode)node).myProfile;
if (nodeProfile != myDefaultProfile) {
removeNodes(Collections.singleton(nodePath));
}
public void removeNodes(Collection<TreePath> paths) {
final List<ProcessorConfigProfile> toRemove = new SmartList<ProcessorConfigProfile>();
for (TreePath path : paths) {
Object node = path.getLastPathComponent();
if (node instanceof ProfileNode) {
final ProcessorConfigProfile nodeProfile = ((ProfileNode)node).myProfile;
if (nodeProfile != myDefaultProfile) {
toRemove.add(nodeProfile);
}
}
}
if (!toRemove.isEmpty()) {
boolean changed = false;
for (ProcessorConfigProfile nodeProfile : toRemove) {
if (mySelectedProfile == nodeProfile) {
mySelectedProfile = null;
}
myModuleProfiles.remove(nodeProfile);
changed |= myModuleProfiles.remove(nodeProfile);
}
if (changed) {
((DataSynchronizable)getRoot()).sync();
final DefaultMutableTreeNode object = TreeUtil.findNodeWithObject((DefaultMutableTreeNode)getRoot(), myDefaultProfile);
if (object != null) {
@@ -30,8 +30,10 @@ import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Arrays;
/**
* @author Konstantin Bulenkov
@@ -98,8 +100,18 @@ class TreeToolbarDecorator extends ToolbarDecorator {
@Override
public void run(AnActionButton button) {
myTree.stopEditing();
final TreePath path = myTree.getSelectionPath();
model.removeNode(path);
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));
}
}
}
};
}
@@ -16,6 +16,7 @@
package com.intellij.util.ui;
import javax.swing.tree.TreePath;
import java.util.Collection;
/**
* @author Konstantin Bulenkov
@@ -29,7 +30,8 @@ public interface EditableTreeModel {
*/
TreePath addNode(TreePath parentOrNeighbour);
void removeNode(TreePath parent);
void removeNode(TreePath path);
void removeNodes(Collection<TreePath> path);
void moveNodeTo(TreePath parentOrNeighbour);
}