mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
SdkPopup - use correct parent to show JdkDownload dialog
GitOrigin-RevId: 96cf4f442c652cab21d9322f8820459658b8956d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
eb51bdbcea
commit
7ccd5663a0
+1
-1
@@ -236,7 +236,7 @@ public class JdkListConfigurable extends BaseStructureConfigurable {
|
||||
notSimpleJavaSdkType(),
|
||||
null,
|
||||
sdk -> false)
|
||||
).createPopup(new SdkPopup.SdkPopupListener() { })
|
||||
).createPopup(myTree, new SdkPopup.SdkPopupListener() { })
|
||||
.showPopup(e);
|
||||
}
|
||||
}
|
||||
|
||||
+12
-10
@@ -72,17 +72,23 @@ public class UnknownSdkEditorNotification implements Disposable {
|
||||
|
||||
panel.createActionLabel("Configure...",
|
||||
() -> {
|
||||
//FileEditorManager#addTopComponent wraps the panel to implement borders, unwrapping
|
||||
Container container = panel.getParent();
|
||||
if (container == null) container = panel;
|
||||
|
||||
UnknownSdkTracker
|
||||
.getInstance(myProject)
|
||||
.showSdkSelectionPopup(sdkName, sdkType, container, () -> removeNotification(panel));
|
||||
.showSdkSelectionPopup(sdkName, sdkType, parentJComponentOrSelf(panel), () -> removeNotification(panel));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JComponent parentJComponentOrSelf(@NotNull JComponent panel) {
|
||||
//FileEditorManager#addTopComponent wraps the panel to implement borders, unwrapping
|
||||
Container parent = panel.getParent();
|
||||
if (parent instanceof JComponent) {
|
||||
return (JComponent)parent;
|
||||
}
|
||||
return panel;
|
||||
}
|
||||
|
||||
private void setupPanel(@NotNull MissingSdkNotificationPanel panel,
|
||||
@NotNull String source,
|
||||
@Nullable Runnable setProjectSdk,
|
||||
@@ -100,13 +106,9 @@ public class UnknownSdkEditorNotification implements Disposable {
|
||||
|
||||
if (setSdk != null) {
|
||||
panel.createActionLabel("Configure...", () -> {
|
||||
//FileEditorManager#addTopComponent wraps the panel to implement borders, unwrapping
|
||||
Container container = panel.getParent();
|
||||
if (container == null) container = panel;
|
||||
|
||||
UnknownSdkTracker
|
||||
.getInstance(myProject)
|
||||
.showSdkSelectionPopup(null, container, sdk -> {
|
||||
.showSdkSelectionPopup(null, parentJComponentOrSelf(panel), sdk -> {
|
||||
setSdk.accept(sdk);
|
||||
removeNotification(panel);
|
||||
});
|
||||
|
||||
+4
-4
@@ -38,7 +38,7 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
@@ -191,7 +191,7 @@ public class UnknownSdkTracker {
|
||||
|
||||
public void showSdkSelectionPopup(@NotNull String sdkName,
|
||||
@Nullable SdkType sdkType,
|
||||
@NotNull Container underneathRightOfComponent,
|
||||
@NotNull JComponent underneathRightOfComponent,
|
||||
@NotNull Runnable onSelectionMade) {
|
||||
showSdkSelectionPopup(sdkType, underneathRightOfComponent, sdk -> {
|
||||
registerNewSdkInJdkTable(sdkName, sdk);
|
||||
@@ -200,7 +200,7 @@ public class UnknownSdkTracker {
|
||||
}
|
||||
|
||||
public void showSdkSelectionPopup(@Nullable SdkType sdkType,
|
||||
@NotNull Container underneathRightOfComponent,
|
||||
@NotNull JComponent underneathRightOfComponent,
|
||||
@NotNull Consumer<? super Sdk> onSelectionMade) {
|
||||
ProjectSdksModel model = new ProjectSdksModel();
|
||||
SdkListModelBuilder modelBuilder = new SdkListModelBuilder(
|
||||
@@ -216,7 +216,7 @@ public class UnknownSdkTracker {
|
||||
modelBuilder
|
||||
);
|
||||
|
||||
popup.createPopup(new SdkPopup.SdkPopupListener() {
|
||||
popup.createPopup(underneathRightOfComponent, new SdkPopup.SdkPopupListener() {
|
||||
private void handleNewItem(@NotNull SdkListItem item) {
|
||||
if (item instanceof SdkListItem.SdkItem) {
|
||||
onSelectionMade.consume(((SdkListItem.SdkItem)item).getSdk());
|
||||
|
||||
+7
-7
@@ -11,6 +11,7 @@ import com.intellij.openapi.ui.popup.LightweightWindowEvent;
|
||||
import com.intellij.ui.AnActionButton;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import com.intellij.ui.popup.list.ComboBoxPopup;
|
||||
import java.util.function.Consumer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -32,12 +33,11 @@ public class SdkPopupFactory {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public SdkPopup createPopup(@NotNull SdkPopupListener listener) {
|
||||
public SdkPopup createPopup(@NotNull JComponent parent,
|
||||
@NotNull SdkPopupListener listener) {
|
||||
SdkListItemContext context = new SdkListItemContext();
|
||||
SdkPopupImpl popup = new SdkPopupImpl(context);
|
||||
|
||||
popup.addItemSelectedListener(value -> {
|
||||
if (myModelBuilder.executeAction(popup.getList(), value, listener::onNewItemAdded)) {
|
||||
SdkPopupImpl popup = new SdkPopupImpl(context, value -> {
|
||||
if (myModelBuilder.executeAction(parent, value, listener::onNewItemAdded)) {
|
||||
return;
|
||||
}
|
||||
listener.onExistingItemSelected(value);
|
||||
@@ -71,8 +71,8 @@ public class SdkPopupFactory {
|
||||
}
|
||||
|
||||
private class SdkPopupImpl extends ComboBoxPopup<SdkListItem> implements SdkPopup {
|
||||
SdkPopupImpl(SdkListItemContext context) {
|
||||
super(context, null);
|
||||
SdkPopupImpl(SdkListItemContext context, Consumer<SdkListItem> onItemSelected) {
|
||||
super(context, null, onItemSelected);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-2
@@ -85,7 +85,7 @@ public class DarculaJBPopupComboPopup<T> implements ComboPopup, ComboBoxPopup.Co
|
||||
|
||||
//noinspection unchecked
|
||||
T selectedItem = (T)myComboBox.getSelectedItem();
|
||||
myPopup = new ComboBoxPopup<T>(this, selectedItem) {
|
||||
myPopup = new ComboBoxPopup<T>(this, selectedItem, value -> myComboBox.setSelectedItem(value)) {
|
||||
@Override
|
||||
public void cancel(InputEvent e) {
|
||||
if (e instanceof MouseEvent) {
|
||||
@@ -98,7 +98,6 @@ public class DarculaJBPopupComboPopup<T> implements ComboPopup, ComboBoxPopup.Co
|
||||
super.cancel(e);
|
||||
}
|
||||
};
|
||||
myPopup.addItemSelectedListener(value -> myComboBox.setSelectedItem(value));
|
||||
myPopup.addListener(new JBPopupListener() {
|
||||
@Override
|
||||
public void beforeShown(@NotNull LightweightWindowEvent event) {
|
||||
|
||||
@@ -28,8 +28,9 @@ public class ComboBoxPopup<T> extends ListPopupImpl {
|
||||
private final Context<T> myContext;
|
||||
|
||||
public ComboBoxPopup(@NotNull Context<T> context,
|
||||
@Nullable T selectedItem) {
|
||||
this(context, null, popupStateFromContext(context, selectedItem), null);
|
||||
@Nullable T selectedItem,
|
||||
@NotNull Consumer<T> onItemSelected) {
|
||||
this(context, null, popupStateFromContext(context, onItemSelected, selectedItem), null);
|
||||
}
|
||||
|
||||
private ComboBoxPopup(@NotNull Context<T> context,
|
||||
@@ -41,15 +42,11 @@ public class ComboBoxPopup<T> extends ListPopupImpl {
|
||||
configurePopup();
|
||||
}
|
||||
|
||||
public void addItemSelectedListener(@NotNull Consumer<T> callback) {
|
||||
//noinspection unchecked
|
||||
((MyBasePopupState<T>)getStep()).addItemSelectedListener(callback);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static <T> MyBasePopupState<T> popupStateFromContext(@NotNull Context<T> context,
|
||||
@Nullable Object selectedItem) {
|
||||
MyBasePopupState<T> step = new MyBasePopupState<T>(t -> {},
|
||||
@NotNull Consumer<T> onItemSelected,
|
||||
@Nullable T selectedItem) {
|
||||
MyBasePopupState<T> step = new MyBasePopupState<T>(onItemSelected,
|
||||
() -> context.getModel(),
|
||||
() -> context.getRenderer()) {
|
||||
@Override
|
||||
@@ -59,7 +56,6 @@ public class ComboBoxPopup<T> extends ListPopupImpl {
|
||||
};
|
||||
|
||||
if (selectedItem != null) {
|
||||
//noinspection SuspiciousMethodCalls
|
||||
step.setDefaultOptionIndex(step.getValues().indexOf(selectedItem));
|
||||
}
|
||||
return step;
|
||||
@@ -177,7 +173,7 @@ public class ComboBoxPopup<T> extends ListPopupImpl {
|
||||
|
||||
private static class MyBasePopupState<T> extends BaseListPopupStep<T> {
|
||||
private final JBList<T> myProxyList = new JBList<>();
|
||||
private Consumer<T> myOnItemSelected;
|
||||
private final Consumer<T> myOnItemSelected;
|
||||
private final Supplier<ListModel<T>> myGetComboboxModel;
|
||||
private final Supplier<ListCellRenderer<? super T>> myGetRenderer;
|
||||
|
||||
@@ -190,10 +186,6 @@ public class ComboBoxPopup<T> extends ListPopupImpl {
|
||||
myGetRenderer = getRenderer;
|
||||
}
|
||||
|
||||
private void addItemSelectedListener(@NotNull Consumer<T> callback) {
|
||||
myOnItemSelected = myOnItemSelected.andThen(callback);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
@@ -203,7 +195,7 @@ public class ComboBoxPopup<T> extends ListPopupImpl {
|
||||
//noinspection unchecked
|
||||
ListModel<T> nextModel = ((ComboBoxPopupState<T>)model).onChosen(selectedValue);
|
||||
if (nextModel != null) {
|
||||
return new MyBasePopupState<>(t -> myOnItemSelected.accept(t) /* mutable callback! */,
|
||||
return new MyBasePopupState<>(myOnItemSelected /* mutable callback! */,
|
||||
() -> nextModel, myGetRenderer);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user