project view -- always shows plus is true by default
[fedora-idea.git] / platform / platform-api / src / com / intellij / ide / util / treeView / AbstractTreeNode.java
blob7c01f74ac33d0253534503d0e64f2d94b40bfcf2
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 com.intellij.ide.util.treeView;
18 import com.intellij.ide.projectView.PresentationData;
19 import com.intellij.navigation.NavigationItem;
20 import com.intellij.openapi.editor.colors.CodeInsightColors;
21 import com.intellij.openapi.editor.colors.TextAttributesKey;
22 import com.intellij.openapi.ide.CopyPasteManager;
23 import com.intellij.openapi.project.Project;
24 import com.intellij.openapi.util.Comparing;
25 import com.intellij.openapi.vcs.FileStatus;
26 import org.jetbrains.annotations.NonNls;
27 import org.jetbrains.annotations.NotNull;
28 import org.jetbrains.annotations.Nullable;
30 import java.awt.*;
31 import java.util.Collection;
33 public abstract class AbstractTreeNode<T> extends PresentableNodeDescriptor implements NavigationItem {
34 private AbstractTreeNode myParent;
35 private T myValue;
36 private NodeDescriptor myParentDescriptor;
38 protected AbstractTreeNode(Project project, T value) {
39 super(project, null);
40 setValue(value);
43 @NotNull
44 public abstract Collection<? extends AbstractTreeNode> getChildren();
47 protected boolean hasProblemFileBeneath() {
48 return false;
51 protected boolean valueIsCut() {
52 return CopyPasteManager.getInstance().isCutElement(getValue());
55 public PresentableNodeDescriptor getChildToHighlightAt(int index) {
56 final Collection<? extends AbstractTreeNode> kids = getChildren();
57 int i = 0;
58 for (final AbstractTreeNode kid : kids) {
59 if (i == index) return kid;
60 i++;
63 return null;
66 @Override
67 protected void postprocess(PresentationData presentation) {
68 if (hasProblemFileBeneath() ) {
69 presentation.setAttributesKey(CodeInsightColors.ERRORS_ATTRIBUTES);
72 Color fgColor = getFileStatus().getColor();
74 if (valueIsCut()) {
75 fgColor = CopyPasteManager.CUT_COLOR;
78 if (presentation.getForcedTextForeground() == null) {
79 presentation.setForcedTextForeground(fgColor);
82 if (hasProblemFileBeneath() ) {
83 presentation.setAttributesKey(CodeInsightColors.ERRORS_ATTRIBUTES);
87 protected boolean shouldUpdateData() {
88 return !myProject.isDisposed() && getValue() != null;
92 public boolean isAlwaysShowPlus() {
93 return true;
96 public boolean isAlwaysExpand() {
97 return false;
100 @Nullable
101 public final Object getElement() {
102 return getValue() != null ? this : null;
105 public boolean equals(Object object) {
106 return object instanceof AbstractTreeNode && Comparing.equal(getValue(), ((AbstractTreeNode)object).getValue());
109 public int hashCode() {
110 return getValue() == null ? 0 : getValue().hashCode();
113 public final AbstractTreeNode getParent() {
114 return myParent;
117 public final void setParent(AbstractTreeNode parent) {
118 myParent = parent;
119 myParentDescriptor = parent;
122 public final AbstractTreeNode setParentDescriptor(NodeDescriptor parentDescriptor) {
123 myParentDescriptor = parentDescriptor;
124 return this;
127 public final NodeDescriptor getParentDescriptor() {
128 return myParentDescriptor;
131 public final T getValue() {
132 return myValue;
135 public final void setValue(T value) {
136 myValue = value;
139 @Nullable
140 @NonNls public String getTestPresentation() {
141 if (myName != null) {
142 return myName;
143 } else if (getValue() != null){
144 return getValue().toString();
145 } else {
146 return null;
151 public FileStatus getFileStatus() {
152 return FileStatus.NOT_CHANGED;
155 public String getName() {
156 return myName;
159 public void navigate(boolean requestFocus) {
162 public boolean canNavigate() {
163 return false;
166 public boolean canNavigateToSource() {
167 return false;
170 @Nullable
171 protected final Object getParentValue() {
172 AbstractTreeNode parent = getParent();
173 return parent == null ? null : parent.getValue();
177 public boolean canRepresent(final Object element) {
178 return Comparing.equal(getValue(), element);
182 * @deprecated use {@link #getPresentation()} instead
184 protected String getToolTip() {
185 return getPresentation().getTooltip();
189 * @deprecated use {@link #getPresentation()} instead
191 @Nullable
192 public TextAttributesKey getAttributesKey() {
193 return getPresentation().getTextAttributesKey();
197 * @deprecated use {@link #getPresentation()} instead
199 @Nullable
200 public String getLocationString() {
201 return getPresentation().getLocationString();