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());
}
}
Aggregations