IDEA-27603 (Indicate which branch is being worked on)
[fedora-idea.git] / platform / vcs-impl / src / com / intellij / openapi / vcs / changes / ui / ChangesBrowserFileNode.java
blobc9abc410f8059491ccddf8056952735cc1aaa92a
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.
17 package com.intellij.openapi.vcs.changes.ui;
19 import com.intellij.openapi.project.Project;
20 import com.intellij.openapi.vcs.FileStatus;
21 import com.intellij.openapi.vcs.FileStatusManager;
22 import com.intellij.openapi.vcs.changes.ChangeListManager;
23 import com.intellij.openapi.vfs.VirtualFile;
24 import com.intellij.ui.SimpleTextAttributes;
25 import com.intellij.util.Icons;
27 /**
28 * @author yole
30 public class ChangesBrowserFileNode extends ChangesBrowserNode<VirtualFile> {
31 private final Project myProject;
33 public ChangesBrowserFileNode(Project project, VirtualFile userObject) {
34 super(userObject);
35 myProject = project;
36 if (!userObject.isDirectory()) {
37 myCount = 1;
38 } else {
39 myDirectoryCount = 1;
43 @Override
44 protected boolean isDirectory() {
45 return (getUserObject()).isDirectory() &&
46 FileStatusManager.getInstance(myProject).getStatus(getUserObject()) != FileStatus.NOT_CHANGED;
50 @Override
51 public void render(final ChangesBrowserNodeRenderer renderer, final boolean selected, final boolean expanded, final boolean hasFocus) {
52 final VirtualFile file = getUserObject();
53 renderer.appendFileName(file, file.getName(), ChangeListManager.getInstance(myProject).getStatus(file).getColor());
54 if (renderer.isShowFlatten() && file.isValid()) {
55 final VirtualFile parentFile = file.getParent();
56 assert parentFile != null;
57 renderer.append(" (" + parentFile.getPresentableUrl() + ")", SimpleTextAttributes.GRAYED_ATTRIBUTES);
59 else if (getCount() != 1 || getDirectoryCount() != 0) {
60 appendCount(renderer);
62 if (file.isDirectory()) {
63 renderer.setIcon(Icons.DIRECTORY_CLOSED_ICON);
65 else {
66 renderer.setIcon(file.getFileType().getIcon());
70 @Override
71 public String getTextPresentation() {
72 return getUserObject().getName();
75 @Override
76 public String toString() {
77 return getUserObject().getPresentableUrl();
80 public int getSortWeight() {
81 return 7;
84 public int compareUserObjects(final Object o2) {
85 if (o2 instanceof VirtualFile) {
86 return getUserObject().getName().compareToIgnoreCase(((VirtualFile)o2).getName());
88 return 0;