[dynamic plugins] refactoring: EnableDisableAction/UninstallAction should be final #IDEA-246104

GitOrigin-RevId: 557828b4566bb5c1c1aa84a96173ba1be273dad9
This commit is contained in:
Andrew Kozlov
2020-11-29 17:42:05 +03:00
committed by intellij-monorepo-bot
parent 4e6c3bc7b5
commit 9fb10da61b
7 changed files with 131 additions and 131 deletions

View File

@@ -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);
}

View File

@@ -52,7 +52,7 @@ public class ListPluginComponent extends JPanel {
private final MyPluginModel myPluginModel;
private final LinkListener<Object> 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<ListPluginComponent> selection) {
Iterator<ListPluginComponent> 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<ListPluginComponent> {
private EnableDisableAction(@NotNull PluginEnableDisableAction action,
@NotNull List<ListPluginComponent> selection) {
this(
null,
action,
selection
);
}
private EnableDisableAction(@Nullable ShortcutSet shortcutSet,
@NotNull PluginEnableDisableAction action,
@NotNull List<ListPluginComponent> selection) {
super(
shortcutSet,
ListPluginComponent.this.myPluginModel,
action,
selection
);
}
@Override
protected @Nullable IdeaPluginDescriptor getPluginDescriptor(@NotNull ListPluginComponent component) {
return component.myPlugin;
}
private @NotNull SelectionBasedPluginModelAction.EnableDisableAction<ListPluginComponent> createEnableDisableAction(@NotNull PluginEnableDisableAction action,
@NotNull List<ListPluginComponent> selection) {
return createEnableDisableAction(
null,
action,
selection
);
}
private final class UninstallAction extends SelectionBasedPluginModelAction.UninstallAction<ListPluginComponent> {
private @NotNull SelectionBasedPluginModelAction.EnableDisableAction<ListPluginComponent> createEnableDisableAction(@Nullable ShortcutSet shortcutSet,
@NotNull PluginEnableDisableAction action,
@NotNull List<ListPluginComponent> selection) {
return new SelectionBasedPluginModelAction.EnableDisableAction<>(
shortcutSet,
myPluginModel,
action,
selection,
ListPluginComponent::getPluginDescriptor
);
}
private UninstallAction(@NotNull List<ListPluginComponent> selection) {
this(
null,
selection
);
}
private @NotNull SelectionBasedPluginModelAction.UninstallAction<ListPluginComponent> createUninstallAction(@NotNull List<ListPluginComponent> selection) {
return createUninstallAction(
null,
selection
);
}
private UninstallAction(@Nullable ShortcutSet shortcutSet,
@NotNull List<ListPluginComponent> selection) {
super(
shortcutSet,
ListPluginComponent.this.myPluginModel,
ListPluginComponent.this,
selection
);
}
@Override
protected @Nullable IdeaPluginDescriptor getPluginDescriptor(@NotNull ListPluginComponent component) {
return component.myPlugin;
}
private @NotNull SelectionBasedPluginModelAction.UninstallAction<ListPluginComponent> createUninstallAction(@Nullable ShortcutSet shortcutSet,
@NotNull List<ListPluginComponent> selection) {
return new SelectionBasedPluginModelAction.UninstallAction<>(
shortcutSet,
myPluginModel,
this,
selection,
ListPluginComponent::getPluginDescriptor
);
}
@NotNull

View File

@@ -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<ListPluginComponent> components =
myInstalledPluginComponentMap.computeIfAbsent(component.myPlugin.getPluginId(), __ -> new ArrayList<>());
myInstalledPluginComponentMap.computeIfAbsent(descriptor.getPluginId(), __ -> new ArrayList<>());
components.add(component);
}
else {
List<ListPluginComponent> 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<ListPluginComponent> components = myInstalledPluginComponentMap.get(component.myPlugin.getPluginId());
List<ListPluginComponent> components = myInstalledPluginComponentMap.get(pluginId);
if (components != null) {
components.remove(component);
if (components.isEmpty()) {
myInstalledPluginComponentMap.remove(component.myPlugin.getPluginId());
myInstalledPluginComponentMap.remove(pluginId);
}
}
}
else {
List<ListPluginComponent> components = myMarketplacePluginComponentMap.get(component.myPlugin.getPluginId());
List<ListPluginComponent> 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<IdeaPluginDescriptor> 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();
}
}

View File

@@ -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<PluginDetailsPageComponent> {
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<PluginDetailsPageComponent> createEnableDisableAction(@NotNull PluginEnableDisableAction action) {
return new SelectionBasedPluginModelAction.EnableDisableAction<>(
null,
myPluginModel,
action,
List.of(this),
PluginDetailsPageComponent::getPlugin
);
}
private final class UninstallAction extends SelectionBasedPluginModelAction.UninstallAction<PluginDetailsPageComponent> {
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<PluginDetailsPageComponent> createUninstallAction() {
return new SelectionBasedPluginModelAction.UninstallAction<>(
null,
myPluginModel,
this,
List.of(this),
PluginDetailsPageComponent::getPlugin
);
}
}

View File

@@ -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();

View File

@@ -29,37 +29,44 @@ abstract class SelectionBasedPluginModelAction<C extends JComponent> extends Dum
protected final @NotNull MyPluginModel myPluginModel;
protected final @NotNull List<C> 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<C> selection) {
@NotNull List<C> 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<? extends IdeaPluginDescriptor> getAllDescriptors() {
return map2SetNotNull(mySelection, this::getPluginDescriptor);
}
static abstract class EnableDisableAction<C extends JComponent> extends SelectionBasedPluginModelAction<C> {
static final class EnableDisableAction<C extends JComponent> extends SelectionBasedPluginModelAction<C> {
protected final @NotNull PluginEnableDisableAction myAction;
private final @NotNull PluginEnableDisableAction myAction;
protected EnableDisableAction(@Nullable ShortcutSet shortcutSet,
@NotNull MyPluginModel pluginModel,
@NotNull PluginEnableDisableAction action,
@NotNull List<C> selection) {
EnableDisableAction(@Nullable ShortcutSet shortcutSet,
@NotNull MyPluginModel pluginModel,
@NotNull PluginEnableDisableAction action,
@NotNull List<C> 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<C extends JComponent> extends Dum
}
}
static abstract class UninstallAction<C extends JComponent> extends SelectionBasedPluginModelAction<C> {
static final class UninstallAction<C extends JComponent> extends SelectionBasedPluginModelAction<C> {
private final @NotNull JComponent myUiParent;
protected UninstallAction(@Nullable ShortcutSet shortcutSet,
@NotNull MyPluginModel pluginModel,
@NotNull JComponent uiParent,
@NotNull List<C> selection) {
UninstallAction(@Nullable ShortcutSet shortcutSet,
@NotNull MyPluginModel pluginModel,
@NotNull JComponent uiParent,
@NotNull List<C> 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<C extends JComponent> extends Dum
}
static <C extends JComponent> void addActionsTo(@NotNull DefaultActionGroup group,
@NotNull Function<@NotNull PluginEnableDisableAction, @NotNull ? extends EnableDisableAction<C>> createEnableDisableAction,
@NotNull Producer<@NotNull ? extends UninstallAction<C>> createUninstallAction) {
@NotNull Function<@NotNull PluginEnableDisableAction, @NotNull EnableDisableAction<C>> createEnableDisableAction,
@NotNull Producer<@NotNull UninstallAction<C>> 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<C extends JComponent> extends Dum
group.add(createUninstallAction.produce());
}
static <C extends JComponent> @NotNull JComponent createGearButton(@NotNull Function<@NotNull PluginEnableDisableAction, @NotNull ? extends EnableDisableAction<C>> createEnableDisableAction,
@NotNull Producer<@NotNull ? extends UninstallAction<C>> createUninstallAction) {
static <C extends JComponent> @NotNull JComponent createGearButton(@NotNull Function<@NotNull PluginEnableDisableAction, @NotNull EnableDisableAction<C>> createEnableDisableAction,
@NotNull Producer<@NotNull UninstallAction<C>> createUninstallAction) {
DefaultActionGroup result = new DefaultActionGroup();
addActionsTo(
result,

View File

@@ -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;
}
}