packaging editor test
[fedora-idea.git] / source / com / intellij / openapi / roots / ui / configuration / packaging / PackagingTreeNode.java
blob34b057d22a5f7dc6f1ade9c89775b62a7f207ae5
1 package com.intellij.openapi.roots.ui.configuration.packaging;
3 import com.intellij.ui.ColoredTreeCellRenderer;
4 import com.intellij.ui.SimpleTextAttributes;
5 import com.intellij.openapi.deployment.ContainerElement;
6 import com.intellij.openapi.roots.ui.configuration.projectRoot.ModuleStructureConfigurable;
7 import org.jetbrains.annotations.NotNull;
8 import org.jetbrains.annotations.Nullable;
10 import javax.swing.tree.DefaultMutableTreeNode;
11 import java.util.ArrayList;
12 import java.util.List;
14 /**
15 * @author nik
17 public abstract class PackagingTreeNode extends DefaultMutableTreeNode implements Comparable<PackagingTreeNode> {
18 private final PackagingArtifact myOwner;
20 protected PackagingTreeNode(final @Nullable PackagingArtifact owner) {
21 myOwner = owner;
24 @NotNull
25 public abstract String getOutputFileName();
27 public abstract double getWeight();
29 public String getSearchName() {
30 return getOutputFileName();
33 public abstract void render(ColoredTreeCellRenderer renderer);
35 public abstract boolean canNavigate();
37 public abstract void navigate(ModuleStructureConfigurable configurable);
39 @Nullable
40 public abstract Object getSourceObject();
42 @Nullable
43 public String getTooltipText() {
44 return null;
47 public void renderTooltip(ColoredTreeCellRenderer renderer) {
50 public int compareTo(final PackagingTreeNode node) {
51 return getOutputFileName().compareToIgnoreCase(node.getOutputFileName());
54 @Nullable
55 public PackagingArtifact getOwner() {
56 return myOwner;
59 @Nullable
60 public ContainerElement getContainerElement() {
61 return null;
64 @Nullable
65 public PackagingTreeNode findChildByName(final @NotNull String outputFileName) {
66 for (int i = 0; i < getChildCount(); i++) {
67 PackagingTreeNode node = (PackagingTreeNode)getChildAt(i);
68 if (node.getOutputFileName().equals(outputFileName)) {
69 return node;
72 return null;
75 @Override
76 public PackagingTreeNode getParent() {
77 return (PackagingTreeNode)super.getParent();
80 @NotNull
81 public List<PackagingTreeNode> getChildren() {
82 List<PackagingTreeNode> children = new ArrayList<PackagingTreeNode>(getChildCount());
83 for (int i = 0; i < getChildCount(); i++) {
84 children.add((PackagingTreeNode)getChildAt(i));
86 return children;
89 protected SimpleTextAttributes getMainAttributes() {
90 return !belongsToIncludedArtifact() ? SimpleTextAttributes.REGULAR_ATTRIBUTES : SimpleTextAttributes.GRAY_ATTRIBUTES;
93 protected SimpleTextAttributes getCommentAttributes() {
94 return !belongsToIncludedArtifact() ? SimpleTextAttributes.GRAY_ATTRIBUTES : SimpleTextAttributes.GRAY_ITALIC_ATTRIBUTES;
97 protected boolean belongsToIncludedArtifact() {
98 if (myOwner == null) return false;
100 PackagingTreeNode parent = getParent();
101 while (parent != null) {
102 if (parent instanceof PackagingArtifactNode && myOwner.equals(((PackagingArtifactNode)parent).getArtifact())) {
103 return false;
105 parent = parent.getParent();
107 return true;