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
;
27 import java
.util
.ArrayList
;
28 import java
.util
.Collection
;
29 import java
.util
.Collections
;
30 import java
.util
.List
;
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
);
50 public Collection
<?
extends AbstractTreeNode
> getChildren() {
51 if (myCachedChildren
== null) {
52 switchToAllLeavesTogether(myRootUsage
);
54 return myCachedChildren
;
58 public List
<?
extends AbstractTreeNode
> getChildrenUnderProgress(ProgressIndicator progress
) {
59 return (List
<?
extends AbstractTreeNode
>)getChildren();
63 protected boolean shouldUpdateData() {
64 return super.shouldUpdateData();
68 protected void update(PresentationData presentation
) {
69 if (presentation
!= null) {
70 presentation
.setChanged(presentation
.isChanged() || changed
);
77 public void customizeCellRenderer(SliceUsageCellRenderer renderer
,
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
);