Search in sources :

Example 1 with FileChooserAction

use of com.intellij.openapi.fileChooser.actions.FileChooserAction in project intellij-community by JetBrains.

the class JdkPopupAction method showPopupMenu.

private static void showPopupMenu(AnActionEvent e, final ArrayList<Pair<File, String>> jdkLocations, boolean showInMiddle, JComponent component) {
    ActionPopupMenu menu = ActionManager.getInstance().createActionPopupMenu(e.getPlace(), new ActionGroup() {

        @NotNull
        @Override
        public AnAction[] getChildren(@Nullable AnActionEvent e) {
            List<AnAction> result = new ArrayList<>();
            for (final Pair<File, String> homes : jdkLocations) {
                result.add(new FileChooserAction("", null, null) {

                    @Override
                    protected void update(FileSystemTree fileChooser, AnActionEvent e) {
                        e.getPresentation().setText(homes.getSecond(), false);
                        boolean selected = false;
                        VirtualFile selectedFile = fileChooser.getSelectedFile();
                        if (selectedFile != null) {
                            selected = homes.getFirst().getAbsolutePath().equals(VfsUtilCore.virtualToIoFile(selectedFile).getAbsolutePath());
                        }
                        e.getPresentation().setIcon(selected ? AllIcons.Diff.CurrentLine : null);
                    }

                    @Override
                    protected void actionPerformed(FileSystemTree fileChooser, AnActionEvent e) {
                        fileChooser.select(VfsUtil.findFileByIoFile(homes.getFirst(), true), null);
                    }
                });
            }
            return result.toArray(new AnAction[result.size()]);
        }
    });
    JPopupMenu menuComponent = menu.getComponent();
    if (showInMiddle) {
        menuComponent.show(component, (component.getWidth() - menuComponent.getWidth()) / 2, (component.getHeight() - menuComponent.getHeight()) / 2);
    } else {
        menuComponent.show(component, 0, component.getHeight());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileChooserAction(com.intellij.openapi.fileChooser.actions.FileChooserAction) NotNull(org.jetbrains.annotations.NotNull) ArrayList(java.util.ArrayList) List(java.util.List) FileSystemTree(com.intellij.openapi.fileChooser.FileSystemTree) Pair(com.intellij.openapi.util.Pair)

Aggregations

FileSystemTree (com.intellij.openapi.fileChooser.FileSystemTree)1 FileChooserAction (com.intellij.openapi.fileChooser.actions.FileChooserAction)1 Pair (com.intellij.openapi.util.Pair)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 NotNull (org.jetbrains.annotations.NotNull)1