mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Cleanup (stricter-typed API; warnings; typos)
GitOrigin-RevId: 5d7d5253187cb1a57d6467ed10693755a59dbf2d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
79f6204fc4
commit
71d3004d59
+14
-24
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// 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.openapi.roots.ui.configuration.libraryEditor;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
@@ -25,6 +11,7 @@ import com.intellij.openapi.roots.ui.OrderRootTypeUIFactory;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.jrt.JrtFileSystem;
|
||||
import com.intellij.ui.components.JBList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
@@ -53,12 +40,12 @@ public class ClassesOrderRootTypeUIFactory implements OrderRootTypeUIFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isRemoveActionEnabled(Object[] values) {
|
||||
if (!super.isRemoveActionEnabled(values)) {
|
||||
protected boolean isRemoveActionEnabled(VirtualFile[] files) {
|
||||
if (!super.isRemoveActionEnabled(files)) {
|
||||
return false;
|
||||
}
|
||||
for (Object value : values) {
|
||||
if (isJrtRoot(value)) {
|
||||
for (VirtualFile file : files) {
|
||||
if (isJrtRoot(file)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -66,17 +53,20 @@ public class ClassesOrderRootTypeUIFactory implements OrderRootTypeUIFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ListCellRenderer createListCellRenderer(JBList list) {
|
||||
protected ListCellRenderer<VirtualFile> createListCellRenderer(JBList<VirtualFile> list) {
|
||||
return new PathCellRenderer() {
|
||||
@Override
|
||||
protected Icon getItemIcon(Object value) {
|
||||
return isJrtRoot(value) ? AllIcons.Nodes.Module : super.getItemIcon(value);
|
||||
protected void customizeCellRenderer(@NotNull JList<? extends VirtualFile> list, VirtualFile file, int index, boolean selected, boolean focused) {
|
||||
super.customizeCellRenderer(list, file, index, selected, focused);
|
||||
if (isJrtRoot(file)) {
|
||||
setIcon(AllIcons.Nodes.Module);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isJrtRoot(Object value) {
|
||||
return value instanceof VirtualFile && JrtFileSystem.isModuleRoot((VirtualFile)value);
|
||||
private static boolean isJrtRoot(VirtualFile file) {
|
||||
return file != null && JrtFileSystem.isModuleRoot(file);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
// 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.
|
||||
// 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.openapi.roots.ui.configuration.libraryEditor;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
@@ -72,7 +72,7 @@ public class JavadocOrderRootTypeUIFactory implements OrderRootTypeUIFactory {
|
||||
addElement(virtualFile);
|
||||
setModified(true);
|
||||
requestDefaultFocus();
|
||||
setSelectedRoots(new Object[]{virtualFile});
|
||||
setSelectedRoots(new VirtualFile[]{virtualFile});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,14 +13,10 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.ex.http.HttpFileSystem;
|
||||
import com.intellij.openapi.vfs.newvfs.ArchiveFileSystem;
|
||||
import com.intellij.openapi.wm.IdeFocusManager;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.ui.ListUtil;
|
||||
import com.intellij.ui.ToolbarDecorator;
|
||||
import com.intellij.ui.TreeUIHelper;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.components.JBList;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import gnu.trove.TIntArrayList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -94,14 +90,13 @@ public class PathEditor {
|
||||
|
||||
public JComponent createComponent() {
|
||||
myList = new JBList<>(getListModel());
|
||||
//noinspection unchecked
|
||||
myList.setCellRenderer(createListCellRenderer(myList));
|
||||
TreeUIHelper.getInstance().installListSpeedSearch(myList, VirtualFile::getPresentableUrl);
|
||||
|
||||
ToolbarDecorator toolbarDecorator = ToolbarDecorator.createDecorator(myList)
|
||||
.disableUpDownActions()
|
||||
.setAddActionUpdater(e -> myEnabled)
|
||||
.setRemoveActionUpdater(e -> isRemoveActionEnabled(PathEditor.this.getSelectedRoots()))
|
||||
.setRemoveActionUpdater(e -> isRemoveActionEnabled(getSelectedRoots()))
|
||||
.setAddAction(button -> {
|
||||
final VirtualFile[] added = doAddItems();
|
||||
if (added.length > 0) {
|
||||
@@ -123,11 +118,10 @@ public class PathEditor {
|
||||
return myPanel;
|
||||
}
|
||||
|
||||
protected void addToolbarButtons(ToolbarDecorator toolbarDecorator) {
|
||||
}
|
||||
protected void addToolbarButtons(ToolbarDecorator toolbarDecorator) { }
|
||||
|
||||
protected boolean isRemoveActionEnabled(Object[] values) {
|
||||
return values.length > 0 && myEnabled;
|
||||
protected boolean isRemoveActionEnabled(VirtualFile[] files) {
|
||||
return files.length > 0 && myEnabled;
|
||||
}
|
||||
|
||||
protected VirtualFile[] doAddItems() {
|
||||
@@ -146,16 +140,15 @@ public class PathEditor {
|
||||
return VfsUtilCore.toVirtualFileArray(added);
|
||||
}
|
||||
|
||||
protected void doRemoveItems(int[] indices, JList list) {
|
||||
List removedItems = ListUtil.removeIndices(list, indices);
|
||||
itemsRemoved(removedItems);
|
||||
protected void doRemoveItems(int[] indices, JList<VirtualFile> list) {
|
||||
itemsRemoved(ListUtil.removeIndices(list, indices));
|
||||
}
|
||||
|
||||
protected DefaultListModel<VirtualFile> createListModel() {
|
||||
return new DefaultListModel<>();
|
||||
}
|
||||
|
||||
protected ListCellRenderer createListCellRenderer(JBList list) {
|
||||
protected ListCellRenderer<VirtualFile> createListCellRenderer(JBList<VirtualFile> list) {
|
||||
return new PathCellRenderer();
|
||||
}
|
||||
|
||||
@@ -246,35 +239,26 @@ public class PathEditor {
|
||||
return myModel;
|
||||
}
|
||||
|
||||
protected void setSelectedRoots(Object[] roots) {
|
||||
ArrayList<Object> rootsList = new ArrayList<>(roots.length);
|
||||
for (Object root : roots) {
|
||||
if (root != null) {
|
||||
rootsList.add(root);
|
||||
}
|
||||
}
|
||||
protected void setSelectedRoots(VirtualFile[] roots) {
|
||||
Set<VirtualFile> set = ContainerUtil.newHashSet(roots);
|
||||
myList.getSelectionModel().clearSelection();
|
||||
int rowCount = getRowCount();
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
for (int i = 0, rowCount = getRowCount(); i < rowCount; i++) {
|
||||
Object currObject = getValueAt(i);
|
||||
LOG.assertTrue(currObject != null);
|
||||
if (rootsList.contains(currObject)) {
|
||||
if (set.contains(currObject)) {
|
||||
myList.getSelectionModel().addSelectionInterval(i, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void keepSelectionState() {
|
||||
final Object[] selectedItems = getSelectedRoots();
|
||||
if (selectedItems != null) {
|
||||
//noinspection SSBasedInspection
|
||||
SwingUtilities.invokeLater(() -> setSelectedRoots(selectedItems));
|
||||
}
|
||||
VirtualFile[] selectedItems = getSelectedRoots();
|
||||
//noinspection SSBasedInspection
|
||||
SwingUtilities.invokeLater(() -> setSelectedRoots(selectedItems));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
protected Object[] getSelectedRoots() {
|
||||
return myList.getSelectedValues();
|
||||
protected VirtualFile[] getSelectedRoots() {
|
||||
return VfsUtilCore.toVirtualFileArray(myList.getSelectedValuesList());
|
||||
}
|
||||
|
||||
protected int getRowCount() {
|
||||
@@ -291,42 +275,20 @@ public class PathEditor {
|
||||
setModified(true);
|
||||
}
|
||||
|
||||
protected static class PathCellRenderer extends DefaultListCellRenderer {
|
||||
protected String getItemText(Object value) {
|
||||
return value instanceof VirtualFile ? ((VirtualFile)value).getPresentableUrl() : "UNKNOWN OBJECT";
|
||||
}
|
||||
|
||||
protected Icon getItemIcon(Object value) {
|
||||
if (!(value instanceof VirtualFile)) {
|
||||
return AllIcons.Nodes.EmptyNode;
|
||||
}
|
||||
VirtualFile file = (VirtualFile)value;
|
||||
if (!file.isValid()) {
|
||||
return AllIcons.Nodes.PpInvalid;
|
||||
}
|
||||
if (file.getFileSystem() instanceof HttpFileSystem) {
|
||||
return PlatformIcons.WEB_ICON;
|
||||
}
|
||||
if (file.getFileSystem() instanceof ArchiveFileSystem) {
|
||||
return PlatformIcons.JAR_ICON;
|
||||
}
|
||||
return PlatformIcons.FILE_ICON;
|
||||
}
|
||||
|
||||
protected static class PathCellRenderer extends ColoredListCellRenderer<VirtualFile> {
|
||||
@Override
|
||||
public final Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||
super.getListCellRendererComponent(list, getItemText(value), index, isSelected, cellHasFocus);
|
||||
protected void customizeCellRenderer(@NotNull JList<? extends VirtualFile> list, VirtualFile file, int index, boolean selected, boolean focused) {
|
||||
String text = file != null ? file.getPresentableUrl() : "UNKNOWN OBJECT";
|
||||
append(text, file != null && file.isValid() ? SimpleTextAttributes.REGULAR_ATTRIBUTES : SimpleTextAttributes.ERROR_ATTRIBUTES);
|
||||
setIcon(getItemIcon(file));
|
||||
}
|
||||
|
||||
if (isSelected) {
|
||||
setForeground(UIUtil.getListSelectionForeground());
|
||||
}
|
||||
else if (value instanceof VirtualFile && !((VirtualFile)value).isValid()) {
|
||||
setForeground(INVALID_COLOR);
|
||||
}
|
||||
|
||||
setIcon(getItemIcon(value));
|
||||
|
||||
return this;
|
||||
protected Icon getItemIcon(VirtualFile file) {
|
||||
if (file == null) return AllIcons.Nodes.EmptyNode;
|
||||
if (!file.isValid()) return AllIcons.Nodes.PpInvalid;
|
||||
if (file.getFileSystem() instanceof HttpFileSystem) return PlatformIcons.WEB_ICON;
|
||||
if (file.getFileSystem() instanceof ArchiveFileSystem) return PlatformIcons.JAR_ICON;
|
||||
return PlatformIcons.FILE_ICON;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -892,7 +892,7 @@ sdk.edit.dialog.associate.virtual.env.current.project=Associate this environment
|
||||
sdk.edit.dialog.specify.interpreter.path=Specify Interpreter Path
|
||||
|
||||
sdk.paths.dialog.title=Interpreter Paths
|
||||
sdk.paths.dialog.reload.paths=Reload list of paths
|
||||
sdk.paths.dialog.reload.paths=Reload List of Paths
|
||||
sdk.paths.dialog.added.by.user.suffix=(added by user)
|
||||
sdk.paths.dialog.removed.by.user.suffix=(removed by user)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// 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.
|
||||
// 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.jetbrains.python.configuration;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
@@ -42,9 +42,7 @@ import java.util.Set;
|
||||
public class PythonPathEditor extends SdkPathEditor {
|
||||
private final PathListModel myPathListModel;
|
||||
|
||||
public PythonPathEditor(final String displayName,
|
||||
@NotNull OrderRootType orderRootType,
|
||||
final FileChooserDescriptor descriptor) {
|
||||
public PythonPathEditor(String displayName, @NotNull OrderRootType orderRootType, FileChooserDescriptor descriptor) {
|
||||
super(displayName, orderRootType, descriptor);
|
||||
myPathListModel = new PathListModel(orderRootType, getListModel());
|
||||
}
|
||||
@@ -99,9 +97,9 @@ public class PythonPathEditor extends SdkPathEditor {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doRemoveItems(int[] idxs, JList list) {
|
||||
protected void doRemoveItems(int[] indices, JList<VirtualFile> list) {
|
||||
List<Pair<VirtualFile, Integer>> removed = Lists.newArrayList();
|
||||
for (int i : idxs) {
|
||||
for (int i : indices) {
|
||||
removed.add(Pair.create(getListModel().get(i), i));
|
||||
}
|
||||
ListUtil.removeIndices(list, myPathListModel.remove(removed));
|
||||
@@ -110,40 +108,36 @@ public class PythonPathEditor extends SdkPathEditor {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ListCellRenderer<VirtualFile> createListCellRenderer(JBList list) {
|
||||
protected ListCellRenderer<VirtualFile> createListCellRenderer(JBList<VirtualFile> list) {
|
||||
return SimpleListCellRenderer.create("", value -> {
|
||||
String suffix = myPathListModel.getPresentationSuffix(value);
|
||||
if (suffix.length() > 0) {
|
||||
suffix = " " + suffix;
|
||||
}
|
||||
if (suffix.length() > 0) suffix = " " + suffix;
|
||||
return getPresentablePath(value) + suffix;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addToolbarButtons(ToolbarDecorator toolbarDecorator) {
|
||||
AnActionButton reloadButton = new AnActionButton(PyBundle.message("sdk.paths.dialog.reload.paths"), AllIcons.Actions.Refresh) {
|
||||
toolbarDecorator.addExtraAction(new AnActionButton(PyBundle.message("sdk.paths.dialog.reload.paths"), AllIcons.Actions.Refresh) {
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
onReloadButtonClicked();
|
||||
}
|
||||
};
|
||||
toolbarDecorator.addExtraAction(reloadButton);
|
||||
});
|
||||
}
|
||||
|
||||
protected void onReloadButtonClicked() {
|
||||
}
|
||||
protected void onReloadButtonClicked() { }
|
||||
|
||||
private static class PathListModel {
|
||||
private Set<VirtualFile> myAdded = Sets.newHashSet();
|
||||
private Set<VirtualFile> myExcluded = Sets.newHashSet();
|
||||
private final Set<VirtualFile> myFoundFiles = Sets.newHashSet();
|
||||
private final List<VirtualFile> myFilteredOut = Lists.newArrayList();
|
||||
private final DefaultListModel myListModel;
|
||||
private final DefaultListModel<VirtualFile> myListModel;
|
||||
private final OrderRootType myOrderRootType;
|
||||
private final Set<VirtualFile> myUserAddedToRemove = Sets.newHashSet();
|
||||
|
||||
PathListModel(OrderRootType orderRootType, DefaultListModel listModel) {
|
||||
PathListModel(OrderRootType orderRootType, DefaultListModel<VirtualFile> listModel) {
|
||||
myOrderRootType = orderRootType;
|
||||
myListModel = listModel;
|
||||
}
|
||||
@@ -153,7 +147,7 @@ public class PythonPathEditor extends SdkPathEditor {
|
||||
}
|
||||
|
||||
private VirtualFile getValueAt(int row) {
|
||||
return (VirtualFile)myListModel.get(row);
|
||||
return myListModel.get(row);
|
||||
}
|
||||
|
||||
public boolean add(List<VirtualFile> files) {
|
||||
@@ -167,7 +161,8 @@ public class PythonPathEditor extends SdkPathEditor {
|
||||
myFoundFiles.add(file);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
myExcluded.remove(file);
|
||||
}
|
||||
}
|
||||
@@ -302,4 +297,4 @@ public class PythonPathEditor extends SdkPathEditor {
|
||||
protected String getPresentablePath(VirtualFile value) {
|
||||
return value.getPresentableUrl();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user