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
;
31 import java
.util
.Collection
;
33 public abstract class AbstractTreeNode
<T
> extends PresentableNodeDescriptor
implements NavigationItem
{
34 private AbstractTreeNode myParent
;
36 private NodeDescriptor myParentDescriptor
;
38 protected AbstractTreeNode(Project project
, T value
) {
44 public abstract Collection
<?
extends AbstractTreeNode
> getChildren();
47 protected boolean hasProblemFileBeneath() {
51 protected boolean valueIsCut() {
52 return CopyPasteManager
.getInstance().isCutElement(getValue());
55 public PresentableNodeDescriptor
getChildToHighlightAt(int index
) {
56 final Collection
<?
extends AbstractTreeNode
> kids
= getChildren();
58 for (final AbstractTreeNode kid
: kids
) {
59 if (i
== index
) return kid
;
67 protected void postprocess(PresentationData presentation
) {
68 if (hasProblemFileBeneath() ) {
69 presentation
.setAttributesKey(CodeInsightColors
.ERRORS_ATTRIBUTES
);
72 Color fgColor
= getFileStatus().getColor();
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() {
96 public boolean isAlwaysExpand() {
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() {
117 public final void setParent(AbstractTreeNode parent
) {
119 myParentDescriptor
= parent
;
122 public final AbstractTreeNode
setParentDescriptor(NodeDescriptor parentDescriptor
) {
123 myParentDescriptor
= parentDescriptor
;
127 public final NodeDescriptor
getParentDescriptor() {
128 return myParentDescriptor
;
131 public final T
getValue() {
135 public final void setValue(T value
) {
140 @NonNls public String
getTestPresentation() {
141 if (myName
!= null) {
143 } else if (getValue() != null){
144 return getValue().toString();
151 public FileStatus
getFileStatus() {
152 return FileStatus
.NOT_CHANGED
;
155 public String
getName() {
159 public void navigate(boolean requestFocus
) {
162 public boolean canNavigate() {
166 public boolean canNavigateToSource() {
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
192 public TextAttributesKey
getAttributesKey() {
193 return getPresentation().getTextAttributesKey();
197 * @deprecated use {@link #getPresentation()} instead
200 public String
getLocationString() {
201 return getPresentation().getLocationString();