diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/PluginManagerConfigurable.java b/platform/platform-impl/src/com/intellij/ide/plugins/PluginManagerConfigurable.java index b0de862580aa..0cea3a1cd606 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/PluginManagerConfigurable.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/PluginManagerConfigurable.java @@ -1212,7 +1212,8 @@ public class PluginManagerConfigurable public void performCopy(@NotNull DataContext dataContext) { StringBuilder result = new StringBuilder(); for (ListPluginComponent pluginComponent : component.getSelection()) { - result.append(pluginComponent.myPlugin.getName()).append(" (").append(pluginComponent.myPlugin.getVersion()).append(")\n"); + IdeaPluginDescriptor descriptor = pluginComponent.getPluginDescriptor(); + result.append(descriptor.getName()).append(" (").append(descriptor.getVersion()).append(")\n"); } CopyPasteManager.getInstance().setContents(new TextTransferable(result.substring(0, result.length() - 1))); } @@ -1569,7 +1570,7 @@ public class PluginManagerConfigurable } else { for (ListPluginComponent component : group.ui.plugins) { - IdeaPluginDescriptor plugin = component.myPlugin; + IdeaPluginDescriptor plugin = component.getPluginDescriptor(); if (myPluginModel.isEnabled(plugin) != myEnable) { descriptors.add(plugin); } diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/newui/ListPluginComponent.java b/platform/platform-impl/src/com/intellij/ide/plugins/newui/ListPluginComponent.java index 26566df00ff5..b2a49304f5fb 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/newui/ListPluginComponent.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/newui/ListPluginComponent.java @@ -52,7 +52,7 @@ public class ListPluginComponent extends JPanel { private final MyPluginModel myPluginModel; private final LinkListener mySearchListener; private final boolean myMarketplace; - public IdeaPluginDescriptor myPlugin; + private @NotNull IdeaPluginDescriptor myPlugin; private boolean myUninstalled; private boolean myOnlyUpdateMode; public IdeaPluginDescriptor myUpdateDescriptor; @@ -184,8 +184,8 @@ public class ListPluginComponent extends JPanel { else { if (Registry.is("ide.plugins.per.project", false)) { myEnableDisableButton = SelectionBasedPluginModelAction.createGearButton( - newState -> new EnableDisableAction(newState, List.of(this)), - () -> new UninstallAction(List.of()) + newState -> createEnableDisableAction(newState, List.of(this)), + () -> createUninstallAction(List.of()) ); myEnableDisableButton.setBorder(JBUI.Borders.emptyLeft(5)); myEnableDisableButton.setBackground(PluginManagerConfigurable.MAIN_BG_COLOR); @@ -724,14 +724,14 @@ public class ListPluginComponent extends JPanel { SelectionBasedPluginModelAction.addActionsTo( group, - state -> new EnableDisableAction( + state -> createEnableDisableAction( state.isPerProject() ? null : new CustomShortcutSet(KeyEvent.VK_SPACE), state, selection ), () -> { ShortcutSet deleteShortcutSet = EventHandler.getShortcuts(IdeActions.ACTION_EDITOR_DELETE); - return new UninstallAction( + return createUninstallAction( deleteShortcutSet != null ? deleteShortcutSet : new CustomShortcutSet(EventHandler.DELETE_CODE), selection ); @@ -809,9 +809,9 @@ public class ListPluginComponent extends JPanel { } DumbAwareAction action = keyCode == KeyEvent.VK_SPACE && event.getModifiersEx() == 0 ? - new EnableDisableAction(getEnableDisableAction(selection), selection) : + createEnableDisableAction(getEnableDisableAction(selection), selection) : keyCode == EventHandler.DELETE_CODE ? - new UninstallAction(selection) : + createUninstallAction(selection) : null; if (action != null) { @@ -833,11 +833,14 @@ public class ListPluginComponent extends JPanel { parent.repaint(); } - @NotNull - public IdeaPluginDescriptor getPluginDescriptor() { + public @NotNull IdeaPluginDescriptor getPluginDescriptor() { return myPlugin; } + public void setPluginDescriptor(@NotNull IdeaPluginDescriptor plugin) { + myPlugin = plugin; + } + private @NotNull PluginEnableDisableAction getEnableDisableAction(@NotNull List selection) { Iterator iterator = selection.iterator(); BooleanSupplier isGloballyEnabledGenerator = () -> @@ -853,57 +856,43 @@ public class ListPluginComponent extends JPanel { return PluginEnableDisableAction.globally(firstDisabled); } - private final class EnableDisableAction extends SelectionBasedPluginModelAction.EnableDisableAction { - - private EnableDisableAction(@NotNull PluginEnableDisableAction action, - @NotNull List selection) { - this( - null, - action, - selection - ); - } - - private EnableDisableAction(@Nullable ShortcutSet shortcutSet, - @NotNull PluginEnableDisableAction action, - @NotNull List selection) { - super( - shortcutSet, - ListPluginComponent.this.myPluginModel, - action, - selection - ); - } - - @Override - protected @Nullable IdeaPluginDescriptor getPluginDescriptor(@NotNull ListPluginComponent component) { - return component.myPlugin; - } + private @NotNull SelectionBasedPluginModelAction.EnableDisableAction createEnableDisableAction(@NotNull PluginEnableDisableAction action, + @NotNull List selection) { + return createEnableDisableAction( + null, + action, + selection + ); } - private final class UninstallAction extends SelectionBasedPluginModelAction.UninstallAction { + private @NotNull SelectionBasedPluginModelAction.EnableDisableAction createEnableDisableAction(@Nullable ShortcutSet shortcutSet, + @NotNull PluginEnableDisableAction action, + @NotNull List selection) { + return new SelectionBasedPluginModelAction.EnableDisableAction<>( + shortcutSet, + myPluginModel, + action, + selection, + ListPluginComponent::getPluginDescriptor + ); + } - private UninstallAction(@NotNull List selection) { - this( - null, - selection - ); - } + private @NotNull SelectionBasedPluginModelAction.UninstallAction createUninstallAction(@NotNull List selection) { + return createUninstallAction( + null, + selection + ); + } - private UninstallAction(@Nullable ShortcutSet shortcutSet, - @NotNull List selection) { - super( - shortcutSet, - ListPluginComponent.this.myPluginModel, - ListPluginComponent.this, - selection - ); - } - - @Override - protected @Nullable IdeaPluginDescriptor getPluginDescriptor(@NotNull ListPluginComponent component) { - return component.myPlugin; - } + private @NotNull SelectionBasedPluginModelAction.UninstallAction createUninstallAction(@Nullable ShortcutSet shortcutSet, + @NotNull List selection) { + return new SelectionBasedPluginModelAction.UninstallAction<>( + shortcutSet, + myPluginModel, + this, + selection, + ListPluginComponent::getPluginDescriptor + ); } @NotNull diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/newui/MyPluginModel.java b/platform/platform-impl/src/com/intellij/ide/plugins/newui/MyPluginModel.java index 148459be26dd..70acafe71a65 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/newui/MyPluginModel.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/newui/MyPluginModel.java @@ -264,43 +264,45 @@ public class MyPluginModel extends InstalledPluginsTableModel implements PluginM } public void addComponent(@NotNull ListPluginComponent component) { + IdeaPluginDescriptor descriptor = component.getPluginDescriptor(); if (!component.isMarketplace()) { - if (myInstallingPlugins.contains(component.myPlugin) && - (myInstalling == null || myInstalling.ui == null || myInstalling.ui.findComponent(component.myPlugin) == null)) { + if (myInstallingPlugins.contains(descriptor) && + (myInstalling == null || myInstalling.ui == null || myInstalling.ui.findComponent(descriptor) == null)) { return; } myInstalledPluginComponents.add(component); List components = - myInstalledPluginComponentMap.computeIfAbsent(component.myPlugin.getPluginId(), __ -> new ArrayList<>()); + myInstalledPluginComponentMap.computeIfAbsent(descriptor.getPluginId(), __ -> new ArrayList<>()); components.add(component); } else { List components = - myMarketplacePluginComponentMap.computeIfAbsent(component.myPlugin.getPluginId(), __ -> new ArrayList<>()); + myMarketplacePluginComponentMap.computeIfAbsent(descriptor.getPluginId(), __ -> new ArrayList<>()); components.add(component); } } public void removeComponent(@NotNull ListPluginComponent component) { + PluginId pluginId = component.getPluginDescriptor().getPluginId(); if (!component.isMarketplace()) { myInstalledPluginComponents.remove(component); - List components = myInstalledPluginComponentMap.get(component.myPlugin.getPluginId()); + List components = myInstalledPluginComponentMap.get(pluginId); if (components != null) { components.remove(component); if (components.isEmpty()) { - myInstalledPluginComponentMap.remove(component.myPlugin.getPluginId()); + myInstalledPluginComponentMap.remove(pluginId); } } } else { - List components = myMarketplacePluginComponentMap.get(component.myPlugin.getPluginId()); + List components = myMarketplacePluginComponentMap.get(pluginId); if (components != null) { components.remove(component); if (components.isEmpty()) { - myMarketplacePluginComponentMap.remove(component.myPlugin.getPluginId()); + myMarketplacePluginComponentMap.remove(pluginId); } } } @@ -502,7 +504,7 @@ public class MyPluginModel extends InstalledPluginsTableModel implements PluginM } } for (PluginDetailsPageComponent panel : myDetailPanels) { - if (panel.myPlugin == descriptor) { + if (panel.getPlugin() == descriptor) { panel.showProgress(); } } @@ -529,7 +531,7 @@ public class MyPluginModel extends InstalledPluginsTableModel implements PluginM if (marketplaceComponents != null) { for (ListPluginComponent gridComponent : marketplaceComponents) { if (installedDescriptor != null) { - gridComponent.myPlugin = installedDescriptor; + gridComponent.setPluginDescriptor(installedDescriptor); } gridComponent.hideProgress(success, restartRequired); } @@ -538,7 +540,7 @@ public class MyPluginModel extends InstalledPluginsTableModel implements PluginM if (installedComponents != null) { for (ListPluginComponent listComponent : installedComponents) { if (installedDescriptor != null) { - listComponent.myPlugin = installedDescriptor; + listComponent.setPluginDescriptor(installedDescriptor); } listComponent.hideProgress(success, restartRequired); listComponent.updateErrors(); @@ -546,9 +548,7 @@ public class MyPluginModel extends InstalledPluginsTableModel implements PluginM } for (PluginDetailsPageComponent panel : myDetailPanels) { if (panel.isShowingPlugin(descriptor)) { - if (installedDescriptor != null) { - panel.myPlugin = installedDescriptor; - } + panel.setPlugin(installedDescriptor); panel.hideProgress(success); } } @@ -605,7 +605,7 @@ public class MyPluginModel extends InstalledPluginsTableModel implements PluginM } else { for (ListPluginComponent listComponent : myInstalling.ui.plugins) { - if (listComponent.myPlugin == descriptor) { + if (listComponent.getPluginDescriptor() == descriptor) { listComponent.clearProgress(); return; } @@ -752,7 +752,11 @@ public class MyPluginModel extends InstalledPluginsTableModel implements PluginM public List getInstalledDescriptors() { assert myInstalledPanel != null; - return myInstalledPanel.getGroups().stream().flatMap(group -> group.plugins.stream()).map(plugin -> plugin.myPlugin) + return myInstalledPanel + .getGroups() + .stream() + .flatMap(group -> group.plugins.stream()) + .map(ListPluginComponent::getPluginDescriptor) .collect(Collectors.toList()); } @@ -1016,7 +1020,7 @@ public class MyPluginModel extends InstalledPluginsTableModel implements PluginM } for (PluginDetailsPageComponent panel : myDetailPanels) { - if (panel.myPlugin == descriptor) { + if (panel.getPlugin() == descriptor) { panel.updateButtons(); } } diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginDetailsPageComponent.java b/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginDetailsPageComponent.java index 69bdb786044a..0d66a6f5047d 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginDetailsPageComponent.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginDetailsPageComponent.java @@ -91,7 +91,7 @@ public class PluginDetailsPageComponent extends MultiPanel { private ChangeNotesPanel myChangeNotesPanel; private OneLineProgressIndicator myIndicator; - public IdeaPluginDescriptor myPlugin; + private @Nullable IdeaPluginDescriptor myPlugin; private IdeaPluginDescriptor myUpdateDescriptor; private ListPluginComponent myShowComponent; @@ -105,6 +105,16 @@ public class PluginDetailsPageComponent extends MultiPanel { setEmptyState(EmptyState.NONE_SELECTED); } + final @Nullable IdeaPluginDescriptor getPlugin() { + return myPlugin; + } + + void setPlugin(@Nullable IdeaPluginDescriptor plugin) { + if (plugin != null) { + myPlugin = plugin; + } + } + public boolean isShowingPlugin(@NotNull IdeaPluginDescriptor pluginDescriptor) { return myPlugin != null && myPlugin.getPluginId().equals(pluginDescriptor.getPluginId()); } @@ -155,8 +165,8 @@ public class PluginDetailsPageComponent extends MultiPanel { header.add(myIconLabel, BorderLayout.WEST); myGearButton = SelectionBasedPluginModelAction.createGearButton( - EnableDisableAction::new, - () -> new UninstallAction() + this::createEnableDisableAction, + () -> createUninstallAction() ); myGearButton.setBorder(JBUI.Borders.emptyLeft(5)); myGearButton.setBackground(PluginManagerConfigurable.MAIN_BG_COLOR); @@ -449,7 +459,7 @@ public class PluginDetailsPageComponent extends MultiPanel { syncLoading = false; startLoading(); ProcessIOExecutorService.INSTANCE.execute(() -> { - component.myPlugin = MarketplaceRequests.getInstance().loadPluginDetails(node); + component.setPluginDescriptor(MarketplaceRequests.getInstance().loadPluginDetails(node)); ApplicationManager.getApplication().invokeLater(() -> { if (myShowComponent == component) { @@ -468,7 +478,7 @@ public class PluginDetailsPageComponent extends MultiPanel { } private void showPlugin(@NotNull ListPluginComponent component) { - myPlugin = component.myPlugin; + myPlugin = component.getPluginDescriptor(); myUpdateDescriptor = component.myUpdateDescriptor; showPlugin(); select(0, true); @@ -848,37 +858,23 @@ public class PluginDetailsPageComponent extends MultiPanel { return StringUtil.isEmptyOrSpaces(notes) ? null : notes; } - private final class EnableDisableAction extends SelectionBasedPluginModelAction.EnableDisableAction { - - private EnableDisableAction(@NotNull PluginEnableDisableAction action) { - super( - null, - PluginDetailsPageComponent.this.myPluginModel, - action, - List.of(PluginDetailsPageComponent.this) - ); - } - - @Override - protected @Nullable IdeaPluginDescriptor getPluginDescriptor(@NotNull PluginDetailsPageComponent component) { - return myPlugin; - } + private @NotNull SelectionBasedPluginModelAction.EnableDisableAction createEnableDisableAction(@NotNull PluginEnableDisableAction action) { + return new SelectionBasedPluginModelAction.EnableDisableAction<>( + null, + myPluginModel, + action, + List.of(this), + PluginDetailsPageComponent::getPlugin + ); } - private final class UninstallAction extends SelectionBasedPluginModelAction.UninstallAction { - - private UninstallAction() { - super( - null, - PluginDetailsPageComponent.this.myPluginModel, - PluginDetailsPageComponent.this, - List.of(PluginDetailsPageComponent.this) - ); - } - - @Override - protected @Nullable IdeaPluginDescriptor getPluginDescriptor(@NotNull PluginDetailsPageComponent component) { - return myPlugin; - } + private @NotNull SelectionBasedPluginModelAction.UninstallAction createUninstallAction() { + return new SelectionBasedPluginModelAction.UninstallAction<>( + null, + myPluginModel, + this, + List.of(this), + PluginDetailsPageComponent::getPlugin + ); } } \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginsGroupComponent.java b/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginsGroupComponent.java index b7495c6a2ccf..e5670452f9cb 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginsGroupComponent.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginsGroupComponent.java @@ -251,7 +251,7 @@ public class PluginsGroupComponent extends JBPanelWithEmptyText { } public void removeFromGroup(@NotNull PluginsGroup group, @NotNull IdeaPluginDescriptor descriptor) { - int index = ContainerUtil.indexOf(group.ui.plugins, component -> component.myPlugin == descriptor); + int index = ContainerUtil.indexOf(group.ui.plugins, component -> component.getPluginDescriptor() == descriptor); assert index != -1; ListPluginComponent component = group.ui.plugins.remove(index); component.close(); diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/newui/SelectionBasedPluginModelAction.java b/platform/platform-impl/src/com/intellij/ide/plugins/newui/SelectionBasedPluginModelAction.java index 175dcfffe7c3..9c16535b0068 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/newui/SelectionBasedPluginModelAction.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/newui/SelectionBasedPluginModelAction.java @@ -29,37 +29,44 @@ abstract class SelectionBasedPluginModelAction extends Dum protected final @NotNull MyPluginModel myPluginModel; protected final @NotNull List mySelection; + private final @NotNull Function<@NotNull ? super C, @Nullable ? extends IdeaPluginDescriptor> myPluginDescriptor; protected SelectionBasedPluginModelAction(@NotNull @Nls String text, @Nullable ShortcutSet shortcutSet, @NotNull MyPluginModel pluginModel, - @NotNull List selection) { + @NotNull List selection, + @NotNull Function<@NotNull ? super C, @Nullable ? extends IdeaPluginDescriptor> pluginDescriptor) { super(text); setShortcutSet(shortcutSet == null ? CustomShortcutSet.EMPTY : shortcutSet); myPluginModel = pluginModel; mySelection = selection; + myPluginDescriptor = pluginDescriptor; } - protected abstract @Nullable IdeaPluginDescriptor getPluginDescriptor(@NotNull C component); + protected final @Nullable IdeaPluginDescriptor getPluginDescriptor(@NotNull C component) { + return myPluginDescriptor.apply(component); + } protected final @NotNull Set getAllDescriptors() { return map2SetNotNull(mySelection, this::getPluginDescriptor); } - static abstract class EnableDisableAction extends SelectionBasedPluginModelAction { + static final class EnableDisableAction extends SelectionBasedPluginModelAction { - protected final @NotNull PluginEnableDisableAction myAction; + private final @NotNull PluginEnableDisableAction myAction; - protected EnableDisableAction(@Nullable ShortcutSet shortcutSet, - @NotNull MyPluginModel pluginModel, - @NotNull PluginEnableDisableAction action, - @NotNull List selection) { + EnableDisableAction(@Nullable ShortcutSet shortcutSet, + @NotNull MyPluginModel pluginModel, + @NotNull PluginEnableDisableAction action, + @NotNull List selection, + @NotNull Function<@NotNull ? super C, @Nullable ? extends IdeaPluginDescriptor> pluginDescriptor) { super( action.toString(), shortcutSet, pluginModel, - selection + selection, + pluginDescriptor ); myAction = action; @@ -102,20 +109,23 @@ abstract class SelectionBasedPluginModelAction extends Dum } } - static abstract class UninstallAction extends SelectionBasedPluginModelAction { + static final class UninstallAction extends SelectionBasedPluginModelAction { private final @NotNull JComponent myUiParent; - protected UninstallAction(@Nullable ShortcutSet shortcutSet, - @NotNull MyPluginModel pluginModel, - @NotNull JComponent uiParent, - @NotNull List selection) { + UninstallAction(@Nullable ShortcutSet shortcutSet, + @NotNull MyPluginModel pluginModel, + @NotNull JComponent uiParent, + @NotNull List selection, + @NotNull Function<@NotNull ? super C, @Nullable ? extends IdeaPluginDescriptor> pluginDescriptor) { super( IdeBundle.message("plugins.configurable.uninstall.button"), shortcutSet, pluginModel, - selection + selection, + pluginDescriptor ); + myUiParent = uiParent; } @@ -152,8 +162,8 @@ abstract class SelectionBasedPluginModelAction extends Dum } static void addActionsTo(@NotNull DefaultActionGroup group, - @NotNull Function<@NotNull PluginEnableDisableAction, @NotNull ? extends EnableDisableAction> createEnableDisableAction, - @NotNull Producer<@NotNull ? extends UninstallAction> createUninstallAction) { + @NotNull Function<@NotNull PluginEnableDisableAction, @NotNull EnableDisableAction> createEnableDisableAction, + @NotNull Producer<@NotNull UninstallAction> createUninstallAction) { PluginEnableDisableAction[] actions = PluginEnableDisableAction.values(); for (int i = 0; i < actions.length; i++) { group.add(createEnableDisableAction.apply(actions[i])); @@ -164,8 +174,8 @@ abstract class SelectionBasedPluginModelAction extends Dum group.add(createUninstallAction.produce()); } - static @NotNull JComponent createGearButton(@NotNull Function<@NotNull PluginEnableDisableAction, @NotNull ? extends EnableDisableAction> createEnableDisableAction, - @NotNull Producer<@NotNull ? extends UninstallAction> createUninstallAction) { + static @NotNull JComponent createGearButton(@NotNull Function<@NotNull PluginEnableDisableAction, @NotNull EnableDisableAction> createEnableDisableAction, + @NotNull Producer<@NotNull UninstallAction> createUninstallAction) { DefaultActionGroup result = new DefaultActionGroup(); addActionsTo( result, diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/newui/UIPluginGroup.java b/platform/platform-impl/src/com/intellij/ide/plugins/newui/UIPluginGroup.java index 6f77a24ba559..d99b4e8cb118 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/newui/UIPluginGroup.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/newui/UIPluginGroup.java @@ -21,7 +21,7 @@ public final class UIPluginGroup { public ListPluginComponent findComponent(@NotNull IdeaPluginDescriptor descriptor) { PluginId pluginId = descriptor.getPluginId(); for (ListPluginComponent component : plugins) { - if (pluginId == component.myPlugin.getPluginId()) { + if (pluginId == component.getPluginDescriptor().getPluginId()) { return component; } }