mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
rework dependency from ProjectSdksModel in SdkListPresenter, make SdkList* classes final
GitOrigin-RevId: f8f5514538b0044d27483110560633d3d658c700
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6e2af7457c
commit
3984bda4ae
@@ -92,19 +92,7 @@ public class JdkComboBox extends SdkComboBoxBase<JdkComboBoxItem> {
|
||||
onNewSdkAdded.consume(sdk);
|
||||
}
|
||||
};
|
||||
setRenderer(new SdkListPresenter(sdkModel) {
|
||||
@NotNull
|
||||
@Override
|
||||
protected SdkListModel getModel() {
|
||||
return ((JdkComboBoxModel)JdkComboBox.this.getModel()).myInnerModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean showProgressIcon() {
|
||||
return JdkComboBox.this.isPopupVisible();
|
||||
}
|
||||
}.forType(JdkComboBox::unwrapItem));
|
||||
|
||||
setRenderer(new SdkListPresenter(() -> ((JdkComboBoxModel)this.getModel()).myInnerModel).forType(JdkComboBox::unwrapItem));
|
||||
reloadModel();
|
||||
}
|
||||
|
||||
|
||||
@@ -45,10 +45,7 @@ class SdkComboBox(model: SdkComboBoxModel) : SdkComboBoxBase<SdkListItem>(model.
|
||||
|
||||
init {
|
||||
setModel(model)
|
||||
setRenderer(object : SdkListPresenter(this.model.sdksModel) {
|
||||
override fun getModel(): SdkListModel = this@SdkComboBox.model.listModel
|
||||
override fun showProgressIcon() = true
|
||||
})
|
||||
setRenderer(SdkListPresenter { this@SdkComboBox.model.listModel })
|
||||
addPopupMenuListener(ModelReloadProvider())
|
||||
reloadModel()
|
||||
}
|
||||
|
||||
+18
-8
@@ -6,6 +6,7 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.intellij.openapi.project.ProjectBundle;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.ui.ComboBoxPopupState;
|
||||
import com.intellij.util.Producer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -14,14 +15,23 @@ import java.util.List;
|
||||
|
||||
import static com.intellij.openapi.roots.ui.configuration.SdkListItem.*;
|
||||
|
||||
public class SdkListModel extends AbstractListModel<SdkListItem> implements ComboBoxPopupState<SdkListItem> {
|
||||
public final class SdkListModel extends AbstractListModel<SdkListItem> implements ComboBoxPopupState<SdkListItem> {
|
||||
private final boolean myIsSearching;
|
||||
private final ImmutableList<SdkListItem> myItems;
|
||||
private final Producer<? extends Sdk> myGetProjectSdk;
|
||||
private final ImmutableMap<SdkListItem, String> mySeparators;
|
||||
|
||||
public SdkListModel(boolean isSearching, @NotNull List<? extends SdkListItem> items) {
|
||||
@NotNull
|
||||
public static SdkListModel emptyModel() {
|
||||
return new SdkListModel(false, ImmutableList.of(), () -> null);
|
||||
}
|
||||
|
||||
SdkListModel(boolean isSearching,
|
||||
@NotNull List<? extends SdkListItem> items,
|
||||
@NotNull Producer<? extends Sdk> getProjectSdk) {
|
||||
myIsSearching = isSearching;
|
||||
myItems = ImmutableList.copyOf(items);
|
||||
myGetProjectSdk = getProjectSdk;
|
||||
|
||||
boolean myFirstSepSet = false;
|
||||
boolean mySuggestedSep = false;
|
||||
@@ -50,6 +60,11 @@ public class SdkListModel extends AbstractListModel<SdkListItem> implements Comb
|
||||
mySeparators = sep.build();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
Sdk resolveProjectSdk() {
|
||||
return myGetProjectSdk.produce();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return myItems.size();
|
||||
@@ -65,7 +80,7 @@ public class SdkListModel extends AbstractListModel<SdkListItem> implements Comb
|
||||
@Override
|
||||
public SdkListModel onChosen(SdkListItem selectedValue) {
|
||||
if (!(selectedValue instanceof GroupItem)) return null;
|
||||
return new SdkListModel(myIsSearching, ((GroupItem)selectedValue).mySubItems);
|
||||
return new SdkListModel(myIsSearching, ((GroupItem)selectedValue).mySubItems, myGetProjectSdk);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,11 +88,6 @@ public class SdkListModel extends AbstractListModel<SdkListItem> implements Comb
|
||||
return selectedValue instanceof GroupItem;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public SdkListModel buildSubModel(@NotNull GroupItem group) {
|
||||
return new SdkListModel(myIsSearching, group.mySubItems);
|
||||
}
|
||||
|
||||
public boolean isSearching() {
|
||||
return myIsSearching;
|
||||
}
|
||||
|
||||
+2
-2
@@ -27,7 +27,7 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class SdkListModelBuilder {
|
||||
public final class SdkListModelBuilder {
|
||||
@Nullable private final Project myProject;
|
||||
@NotNull private final ProjectSdksModel mySdkModel;
|
||||
@NotNull private final Condition<? super Sdk> mySdkFilter;
|
||||
@@ -135,7 +135,7 @@ public class SdkListModelBuilder {
|
||||
newModel.add(item);
|
||||
}
|
||||
|
||||
return new SdkListModel(myIsSdkDetectorInProgress, newModel.build());
|
||||
return new SdkListModel(myIsSdkDetectorInProgress, newModel.build(), () -> mySdkModel.getProjectSdk());
|
||||
}
|
||||
|
||||
private boolean isApplicableSuggestedItem(@NotNull SuggestedItem item) {
|
||||
|
||||
+8
-18
@@ -9,12 +9,12 @@ import com.intellij.openapi.projectRoots.SdkType;
|
||||
import com.intellij.openapi.roots.ui.SdkAppearanceService;
|
||||
import com.intellij.openapi.roots.ui.configuration.SdkListItem.GroupItem;
|
||||
import com.intellij.openapi.roots.ui.configuration.SdkListItem.SdkItem;
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.IconUtil;
|
||||
import com.intellij.util.Producer;
|
||||
import com.intellij.util.ui.EmptyIcon;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -26,24 +26,14 @@ import java.util.Objects;
|
||||
|
||||
import static com.intellij.openapi.roots.ui.configuration.SdkListItem.*;
|
||||
|
||||
public abstract class SdkListPresenter extends ColoredListCellRenderer<SdkListItem> {
|
||||
public final class SdkListPresenter extends ColoredListCellRenderer<SdkListItem> {
|
||||
private static final Icon EMPTY_ICON = EmptyIcon.create(1, 16);
|
||||
@NotNull private final Producer<SdkListModel> myGetModel;
|
||||
|
||||
@NotNull
|
||||
private final ProjectSdksModel mySdkModel;
|
||||
|
||||
protected SdkListPresenter(@NotNull ProjectSdksModel sdkModel) {
|
||||
mySdkModel = sdkModel;
|
||||
public SdkListPresenter(@NotNull Producer<SdkListModel> getSdkListModel) {
|
||||
myGetModel = getSdkListModel;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected abstract SdkListModel getModel();
|
||||
|
||||
protected boolean showProgressIcon() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public <T> ListCellRenderer<T> forType(@NotNull Function<? super T, ? extends SdkListItem> unwrap) {
|
||||
return new ListCellRenderer<T>() {
|
||||
@@ -79,12 +69,12 @@ public abstract class SdkListPresenter extends ColoredListCellRenderer<SdkListIt
|
||||
};
|
||||
panel.add(component, BorderLayout.CENTER);
|
||||
|
||||
SdkListModel model = getModel();
|
||||
SdkListModel model = myGetModel.produce();
|
||||
//handle the selected item to show in the ComboBox, not in the popup
|
||||
if (index == -1) {
|
||||
component.setOpaque(false);
|
||||
panel.setOpaque(false);
|
||||
if (model.isSearching() && showProgressIcon()) {
|
||||
if (model.isSearching()) {
|
||||
JBLabel progressIcon = new JBLabel(AnimatedIcon.Default.INSTANCE);
|
||||
panel.add(progressIcon, BorderLayout.EAST);
|
||||
}
|
||||
@@ -133,7 +123,7 @@ public abstract class SdkListPresenter extends ColoredListCellRenderer<SdkListIt
|
||||
append(str, SimpleTextAttributes.ERROR_ATTRIBUTES);
|
||||
}
|
||||
else if (value instanceof ProjectSdkItem) {
|
||||
final Sdk sdk = mySdkModel.getProjectSdk();
|
||||
final Sdk sdk = myGetModel.produce().resolveProjectSdk();
|
||||
if (sdk != null) {
|
||||
setIcon(((SdkType)sdk.getSdkType()).getIcon());
|
||||
append(ProjectBundle.message("project.roots.project.jdk.inherited"), SimpleTextAttributes.REGULAR_ATTRIBUTES);
|
||||
|
||||
+4
-9
@@ -288,7 +288,7 @@ internal class PlatformSdkPopupFactory : SdkPopupFactory {
|
||||
listener: SdkPopupListener
|
||||
): SdkPopup {
|
||||
lateinit var popup: SdkPopupImpl
|
||||
val context = SdkListItemContext(project, projectSdksModel)
|
||||
val context = SdkListItemContext(project)
|
||||
|
||||
val onItemSelected = Consumer<SdkListItem> { value ->
|
||||
myModelBuilder.processSelectedElement(popup.popupOwner, value,
|
||||
@@ -365,16 +365,11 @@ internal class PlatformSdkPopupFactory : SdkPopupFactory {
|
||||
}
|
||||
|
||||
private class SdkListItemContext(
|
||||
private val myProject: Project?,
|
||||
mySdksModel: ProjectSdksModel
|
||||
private val myProject: Project?
|
||||
) : ComboBoxPopup.Context<SdkListItem> {
|
||||
var myModel = SdkListModel(true, emptyList())
|
||||
var myModel = SdkListModel.emptyModel()
|
||||
|
||||
private val myRenderer = object : SdkListPresenter(mySdksModel) {
|
||||
override fun getModel(): SdkListModel {
|
||||
return myModel
|
||||
}
|
||||
}
|
||||
private val myRenderer = SdkListPresenter { myModel }
|
||||
|
||||
override fun getProject() = myProject
|
||||
override fun getMaximumRowCount() = 30
|
||||
|
||||
Reference in New Issue
Block a user