Merge remote-tracking branch 'origin/master'

This commit is contained in:
Konstantin Bulenkov
2017-05-16 23:30:59 +03:00
21 changed files with 130 additions and 151 deletions
@@ -21,7 +21,7 @@ import com.intellij.codeInspection.ex.GlobalInspectionContextImpl;
import com.intellij.codeInspection.ex.GlobalInspectionToolWrapper;
import com.intellij.codeInspection.ex.InspectionToolWrapper;
import com.intellij.icons.AllIcons;
import com.intellij.util.containers.FactoryMap;
import gnu.trove.TObjectIntHashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -53,7 +53,7 @@ public class EntryPointsNode extends InspectionNode {
}
@Override
public void visitProblemSeverities(FactoryMap<HighlightDisplayLevel, Integer> counter) {
public void visitProblemSeverities(TObjectIntHashMap<HighlightDisplayLevel> counter) {
//do nothing here
}
@@ -80,7 +80,7 @@ public class TurnRefsToSuperDialog extends RefactoringDialog {
final JLabel classListLabel = new JLabel();
panel.add(classListLabel, BorderLayout.NORTH);
mySuperClassesList = new JBList<>(mySuperClasses.toArray());
mySuperClassesList = new JBList<>(mySuperClasses);
mySuperClassesList.setCellRenderer(new ClassCellRenderer(mySuperClassesList.getCellRenderer()));
mySuperClassesList.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
classListLabel.setText(RefactoringBundle.message("turnRefsToSuper.change.usages.to", mySubClass.getQualifiedName()));
@@ -188,17 +188,8 @@ public class LayeredLexerEditorHighlighter extends LexerEditorHighlighter {
@NotNull
@Override
public HighlighterIterator createIterator(int startOffset) {
// do NOT synchronize before updateLayers due to deadlock with PsiLock
final boolean changed = updateLayers();
//noinspection SynchronizeOnThis
synchronized (this) {
if (changed) {
Document document = getDocument();
if (document != null) {
resetText(document.getImmutableCharSequence());
}
}
return new LayeredHighlighterIteratorImpl(startOffset);
}
}
@@ -56,8 +56,8 @@ public class PathEditor {
public static final Color INVALID_COLOR = new JBColor(new Color(210, 0, 0), JBColor.RED);
protected JPanel myPanel;
private JBList myList;
private final DefaultListModel myModel;
private JBList<VirtualFile> myList;
private final DefaultListModel<VirtualFile> myModel;
private final Set<VirtualFile> myAllFiles = new HashSet<>();
private boolean myModified = false;
protected boolean myEnabled = false;
@@ -108,9 +108,10 @@ public class PathEditor {
}
public JComponent createComponent() {
myList = new JBList(getListModel());
myList = new JBList<>(getListModel());
//noinspection unchecked
myList.setCellRenderer(createListCellRenderer(myList));
TreeUIHelper.getInstance().installListSpeedSearch(myList, file -> ((VirtualFile)file).getPresentableUrl());
TreeUIHelper.getInstance().installListSpeedSearch(myList, VirtualFile::getPresentableUrl);
ToolbarDecorator toolbarDecorator = ToolbarDecorator.createDecorator(myList)
.disableUpDownActions()
@@ -181,15 +182,15 @@ public class PathEditor {
itemsRemoved(removedItems);
}
protected DefaultListModel createListModel() {
return new DefaultListModel();
protected DefaultListModel<VirtualFile> createListModel() {
return new DefaultListModel<>();
}
protected ListCellRenderer createListCellRenderer(JBList list) {
return new PathCellRenderer();
}
protected void itemsRemoved(List removedItems) {
protected void itemsRemoved(List<VirtualFile> removedItems) {
myAllFiles.removeAll(removedItems);
if (removedItems.size() > 0) {
setModified(true);
@@ -213,16 +214,15 @@ public class PathEditor {
protected boolean isUrlInserted() {
if (getRowCount() > 0) {
return ((VirtualFile)getListModel().lastElement()).getFileSystem() instanceof HttpFileSystem;
return getListModel().lastElement().getFileSystem() instanceof HttpFileSystem;
}
return false;
}
protected void requestDefaultFocus() {
if (myList != null) {
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
IdeFocusManager.getGlobalInstance().requestFocus(myList, true);
});
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(
() -> IdeFocusManager.getGlobalInstance().requestFocus(myList, true));
}
}
@@ -249,7 +249,7 @@ public class PathEditor {
indicesToRemove.add(idx);
}
}
final List list = ListUtil.removeIndices(myList, indicesToRemove.toNativeArray());
final List<VirtualFile> list = ListUtil.removeIndices(myList, indicesToRemove.toNativeArray());
itemsRemoved(list);
}
@@ -273,7 +273,7 @@ public class PathEditor {
return true;
}
protected DefaultListModel getListModel() {
protected DefaultListModel<VirtualFile> getListModel() {
return myModel;
}
@@ -313,7 +313,7 @@ public class PathEditor {
}
protected VirtualFile getValueAt(int row) {
return (VirtualFile)getListModel().get(row);
return getListModel().get(row);
}
public void clearList() {
@@ -33,10 +33,10 @@ import com.intellij.ui.ListSpeedSearch;
import com.intellij.ui.SeparatorWithText;
import com.intellij.ui.components.JBCheckBox;
import com.intellij.ui.speedSearch.SpeedSearchSupply;
import com.intellij.util.Function;
import com.intellij.util.NullableFunction;
import com.intellij.util.ObjectUtils;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.Convertor;
import com.intellij.util.containers.MultiMap;
import com.intellij.util.containers.hash.HashSet;
import com.intellij.util.ui.EmptyIcon;
@@ -221,7 +221,7 @@ public class GutterIconsConfigurable implements SearchableConfigurable, Configur
};
myList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
myList.setBorder(BorderFactory.createEmptyBorder());
new ListSpeedSearch(myList, (Convertor<Object, String>)o -> o instanceof JCheckBox ? ((JCheckBox)o).getText() : null);
new ListSpeedSearch<>(myList, (Function<JCheckBox, String>)JCheckBox::getText);
}
@NotNull
@@ -129,6 +129,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
private EditorEx myPreviewEditor;
private InspectionTreeLoadingProgressAware myLoadingProgressPreview;
private final ExcludedInspectionTreeNodesManager myExcludedInspectionTreeNodesManager;
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
private final FactoryMap<String, Set<Object>> mySuppressedNodes = new FactoryMap<String, Set<Object>>() {
@Override
protected Set<Object> create(String key) {
@@ -390,27 +391,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
DefaultActionGroup group = new DefaultActionGroup();
group.add(new RerunAction(this));
group.add(new CloseAction());
final TreeExpander treeExpander = new TreeExpander() {
@Override
public void expandAll() {
TreeUtil.expandAll(myTree);
}
@Override
public boolean canExpand() {
return true;
}
@Override
public void collapseAll() {
TreeUtil.collapseAll(myTree, 0);
}
@Override
public boolean canCollapse() {
return true;
}
};
final TreeExpander treeExpander = new DefaultTreeExpander(myTree);
group.add(actionsManager.createExpandAllAction(treeExpander, myTree));
group.add(actionsManager.createCollapseAllAction(treeExpander, myTree));
group.add(actionsManager.createPrevOccurenceAction(getOccurenceNavigator()));
@@ -712,7 +693,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren
}
void addProblemDescriptors(InspectionToolWrapper wrapper, RefEntity refElement, CommonProblemDescriptor[] descriptors) {
myTreeUpdater.submit((Runnable)() -> ReadAction.run(() -> {
myTreeUpdater.submit(() -> ReadAction.run(() -> {
if (!isDisposed()) {
ApplicationManager.getApplication().assertReadAccessAllowed();
synchronized (myTreeStructureUpdateLock) {
@@ -20,8 +20,8 @@ import com.intellij.codeHighlighting.HighlightDisplayLevel;
import com.intellij.codeInspection.reference.RefEntity;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.vcs.FileStatus;
import com.intellij.util.containers.FactoryMap;
import com.intellij.util.ui.tree.TreeUtil;
import gnu.trove.TObjectIntHashMap;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -44,7 +44,7 @@ public abstract class InspectionTreeNode extends DefaultMutableTreeNode {
return null;
}
public void visitProblemSeverities(FactoryMap<HighlightDisplayLevel, Integer> counter) {
public void visitProblemSeverities(TObjectIntHashMap<HighlightDisplayLevel> counter) {
Enumeration enumeration = children();
while (enumeration.hasMoreElements()) {
InspectionTreeNode child = (InspectionTreeNode)enumeration.nextElement();
@@ -24,14 +24,14 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.Gray;
import com.intellij.ui.JBColor;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.util.containers.FactoryMap;
import com.intellij.util.containers.SoftHashMap;
import org.jetbrains.annotations.Nullable;
import gnu.trove.TObjectIntHashMap;
import java.awt.*;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
/**
* @author Dmitry Batkovich
@@ -45,26 +45,13 @@ public abstract class InspectionTreeTailRenderer {
private final Map<HighlightSeverity, String> myPluralizedSeverityNames = new SoftHashMap<>();
private final Map<HighlightSeverity, String> myUnpluralizedSeverityNames = new SoftHashMap<>();
private final FactoryMap<HighlightDisplayLevel, Integer> myItemCounter;
private final TObjectIntHashMap<HighlightDisplayLevel> myItemCounter = new TObjectIntHashMap<>();
private final SeverityRegistrar myRegistrar;
private final GlobalInspectionContextImpl myContext;
public InspectionTreeTailRenderer(GlobalInspectionContextImpl context) {
myRegistrar = SeverityRegistrar.getSeverityRegistrar(context.getProject());
myContext = context;
myItemCounter = new FactoryMap<HighlightDisplayLevel, Integer>() {
@Nullable
@Override
protected Integer create(HighlightDisplayLevel key) {
return 0;
}
@Override
protected Map<HighlightDisplayLevel, Integer> createMap() {
return new TreeMap<>((o1, o2) -> -myRegistrar.compare(o1.getSeverity(), o2.getSeverity()));
}
};
}
public void appendTailText(InspectionTreeNode node) {
@@ -78,14 +65,16 @@ public abstract class InspectionTreeTailRenderer {
myItemCounter.clear();
node.visitProblemSeverities(myItemCounter);
if (myItemCounter.size() > MAX_LEVEL_TYPES) {
appendText(InspectionsBundle.message("inspection.problem.descriptor.count",
myItemCounter.values().stream().mapToInt(Integer::intValue).sum()) + " ",
SimpleTextAttributes.GRAYED_ATTRIBUTES);
appendText(InspectionsBundle.message("inspection.problem.descriptor.count", sum(myItemCounter.getValues()) + " ",
SimpleTextAttributes.GRAYED_ATTRIBUTES));
}
else {
for (Map.Entry<HighlightDisplayLevel, Integer> entry : myItemCounter.entrySet()) {
final HighlightDisplayLevel level = entry.getKey();
final Integer occur = entry.getValue();
Object[] levels = myItemCounter.keys();
Arrays.sort(levels, Comparator.comparing(l -> ((HighlightDisplayLevel) l).getSeverity()).reversed());
for (Object o : levels) {
HighlightDisplayLevel level = (HighlightDisplayLevel) o;
int occur = myItemCounter.get(level);
SimpleTextAttributes attrs = SimpleTextAttributes.GRAY_ATTRIBUTES;
attrs = attrs.derive(-1, level == HighlightDisplayLevel.ERROR && !myContext.getUIOptions().GROUP_BY_SEVERITY
@@ -121,4 +110,12 @@ public abstract class InspectionTreeTailRenderer {
return name;
}
}
private static int sum(int[] numbers) {
int result = 0;
for (int number : numbers) {
result += number;
}
return result;
}
}
@@ -28,8 +28,8 @@ import com.intellij.codeInspection.reference.RefEntity;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.FileStatus;
import com.intellij.psi.PsiElement;
import com.intellij.util.containers.FactoryMap;
import com.intellij.xml.util.XmlStringUtil;
import gnu.trove.TObjectIntHashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -105,7 +105,7 @@ public class ProblemDescriptionNode extends SuppressableInspectionTreeNode {
}
@Override
public void visitProblemSeverities(FactoryMap<HighlightDisplayLevel, Integer> counter) {
public void visitProblemSeverities(TObjectIntHashMap<HighlightDisplayLevel> counter) {
if (!myPresentation.isProblemResolved(getElement(), myDescriptor)) {
counter.put(myLevel, counter.get(myLevel) + 1);
}
@@ -23,7 +23,7 @@ import com.intellij.codeInspection.reference.RefDirectory;
import com.intellij.codeInspection.reference.RefElement;
import com.intellij.codeInspection.reference.RefEntity;
import com.intellij.openapi.vcs.FileStatus;
import com.intellij.util.containers.FactoryMap;
import gnu.trove.TObjectIntHashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -126,7 +126,7 @@ public class RefElementNode extends SuppressableInspectionTreeNode {
}
@Override
public void visitProblemSeverities(FactoryMap<HighlightDisplayLevel, Integer> counter) {
public void visitProblemSeverities(TObjectIntHashMap<HighlightDisplayLevel> counter) {
if (isLeaf() && !myPresentation.isElementIgnored(getElement())) {
counter.put(HighlightDisplayLevel.WARNING, counter.get(HighlightDisplayLevel.WARNING) + 1);
return;
@@ -41,7 +41,7 @@ import java.awt.event.KeyEvent;
* @author Dennis.Ushakov
*/
public abstract class AbstractNewProjectDialog extends DialogWrapper {
private Pair<JPanel, JBList> myPair;
private Pair<JPanel, JBList<AnAction>> myPair;
public AbstractNewProjectDialog() {
super(ProjectManager.getInstance().getDefaultProject());
@@ -68,7 +68,7 @@ public abstract class AbstractNewProjectDialog extends DialogWrapper {
DefaultActionGroup root = createRootStep();
Disposer.register(getDisposable(), () -> root.removeAll());
Pair<JPanel, JBList> pair = FlatWelcomeFrame.createActionGroupPanel(root, getRootPane(), null, getDisposable());
Pair<JPanel, JBList<AnAction>> pair = FlatWelcomeFrame.createActionGroupPanel(root, getRootPane(), null, getDisposable());
JPanel component = pair.first;
new AnAction() {
@Override
@@ -40,16 +40,16 @@ import java.util.Map;
/**
* @author oleg
*/
public class CheckBoxList<T> extends JBList {
public class CheckBoxList<T> extends JBList<JCheckBox> {
private final CellRenderer myCellRenderer;
private CheckBoxListListener checkBoxListListener;
private final BidirectionalMap<T, JCheckBox> myItemMap = new BidirectionalMap<>();
public CheckBoxList(final CheckBoxListListener checkBoxListListener) {
this(new DefaultListModel(), checkBoxListListener);
this(new DefaultListModel<>(), checkBoxListListener);
}
public CheckBoxList(final DefaultListModel dataModel, final CheckBoxListListener checkBoxListListener) {
public CheckBoxList(DefaultListModel<JCheckBox> dataModel, CheckBoxListListener checkBoxListListener) {
this(dataModel);
setCheckBoxListListener(checkBoxListListener);
}
@@ -189,7 +189,7 @@ public class CheckBoxList<T> extends JBList {
@NotNull
private JCheckBox getCheckBoxAt(int index) {
return (JCheckBox)getModel().getElementAt(index);
return getModel().getElementAt(index);
}
public void setStringItems(final Map<String, Boolean> items) {
@@ -220,7 +220,7 @@ public class CheckBoxList<T> extends JBList {
JCheckBox checkBox = myItemMap.remove(oldItem);
myItemMap.put(newItem, checkBox);
checkBox.setText(newText);
DefaultListModel model = (DefaultListModel)getModel();
DefaultListModel<JCheckBox> model = (DefaultListModel<JCheckBox>)getModel();
int ind = model.indexOf(checkBox);
if (ind >= 0) {
model.set(ind, checkBox); // to fire contentsChanged event
@@ -229,7 +229,7 @@ public class CheckBoxList<T> extends JBList {
@Nullable
public T getItemAt(int index) {
JCheckBox checkBox = (JCheckBox)getModel().getElementAt(index);
JCheckBox checkBox = getModel().getElementAt(index);
List<T> value = myItemMap.getKeysByValue(checkBox);
return value == null || value.isEmpty() ? null : value.get(0);
}
@@ -240,7 +240,7 @@ public class CheckBoxList<T> extends JBList {
}
public boolean isItemSelected(int index) {
return ((JCheckBox)getModel().getElementAt(index)).isSelected();
return getModel().getElementAt(index).isSelected();
}
public boolean isItemSelected(T item) {
@@ -283,7 +283,7 @@ public class CheckBoxList<T> extends JBList {
return rootComponent;
}
private class CellRenderer implements ListCellRenderer {
private class CellRenderer implements ListCellRenderer<JCheckBox> {
private final Border mySelectedBorder;
private final Border myBorder;
private final Insets myBorderInsets;
@@ -295,9 +295,7 @@ public class CheckBoxList<T> extends JBList {
}
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
JCheckBox checkbox = (JCheckBox)value;
public Component getListCellRendererComponent(JList list, JCheckBox checkbox, int index, boolean isSelected, boolean cellHasFocus) {
Color textColor = getForeground(isSelected);
Color backgroundColor = getBackground(isSelected);
Font font = getFont();
@@ -23,17 +23,17 @@ import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
public class ExpandedItemListCellRendererWrapper implements ListCellRenderer {
@NotNull private final ListCellRenderer myWrappee;
public class ExpandedItemListCellRendererWrapper<T> implements ListCellRenderer<T> {
@NotNull private final ListCellRenderer<T> myWrappee;
@NotNull private final ExpandableItemsHandler<Integer> myHandler;
public ExpandedItemListCellRendererWrapper(@NotNull ListCellRenderer wrappee, @NotNull ExpandableItemsHandler<Integer> handler) {
public ExpandedItemListCellRendererWrapper(@NotNull ListCellRenderer<T> wrappee, @NotNull ExpandableItemsHandler<Integer> handler) {
myWrappee = wrappee;
myHandler = handler;
}
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
public Component getListCellRendererComponent(JList<? extends T> list, T value, int index, boolean isSelected, boolean cellHasFocus) {
GraphicsUtil.setAntialiasingType(list, AntialiasingType.getAAHintForSwingComponent());
Component result = myWrappee.getListCellRendererComponent(list, UIUtil.htmlInjectionGuard(value), index, isSelected, cellHasFocus);
if (!myHandler.getExpandedItems().contains(index)) return result;
@@ -78,7 +78,7 @@ public class ListUtil {
return removeSelectedItems(list, null);
}
public static List removeIndices(JList list, int[] indices) {
public static <T> List<T> removeIndices(JList<T> list, int[] indices) {
return removeIndices(list, indices, null);
}
@@ -45,9 +45,9 @@ public abstract class TreeUIHelper {
public abstract void installEditSourceOnDoubleClick(JTree tree);
public abstract void installTreeSpeedSearch(JTree tree);
public abstract void installListSpeedSearch(JList list);
public abstract void installListSpeedSearch(JList<?> list);
public abstract void installTreeSpeedSearch(JTree tree, Convertor<TreePath, String> convertor, boolean canExpand);
public abstract void installListSpeedSearch(JList list, Convertor<Object, String> convertor);
public abstract <T> void installListSpeedSearch(JList<T> list, Convertor<T, String> convertor);
public abstract void installEditSourceOnEnterKeyHandler(JTree tree);
@@ -22,7 +22,6 @@ import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.*;
import com.intellij.util.ArrayUtil;
import com.intellij.util.NotNullFunction;
import com.intellij.util.ui.*;
import org.jetbrains.annotations.NotNull;
@@ -40,6 +39,7 @@ import java.awt.*;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
/**
@@ -47,38 +47,42 @@ import java.util.Collection;
* @author Konstantin Bulenkov
*/
public class JBList<E> extends JList<E> implements ComponentWithEmptyText, ComponentWithExpandableItems<Integer>{
@NotNull private StatusText myEmptyText;
@NotNull private ExpandableItemsHandler<Integer> myExpandableItemsHandler;
private StatusText myEmptyText;
private ExpandableItemsHandler<Integer> myExpandableItemsHandler;
@Nullable private AsyncProcessIcon myBusyIcon;
private boolean myBusy;
public JBList() {
init();
}
public JBList(@NotNull ListModel dataModel) {
public JBList(@NotNull ListModel<E> dataModel) {
super(dataModel);
init();
}
public JBList(@NotNull Object... listData) {
public JBList(@NotNull E... listData) {
super(createDefaultListModel(listData));
init();
}
@NotNull
public static DefaultListModel createDefaultListModel(@NotNull Object... items) {
final DefaultListModel model = new DefaultListModel();
for (Object item : items) {
public static <T> DefaultListModel<T> createDefaultListModel(@NotNull T... items) {
return createDefaultListModel(Arrays.asList(items));
}
@NotNull
public static <T> DefaultListModel<T> createDefaultListModel(@NotNull Iterable<T> items) {
DefaultListModel<T> model = new DefaultListModel<>();
for (T item : items) {
model.add(model.getSize(), item);
}
return model;
}
public JBList(@NotNull Collection<E> items) {
this(ArrayUtil.toObjectArray(items));
this(createDefaultListModel(items));
}
@Override
@@ -297,7 +301,7 @@ public class JBList<E> extends JList<E> implements ComponentWithEmptyText, Compo
super.setCellRenderer(cellRenderer);
return;
}
super.setCellRenderer(new ExpandedItemListCellRendererWrapper(cellRenderer, myExpandableItemsHandler));
super.setCellRenderer(new ExpandedItemListCellRendererWrapper<>(cellRenderer, myExpandableItemsHandler));
}
public <T> void installCellRenderer(@NotNull final NotNullFunction<T, JComponent> fun) {
@@ -378,7 +382,7 @@ public class JBList<E> extends JList<E> implements ComponentWithEmptyText, Compo
}
protected class AccessibleJBListChild extends AccessibleJListChild {
public AccessibleJBListChild(JBList parent, int indexInParent) {
public AccessibleJBListChild(JBList<E> parent, int indexInParent) {
super(parent, indexInParent);
}
@@ -50,9 +50,8 @@ import com.intellij.ui.components.labels.ActionLink;
import com.intellij.ui.components.panels.NonOpaquePanel;
import com.intellij.ui.popup.PopupFactoryImpl;
import com.intellij.ui.popup.list.GroupedItemsListRenderer;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.Convertor;
import com.intellij.util.ui.EmptyIcon;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.MouseEventAdapter;
@@ -204,8 +203,8 @@ public class FlatWelcomeFrame extends JFrame implements IdeFrame, Disposable, Ac
return "Welcome to " + ApplicationNamesInfo.getInstance().getFullProductName();
}
@Nullable
public static JComponent getPreferredFocusedComponent(@NotNull Pair<JPanel, JBList> pair) {
@NotNull
public static JComponent getPreferredFocusedComponent(@NotNull Pair<JPanel, JBList<AnAction>> pair) {
if (pair.second.getModel().getSize() == 1) {
JBTextField textField = UIUtil.uiTraverser(pair.first).filter(JBTextField.class).first();
if (textField != null) {
@@ -476,10 +475,10 @@ public class FlatWelcomeFrame extends JFrame implements IdeFrame, Disposable, Ac
private AnAction wrapGroups(AnAction action) {
if (action instanceof ActionGroup && ((ActionGroup)action).isPopup()) {
final Pair<JPanel, JBList> panel = createActionGroupPanel((ActionGroup)action, mySlidingPanel, () -> goBack(), this);
final Pair<JPanel, JBList<AnAction>> panel = createActionGroupPanel((ActionGroup)action, mySlidingPanel, () -> goBack(), this);
final Runnable onDone = () -> {
setTitle("New Project");
final JBList list = panel.second;
final JBList<AnAction> list = panel.second;
ScrollingUtil.ensureSelectionExists(list);
final ListSelectionListener[] listeners =
((DefaultListSelectionModel)list.getSelectionModel()).getListeners(ListSelectionListener.class);
@@ -489,9 +488,7 @@ public class FlatWelcomeFrame extends JFrame implements IdeFrame, Disposable, Ac
listener.valueChanged(new ListSelectionEvent(list, list.getSelectedIndex(), list.getSelectedIndex(), true));
}
JComponent toFocus = getPreferredFocusedComponent(panel);
if (toFocus != null) {
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> IdeFocusManager.getGlobalInstance().requestFocus(toFocus, true));
}
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> IdeFocusManager.getGlobalInstance().requestFocus(toFocus, true));
};
final String name = action.getClass().getName();
mySlidingPanel.add(name, panel.first);
@@ -783,23 +780,19 @@ public class FlatWelcomeFrame extends JFrame implements IdeFrame, Disposable, Ac
return getRootPane();
}
public static void notifyFrameClosed(JFrame frame) {
saveLocation(frame.getBounds());
}
public static class WelcomeScreenActionsPanel {
private JPanel root;
private JPanel actions;
}
public static Pair<JPanel, JBList> createActionGroupPanel(final ActionGroup action,
final JComponent parent,
final Runnable backAction,
@NotNull Disposable parentDisposable) {
public static Pair<JPanel, JBList<AnAction>> createActionGroupPanel(final ActionGroup action,
final JComponent parent,
final Runnable backAction,
@NotNull Disposable parentDisposable) {
JPanel actionsListPanel = new JPanel(new BorderLayout());
actionsListPanel.setBackground(getProjectsBackground());
final List<AnAction> groups = flattenActionGroups(action);
final DefaultListModel<AnAction> model = JBList.createDefaultListModel(ArrayUtil.toObjectArray(groups));
final DefaultListModel<AnAction> model = JBList.createDefaultListModel(groups);
final JBList<AnAction> list = new JBList<>(model);
for (AnAction group : groups) {
if (group instanceof Disposable) {
@@ -957,10 +950,10 @@ public class FlatWelcomeFrame extends JFrame implements IdeFrame, Disposable, Ac
return back;
}
public static void installQuickSearch(JBList list) {
new ListSpeedSearch(list, (Convertor<Object, String>)o -> {
public static void installQuickSearch(JBList<AnAction> list) {
new ListSpeedSearch<>(list, (Function<AnAction, String>)o -> {
if (o instanceof AbstractActionWithPanel) { //to avoid dependency mess with ProjectSettingsStepBase
return ((AbstractActionWithPanel)o).getTemplatePresentation().getText();
return o.getTemplatePresentation().getText();
}
return null;
});
@@ -31,21 +31,33 @@ import javax.swing.*;
import java.util.Arrays;
import java.util.List;
public class ListSpeedSearch extends SpeedSearchBase<JList> {
private final Convertor<Object, String> myToStringConvertor;
public class ListSpeedSearch<T> extends SpeedSearchBase<JList<T>> {
@Nullable private final Function<T, String> myToStringConvertor;
public ListSpeedSearch(JList list) {
this(list, (Convertor<Object, String>)null);
public ListSpeedSearch(JList<T> list) {
super(list);
myToStringConvertor = null;
registerSelectAll(list);
}
public ListSpeedSearch(final JList list, @NotNull Function<Object, String> convertor) {
this(list, (Convertor<Object, String>)convertor::fun);
}
public ListSpeedSearch(final JList list, @Nullable Convertor<Object, String> convertor) {
@SuppressWarnings("LambdaUnfriendlyMethodOverload")
public ListSpeedSearch(final JList<T> list, @NotNull Function<T, String> convertor) {
super(list);
myToStringConvertor = convertor;
registerSelectAll(list);
}
/**
* @deprecated use {@link #ListSpeedSearch(JList, Function)}
*/
@SuppressWarnings("LambdaUnfriendlyMethodOverload")
public ListSpeedSearch(final JList<T> list, @Nullable Convertor<T, String> convertor) {
super(list);
myToStringConvertor = convertor == null ? null : convertor::convert;
registerSelectAll(list);
}
private void registerSelectAll(JList<T> list) {
new MySelectAllAction(list, this).registerCustomShortcutSet(list, null);
}
@@ -86,7 +98,8 @@ public class ListSpeedSearch extends SpeedSearchBase<JList> {
@Override
protected String getElementText(Object element) {
if (myToStringConvertor != null) {
return myToStringConvertor.convert(element);
//noinspection unchecked
return myToStringConvertor.fun((T)element);
}
return element == null ? null : element.toString();
}
@@ -20,6 +20,7 @@ import com.intellij.ui.table.JBTable;
import com.intellij.ui.treeStructure.Tree;
import com.intellij.util.EditSourceOnDoubleClickHandler;
import com.intellij.util.EditSourceOnEnterKeyHandler;
import com.intellij.util.Function;
import com.intellij.util.containers.Convertor;
import javax.swing.*;
@@ -57,12 +58,12 @@ public class TreeUIHelperImpl extends TreeUIHelper {
new TreeSpeedSearch(tree, convertor, canExpand);
}
public void installListSpeedSearch(JList list) {
new ListSpeedSearch(list);
public void installListSpeedSearch(JList<?> list) {
new ListSpeedSearch<>(list);
}
public void installListSpeedSearch(JList list, Convertor<Object, String> convertor) {
new ListSpeedSearch(list, convertor);
public <T> void installListSpeedSearch(JList<T> list, Convertor<T, String> convertor) {
new ListSpeedSearch<>(list, (Function<T, String>)convertor::convert);
}
public void installEditSourceOnEnterKeyHandler(final JTree tree) {
@@ -28,7 +28,7 @@ import com.intellij.structuralsearch.StructuralSearchUtil;
import com.intellij.ui.*;
import com.intellij.ui.components.JBList;
import com.intellij.ui.treeStructure.Tree;
import com.intellij.util.containers.Convertor;
import com.intellij.util.Function;
import com.intellij.util.text.DateFormatUtil;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.tree.TreeUtil;
@@ -149,7 +149,7 @@ public class ExistingTemplatesComponent {
historyList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
historyList.setSelectedIndex(0);
final ListSpeedSearch speedSearch = new ListSpeedSearch(historyList, (Convertor<Object, String>)o -> o instanceof Configuration ? ((Configuration)o).getName() : o.toString());
ListSpeedSearch<Configuration> speedSearch = new ListSpeedSearch<>(historyList, (Function<Configuration, String>)Configuration::getName);
historyList.setCellRenderer(new ExistingTemplatesListCellRenderer(speedSearch));
configureSelectTemplateAction(historyList);
}
@@ -2574,9 +2574,10 @@ public class UIUtil {
}
}
//Escape error-prone HTML data (if any) when we use it in renderers, see IDEA-170768
public static Object htmlInjectionGuard(Object toRender) {
public static <T> T htmlInjectionGuard(T toRender) {
if (toRender instanceof String && ((String)toRender).toLowerCase(Locale.US).startsWith("<html>")) {
toRender = "<html>" + StringUtil.escapeXml((String)toRender);
//noinspection unchecked
return (T) ("<html>" + StringUtil.escapeXml((String)toRender));
}
return toRender;
}