diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/LinkPanel.java b/platform/platform-impl/src/com/intellij/ide/plugins/LinkPanel.java index e584e5e2288c..0869ad96de29 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/LinkPanel.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/LinkPanel.java @@ -2,7 +2,7 @@ package com.intellij.ide.plugins; import com.intellij.icons.AllIcons; -import com.intellij.ide.plugins.newui.CellPluginComponent; +import com.intellij.ide.plugins.newui.ListPluginComponent; import com.intellij.ui.components.labels.LinkLabel; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -19,7 +19,7 @@ public class LinkPanel { public LinkPanel(@NotNull JPanel parent, boolean icon, @Nullable Object labelConstraints, @Nullable Object linkConstraints) { myLinkLabel = createLink(icon); - myTextLabel.setForeground(CellPluginComponent.GRAY_COLOR); + myTextLabel.setForeground(ListPluginComponent.GRAY_COLOR); parent.add(myTextLabel, labelConstraints); parent.add(myLinkLabel, linkConstraints); } 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 2efecd58489f..fb19d9ff931a 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/PluginManagerConfigurable.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/PluginManagerConfigurable.java @@ -829,7 +829,7 @@ public class PluginManagerConfigurable public void linkSelected(LinkLabel aSource, Object aLinkData) { myUpdateAll.setEnabled(false); - for (CellPluginComponent plugin : downloaded.ui.plugins) { + for (ListPluginComponent plugin : downloaded.ui.plugins) { ((ListPluginComponent)plugin).updatePlugin(); } } @@ -1096,7 +1096,7 @@ public class PluginManagerConfigurable private static void clearUpdates(@NotNull PluginsGroupComponent panel) { for (UIPluginGroup group : panel.getGroups()) { - for (CellPluginComponent plugin : group.plugins) { + for (ListPluginComponent plugin : group.plugins) { ((ListPluginComponent)plugin).setUpdateDescriptor(null); } } @@ -1106,7 +1106,7 @@ public class PluginManagerConfigurable for (PluginDownloader downloader : updates) { IdeaPluginDescriptor descriptor = downloader.getDescriptor(); for (UIPluginGroup group : panel.getGroups()) { - CellPluginComponent component = group.findComponent(descriptor); + ListPluginComponent component = group.findComponent(descriptor); if (component != null) { ((ListPluginComponent)component).setUpdateDescriptor(descriptor); break; @@ -1120,7 +1120,7 @@ public class PluginManagerConfigurable @Override public void performCopy(@NotNull DataContext dataContext) { StringBuilder result = new StringBuilder(); - for (CellPluginComponent pluginComponent : component.getSelection()) { + for (ListPluginComponent pluginComponent : component.getSelection()) { result.append(pluginComponent.myPlugin.getName()).append(" (").append(pluginComponent.myPlugin.getVersion()).append(")\n"); } CopyPasteManager.getInstance().setContents(new TextTransferable(result.substring(0, result.length() - 1))); @@ -1619,11 +1619,11 @@ public class PluginManagerConfigurable return; } - List components = new ArrayList<>(); + List components = new ArrayList<>(); for (IdeaPluginDescriptor descriptor : descriptors) { for (UIPluginGroup group : myInstalledPanel.getGroups()) { - CellPluginComponent component = group.findComponent(descriptor); + ListPluginComponent component = group.findComponent(descriptor); if (component != null) { components.add(component); break; @@ -1675,7 +1675,7 @@ public class PluginManagerConfigurable if (select) { for (UIPluginGroup group : myInstalledPanel.getGroups()) { - CellPluginComponent component = group.findComponent(callbackData.getPluginDescriptor()); + ListPluginComponent component = group.findComponent(callbackData.getPluginDescriptor()); if (component != null) { myInstalledPanel.setSelection(component); break; diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/newui/BaselinePanel.java b/platform/platform-impl/src/com/intellij/ide/plugins/newui/BaselinePanel.java index 93510c0f5a87..56e2128e8b24 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/newui/BaselinePanel.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/newui/BaselinePanel.java @@ -314,7 +314,7 @@ public class BaselinePanel extends NonOpaquePanel { remove(component); } - public void setProgressComponent(@Nullable CellPluginComponent pluginComponent, @NotNull JComponent progressComponent) { + public void setProgressComponent(@Nullable ListPluginComponent pluginComponent, @NotNull JComponent progressComponent) { assert myProgressComponent == null; myProgressComponent = progressComponent; add(progressComponent, null); diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/newui/CellPluginComponent.java b/platform/platform-impl/src/com/intellij/ide/plugins/newui/CellPluginComponent.java deleted file mode 100644 index fff29d9675ec..000000000000 --- a/platform/platform-impl/src/com/intellij/ide/plugins/newui/CellPluginComponent.java +++ /dev/null @@ -1,230 +0,0 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -package com.intellij.ide.plugins.newui; - -import com.intellij.icons.AllIcons; -import com.intellij.ide.plugins.IdeaPluginDescriptor; -import com.intellij.ide.plugins.PluginManagerConfigurable; -import com.intellij.openapi.actionSystem.DefaultActionGroup; -import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.wm.IdeFocusManager; -import com.intellij.ui.Gray; -import com.intellij.ui.JBColor; -import com.intellij.ui.RelativeFont; -import com.intellij.ui.components.labels.LinkLabel; -import com.intellij.ui.components.labels.LinkListener; -import com.intellij.ui.scale.JBUIScale; -import com.intellij.util.ui.JBDimension; -import com.intellij.util.ui.UIUtil; -import com.intellij.xml.util.XmlStringUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import javax.swing.text.View; -import java.awt.*; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.util.List; - -/** - * @author Alexander Lobas - */ -public abstract class CellPluginComponent extends JPanel { - public static final Color GRAY_COLOR = JBColor.namedColor("Label.infoForeground", new JBColor(Gray._120, Gray._135)); - private static final Color HOVER_COLOR = JBColor.namedColor("Plugins.lightSelectionBackground", new JBColor(0xF5F9FF, 0x36393B)); - - public static boolean HANDLE_FOCUS_ON_SELECTION = true; - - public final IdeaPluginDescriptor myPlugin; - - protected LinkLabel myIconLabel; - protected LinkLabel myName; - protected JEditorPane myDescription; - protected MouseListener myHoverNameListener; - - protected EventHandler.SelectionType mySelection = EventHandler.SelectionType.NONE; - - protected CellPluginComponent(@NotNull IdeaPluginDescriptor plugin) { - myPlugin = plugin; - } - - @NotNull - public IdeaPluginDescriptor getPluginDescriptor() { - return myPlugin; - } - - protected void addIconComponent(@NotNull JPanel parent, @Nullable Object constraints) { - myIconLabel = new LinkLabel(null, AllIcons.Plugins.PluginLogo_40); - myIconLabel.setVerticalAlignment(SwingConstants.TOP); - myIconLabel.setOpaque(false); - parent.add(myIconLabel, constraints); - } - - protected void addNameComponent(@NotNull JPanel parent) { - myName = new LinkComponent() { - @Override - public String getToolTipText() { - return getPreferredSize().width > getWidth() ? super.getToolTipText() : null; - } - }; - myName.setText(myPlugin.getName()); - myName.setToolTipText(myPlugin.getName()); - parent.add(RelativeFont.BOLD.install(myName)); - } - - protected void updateIcon(boolean errors, boolean disabled) { - myIconLabel.setIcon(PluginLogo.getIcon(myPlugin, false, PluginManagerConfigurable.isJBPlugin(myPlugin), errors, disabled)); - } - - protected void addDescriptionComponent(@NotNull JPanel parent, @Nullable String description, @NotNull LineFunction function) { - if (StringUtil.isEmptyOrSpaces(description)) { - return; - } - - myDescription = new JEditorPane() { - @Override - public Dimension getPreferredSize() { - if (getWidth() == 0 || getHeight() == 0) { - setSize(new JBDimension(180, 20)); - } - Integer property = (Integer)getClientProperty("parent.width"); - int width = property == null ? JBUIScale.scale(180) : property; - View view = getUI().getRootView(this); - view.setSize(width, Integer.MAX_VALUE); - return new Dimension(width, function.getHeight(this)); - } - - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - function.paintComponent(this, g); - } - }; - - PluginManagerConfigurable.setTinyFont(myDescription); - myDescription.setEditable(false); - myDescription.setFocusable(false); - myDescription.setOpaque(false); - myDescription.setBorder(null); - myDescription.setCaret(EmptyCaret.INSTANCE); - - myDescription.setEditorKit(new UIUtil.JBWordWrapHtmlEditorKit()); - myDescription.setText(XmlStringUtil.wrapInHtml(description)); - - parent.add(myDescription); - } - - @NotNull - public EventHandler.SelectionType getSelection() { - return mySelection; - } - - public void setSelection(@NotNull EventHandler.SelectionType type) { - setSelection(type, type == EventHandler.SelectionType.SELECTION); - } - - public void setSelection(@NotNull EventHandler.SelectionType type, boolean scrollAndFocus) { - mySelection = type; - - if (scrollAndFocus) { - scrollToVisible(); - if (getParent() != null && type == EventHandler.SelectionType.SELECTION && HANDLE_FOCUS_ON_SELECTION) { - IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> IdeFocusManager.getGlobalInstance().requestFocus(this, true)); - } - } - - updateColors(type); - repaint(); - } - - public void scrollToVisible() { - JComponent parent = (JComponent)getParent(); - if (parent == null) { - return; - } - - Rectangle bounds = getBounds(); - if (!parent.getVisibleRect().contains(bounds)) { - parent.scrollRectToVisible(bounds); - } - } - - protected void updateColors(@NotNull EventHandler.SelectionType type) { - updateColors(GRAY_COLOR, type == EventHandler.SelectionType.NONE ? PluginManagerConfigurable.MAIN_BG_COLOR : HOVER_COLOR); - } - - protected void updateColors(@NotNull Color grayedFg, @NotNull Color background) { - setBackground(background); - - if (myDescription != null) { - myDescription.setForeground(grayedFg); - } - } - - protected void fullRepaint() { - Container parent = getParent(); - parent.doLayout(); - parent.revalidate(); - parent.repaint(); - } - - public void setListeners(@NotNull LinkListener listener, - @NotNull LinkListener searchListener, - @NotNull EventHandler eventHandler) { - //noinspection unchecked - myIconLabel.setListener(listener, myPlugin); - //noinspection unchecked - myName.setListener(listener, myPlugin); - - myHoverNameListener = new MouseAdapter() { - @Override - public void mouseEntered(MouseEvent event) { - myName.entered(event); - } - - @Override - public void mouseExited(MouseEvent event) { - myName.exited(event); - } - }; - myIconLabel.addMouseListener(myHoverNameListener); - - eventHandler.addAll(this); - } - - public void createPopupMenu(@NotNull DefaultActionGroup group, @NotNull List selection) { - } - - public void handleKeyAction(int keyCode, @NotNull List selection) { - } - - public abstract void showProgress(); - - public abstract void hideProgress(boolean success, boolean restartRequired); - - public void clearProgress() { - throw new UnsupportedOperationException(); - } - - public void close() { - } - - public abstract boolean isMarketplace(); - - public void updateEnabledState() { - throw new UnsupportedOperationException(); - } - - public void updateAfterUninstall(boolean needRestartForUninstall) { - throw new UnsupportedOperationException(); - } - - public void updateErrors() { - throw new UnsupportedOperationException(); - } - - public void enableRestart() { - throw new UnsupportedOperationException(); - } -} \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/newui/EventHandler.java b/platform/platform-impl/src/com/intellij/ide/plugins/newui/EventHandler.java index 14c1ce0ba71b..b694f1bcda69 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/newui/EventHandler.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/newui/EventHandler.java @@ -23,16 +23,16 @@ public abstract class EventHandler { public void connect(@NotNull PluginsGroupComponent container) { } - public void addCell(@NotNull CellPluginComponent component, int index) { + public void addCell(@NotNull ListPluginComponent component, int index) { } - public void addCell(@NotNull CellPluginComponent component, @Nullable CellPluginComponent anchor) { + public void addCell(@NotNull ListPluginComponent component, @Nullable ListPluginComponent anchor) { } - public void removeCell(@NotNull CellPluginComponent component) { + public void removeCell(@NotNull ListPluginComponent component) { } - public int getCellIndex(@NotNull CellPluginComponent component) { + public int getCellIndex(@NotNull ListPluginComponent component) { return -1; } @@ -46,25 +46,25 @@ public abstract class EventHandler { } } - public void updateHover(@NotNull CellPluginComponent component) { + public void updateHover(@NotNull ListPluginComponent component) { } public void initialSelection(boolean scrollAndFocus) { } @NotNull - public List getSelection() { + public List getSelection() { return Collections.emptyList(); } - public void setSelection(@NotNull CellPluginComponent component) { + public void setSelection(@NotNull ListPluginComponent component) { setSelection(component, true); } - public void setSelection(@NotNull CellPluginComponent component, boolean scrollAndFocus) { + public void setSelection(@NotNull ListPluginComponent component, boolean scrollAndFocus) { } - public void setSelection(@NotNull List components) { + public void setSelection(@NotNull List components) { } public void updateSelection() { @@ -103,9 +103,9 @@ public abstract class EventHandler { } @NotNull - protected static CellPluginComponent get(@NotNull ComponentEvent event) { + protected static ListPluginComponent get(@NotNull ComponentEvent event) { //noinspection ConstantConditions - return ComponentUtil.getParentOfType((Class)CellPluginComponent.class, event.getComponent()); + return ComponentUtil.getParentOfType((Class)ListPluginComponent.class, event.getComponent()); } @Nullable diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/newui/GridCellPluginComponent.java b/platform/platform-impl/src/com/intellij/ide/plugins/newui/GridCellPluginComponent.java deleted file mode 100644 index bcc13d42c7f8..000000000000 --- a/platform/platform-impl/src/com/intellij/ide/plugins/newui/GridCellPluginComponent.java +++ /dev/null @@ -1,270 +0,0 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -package com.intellij.ide.plugins.newui; - -import com.intellij.icons.AllIcons; -import com.intellij.ide.plugins.*; -import com.intellij.openapi.wm.ex.ProgressIndicatorEx; -import com.intellij.ui.components.labels.LinkListener; -import com.intellij.ui.components.panels.NonOpaquePanel; -import com.intellij.ui.scale.JBUIScale; -import com.intellij.util.ui.AbstractLayoutManager; -import com.intellij.util.ui.JBInsets; -import com.intellij.util.ui.JBUI; -import com.intellij.util.ui.UIUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import javax.swing.*; -import javax.swing.border.Border; -import java.awt.*; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.ArrayList; -import java.util.List; - -/** - * @author Alexander Lobas - */ -public class GridCellPluginComponent extends CellPluginComponent { - private final MyPluginModel myPluginModel; - private JLabel myLastUpdated; - private JLabel myDownloads; - private JLabel myRating; - private final JButton myInstallButton = new InstallButton(false); - private JComponent myLastComponent; - private List myTagComponents; - private ProgressIndicatorEx myIndicator; - - public GridCellPluginComponent(@NotNull MyPluginModel pluginsModel, - @NotNull IdeaPluginDescriptor plugin, - @NotNull TagBuilder tagBuilder) { - super(plugin); - myPluginModel = pluginsModel; - pluginsModel.addComponent(this); - - JPanel container = new NonOpaquePanel(new BorderLayout(JBUIScale.scale(10), 0)); - add(container); - addIconComponent(container, BorderLayout.WEST); - - JPanel centerPanel = new NonOpaquePanel(new VerticalLayout(PluginManagerConfigurable.offset5(), JBUIScale.scale(181))); - container.add(centerPanel); - - addNameComponent(centerPanel); - addTags(centerPanel, tagBuilder); - addDescriptionComponent(centerPanel, PluginSiteUtils.preparePluginDescription(myPlugin.getDescription(), false), new LineFunction(3, true)); - - createMetricsPanel(centerPanel); - - addInstallButton(); - - setOpaque(true); - setBorder(JBUI.Borders.empty(10)); - - setLayout(new AbstractLayoutManager() { - @Override - public Dimension preferredLayoutSize(Container parent) { - Dimension size = container.getPreferredSize(); - size.height += PluginManagerConfigurable.offset5(); - size.height += myLastComponent.getPreferredSize().height; - JBInsets.addTo(size, parent.getInsets()); - return size; - } - - @Override - public void layoutContainer(Container parent) { - Insets insets = parent.getInsets(); - Dimension size = container.getPreferredSize(); - Rectangle bounds = new Rectangle(insets.left, insets.top, size.width, size.height); - container.setBounds(bounds); - container.doLayout(); - - Point location = centerPanel.getLocation(); - Dimension buttonSize = myLastComponent.getPreferredSize(); - Border border = myLastComponent.getBorder(); - int borderOffset = border == null ? 0 : border.getBorderInsets(myLastComponent).left; - myLastComponent - .setBounds(bounds.x + location.x - borderOffset, bounds.y + PluginManagerConfigurable.offset5() + bounds.height, - Math.min(buttonSize.width, size.width), - buttonSize.height); - } - }); - - updateIcon(false, false); - updateColors(EventHandler.SelectionType.NONE); - } - - private void createMetricsPanel(@NotNull JPanel centerPanel) { - if (!(myPlugin instanceof PluginNode)) { - return; - } - - String downloads = PluginManagerConfigurable.getDownloads(myPlugin); - String date = PluginManagerConfigurable.getLastUpdatedDate(myPlugin); - String rating = PluginManagerConfigurable.getRating(myPlugin); - - if (downloads != null || date != null || rating != null) { - JPanel panel = new NonOpaquePanel(new HorizontalLayout(JBUIScale.scale(7))); - centerPanel.add(panel); - - if (date != null) { - myLastUpdated = createRatingLabel(panel, date, AllIcons.Plugins.Updated); - } - if (downloads != null) { - myDownloads = createRatingLabel(panel, downloads, AllIcons.Plugins.Downloads); - } - if (rating != null) { - myRating = createRatingLabel(panel, rating, AllIcons.Plugins.Rating); - } - } - } - - @NotNull - static JLabel createRatingLabel(@NotNull JPanel panel, @NotNull String text, @Nullable Icon icon) { - return createRatingLabel(panel, null, text, icon, null, true); - } - - @NotNull - static JLabel createRatingLabel(@NotNull JPanel panel, - @Nullable Object constraints, - @NotNull String text, - @Nullable Icon icon, - @Nullable Color color, - boolean tiny) { - JLabel label = new JLabel(text, icon, SwingConstants.CENTER); - label.setOpaque(false); - label.setIconTextGap(2); - if (color != null) { - label.setForeground(color); - } - panel.add(tiny ? PluginManagerConfigurable.setTinyFont(label) : label, constraints); - return label; - } - - private void addInstallButton() { - if (InstalledPluginsState.getInstance().wasInstalled(myPlugin.getPluginId())) { - add(myLastComponent = new RestartButton(myPluginModel)); - return; - } - - myInstallButton.addActionListener(e -> myPluginModel.installOrUpdatePlugin(myPlugin, null)); - myInstallButton.setEnabled(PluginManagerCore.getPlugin(myPlugin.getPluginId()) == null); - add(myLastComponent = myInstallButton); - - if (MyPluginModel.isInstallingOrUpdate(myPlugin)) { - showProgress(false); - } - } - - @Override - public void showProgress() { - showProgress(true); - } - - private void showProgress(boolean repaint) { - TwoLineProgressIndicator indicator = new TwoLineProgressIndicator(); - indicator.setCancelRunnable(() -> myPluginModel.finishInstall(myPlugin, false, false, true)); - myIndicator = indicator; - - myInstallButton.setVisible(false); - add(myLastComponent = indicator.getComponent()); - doLayout(); - - MyPluginModel.addProgress(myPlugin, indicator); - - if (repaint) { - fullRepaint(); - } - } - - @Override - public void hideProgress(boolean success, boolean restartRequired) { - myIndicator = null; - JComponent lastComponent = myLastComponent; - if (success) { - add(myLastComponent = new RestartButton(myPluginModel)); - } - else { - myLastComponent = myInstallButton; - myInstallButton.setVisible(true); - } - remove(lastComponent); - doLayout(); - fullRepaint(); - } - - private void addTags(@NotNull JPanel parent, @NotNull TagBuilder tagBuilder) { - List tags = PluginManagerConfigurable.getTags(myPlugin); - if (tags.isEmpty()) { - return; - } - - NonOpaquePanel panel = new NonOpaquePanel(new HorizontalLayout(JBUIScale.scale(6))); - parent.add(panel); - - myTagComponents = new ArrayList<>(); - - for (String tag : tags) { - TagComponent component = tagBuilder.createTagComponent(tag); - panel.add(component); - myTagComponents.add(component); - } - } - - @Override - public void setListeners(@NotNull LinkListener listener, - @NotNull LinkListener searchListener, - @NotNull EventHandler eventHandler) { - super.setListeners(listener, searchListener, eventHandler); - - if (myDescription != null) { - UIUtil.setCursor(myDescription, Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); - - myDescription.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent event) { - if (SwingUtilities.isLeftMouseButton(event)) { - listener.linkSelected(myName, myPlugin); - } - } - }); - myDescription.addMouseListener(myHoverNameListener); - } - - if (myTagComponents != null) { - for (TagComponent component : myTagComponents) { - //noinspection unchecked - component.setListener(searchListener, SearchQueryParser.getTagQuery(component.getText())); - } - myTagComponents = null; - } - } - - @Override - protected void updateColors(@NotNull Color grayedFg, @NotNull Color background) { - super.updateColors(grayedFg, background); - - if (myLastUpdated != null) { - myLastUpdated.setForeground(grayedFg); - } - if (myDownloads != null) { - myDownloads.setForeground(grayedFg); - } - if (myRating != null) { - myRating.setForeground(grayedFg); - } - } - - @Override - public void close() { - if (myIndicator != null) { - MyPluginModel.removeProgress(myPlugin, myIndicator); - myIndicator = null; - } - myPluginModel.removeComponent(this); - } - - @Override - public boolean isMarketplace() { - return true; - } -} \ No newline at end of file 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 8d5c98b84af4..13de0d7c8c02 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 @@ -10,6 +10,8 @@ import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.wm.IdeFocusManager; +import com.intellij.ui.Gray; import com.intellij.ui.JBColor; import com.intellij.ui.LicensingFacade; import com.intellij.ui.RelativeFont; @@ -32,11 +34,15 @@ import java.util.ListIterator; /** * @author Alexander Lobas */ -public class ListPluginComponent extends CellPluginComponent { +public class ListPluginComponent extends JPanel { public static final Color DisabledColor = JBColor.namedColor("Plugins.disabledForeground", new JBColor(0xB1B1B1, 0x696969)); + public static final Color GRAY_COLOR = JBColor.namedColor("Label.infoForeground", new JBColor(Gray._120, Gray._135)); + private static final Color HOVER_COLOR = JBColor.namedColor("Plugins.lightSelectionBackground", new JBColor(0xF5F9FF, 0x36393B)); + private final MyPluginModel myPluginModel; private final LinkListener mySearchListener; private final boolean myMarketplace; + public final IdeaPluginDescriptor myPlugin; private boolean myUninstalled; private boolean myUninstalledWithoutRestart; public IdeaPluginDescriptor myUpdateDescriptor; @@ -44,9 +50,9 @@ public class ListPluginComponent extends CellPluginComponent { private final JLabel myNameComponent = new JLabel(); private final JLabel myIconComponent = new JLabel(AllIcons.Plugins.PluginLogo_40); private final BaselineLayout myLayout = new BaselineLayout(); - private JButton myRestartButton; - private InstallButton myInstallButton; - private JButton myUpdateButton; + protected JButton myRestartButton; + protected InstallButton myInstallButton; + protected JButton myUpdateButton; private JCheckBox myEnableDisableButton; private JLabel myRating; private JLabel myDownloads; @@ -57,12 +63,15 @@ public class ListPluginComponent extends CellPluginComponent { private JComponent myErrorComponent; private OneLineProgressIndicator myIndicator; private EventHandler myEventHandler; + protected EventHandler.SelectionType mySelection = EventHandler.SelectionType.NONE; + + public static boolean HANDLE_FOCUS_ON_SELECTION = true; public ListPluginComponent(@NotNull MyPluginModel pluginModel, @NotNull IdeaPluginDescriptor plugin, @NotNull LinkListener searchListener, boolean marketplace) { - super(plugin); + myPlugin = plugin; myPluginModel = pluginModel; mySearchListener = searchListener; myMarketplace = marketplace; @@ -96,6 +105,40 @@ public class ListPluginComponent extends CellPluginComponent { updateColors(EventHandler.SelectionType.NONE); } + public EventHandler.SelectionType getSelection() { + return mySelection; + } + + public void setSelection(@NotNull EventHandler.SelectionType type) { + setSelection(type, type == EventHandler.SelectionType.SELECTION); + } + + public void setSelection(@NotNull EventHandler.SelectionType type, boolean scrollAndFocus) { + mySelection = type; + + if (scrollAndFocus) { + scrollToVisible(); + if (getParent() != null && type == EventHandler.SelectionType.SELECTION && HANDLE_FOCUS_ON_SELECTION) { + IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> IdeFocusManager.getGlobalInstance().requestFocus(this, true)); + } + } + + updateColors(type); + repaint(); + } + + public void scrollToVisible() { + JComponent parent = (JComponent)getParent(); + if (parent == null) { + return; + } + + Rectangle bounds = getBounds(); + if (!parent.getVisibleRect().contains(bounds)) { + parent.scrollRectToVisible(bounds); + } + } + private void createButtons() { if (myMarketplace) { if (InstalledPluginsState.getInstance().wasInstalled(myPlugin.getPluginId())) { @@ -164,24 +207,24 @@ public class ListPluginComponent extends CellPluginComponent { if (myMarketplace) { String downloads = PluginManagerConfigurable.getDownloads(myPlugin); if (downloads != null) { - myDownloads = GridCellPluginComponent.createRatingLabel(panel, downloads, AllIcons.Plugins.Downloads); + myDownloads = createRatingLabel(panel, downloads, AllIcons.Plugins.Downloads); } String rating = PluginManagerConfigurable.getRating(myPlugin); if (rating != null) { - myRating = GridCellPluginComponent.createRatingLabel(panel, rating, AllIcons.Plugins.Rating); + myRating = createRatingLabel(panel, rating, AllIcons.Plugins.Rating); } } else { String version = !myPlugin.isBundled() || myPlugin.allowBundledUpdate() ? myPlugin.getVersion() : "bundled"; if (!StringUtil.isEmptyOrSpaces(version)) { - myVersion = GridCellPluginComponent.createRatingLabel(panel, version, null); + myVersion = createRatingLabel(panel, version, null); } } String vendor = myPlugin.isBundled() ? null : StringUtil.trim(myPlugin.getVendor()); if (!StringUtil.isEmptyOrSpaces(vendor)) { - myVendor = GridCellPluginComponent.createRatingLabel(panel, TextHorizontalLayout.FIX_LABEL, vendor, null, null, true); + myVendor = createRatingLabel(panel, TextHorizontalLayout.FIX_LABEL, vendor, null, null, true); } } @@ -284,7 +327,6 @@ public class ListPluginComponent extends CellPluginComponent { doLayout(); } - @Override public void setListeners(@NotNull LinkListener listener, @NotNull LinkListener searchListener, @NotNull EventHandler eventHandler) { @@ -292,7 +334,10 @@ public class ListPluginComponent extends CellPluginComponent { eventHandler.addAll(this); } - @Override + protected void updateColors(@NotNull EventHandler.SelectionType type) { + updateColors(GRAY_COLOR, type == EventHandler.SelectionType.NONE ? PluginManagerConfigurable.MAIN_BG_COLOR : HOVER_COLOR); + } + protected void updateColors(@NotNull Color grayedFg, @NotNull Color background) { setBackground(background); @@ -330,7 +375,6 @@ public class ListPluginComponent extends CellPluginComponent { } } - @Override public void updateErrors() { boolean errors = myPluginModel.hasErrors(myPlugin); updateIcon(errors, myUninstalled || !myPluginModel.isEnabled(myPlugin)); @@ -367,12 +411,10 @@ public class ListPluginComponent extends CellPluginComponent { } } - @Override protected void updateIcon(boolean errors, boolean disabled) { myIconComponent.setIcon(PluginLogo.getIcon(myPlugin, false, PluginManagerConfigurable.isJBPlugin(myPlugin), errors, disabled)); } - @Override public void showProgress() { showProgress(true); } @@ -389,7 +431,6 @@ public class ListPluginComponent extends CellPluginComponent { } } - @Override public void hideProgress(boolean success, boolean restartRequired) { myIndicator = null; myLayout.removeProgressComponent(); @@ -406,12 +447,10 @@ public class ListPluginComponent extends CellPluginComponent { fullRepaint(); } - @Override public void clearProgress() { myIndicator = null; } - @Override public void enableRestart() { if (myInstallButton != null) { myLayout.removeButtonComponent(myInstallButton); @@ -430,7 +469,6 @@ public class ListPluginComponent extends CellPluginComponent { } } - @Override public void updateEnabledState() { if (!myUninstalled && myEnableDisableButton != null) { myEnableDisableButton.setSelected(isEnabledState()); @@ -439,7 +477,6 @@ public class ListPluginComponent extends CellPluginComponent { setSelection(mySelection, false); } - @Override public void updateAfterUninstall(boolean needRestartForUninstall) { myUninstalled = true; myUninstalledWithoutRestart = !needRestartForUninstall; @@ -455,16 +492,14 @@ public class ListPluginComponent extends CellPluginComponent { } } - private boolean isEnabledState() { + protected boolean isEnabledState() { return myPluginModel.isEnabled(myPlugin); } - @Override public boolean isMarketplace() { return myMarketplace; } - @Override public void close() { if (myIndicator != null) { MyPluginModel.removeProgress(myPlugin, myIndicator); @@ -473,23 +508,22 @@ public class ListPluginComponent extends CellPluginComponent { myPluginModel.removeComponent(this); } - @Override - public void createPopupMenu(@NotNull DefaultActionGroup group, @NotNull List selection) { - for (CellPluginComponent component : selection) { + public void createPopupMenu(@NotNull DefaultActionGroup group, @NotNull List selection) { + for (ListPluginComponent component : selection) { if (MyPluginModel.isInstallingOrUpdate(component.myPlugin)) { return; } } boolean restart = true; - for (CellPluginComponent component : selection) { - if (((ListPluginComponent)component).myRestartButton == null) { + for (ListPluginComponent component : selection) { + if (component.myRestartButton == null) { restart = false; break; } } if (restart) { - group.add(new ButtonAnAction(((ListPluginComponent)selection.get(0)).myRestartButton)); + group.add(new ButtonAnAction(selection.get(0).myRestartButton)); return; } @@ -499,7 +533,7 @@ public class ListPluginComponent extends CellPluginComponent { JButton[] installButtons = new JButton[size]; for (int i = 0; i < size; i++) { - JButton button = ((ListPluginComponent)selection.get(i)).myInstallButton; + JButton button = selection.get(i).myInstallButton; if (button == null || !button.isVisible() || !button.isEnabled()) { return; } @@ -511,7 +545,7 @@ public class ListPluginComponent extends CellPluginComponent { } boolean showUpdateAndState = true; - for (CellPluginComponent component : selection) { + for (ListPluginComponent component : selection) { if (myPluginModel.hasErrors(component.myPlugin)) { showUpdateAndState = false; break; @@ -522,7 +556,7 @@ public class ListPluginComponent extends CellPluginComponent { JButton[] updateButtons = new JButton[size]; for (int i = 0; i < size; i++) { - JButton button = ((ListPluginComponent)selection.get(i)).myUpdateButton; + JButton button = selection.get(i).myUpdateButton; if (button == null || !button.isVisible()) { updateButtons = null; break; @@ -546,8 +580,8 @@ public class ListPluginComponent extends CellPluginComponent { }); } - for (CellPluginComponent component : selection) { - if (((ListPluginComponent)component).myUninstalled || component.myPlugin.isBundled()) { + for (ListPluginComponent component : selection) { + if (component.myUninstalled || component.myPlugin.isBundled()) { return; } } @@ -562,24 +596,23 @@ public class ListPluginComponent extends CellPluginComponent { if (!MyPluginModel.showUninstallDialog(selection)) { return; } - for (CellPluginComponent component : selection) { + for (ListPluginComponent component : selection) { myPluginModel.doUninstall(component, component.myPlugin, null); } } }); } - @Override - public void handleKeyAction(int keyCode, @NotNull List selection) { - for (CellPluginComponent component : selection) { + public void handleKeyAction(int keyCode, @NotNull List selection) { + for (ListPluginComponent component : selection) { if (MyPluginModel.isInstallingOrUpdate(component.myPlugin)) { return; } } boolean restart = true; - for (CellPluginComponent component : selection) { - if (((ListPluginComponent)component).myRestartButton == null) { + for (ListPluginComponent component : selection) { + if (component.myRestartButton == null) { restart = false; break; } @@ -588,25 +621,25 @@ public class ListPluginComponent extends CellPluginComponent { if (myMarketplace) { if (keyCode == KeyEvent.VK_ENTER) { if (restart) { - ((ListPluginComponent)selection.get(0)).myRestartButton.doClick(); + selection.get(0).myRestartButton.doClick(); } - for (CellPluginComponent component : selection) { - JButton button = ((ListPluginComponent)component).myInstallButton; + for (ListPluginComponent component : selection) { + JButton button = component.myInstallButton; if (button == null || !button.isVisible() || !button.isEnabled()) { return; } } - for (CellPluginComponent component : selection) { - ((ListPluginComponent)component).myInstallButton.doClick(); + for (ListPluginComponent component : selection) { + component.myInstallButton.doClick(); } } return; } boolean update = true; - for (CellPluginComponent component : selection) { - JButton button = ((ListPluginComponent)component).myUpdateButton; + for (ListPluginComponent component : selection) { + JButton button = component.myUpdateButton; if (button == null || !button.isVisible()) { update = false; break; @@ -615,17 +648,17 @@ public class ListPluginComponent extends CellPluginComponent { if (keyCode == KeyEvent.VK_ENTER) { if (restart) { - ((ListPluginComponent)selection.get(0)).myRestartButton.doClick(); + selection.get(0).myRestartButton.doClick(); } else if (update) { - for (CellPluginComponent component : selection) { - ((ListPluginComponent)component).myUpdateButton.doClick(); + for (ListPluginComponent component : selection) { + component.myUpdateButton.doClick(); } } } else if (!restart && !update) { if (keyCode == KeyEvent.VK_SPACE) { - for (CellPluginComponent component : selection) { + for (ListPluginComponent component : selection) { if (myPluginModel.hasErrors(component.myPlugin)) { return; } @@ -640,28 +673,40 @@ public class ListPluginComponent extends CellPluginComponent { } } else if (keyCode == EventHandler.DELETE_CODE) { - for (CellPluginComponent component : selection) { - if (((ListPluginComponent)component).myUninstalled || component.myPlugin.isBundled()) { + for (ListPluginComponent component : selection) { + if (component.myUninstalled || component.myPlugin.isBundled()) { return; } } if (!MyPluginModel.showUninstallDialog(selection)) { return; } - for (CellPluginComponent component : selection) { + for (ListPluginComponent component : selection) { myPluginModel.doUninstall(this, component.myPlugin, null); } } } } + protected void fullRepaint() { + Container parent = getParent(); + parent.doLayout(); + parent.revalidate(); + parent.repaint(); + } + @NotNull - private static Pair getSelectionNewState(@NotNull List selection) { - boolean state = ((ListPluginComponent)selection.get(0)).isEnabledState(); + public IdeaPluginDescriptor getPluginDescriptor() { + return myPlugin; + } + + @NotNull + private static Pair getSelectionNewState(@NotNull List selection) { + boolean state = selection.get(0).isEnabledState(); boolean setTrue = false; - for (ListIterator I = selection.listIterator(1); I.hasNext(); ) { - if (state != ((ListPluginComponent)I.next()).isEnabledState()) { + for (ListIterator I = selection.listIterator(1); I.hasNext(); ) { + if (state != I.next().isEnabledState()) { setTrue = true; break; } @@ -676,6 +721,28 @@ public class ListPluginComponent extends CellPluginComponent { return Pair.create(setTrue || !state, plugins); } + @NotNull + static JLabel createRatingLabel(@NotNull JPanel panel, @NotNull String text, @Nullable Icon icon) { + return createRatingLabel(panel, null, text, icon, null, true); + } + + @NotNull + static JLabel createRatingLabel(@NotNull JPanel panel, + @Nullable Object constraints, + @NotNull String text, + @Nullable Icon icon, + @Nullable Color color, + boolean tiny) { + JLabel label = new JLabel(text, icon, SwingConstants.CENTER); + label.setOpaque(false); + label.setIconTextGap(2); + if (color != null) { + label.setForeground(color); + } + panel.add(tiny ? PluginManagerConfigurable.setTinyFont(label) : label, constraints); + return label; + } + public static class ButtonAnAction extends DumbAwareAction { private final JButton[] myButtons; diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/newui/MultiSelectionEventHandler.java b/platform/platform-impl/src/com/intellij/ide/plugins/newui/MultiSelectionEventHandler.java index f0de77e7fe88..d526b1bf105c 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/newui/MultiSelectionEventHandler.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/newui/MultiSelectionEventHandler.java @@ -20,9 +20,9 @@ import java.util.function.Consumer; public class MultiSelectionEventHandler extends EventHandler { private PluginsGroupComponent myContainer; private PagePluginLayout myLayout; - private List myComponents; + private List myComponents; - private CellPluginComponent myHoverComponent; + private ListPluginComponent myHoverComponent; private int mySelectionIndex; private int mySelectionLength; @@ -45,7 +45,7 @@ public class MultiSelectionEventHandler extends EventHandler { @Override public void mouseClicked(MouseEvent event) { if (SwingUtilities.isLeftMouseButton(event)) { - CellPluginComponent component = get(event); + ListPluginComponent component = get(event); int index = getIndex(component); if (event.isShiftDown()) { @@ -69,7 +69,7 @@ public class MultiSelectionEventHandler extends EventHandler { } } else if (SwingUtilities.isRightMouseButton(event)) { - CellPluginComponent component = get(event); + ListPluginComponent component = get(event); if (myAllSelected || myMixSelection) { int size = getSelection().size(); @@ -110,7 +110,7 @@ public class MultiSelectionEventHandler extends EventHandler { @Override public void mouseMoved(MouseEvent event) { if (myHoverComponent == null) { - CellPluginComponent component = get(event); + ListPluginComponent component = get(event); if (component.getSelection() == SelectionType.NONE) { myHoverComponent = component; component.setSelection(SelectionType.HOVER); @@ -172,7 +172,7 @@ public class MultiSelectionEventHandler extends EventHandler { } else if (code == KeyEvent.VK_SPACE || code == KeyEvent.VK_ENTER || code == DELETE_CODE) { assert mySelectionLength != 0; - CellPluginComponent component = myComponents.get(mySelectionIndex); + ListPluginComponent component = myComponents.get(mySelectionIndex); if (component.getSelection() != SelectionType.SELECTION) { component.setSelection(SelectionType.SELECTION); } @@ -185,7 +185,7 @@ public class MultiSelectionEventHandler extends EventHandler { @Override public void focusGained(FocusEvent event) { if (mySelectionIndex >= 0 && mySelectionLength == 1 && !myMixSelection) { - CellPluginComponent component = get(event); + ListPluginComponent component = get(event); int index = getIndex(component); if (mySelectionIndex != index) { clearSelectionWithout(index); @@ -204,13 +204,13 @@ public class MultiSelectionEventHandler extends EventHandler { try { //noinspection AssignmentToStaticFieldFromInstanceMethod - CellPluginComponent.HANDLE_FOCUS_ON_SELECTION = false; + ListPluginComponent.HANDLE_FOCUS_ON_SELECTION = false; myKeyListener.keyPressed(event); } finally { //noinspection AssignmentToStaticFieldFromInstanceMethod - CellPluginComponent.HANDLE_FOCUS_ON_SELECTION = true; + ListPluginComponent.HANDLE_FOCUS_ON_SELECTION = true; } } @@ -221,7 +221,7 @@ public class MultiSelectionEventHandler extends EventHandler { } @Override - public void addCell(@NotNull CellPluginComponent component, int index) { + public void addCell(@NotNull ListPluginComponent component, int index) { if (index == -1) { myComponents.add(component); } @@ -231,7 +231,7 @@ public class MultiSelectionEventHandler extends EventHandler { } @Override - public void addCell(@NotNull CellPluginComponent component, @Nullable CellPluginComponent anchor) { + public void addCell(@NotNull ListPluginComponent component, @Nullable ListPluginComponent anchor) { if (anchor == null) { myComponents.add(component); } @@ -241,12 +241,12 @@ public class MultiSelectionEventHandler extends EventHandler { } @Override - public void removeCell(@NotNull CellPluginComponent component) { + public void removeCell(@NotNull ListPluginComponent component) { myComponents.remove(component); } @Override - public int getCellIndex(@NotNull CellPluginComponent component) { + public int getCellIndex(@NotNull ListPluginComponent component) { return myComponents.indexOf(component); } @@ -270,10 +270,10 @@ public class MultiSelectionEventHandler extends EventHandler { @Override @NotNull - public List getSelection() { - List selection = new ArrayList<>(); + public List getSelection() { + List selection = new ArrayList<>(); - for (CellPluginComponent component : myComponents) { + for (ListPluginComponent component : myComponents) { if (component.getSelection() == SelectionType.SELECTION) { selection.add(component); } @@ -332,7 +332,7 @@ public class MultiSelectionEventHandler extends EventHandler { myMixSelection = false; myHoverComponent = null; - for (CellPluginComponent component : myComponents) { + for (ListPluginComponent component : myComponents) { if (component.getSelection() != SelectionType.SELECTION) { component.setSelection(SelectionType.SELECTION, false); } @@ -423,7 +423,7 @@ public class MultiSelectionEventHandler extends EventHandler { } } - private int getIndex(@NotNull CellPluginComponent component) { + private int getIndex(@NotNull ListPluginComponent component) { int index = myComponents.indexOf(component); assert index >= 0 : component; return index; @@ -434,7 +434,7 @@ public class MultiSelectionEventHandler extends EventHandler { return; } if (myMixSelection && mySelectionIndex != -1) { - CellPluginComponent component = myComponents.get(mySelectionIndex); + ListPluginComponent component = myComponents.get(mySelectionIndex); if (component.getSelection() != SelectionType.SELECTION) { component.setSelection(SelectionType.SELECTION); } @@ -455,13 +455,13 @@ public class MultiSelectionEventHandler extends EventHandler { } for (int i = 0; i < first; i++) { - CellPluginComponent component = myComponents.get(i); + ListPluginComponent component = myComponents.get(i); if (component.getSelection() == SelectionType.SELECTION) { component.setSelection(SelectionType.NONE); } } for (int i = last, size = myComponents.size(); i < size; i++) { - CellPluginComponent component = myComponents.get(i); + ListPluginComponent component = myComponents.get(i); if (component.getSelection() == SelectionType.SELECTION) { component.setSelection(SelectionType.NONE); } @@ -473,7 +473,7 @@ public class MultiSelectionEventHandler extends EventHandler { myMixSelection = false; for (int i = 0, size = myComponents.size(); i < size; i++) { if (i != withoutIndex) { - CellPluginComponent component = myComponents.get(i); + ListPluginComponent component = myComponents.get(i); if (component.getSelection() == SelectionType.SELECTION) { component.setSelection(SelectionType.NONE); } @@ -481,7 +481,7 @@ public class MultiSelectionEventHandler extends EventHandler { } } - private void ensureMoveSingleSelection(CellPluginComponent component) { + private void ensureMoveSingleSelection(ListPluginComponent component) { int index = getIndex(component); if (mySelectionLength == 0 || mySelectionIndex != index) { clearSelectionWithout(index); @@ -490,13 +490,13 @@ public class MultiSelectionEventHandler extends EventHandler { } @Override - public void setSelection(@NotNull CellPluginComponent component, boolean scrollAndFocus) { + public void setSelection(@NotNull ListPluginComponent component, boolean scrollAndFocus) { clearSelectionWithout(-1); singleSelection(component, getIndex(component), scrollAndFocus); } @Override - public void setSelection(@NotNull List components) { + public void setSelection(@NotNull List components) { clearSelectionWithout(-1); mySelectionIndex = -1; mySelectionLength = components.size(); @@ -507,7 +507,7 @@ public class MultiSelectionEventHandler extends EventHandler { mySelectionIndex = getIndex(components.get(0)); - for (CellPluginComponent component : components) { + for (ListPluginComponent component : components) { mySelectionIndex = Math.min(mySelectionIndex, getIndex(component)); if (component.getSelection() != SelectionType.SELECTION) { component.setSelection(SelectionType.SELECTION, true); @@ -521,11 +521,11 @@ public class MultiSelectionEventHandler extends EventHandler { singleSelection(myComponents.get(index), index); } - private void singleSelection(@NotNull CellPluginComponent component, int index) { + private void singleSelection(@NotNull ListPluginComponent component, int index) { singleSelection(component, index, true); } - private void singleSelection(@NotNull CellPluginComponent component, int index, boolean scrollAndFocus) { + private void singleSelection(@NotNull ListPluginComponent component, int index, boolean scrollAndFocus) { mySelectionIndex = index; mySelectionLength = 1; if (myHoverComponent == component) { @@ -546,7 +546,7 @@ public class MultiSelectionEventHandler extends EventHandler { } @Override - public void updateHover(@NotNull CellPluginComponent component) { + public void updateHover(@NotNull ListPluginComponent component) { ApplicationManager.getApplication().invokeLater(() -> { myHoverComponent = component; if (component.getSelection() == SelectionType.NONE) { 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 51743f730a7c..902c0bd092d0 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 @@ -34,9 +34,9 @@ import java.util.stream.Collectors; * @author Alexander Lobas */ public class MyPluginModel extends InstalledPluginsTableModel implements PluginManagerMain.PluginEnabler { - private final List myListComponents = new ArrayList<>(); - private final Map> myListMap = new HashMap<>(); - private final Map> myGridMap = new HashMap<>(); + private final List myInstalledPluginComponents = new ArrayList<>(); + private final Map> myInstalledPluginComponentMap = new HashMap<>(); + private final Map> myMarketplacePluginComponentMap = new HashMap<>(); private final List myEnabledGroups = new ArrayList<>(); private PluginsGroupComponent myInstalledPanel; private PluginsGroup myDownloaded; @@ -219,40 +219,39 @@ public class MyPluginModel extends InstalledPluginsTableModel implements PluginM } } - public void addComponent(@NotNull CellPluginComponent component) { + public void addComponent(@NotNull ListPluginComponent component) { if (!component.isMarketplace()) { if (myInstallingPlugins.contains(component.myPlugin)) { return; } - myListComponents.add(component); - List components = myListMap.computeIfAbsent(component.myPlugin, __ -> new ArrayList<>()); + List components = myInstalledPluginComponentMap.computeIfAbsent(component.myPlugin, __ -> new ArrayList<>()); components.add(component); } else { - List components = myGridMap.computeIfAbsent(component.myPlugin, __ -> new ArrayList<>()); + List components = myMarketplacePluginComponentMap.computeIfAbsent(component.myPlugin, __ -> new ArrayList<>()); components.add(component); } } - public void removeComponent(@NotNull CellPluginComponent component) { + public void removeComponent(@NotNull ListPluginComponent component) { if (!component.isMarketplace()) { - myListComponents.remove(component); + myInstalledPluginComponents.remove(component); - List components = myListMap.get(component.myPlugin); + List components = myInstalledPluginComponentMap.get(component.myPlugin); if (components != null) { components.remove(component); if (components.isEmpty()) { - myListMap.remove(component.myPlugin); + myInstalledPluginComponentMap.remove(component.myPlugin); } } } else { - List components = myGridMap.get(component.myPlugin); + List components = myMarketplacePluginComponentMap.get(component.myPlugin); if (components != null) { components.remove(component); if (components.isEmpty()) { - myGridMap.remove(component.myPlugin); + myMarketplacePluginComponentMap.remove(component.myPlugin); } } } @@ -376,15 +375,15 @@ public class MyPluginModel extends InstalledPluginsTableModel implements PluginM myInstalledPanel.doLayout(); } - List gridComponents = myGridMap.get(descriptor); + List gridComponents = myMarketplacePluginComponentMap.get(descriptor); if (gridComponents != null) { - for (CellPluginComponent gridComponent : gridComponents) { + for (ListPluginComponent gridComponent : gridComponents) { gridComponent.showProgress(); } } - List listComponents = myListMap.get(descriptor); + List listComponents = myInstalledPluginComponentMap.get(descriptor); if (listComponents != null) { - for (CellPluginComponent listComponent : listComponents) { + for (ListPluginComponent listComponent : listComponents) { listComponent.showProgress(); } } @@ -404,15 +403,15 @@ public class MyPluginModel extends InstalledPluginsTableModel implements PluginM myTopController.showProgress(false); } - List gridComponents = myGridMap.get(descriptor); + List gridComponents = myMarketplacePluginComponentMap.get(descriptor); if (gridComponents != null) { - for (CellPluginComponent gridComponent : gridComponents) { + for (ListPluginComponent gridComponent : gridComponents) { gridComponent.hideProgress(success, restartRequired); } } - List listComponents = myListMap.get(descriptor); + List listComponents = myInstalledPluginComponentMap.get(descriptor); if (listComponents != null) { - for (CellPluginComponent listComponent : listComponents) { + for (ListPluginComponent listComponent : listComponents) { listComponent.hideProgress(success, restartRequired); } } @@ -448,7 +447,7 @@ public class MyPluginModel extends InstalledPluginsTableModel implements PluginM } else if (success) { if (myDownloaded != null && myDownloaded.ui != null && restartRequired) { - CellPluginComponent component = myDownloaded.ui.findComponent(descriptor); + ListPluginComponent component = myDownloaded.ui.findComponent(descriptor); if (component != null) { component.enableRestart(); } @@ -472,12 +471,12 @@ public class MyPluginModel extends InstalledPluginsTableModel implements PluginM private void clearInstallingProgress(@NotNull IdeaPluginDescriptor descriptor) { if (myInstallingPlugins.isEmpty()) { - for (CellPluginComponent listComponent : myInstalling.ui.plugins) { + for (ListPluginComponent listComponent : myInstalling.ui.plugins) { listComponent.clearProgress(); } } else { - for (CellPluginComponent listComponent : myInstalling.ui.plugins) { + for (ListPluginComponent listComponent : myInstalling.ui.plugins) { if (listComponent.myPlugin == descriptor) { listComponent.clearProgress(); return; @@ -534,9 +533,9 @@ public class MyPluginModel extends InstalledPluginsTableModel implements PluginM String id = descriptor.getPluginId().getIdString(); - for (Entry> entry : myGridMap.entrySet()) { + for (Entry> entry : myMarketplacePluginComponentMap.entrySet()) { if (id.equals(entry.getKey().getPluginId().getIdString())) { - for (CellPluginComponent component : entry.getValue()) { + for (ListPluginComponent component : entry.getValue()) { component.hideProgress(true, true); } break; @@ -573,7 +572,7 @@ public class MyPluginModel extends InstalledPluginsTableModel implements PluginM addEnabledGroup(myDownloaded); } else { - CellPluginComponent component = myDownloaded.ui.findComponent(descriptor); + ListPluginComponent component = myDownloaded.ui.findComponent(descriptor); if (component != null) { myInstalledPanel.setSelection(component); component.enableRestart(); @@ -728,7 +727,7 @@ public class MyPluginModel extends InstalledPluginsTableModel implements PluginM } private void updateAfterEnableDisable() { - for (CellPluginComponent component : myListComponents) { + for (ListPluginComponent component : myInstalledPluginComponents) { component.updateEnabledState(); } for (PluginDetailsPageComponent detailPanel : myDetailPanels) { @@ -739,7 +738,7 @@ public class MyPluginModel extends InstalledPluginsTableModel implements PluginM } } - static boolean showUninstallDialog(@NotNull List selection) { + static boolean showUninstallDialog(@NotNull List selection) { int size = selection.size(); return showUninstallDialog(size == 1 ? selection.get(0).myPlugin.getName() : null, size); } @@ -783,14 +782,14 @@ public class MyPluginModel extends InstalledPluginsTableModel implements PluginM update.run(); } - List listComponents = myListMap.get(descriptor); + List listComponents = myInstalledPluginComponentMap.get(descriptor); if (listComponents != null) { - for (CellPluginComponent listComponent : listComponents) { + for (ListPluginComponent listComponent : listComponents) { listComponent.updateAfterUninstall(needRestartForUninstall); } } - for (CellPluginComponent component : myListComponents) { + for (ListPluginComponent component : myInstalledPluginComponents) { component.updateErrors(); } 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 74b5119f0aa6..2fb6312178f8 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 @@ -215,7 +215,7 @@ public class PluginDetailsPageComponent extends MultiPanel { PluginManagerConfigurable.setTinyFont(myVersion); myVersion.setBorder(null); myVersion.setOpaque(false); - myVersion.setForeground(CellPluginComponent.GRAY_COLOR); + myVersion.setForeground(ListPluginComponent.GRAY_COLOR); myVersion.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { @@ -234,10 +234,10 @@ public class PluginDetailsPageComponent extends MultiPanel { centerPanel.add(panel1); if (myMarketplace) { myDownloads = - GridCellPluginComponent.createRatingLabel(panel1, null, "", AllIcons.Plugins.Downloads, CellPluginComponent.GRAY_COLOR, false); + ListPluginComponent.createRatingLabel(panel1, null, "", AllIcons.Plugins.Downloads, ListPluginComponent.GRAY_COLOR, false); myRating = - GridCellPluginComponent.createRatingLabel(panel1, null, "", AllIcons.Plugins.Rating, CellPluginComponent.GRAY_COLOR, false); + ListPluginComponent.createRatingLabel(panel1, null, "", AllIcons.Plugins.Rating, ListPluginComponent.GRAY_COLOR, false); } myVendor = new LinkPanel(panel1, false, null, TextHorizontalLayout.FIX_LABEL); @@ -266,7 +266,7 @@ public class PluginDetailsPageComponent extends MultiPanel { panel2.add(myTagPanel = new TagPanel(mySearchListener)); panel2.add(myVersion); myDate = - GridCellPluginComponent.createRatingLabel(panel2, TextHorizontalLayout.FIX_LABEL, "", null, CellPluginComponent.GRAY_COLOR, true); + ListPluginComponent.createRatingLabel(panel2, TextHorizontalLayout.FIX_LABEL, "", null, ListPluginComponent.GRAY_COLOR, true); centerPanel.add(panel2); } @@ -310,7 +310,7 @@ public class PluginDetailsPageComponent extends MultiPanel { } } - public void showPlugin(@Nullable CellPluginComponent component, boolean multiSelection) { + public void showPlugin(@Nullable ListPluginComponent component, boolean multiSelection) { if (myIndicator != null) { MyPluginModel.removeProgress(myPlugin, myIndicator); hideProgress(false, false); diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginListLayout.java b/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginListLayout.java index 3e1374ea407b..e8626b12ee59 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginListLayout.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginListLayout.java @@ -64,7 +64,7 @@ public class PluginListLayout extends AbstractLayoutManager implements PagePlugi component.setBounds(0, y, width, height); y += height; - for (CellPluginComponent plugin : group.plugins) { + for (ListPluginComponent plugin : group.plugins) { int lineHeight = plugin.getPreferredSize().height; plugin.setBounds(0, y, width, lineHeight); y += lineHeight; 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 fa3ea1c1b683..0b4caf352eed 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 @@ -30,14 +30,14 @@ public class PluginsGroupComponent extends JBPanelWithEmptyText { private final EventHandler myEventHandler; private final LinkListener myListener; private final LinkListener mySearchListener; - private final Function myFunction; + private final Function myFunction; private final List myGroups = new ArrayList<>(); public PluginsGroupComponent(@NotNull LayoutManager layout, @NotNull EventHandler eventHandler, @NotNull LinkListener listener, @NotNull LinkListener searchListener, - @NotNull Function function) { + @NotNull Function function) { super(layout); myEventHandler = eventHandler; myListener = listener; @@ -60,15 +60,15 @@ public class PluginsGroupComponent extends JBPanelWithEmptyText { } @NotNull - public List getSelection() { + public List getSelection() { return myEventHandler.getSelection(); } - public void setSelection(@NotNull CellPluginComponent component) { + public void setSelection(@NotNull ListPluginComponent component) { myEventHandler.setSelection(component); } - public void setSelection(@NotNull List components) { + public void setSelection(@NotNull List components) { myEventHandler.setSelection(components); } @@ -92,7 +92,7 @@ public class PluginsGroupComponent extends JBPanelWithEmptyText { if ((scrollBar.getValue() + scrollBar.getVisibleAmount()) >= scrollBar.getMaximum()) { int fromIndex = group.ui.plugins.size(); int toIndex = Math.min(fromIndex + gapSize, group.descriptors.size()); - CellPluginComponent lastComponent = group.ui.plugins.get(fromIndex - 1); + ListPluginComponent lastComponent = group.ui.plugins.get(fromIndex - 1); int uiIndex = getComponentIndex(lastComponent); int eventIndex = myEventHandler.getCellIndex(lastComponent); PluginLogo.startBatchMode(); @@ -187,7 +187,7 @@ public class PluginsGroupComponent extends JBPanelWithEmptyText { private int getEventIndexForGroup(int groupIndex) { for (int i = groupIndex; i >= 0; i--) { - List plugins = myGroups.get(i).plugins; + List plugins = myGroups.get(i).plugins; if (!plugins.isEmpty()) { return myEventHandler.getCellIndex(plugins.get(0)); } @@ -197,7 +197,7 @@ public class PluginsGroupComponent extends JBPanelWithEmptyText { private void addToGroup(@NotNull PluginsGroup group, @NotNull List descriptors, int index, int eventIndex) { for (IdeaPluginDescriptor descriptor : descriptors) { - CellPluginComponent pluginComponent = myFunction.fun(descriptor); + ListPluginComponent pluginComponent = myFunction.fun(descriptor); group.ui.plugins.add(pluginComponent); add(pluginComponent, index); myEventHandler.addCell(pluginComponent, eventIndex); @@ -213,7 +213,7 @@ public class PluginsGroupComponent extends JBPanelWithEmptyText { public void addToGroup(@NotNull PluginsGroup group, @NotNull IdeaPluginDescriptor descriptor) { int index = group.addWithIndex(descriptor); - CellPluginComponent anchor = null; + ListPluginComponent anchor = null; int uiIndex = -1; if (index == group.ui.plugins.size()) { @@ -229,7 +229,7 @@ public class PluginsGroupComponent extends JBPanelWithEmptyText { uiIndex = getComponentIndex(anchor); } - CellPluginComponent pluginComponent = myFunction.fun(descriptor); + ListPluginComponent pluginComponent = myFunction.fun(descriptor); group.ui.plugins.add(index, pluginComponent); add(pluginComponent, uiIndex); myEventHandler.addCell(pluginComponent, anchor); @@ -240,7 +240,7 @@ public class PluginsGroupComponent extends JBPanelWithEmptyText { myGroups.remove(group.ui); remove(group.ui.panel); - for (CellPluginComponent plugin : group.ui.plugins) { + for (ListPluginComponent plugin : group.ui.plugins) { plugin.close(); remove(plugin); myEventHandler.removeCell(plugin); @@ -253,7 +253,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); assert index != -1; - CellPluginComponent component = group.ui.plugins.remove(index); + ListPluginComponent component = group.ui.plugins.remove(index); component.close(); remove(component); myEventHandler.removeCell(component); @@ -275,7 +275,7 @@ public class PluginsGroupComponent extends JBPanelWithEmptyText { public void clear() { for (UIPluginGroup group : myGroups) { - for (CellPluginComponent plugin : group.plugins) { + for (ListPluginComponent plugin : group.plugins) { plugin.close(); } } diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginsGroupComponentWithProgress.java b/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginsGroupComponentWithProgress.java index b2549632f734..38464da7b914 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginsGroupComponentWithProgress.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginsGroupComponentWithProgress.java @@ -22,7 +22,7 @@ public class PluginsGroupComponentWithProgress extends PluginsGroupComponent { @NotNull EventHandler eventHandler, @NotNull LinkListener listener, @NotNull LinkListener searchListener, - @NotNull Function function) { + @NotNull Function function) { super(layout, eventHandler, listener, searchListener, function); myIcon.setOpaque(false); myIcon.setPaintPassiveIcon(false); diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginsListLayout.java b/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginsListLayout.java index ab1a8dc11d98..ca48b223d6b3 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginsListLayout.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginsListLayout.java @@ -45,7 +45,7 @@ public class PluginsListLayout extends AbstractLayoutManager implements PagePlug component.setBounds(0, y, width, height); y += height; - for (CellPluginComponent plugin : group.plugins) { + for (ListPluginComponent plugin : group.plugins) { plugin.setBounds(0, y, width, myLineHeight); y += myLineHeight; } @@ -63,15 +63,7 @@ public class PluginsListLayout extends AbstractLayoutManager implements PagePlug myLineHeight = 0; for (UIPluginGroup group : groups) { - for (CellPluginComponent plugin : group.plugins) { - JEditorPane description = plugin.myDescription; - if (description != null) { - plugin.doLayout(); - int parentWidth = width - SwingUtilities.convertPoint(description.getParent(), description.getLocation(), plugin).x; - if (parentWidth > 0) { - description.putClientProperty("parent.width", new Integer(parentWidth)); - } - } + for (ListPluginComponent plugin : group.plugins) { plugin.doLayout(); myLineHeight = Math.max(myLineHeight, plugin.getPreferredSize().height); diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginsTab.java b/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginsTab.java index 21761d6adb57..358a31905fdf 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginsTab.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginsTab.java @@ -68,7 +68,7 @@ public abstract class PluginsTab { return; } - List selection = panel.getSelection(); + List selection = panel.getSelection(); int size = selection.size(); myDetailsPage.showPlugin(size == 1 ? selection.get(0) : null, size > 1); }; @@ -221,7 +221,7 @@ public abstract class PluginsTab { String text = "Type / to see options"; StatusText emptyText = mySearchTextField.getTextEditor().getEmptyText(); - emptyText.appendText(text, new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, CellPluginComponent.GRAY_COLOR)); + emptyText.appendText(text, new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, ListPluginComponent.GRAY_COLOR)); } @NotNull diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/newui/ScrollEventHandler.java b/platform/platform-impl/src/com/intellij/ide/plugins/newui/ScrollEventHandler.java deleted file mode 100644 index df82bb6bf034..000000000000 --- a/platform/platform-impl/src/com/intellij/ide/plugins/newui/ScrollEventHandler.java +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -package com.intellij.ide.plugins.newui; - -import org.jetbrains.annotations.NotNull; - -import java.awt.*; -import java.awt.event.FocusAdapter; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; - -/** - * @author Alexander Lobas - */ -public class ScrollEventHandler extends EventHandler { - private final FocusListener myFocusListener = new FocusAdapter() { - @Override - public void focusGained(FocusEvent e) { - get(e).scrollToVisible(); - } - }; - - @Override - public void add(@NotNull Component component) { - component.addFocusListener(myFocusListener); - } -} \ No newline at end of file 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 9fd2590d33b6..9d7eae47253e 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 @@ -14,12 +14,12 @@ import java.util.List; */ public class UIPluginGroup { public Component panel; - public List plugins = new ArrayList<>(); + public List plugins = new ArrayList<>(); @Nullable - public CellPluginComponent findComponent(@NotNull IdeaPluginDescriptor descriptor) { + public ListPluginComponent findComponent(@NotNull IdeaPluginDescriptor descriptor) { String pluginId = descriptor.getPluginId().getIdString(); - for (CellPluginComponent component : plugins) { + for (ListPluginComponent component : plugins) { if (pluginId.equals(component.myPlugin.getPluginId().getIdString())) { return component; } diff --git a/platform/testGuiFramework/src/com/intellij/testGuiFramework/fixtures/PluginDialogFixture.kt b/platform/testGuiFramework/src/com/intellij/testGuiFramework/fixtures/PluginDialogFixture.kt index 6e9fbd449abd..395c056e463d 100644 --- a/platform/testGuiFramework/src/com/intellij/testGuiFramework/fixtures/PluginDialogFixture.kt +++ b/platform/testGuiFramework/src/com/intellij/testGuiFramework/fixtures/PluginDialogFixture.kt @@ -2,8 +2,7 @@ package com.intellij.testGuiFramework.fixtures import com.intellij.ide.plugins.IdeaPluginDescriptor -import com.intellij.ide.plugins.newui.CellPluginComponent -import com.intellij.ide.plugins.newui.TabHeaderComponent +import com.intellij.ide.plugins.newui.ListPluginComponent import com.intellij.openapi.fileChooser.actions.RefreshFileChooserAction import com.intellij.openapi.options.ex.ConfigurableCardPanel import com.intellij.testGuiFramework.framework.GuiTestUtil.findAndClickButtonWhenEnabled @@ -73,7 +72,7 @@ class PluginDialogFixture(robot: Robot, pluginDialog: JDialog) : JDialogFixture( fun cancel() = findAndClickCancelButton(this) private fun findPluginsAppearedOnTheScreen(): List = - waitUntilFoundList(findPluginCardsPanel(), CellPluginComponent::class.java, + waitUntilFoundList(findPluginCardsPanel(), ListPluginComponent::class.java, Timeouts.defaultTimeout) { it.isShowing }.map { it.pluginDescriptor } private fun findCheckBox(pluginName: String) = @@ -82,8 +81,8 @@ class PluginDialogFixture(robot: Robot, pluginDialog: JDialog) : JDialogFixture( private fun findPluginCardsPanel(): ConfigurableCardPanel = waitUntilFound(target(), ConfigurableCardPanel::class.java, Timeouts.defaultTimeout) { true } - private fun findCellPluginComponent(pluginName: String): CellPluginComponent = - waitUntilFound(findPluginCardsPanel(), CellPluginComponent::class.java, + private fun findCellPluginComponent(pluginName: String): ListPluginComponent = + waitUntilFound(findPluginCardsPanel(), ListPluginComponent::class.java, Timeouts.defaultTimeout) { it.isShowing && it.pluginDescriptor.name == pluginName } private fun findPluginDetailsLink(pluginName: String): JLabel =