mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
FinderRecursivePanel: cleanup, generify, fix tests
This commit is contained in:
@@ -73,7 +73,7 @@ public abstract class FinderRecursivePanel<T> extends OnePixelSplitter implement
|
||||
@Nullable
|
||||
private JComponent myChild = null;
|
||||
|
||||
protected JBList myList;
|
||||
protected JBList<T> myList;
|
||||
protected final CollectionListModel<T> myListModel = new CollectionListModel<>();
|
||||
|
||||
private final MergingUpdateQueue myMergingUpdateQueue = new MergingUpdateQueue("FinderRecursivePanel", 100, true, this, this);
|
||||
@@ -189,16 +189,11 @@ public abstract class FinderRecursivePanel<T> extends OnePixelSplitter implement
|
||||
ScrollPaneFactory.createScrollPane(myList,
|
||||
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
|
||||
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
return ListWithFilter.wrap(myList, pane, new Function<T, String>() {
|
||||
@Override
|
||||
public String fun(T o) {
|
||||
return getItemText(o);
|
||||
}
|
||||
});
|
||||
return ListWithFilter.wrap(myList, pane, (Function<T, String>)o -> getItemText(o));
|
||||
}
|
||||
|
||||
protected JBList createList() {
|
||||
final JBList list = new JBList(myListModel);
|
||||
protected JBList<T> createList() {
|
||||
final JBList<T> list = new JBList<>(myListModel);
|
||||
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
list.setEmptyText(getListEmptyText());
|
||||
list.setCellRenderer(createListCellRenderer());
|
||||
@@ -330,8 +325,8 @@ public abstract class FinderRecursivePanel<T> extends OnePixelSplitter implement
|
||||
return false;
|
||||
}
|
||||
|
||||
protected ListCellRenderer createListCellRenderer() {
|
||||
return new ColoredListCellRenderer() {
|
||||
protected ListCellRenderer<T> createListCellRenderer() {
|
||||
return new ColoredListCellRenderer<T>() {
|
||||
|
||||
private final FileColorManager myFileColorManager = FileColorManager.getInstance(getProject());
|
||||
|
||||
@@ -372,7 +367,7 @@ public abstract class FinderRecursivePanel<T> 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<T> extends OnePixelSplitter implement
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nullable
|
||||
public T getSelectedValue() {
|
||||
return (T)myList.getSelectedValue();
|
||||
return myList.getSelectedValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -467,12 +462,7 @@ public abstract class FinderRecursivePanel<T> extends OnePixelSplitter implement
|
||||
// load list items synchronously
|
||||
myList.setPaintBusy(true);
|
||||
try {
|
||||
final List<T> listItems = ApplicationManager.getApplication().runReadAction(new Computable<List<T>>() {
|
||||
@Override
|
||||
public List<T> compute() {
|
||||
return getListItems();
|
||||
}
|
||||
});
|
||||
final List<T> listItems = ApplicationManager.getApplication().runReadAction((Computable<List<T>>)() -> getListItems());
|
||||
mergeListItems(myListModel, myList, listItems);
|
||||
}
|
||||
finally {
|
||||
@@ -540,7 +530,7 @@ public abstract class FinderRecursivePanel<T> extends OnePixelSplitter implement
|
||||
});
|
||||
}
|
||||
|
||||
protected void mergeListItems(@NotNull CollectionListModel<T> listModel, @NotNull JList list, @NotNull List<T> newItems) {
|
||||
protected void mergeListItems(@NotNull CollectionListModel<T> listModel, @NotNull JList<T> list, @NotNull List<T> newItems) {
|
||||
setMergeListItemsRunning(true);
|
||||
|
||||
try {
|
||||
@@ -554,7 +544,7 @@ public abstract class FinderRecursivePanel<T> extends OnePixelSplitter implement
|
||||
|
||||
int newSelectedIndex = -1;
|
||||
|
||||
T selection = (T)list.getSelectedValue();
|
||||
T selection = list.getSelectedValue();
|
||||
if (selection != null) {
|
||||
newSelectedIndex = newItems.indexOf(selection);
|
||||
}
|
||||
|
||||
+7
-7
@@ -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<String> list = panel.getList();
|
||||
CollectionListModel<String> 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<String> getList() {
|
||||
return myList;
|
||||
}
|
||||
|
||||
@@ -156,13 +156,13 @@ public class FinderRecursivePanelListModelMergeTest extends LightPlatformTestCas
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JBList createList() {
|
||||
protected JBList<String> createList() {
|
||||
myList = super.createList();
|
||||
((CollectionListModel)myList.getModel()).replaceAll(getListItems());
|
||||
((CollectionListModel<String>)myList.getModel()).replaceAll(getListItems());
|
||||
return myList;
|
||||
}
|
||||
|
||||
public void merge(@NotNull CollectionListModel<String> listModel, @NotNull JList list, @NotNull List<String> newItems) {
|
||||
public void merge(@NotNull CollectionListModel<String> listModel, @NotNull JList<String> list, @NotNull List<String> newItems) {
|
||||
mergeListItems(listModel, list, newItems);
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -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<String> {
|
||||
|
||||
private JBList myList;
|
||||
private JBList<String> 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<String> createList() {
|
||||
myList = super.createList();
|
||||
((CollectionListModel)myList.getModel()).replaceAll(getListItems());
|
||||
((CollectionListModel<String>)myList.getModel()).replaceAll(getListItems());
|
||||
return myList;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user