IDEA-50121
[fedora-idea.git] / java / java-impl / src / com / intellij / slicer / SliceLeafValueRootNode.java
blob82b714aeac8d0606171eb8eed9dd43b752a0e549
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.slicer;
18 import com.intellij.ide.projectView.PresentationData;
19 import com.intellij.openapi.project.Project;
20 import com.intellij.psi.PsiElement;
21 import com.intellij.ui.SimpleTextAttributes;
22 import com.intellij.usageView.UsageViewBundle;
23 import com.intellij.usages.Usage;
24 import com.intellij.usages.UsageInfo2UsageAdapter;
25 import org.jetbrains.annotations.NotNull;
27 import javax.swing.*;
28 import java.util.Collection;
29 import java.util.List;
31 /**
32 * @author cdr
34 public class SliceLeafValueRootNode extends SliceNode implements MyColoredTreeCellRenderer {
35 protected final List<SliceNode> myCachedChildren;
37 public SliceLeafValueRootNode(@NotNull Project project, PsiElement leafExpression, SliceNode root, List<SliceNode> children,
38 SliceAnalysisParams params) {
39 super(project, new SliceUsage(leafExpression, params), root.targetEqualUsages);
40 myCachedChildren = children;
43 @NotNull
44 public Collection<SliceNode> getChildren() {
45 return myCachedChildren;
48 @Override
49 protected void update(PresentationData presentation) {
52 @Override
53 public String toString() {
54 Usage myLeafExpression = getValue();
55 String text;
56 if (myLeafExpression instanceof UsageInfo2UsageAdapter) {
57 PsiElement element = ((UsageInfo2UsageAdapter)myLeafExpression).getUsageInfo().getElement();
58 text = element == null ? "" : element.getText();
60 else {
61 text = "Other";
63 return "Value: "+ text;
66 public boolean isValid() {
67 return getValue().isValid();
70 public void customizeCellRenderer(SliceUsageCellRenderer renderer,
71 JTree tree,
72 Object value,
73 boolean selected,
74 boolean expanded,
75 boolean leaf,
76 int row,
77 boolean hasFocus) {
78 Usage usage = getValue();
79 renderer.append("Value: ", SimpleTextAttributes.REGULAR_ATTRIBUTES);
81 if (usage instanceof UsageInfo2UsageAdapter) {
82 PsiElement element = ((UsageInfo2UsageAdapter)usage).getElement();
83 if (element == null) {
84 renderer.append(UsageViewBundle.message("node.invalid") + " ", SliceUsageCellRenderer.ourInvalidAttributes);
86 else {
87 renderer.append(element.getText(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
90 else {
91 renderer.append("Other", SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
95 @Override
96 public void navigate(boolean requestFocus) {
97 getValue().navigate(requestFocus);
100 @Override
101 public boolean canNavigate() {
102 return getValue().canNavigate();
105 @Override
106 public boolean canNavigateToSource() {
107 return getValue().canNavigateToSource();