mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
library roots tree: simplified
This commit is contained in:
+78
-21
@@ -15,46 +15,53 @@
|
||||
*/
|
||||
package com.intellij.openapi.roots.ui.configuration.libraryEditor;
|
||||
|
||||
import com.intellij.ide.util.treeView.NodeDescriptor;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.IconUtilEx;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.intellij.openapi.vfs.ex.http.HttpFileSystem;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
|
||||
|
||||
class ItemElement extends LibraryTableTreeContentElement {
|
||||
private final OrderRootTypeElement myParent;
|
||||
class ItemElement extends LibraryTableTreeContentElement<ItemElement> {
|
||||
private final String myUrl;
|
||||
private final OrderRootType myRootType;
|
||||
private final boolean myIsJarDirectory;
|
||||
private final boolean myValid;
|
||||
|
||||
public ItemElement(OrderRootTypeElement parent, String url, OrderRootType rootType, final boolean isJarDirectory,
|
||||
boolean isValid) {
|
||||
myParent = parent;
|
||||
super(parent);
|
||||
myUrl = url;
|
||||
myRootType = rootType;
|
||||
myIsJarDirectory = isJarDirectory;
|
||||
myValid = isValid;
|
||||
myName = getPresentablePath(url).replace('/', File.separatorChar);
|
||||
myColor = isValid ? UIUtil.getListForeground() : JBColor.RED;
|
||||
setIcon(getIconForUrl(url, isValid, isJarDirectory));
|
||||
}
|
||||
|
||||
public OrderRootTypeElement getParent() {
|
||||
return myParent;
|
||||
return (OrderRootTypeElement)getParentDescriptor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeDescriptor createDescriptor(final NodeDescriptor parentDescriptor, final LibraryRootsComponent parentEditor) {
|
||||
return new ItemElementDescriptor(parentDescriptor, this);
|
||||
public boolean update() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemElement getElement() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return myUrl;
|
||||
}
|
||||
|
||||
public boolean isJarDirectory() {
|
||||
return myIsJarDirectory;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return myValid;
|
||||
}
|
||||
|
||||
public OrderRootType getRootType() {
|
||||
return myRootType;
|
||||
@@ -66,7 +73,7 @@ class ItemElement extends LibraryTableTreeContentElement {
|
||||
|
||||
final ItemElement itemElement = (ItemElement)o;
|
||||
|
||||
if (!myParent.equals(itemElement.myParent)) return false;
|
||||
if (!getParent().equals(itemElement.getParent())) return false;
|
||||
if (!myRootType.equals(itemElement.myRootType)) return false;
|
||||
if (!myUrl.equals(itemElement.myUrl)) return false;
|
||||
|
||||
@@ -75,9 +82,59 @@ class ItemElement extends LibraryTableTreeContentElement {
|
||||
|
||||
public int hashCode() {
|
||||
int result;
|
||||
result = myParent.hashCode();
|
||||
result = getParent().hashCode();
|
||||
result = 29 * result + myUrl.hashCode();
|
||||
result = 29 * result + myRootType.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Icon getIconForUrl(final String url, final boolean isValid, final boolean isJarDirectory) {
|
||||
final Icon icon;
|
||||
if (isValid) {
|
||||
VirtualFile presentableFile;
|
||||
if (isJarFileRoot(url)) {
|
||||
presentableFile = LocalFileSystem.getInstance().findFileByPath(getPresentablePath(url));
|
||||
}
|
||||
else {
|
||||
presentableFile = VirtualFileManager.getInstance().findFileByUrl(url);
|
||||
}
|
||||
if (presentableFile != null && presentableFile.isValid()) {
|
||||
if (presentableFile.getFileSystem() instanceof HttpFileSystem) {
|
||||
icon = PlatformIcons.WEB_ICON;
|
||||
}
|
||||
else {
|
||||
if (presentableFile.isDirectory()) {
|
||||
if (isJarDirectory) {
|
||||
icon = AllIcons.Nodes.JarDirectory;
|
||||
}
|
||||
else {
|
||||
icon = PlatformIcons.DIRECTORY_CLOSED_ICON;
|
||||
}
|
||||
}
|
||||
else {
|
||||
icon = IconUtilEx.getIcon(presentableFile, 0, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
icon = AllIcons.Nodes.PpInvalid;
|
||||
}
|
||||
}
|
||||
else {
|
||||
icon = AllIcons.Nodes.PpInvalid;
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
private static String getPresentablePath(final String url) {
|
||||
String presentablePath = VirtualFileManager.extractPath(url);
|
||||
if (isJarFileRoot(url)) {
|
||||
presentablePath = presentablePath.substring(0, presentablePath.length() - JarFileSystem.JAR_SEPARATOR.length());
|
||||
}
|
||||
return presentablePath;
|
||||
}
|
||||
|
||||
private static boolean isJarFileRoot(final String url) {
|
||||
return VirtualFileManager.extractPath(url).endsWith(JarFileSystem.JAR_SEPARATOR);
|
||||
}
|
||||
}
|
||||
|
||||
-107
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.
|
||||
*/
|
||||
package com.intellij.openapi.roots.ui.configuration.libraryEditor;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.IconUtilEx;
|
||||
import com.intellij.ide.util.treeView.NodeDescriptor;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.intellij.openapi.vfs.ex.http.HttpFileSystem;
|
||||
import com.intellij.ui.JBColor;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
|
||||
class ItemElementDescriptor extends NodeDescriptor<ItemElement> {
|
||||
private final ItemElement myElement;
|
||||
|
||||
public ItemElementDescriptor(NodeDescriptor parentDescriptor, ItemElement element) {
|
||||
super(null, parentDescriptor);
|
||||
myElement = element;
|
||||
final String url = element.getUrl();
|
||||
myName = getPresentablePath(url).replace('/', File.separatorChar);
|
||||
setIcon(getIconForUrl(url, element.isValid(), element.isJarDirectory()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update() {
|
||||
Color color = myElement.isValid()? UIUtil.getListForeground() : JBColor.RED;
|
||||
final boolean changes = !color.equals(myColor);
|
||||
myColor = color;
|
||||
return changes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemElement getElement() {
|
||||
return myElement;
|
||||
}
|
||||
|
||||
private static Icon getIconForUrl(final String url, final boolean isValid, final boolean isJarDirectory) {
|
||||
final Icon icon;
|
||||
if (isValid) {
|
||||
VirtualFile presentableFile;
|
||||
if (isJarFileRoot(url)) {
|
||||
presentableFile = LocalFileSystem.getInstance().findFileByPath(getPresentablePath(url));
|
||||
}
|
||||
else {
|
||||
presentableFile = VirtualFileManager.getInstance().findFileByUrl(url);
|
||||
}
|
||||
if (presentableFile != null && presentableFile.isValid()) {
|
||||
if (presentableFile.getFileSystem() instanceof HttpFileSystem) {
|
||||
icon = PlatformIcons.WEB_ICON;
|
||||
}
|
||||
else {
|
||||
if (presentableFile.isDirectory()) {
|
||||
if (isJarDirectory) {
|
||||
icon = AllIcons.Nodes.JarDirectory;
|
||||
}
|
||||
else {
|
||||
icon = PlatformIcons.DIRECTORY_CLOSED_ICON;
|
||||
}
|
||||
}
|
||||
else {
|
||||
icon = IconUtilEx.getIcon(presentableFile, 0, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
icon = AllIcons.Nodes.PpInvalid;
|
||||
}
|
||||
}
|
||||
else {
|
||||
icon = AllIcons.Nodes.PpInvalid;
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
static String getPresentablePath(final String url) {
|
||||
String presentablePath = VirtualFileManager.extractPath(url);
|
||||
if (isJarFileRoot(url)) {
|
||||
presentablePath = presentablePath.substring(0, presentablePath.length() - JarFileSystem.JAR_SEPARATOR.length());
|
||||
}
|
||||
return presentablePath;
|
||||
}
|
||||
|
||||
private static boolean isJarFileRoot(final String url) {
|
||||
return VirtualFileManager.extractPath(url).endsWith(JarFileSystem.JAR_SEPARATOR);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -34,7 +34,7 @@ class LibraryRootsTreeSpeedSearch extends TreeSpeedSearch {
|
||||
@Override
|
||||
public boolean isMatchingElement(Object element, String pattern) {
|
||||
Object userObject = ((DefaultMutableTreeNode)((TreePath)element).getLastPathComponent()).getUserObject();
|
||||
if (userObject instanceof ItemElementDescriptor) {
|
||||
if (userObject instanceof ItemElement) {
|
||||
String str = getElementText(element);
|
||||
if (str == null) {
|
||||
return false;
|
||||
|
||||
+5
-3
@@ -16,8 +16,10 @@
|
||||
package com.intellij.openapi.roots.ui.configuration.libraryEditor;
|
||||
|
||||
import com.intellij.ide.util.treeView.NodeDescriptor;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class LibraryTableTreeContentElement {
|
||||
|
||||
public abstract NodeDescriptor createDescriptor(NodeDescriptor parentDescriptor, final LibraryRootsComponent parentEditor);
|
||||
public abstract class LibraryTableTreeContentElement<E> extends NodeDescriptor<E> {
|
||||
protected LibraryTableTreeContentElement(@Nullable NodeDescriptor parentDescriptor) {
|
||||
super(null, parentDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
+6
-21
@@ -28,7 +28,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class LibraryTreeStructure extends AbstractTreeStructure {
|
||||
private final Object myRootElement;
|
||||
private final NodeDescriptor myRootElementDescriptor;
|
||||
private final LibraryRootsComponent myParentEditor;
|
||||
private final LibraryRootsComponentDescriptor myComponentDescriptor;
|
||||
@@ -36,7 +35,6 @@ public class LibraryTreeStructure extends AbstractTreeStructure {
|
||||
public LibraryTreeStructure(LibraryRootsComponent parentElement, LibraryRootsComponentDescriptor componentDescriptor) {
|
||||
myParentEditor = parentElement;
|
||||
myComponentDescriptor = componentDescriptor;
|
||||
myRootElement = new Object();
|
||||
myRootElementDescriptor = new NodeDescriptor(null, null) {
|
||||
@Override
|
||||
public boolean update() {
|
||||
@@ -45,19 +43,19 @@ public class LibraryTreeStructure extends AbstractTreeStructure {
|
||||
}
|
||||
@Override
|
||||
public Object getElement() {
|
||||
return myRootElement;
|
||||
return this;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getRootElement() {
|
||||
return myRootElement;
|
||||
return myRootElementDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getChildElements(Object element) {
|
||||
if (element == myRootElement) {
|
||||
if (element == myRootElementDescriptor) {
|
||||
ArrayList<LibraryTableTreeContentElement> elements = new ArrayList<LibraryTableTreeContentElement>(3);
|
||||
final LibraryEditor parentEditor = myParentEditor.getLibraryEditor();
|
||||
for (OrderRootType type : myComponentDescriptor.getRootTypes()) {
|
||||
@@ -67,7 +65,7 @@ public class LibraryTreeStructure extends AbstractTreeStructure {
|
||||
if (presentation == null) {
|
||||
presentation = DefaultLibraryRootsComponentDescriptor.getDefaultPresentation(type);
|
||||
}
|
||||
elements.add(new OrderRootTypeElement(type, presentation.getNodeText(), presentation.getIcon()));
|
||||
elements.add(new OrderRootTypeElement(myRootElementDescriptor, type, presentation.getNodeText(), presentation.getIcon()));
|
||||
}
|
||||
}
|
||||
return elements.toArray();
|
||||
@@ -99,25 +97,12 @@ public class LibraryTreeStructure extends AbstractTreeStructure {
|
||||
|
||||
@Override
|
||||
public Object getParentElement(Object element) {
|
||||
Object rootElement = getRootElement();
|
||||
if (element == rootElement) {
|
||||
return null;
|
||||
}
|
||||
if (element instanceof ItemElement) {
|
||||
return ((ItemElement)element).getParent();
|
||||
}
|
||||
return rootElement;
|
||||
return ((NodeDescriptor)element).getParentDescriptor();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public NodeDescriptor createDescriptor(Object element, NodeDescriptor parentDescriptor) {
|
||||
if (element == myRootElement) {
|
||||
return myRootElementDescriptor;
|
||||
}
|
||||
if (element instanceof LibraryTableTreeContentElement) {
|
||||
return ((LibraryTableTreeContentElement)element).createDescriptor(parentDescriptor, myParentEditor);
|
||||
}
|
||||
return null;
|
||||
return (NodeDescriptor)element;
|
||||
}
|
||||
}
|
||||
|
||||
+12
-8
@@ -24,15 +24,14 @@ import javax.swing.*;
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class OrderRootTypeElement extends LibraryTableTreeContentElement {
|
||||
public class OrderRootTypeElement extends LibraryTableTreeContentElement<OrderRootTypeElement> {
|
||||
private final OrderRootType myRootType;
|
||||
private String myNodeText;
|
||||
private Icon myIcon;
|
||||
|
||||
public OrderRootTypeElement(@NotNull OrderRootType rootType, final String nodeText, final Icon icon) {
|
||||
public OrderRootTypeElement(NodeDescriptor rootElementDescriptor, @NotNull OrderRootType rootType, final String nodeText, final Icon icon) {
|
||||
super(rootElementDescriptor);
|
||||
myRootType = rootType;
|
||||
myNodeText = nodeText;
|
||||
myIcon = icon;
|
||||
setIcon(icon);
|
||||
myName = nodeText;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -51,7 +50,12 @@ public class OrderRootTypeElement extends LibraryTableTreeContentElement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeDescriptor createDescriptor(final NodeDescriptor parentDescriptor, final LibraryRootsComponent parentEditor) {
|
||||
return new OrderRootTypeElementDescriptor(parentDescriptor, this, myNodeText, myIcon);
|
||||
public boolean update() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderRootTypeElement getElement() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.
|
||||
*/
|
||||
package com.intellij.openapi.roots.ui.configuration.libraryEditor;
|
||||
|
||||
import com.intellij.ide.util.treeView.NodeDescriptor;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class OrderRootTypeElementDescriptor extends NodeDescriptor<OrderRootTypeElement> {
|
||||
private final OrderRootTypeElement myElement;
|
||||
|
||||
public OrderRootTypeElementDescriptor(NodeDescriptor parentDescriptor,
|
||||
OrderRootTypeElement element, String text, Icon icon) {
|
||||
super(null, parentDescriptor);
|
||||
myElement = element;
|
||||
setIcon(icon);
|
||||
myName = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderRootTypeElement getElement() {
|
||||
return myElement;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user