update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / slicer / SliceRootNode.java
blob9f810354f365b3dd0025583e6311545771cdb43b
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.analysis.AnalysisScope;
19 import com.intellij.ide.projectView.PresentationData;
20 import com.intellij.ide.util.treeView.AbstractTreeNode;
21 import com.intellij.openapi.progress.ProgressIndicator;
22 import com.intellij.openapi.project.Project;
23 import com.intellij.psi.PsiElement;
24 import org.jetbrains.annotations.NotNull;
26 import javax.swing.*;
27 import java.util.ArrayList;
28 import java.util.Collection;
29 import java.util.Collections;
30 import java.util.List;
32 /**
33 * @author cdr
35 public abstract class SliceRootNode extends SliceNode {
36 private final SliceUsage myRootUsage;
38 protected SliceRootNode(@NotNull Project project, @NotNull DuplicateMap targetEqualUsages,
39 AnalysisScope scope, final SliceUsage rootUsage) {
40 super(project, new SliceUsage(rootUsage.getElement().getContainingFile(), scope), targetEqualUsages, Collections.<PsiElement>emptyList());
41 myRootUsage = rootUsage;
44 void switchToAllLeavesTogether(SliceUsage rootUsage) {
45 AbstractTreeNode node = new SliceNode(getProject(), rootUsage, targetEqualUsages, getTreeBuilder(), getLeafExpressions());
46 myCachedChildren = Collections.singletonList(node);
49 @NotNull
50 public Collection<? extends AbstractTreeNode> getChildren() {
51 if (myCachedChildren == null) {
52 switchToAllLeavesTogether(myRootUsage);
54 return myCachedChildren;
57 @Override
58 public List<? extends AbstractTreeNode> getChildrenUnderProgress(ProgressIndicator progress) {
59 return (List<? extends AbstractTreeNode>)getChildren();
62 @Override
63 protected boolean shouldUpdateData() {
64 return super.shouldUpdateData();
67 @Override
68 protected void update(PresentationData presentation) {
69 if (presentation != null) {
70 presentation.setChanged(presentation.isChanged() || changed);
71 changed = false;
76 @Override
77 public void customizeCellRenderer(SliceUsageCellRenderer renderer,
78 JTree tree,
79 Object value,
80 boolean selected,
81 boolean expanded,
82 boolean leaf,
83 int row,
84 boolean hasFocus) {
87 public void restructureByLeaves(Collection<PsiElement> leafExpressions) {
88 assert myCachedChildren.size() == 1;
89 SliceNode root = (SliceNode)myCachedChildren.get(0);
90 myCachedChildren = new ArrayList<AbstractTreeNode>(leafExpressions.size());
91 for (PsiElement leaf : leafExpressions) {
92 SliceLeafValueRootNode node = new SliceLeafValueRootNode(getProject(), leaf, root);
93 myCachedChildren.add(node);