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
;
30 public class ChangesBrowserFileNode
extends ChangesBrowserNode
<VirtualFile
> {
31 private final Project myProject
;
33 public ChangesBrowserFileNode(Project project
, VirtualFile userObject
) {
36 if (!userObject
.isDirectory()) {
44 protected boolean isDirectory() {
45 return (getUserObject()).isDirectory() &&
46 FileStatusManager
.getInstance(myProject
).getStatus(getUserObject()) != FileStatus
.NOT_CHANGED
;
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
);
66 renderer
.setIcon(file
.getFileType().getIcon());
71 public String
getTextPresentation() {
72 return getUserObject().getName();
76 public String
toString() {
77 return getUserObject().getPresentableUrl();
80 public int getSortWeight() {
84 public int compareUserObjects(final Object o2
) {
85 if (o2
instanceof VirtualFile
) {
86 return getUserObject().getName().compareToIgnoreCase(((VirtualFile
)o2
).getName());