diff --git a/src/main/java/com/redhat/devtools/intellij/quarkus/module/QuarkusExtensionsStep.java b/src/main/java/com/redhat/devtools/intellij/quarkus/module/QuarkusExtensionsStep.java index f0ab6da47..777d802b2 100644 --- a/src/main/java/com/redhat/devtools/intellij/quarkus/module/QuarkusExtensionsStep.java +++ b/src/main/java/com/redhat/devtools/intellij/quarkus/module/QuarkusExtensionsStep.java @@ -23,6 +23,7 @@ import com.redhat.devtools.intellij.quarkus.QuarkusConstants; import org.apache.commons.lang.StringUtils; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,6 +40,7 @@ import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; import java.awt.*; +import java.awt.event.*; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashSet; @@ -204,6 +206,7 @@ public void hyperlinkUpdate(HyperlinkEvent e) { } } }); + extensionsTree.addCheckboxTreeListener(new CheckboxTreeListener() { @Override public void nodeStateChanged(@NotNull CheckedTreeNode node) { @@ -220,6 +223,53 @@ public void nodeStateChanged(@NotNull CheckedTreeNode node) { selectedExtensions.setModel(new SelectedExtensionsModel(categories)); } }); + + //(Un)Check extension on double-click + extensionsTree.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() == 2) { + TreePath path = extensionsTree.getPathForLocation(e.getX(), e.getY()); + if (path != null && path.getLastPathComponent() instanceof CheckedTreeNode) { + var treeNode = (CheckedTreeNode) path.getLastPathComponent(); + extensionsTree.setNodeState(treeNode, !treeNode.isChecked()); + } + } + } + }); + + //Unselect extensions on double-click + selectedExtensions.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() == 2) { + int selectedIndex = selectedExtensions.getSelectedIndex(); + if (selectedIndex > -1) { + QuarkusExtension extension = selectedExtensions.getModel().getElementAt(selectedIndex); + CheckedTreeNode treeNode = findTreeNodeForExtension(root, extension); + if (treeNode != null) { + extensionsTree.setNodeState(treeNode, false); + } + } + } + } + }); + + //Unselect extensions when pressing the DELETE or BACKSPACE key + selectedExtensions.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_DELETE || e.getKeyCode() == KeyEvent.VK_BACK_SPACE) { + for (QuarkusExtension extension : selectedExtensions.getSelectedValuesList()) { + CheckedTreeNode treeNode = findTreeNodeForExtension(root, extension); + if (treeNode != null) { + extensionsTree.setNodeState(treeNode, false); + } + } + selectedExtensions.clearSelection(); + } + } + }); + extensionsTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { @@ -274,6 +324,17 @@ private CheckedTreeNode getModel(List categories, SearchTextFie return root; } + private @Nullable CheckedTreeNode findTreeNodeForExtension(@NotNull CheckedTreeNode rootNode, @NotNull QuarkusExtension extension) { + Enumeration enumeration = rootNode.depthFirstEnumeration(); + while (enumeration.hasMoreElements()) { + TreeNode node = enumeration.nextElement(); + if (node instanceof CheckedTreeNode && ((CheckedTreeNode)node).getUserObject() == extension) { + return (CheckedTreeNode)node; + } + } + return null; + } + /** * Use reflection to get IntelliJ specific HTML editor kit as it has moved in 2020.1 *