IDEA-50121
[fedora-idea.git] / java / java-impl / src / com / intellij / slicer / SliceRootNode.java
blobbba0dc5d602f03d9b9b76bd1ec2e992d49e35640
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.ide.util.treeView.AbstractTreeNode;
20 import com.intellij.openapi.progress.ProgressIndicator;
21 import com.intellij.openapi.project.Project;
22 import org.jetbrains.annotations.NotNull;
24 import javax.swing.*;
25 import java.util.Collection;
26 import java.util.Collections;
27 import java.util.List;
29 /**
30 * @author cdr
32 public class SliceRootNode extends SliceNode {
33 private final SliceUsage myRootUsage;
35 public SliceRootNode(@NotNull Project project, @NotNull DuplicateMap targetEqualUsages, final SliceUsage rootUsage) {
36 super(project, new SliceUsage(rootUsage.getElement().getContainingFile(), rootUsage.params), targetEqualUsages);
37 myRootUsage = rootUsage;
40 void switchToAllLeavesTogether(SliceUsage rootUsage) {
41 SliceNode node = new SliceNode(getProject(), rootUsage, targetEqualUsages);
42 myCachedChildren = Collections.singletonList(node);
45 @Override
46 SliceRootNode copy() {
47 SliceUsage newUsage = getValue().copy();
48 SliceRootNode newNode = new SliceRootNode(getProject(), new DuplicateMap(), newUsage);
49 newNode.initialized = initialized;
50 newNode.duplicate = duplicate;
51 return newNode;
54 @NotNull
55 public Collection<? extends AbstractTreeNode> getChildren() {
56 if (myCachedChildren == null) {
57 switchToAllLeavesTogether(myRootUsage);
59 return myCachedChildren;
62 @Override
63 public List<? extends AbstractTreeNode> getChildrenUnderProgress(ProgressIndicator progress) {
64 return (List<? extends AbstractTreeNode>)getChildren();
67 @Override
68 protected boolean shouldUpdateData() {
69 return super.shouldUpdateData();
72 @Override
73 protected void update(PresentationData presentation) {
74 if (presentation != null) {
75 presentation.setChanged(presentation.isChanged() || changed);
76 changed = false;
81 @Override
82 public void customizeCellRenderer(SliceUsageCellRenderer renderer,
83 JTree tree,
84 Object value,
85 boolean selected,
86 boolean expanded,
87 boolean leaf,
88 int row,
89 boolean hasFocus) {
92 public SliceUsage getRootUsage() {
93 return myRootUsage;