SVN auth
[fedora-idea.git] / plugins / svn4idea / src / org / jetbrains / idea / svn / dialogs / SvnRepositoryTreeCellRenderer.java
blob738c8bbadadfe7c192543aef468d265ccec0b8e1
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.jetbrains.idea.svn.dialogs;
18 import com.intellij.CommonBundle;
19 import com.intellij.openapi.fileTypes.FileTypeManager;
20 import com.intellij.ui.ColoredTreeCellRenderer;
21 import com.intellij.ui.SimpleTextAttributes;
22 import com.intellij.util.Icons;
23 import org.tmatesoft.svn.core.SVNDirEntry;
24 import org.tmatesoft.svn.core.SVNErrorMessage;
25 import org.tmatesoft.svn.core.SVNNodeKind;
27 import javax.swing.*;
28 import javax.swing.tree.DefaultMutableTreeNode;
30 public class SvnRepositoryTreeCellRenderer extends ColoredTreeCellRenderer {
32 private boolean myIsShowDetails;
35 public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
36 setIcon(null);
37 if (value instanceof RepositoryTreeNode) {
38 RepositoryTreeNode node = (RepositoryTreeNode) value;
39 if (node.getSVNDirEntry() == null) {
40 append(node.getURL().toString(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
41 setDirectoryIcon(expanded);
42 } else {
43 String name = node.getSVNDirEntry().getName();
44 append(name, node.isCached() ? SimpleTextAttributes.GRAY_ITALIC_ATTRIBUTES : SimpleTextAttributes.REGULAR_ATTRIBUTES);
45 if (myIsShowDetails) {
46 SVNDirEntry entry = node.getSVNDirEntry();
47 append(" " + entry.getRevision(), SimpleTextAttributes.GRAY_ATTRIBUTES);
48 if (entry.getAuthor() != null) {
49 append(" " + entry.getAuthor(), SimpleTextAttributes.GRAYED_BOLD_ATTRIBUTES);
51 if (entry.getDate() != null) {
52 append(" " + entry.getDate().toString(), SimpleTextAttributes.GRAY_ATTRIBUTES);
55 if (node.getSVNDirEntry().getKind() == SVNNodeKind.FILE) {
56 setIcon(FileTypeManager.getInstance().getFileTypeByFileName(name).getIcon());
57 } else {
58 setDirectoryIcon(expanded);
61 } else if (value instanceof DefaultMutableTreeNode) {
62 DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
63 if (node.getUserObject() instanceof String) {
64 append(CommonBundle.getLoadingTreeNodeText(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
65 } else if (node.getUserObject() instanceof SVNErrorMessage) {
66 append(node.getUserObject().toString(), SimpleTextAttributes.ERROR_ATTRIBUTES);
71 private void setDirectoryIcon(final boolean expanded) {
72 if (expanded) {
73 setIcon(Icons.DIRECTORY_OPEN_ICON);
74 } else {
75 setIcon(Icons.DIRECTORY_CLOSED_ICON);
79 public void setShowDetails(boolean state) {
80 myIsShowDetails = state;