From e2a3dc0c4bf9f72a6cfcb46253ca7cd04e7be2b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yann=20C=C3=A9bron?= Date: Fri, 9 Sep 2016 11:17:29 +0200 Subject: [PATCH] FinderRecursivePanel: cleanup, generify, fix tests --- .../com/intellij/ui/FinderRecursivePanel.java | 32 +++++++------------ ...inderRecursivePanelListModelMergeTest.java | 14 ++++---- ...nderRecursivePanelSelectionUpdateTest.java | 12 +++---- 3 files changed, 24 insertions(+), 34 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ui/FinderRecursivePanel.java b/platform/platform-impl/src/com/intellij/ui/FinderRecursivePanel.java index bb3a9060989c..cfe8ddc67f90 100644 --- a/platform/platform-impl/src/com/intellij/ui/FinderRecursivePanel.java +++ b/platform/platform-impl/src/com/intellij/ui/FinderRecursivePanel.java @@ -73,7 +73,7 @@ public abstract class FinderRecursivePanel extends OnePixelSplitter implement @Nullable private JComponent myChild = null; - protected JBList myList; + protected JBList myList; protected final CollectionListModel myListModel = new CollectionListModel<>(); private final MergingUpdateQueue myMergingUpdateQueue = new MergingUpdateQueue("FinderRecursivePanel", 100, true, this, this); @@ -189,16 +189,11 @@ public abstract class FinderRecursivePanel extends OnePixelSplitter implement ScrollPaneFactory.createScrollPane(myList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); - return ListWithFilter.wrap(myList, pane, new Function() { - @Override - public String fun(T o) { - return getItemText(o); - } - }); + return ListWithFilter.wrap(myList, pane, (Function)o -> getItemText(o)); } - protected JBList createList() { - final JBList list = new JBList(myListModel); + protected JBList createList() { + final JBList list = new JBList<>(myListModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setEmptyText(getListEmptyText()); list.setCellRenderer(createListCellRenderer()); @@ -330,8 +325,8 @@ public abstract class FinderRecursivePanel extends OnePixelSplitter implement return false; } - protected ListCellRenderer createListCellRenderer() { - return new ColoredListCellRenderer() { + protected ListCellRenderer createListCellRenderer() { + return new ColoredListCellRenderer() { private final FileColorManager myFileColorManager = FileColorManager.getInstance(getProject()); @@ -372,7 +367,7 @@ public abstract class FinderRecursivePanel extends OnePixelSplitter implement setBackground(bg); if (hasChildren(t)) { - JPanel result = new JPanel(new BorderLayout(0, 0)); + JPanel result = new JPanel(new BorderLayout()); JLabel childrenLabel = new JLabel(); childrenLabel.setOpaque(true); childrenLabel.setVisible(true); @@ -432,7 +427,7 @@ public abstract class FinderRecursivePanel extends OnePixelSplitter implement @SuppressWarnings("unchecked") @Nullable public T getSelectedValue() { - return (T)myList.getSelectedValue(); + return myList.getSelectedValue(); } /** @@ -467,12 +462,7 @@ public abstract class FinderRecursivePanel extends OnePixelSplitter implement // load list items synchronously myList.setPaintBusy(true); try { - final List listItems = ApplicationManager.getApplication().runReadAction(new Computable>() { - @Override - public List compute() { - return getListItems(); - } - }); + final List listItems = ApplicationManager.getApplication().runReadAction((Computable>)() -> getListItems()); mergeListItems(myListModel, myList, listItems); } finally { @@ -540,7 +530,7 @@ public abstract class FinderRecursivePanel extends OnePixelSplitter implement }); } - protected void mergeListItems(@NotNull CollectionListModel listModel, @NotNull JList list, @NotNull List newItems) { + protected void mergeListItems(@NotNull CollectionListModel listModel, @NotNull JList list, @NotNull List newItems) { setMergeListItemsRunning(true); try { @@ -554,7 +544,7 @@ public abstract class FinderRecursivePanel extends OnePixelSplitter implement int newSelectedIndex = -1; - T selection = (T)list.getSelectedValue(); + T selection = list.getSelectedValue(); if (selection != null) { newSelectedIndex = newItems.indexOf(selection); } diff --git a/platform/platform-tests/testSrc/com/intellij/ui/FinderRecursivePanelListModelMergeTest.java b/platform/platform-tests/testSrc/com/intellij/ui/FinderRecursivePanelListModelMergeTest.java index 8ffe9f6e86b2..ce1e65456a9e 100644 --- a/platform/platform-tests/testSrc/com/intellij/ui/FinderRecursivePanelListModelMergeTest.java +++ b/platform/platform-tests/testSrc/com/intellij/ui/FinderRecursivePanelListModelMergeTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -90,7 +90,7 @@ public class FinderRecursivePanelListModelMergeTest extends LightPlatformTestCas final StringFinderRecursivePanel panel = createStringPanel(initialItems); disposeOnTearDown(panel); - JBList list = panel.getList(); + JBList list = panel.getList(); CollectionListModel model = panel.getListModel(); list.setSelectedIndex(initialSelectionIdx); @@ -118,7 +118,7 @@ public class FinderRecursivePanelListModelMergeTest extends LightPlatformTestCas @NotNull private StringFinderRecursivePanel createStringPanel(String[] initialItems) { StringFinderRecursivePanel panel = new StringFinderRecursivePanel(initialItems); - panel.init(); + panel.initPanel(); return panel; } @@ -147,7 +147,7 @@ public class FinderRecursivePanelListModelMergeTest extends LightPlatformTestCas return false; } - public JBList getList() { + public JBList getList() { return myList; } @@ -156,13 +156,13 @@ public class FinderRecursivePanelListModelMergeTest extends LightPlatformTestCas } @Override - protected JBList createList() { + protected JBList createList() { myList = super.createList(); - ((CollectionListModel)myList.getModel()).replaceAll(getListItems()); + ((CollectionListModel)myList.getModel()).replaceAll(getListItems()); return myList; } - public void merge(@NotNull CollectionListModel listModel, @NotNull JList list, @NotNull List newItems) { + public void merge(@NotNull CollectionListModel listModel, @NotNull JList list, @NotNull List newItems) { mergeListItems(listModel, list, newItems); } } diff --git a/platform/platform-tests/testSrc/com/intellij/ui/FinderRecursivePanelSelectionUpdateTest.java b/platform/platform-tests/testSrc/com/intellij/ui/FinderRecursivePanelSelectionUpdateTest.java index c3840cf9e7b0..954521bc1f36 100644 --- a/platform/platform-tests/testSrc/com/intellij/ui/FinderRecursivePanelSelectionUpdateTest.java +++ b/platform/platform-tests/testSrc/com/intellij/ui/FinderRecursivePanelSelectionUpdateTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -60,16 +60,16 @@ public class FinderRecursivePanelSelectionUpdateTest extends LightPlatformTestCa @SuppressWarnings("InnerClassMayBeStatic") private class StringFinderRecursivePanel extends FinderRecursivePanel { - private JBList myList; + private JBList myList; private StringFinderRecursivePanel(Project project) { super(project, "fooPanel"); - init(); + initPanel(); } public StringFinderRecursivePanel(StringFinderRecursivePanel panel) { super(panel); - init(); + initPanel(); } @NotNull @@ -96,9 +96,9 @@ public class FinderRecursivePanelSelectionUpdateTest extends LightPlatformTestCa } @Override - protected JBList createList() { + protected JBList createList() { myList = super.createList(); - ((CollectionListModel)myList.getModel()).replaceAll(getListItems()); + ((CollectionListModel)myList.getModel()).replaceAll(getListItems()); return myList; }