update copyright
[fedora-idea.git] / java / idea-ui / src / com / intellij / openapi / roots / ui / configuration / artifacts / sourceItems / SourceItemNodeBase.java
blob212c9582b7573b0b06925cd0a4b053158571b4f6
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.openapi.roots.ui.configuration.artifacts.sourceItems;
18 import com.intellij.ide.projectView.PresentationData;
19 import com.intellij.ide.util.treeView.NodeDescriptor;
20 import com.intellij.openapi.extensions.Extensions;
21 import com.intellij.openapi.roots.ui.configuration.artifacts.ArtifactEditorEx;
22 import com.intellij.openapi.roots.ui.configuration.artifacts.nodes.ArtifactsTreeNode;
23 import com.intellij.packaging.artifacts.Artifact;
24 import com.intellij.packaging.ui.ArtifactEditorContext;
25 import com.intellij.packaging.ui.PackagingSourceItem;
26 import com.intellij.packaging.ui.PackagingSourceItemsProvider;
27 import com.intellij.packaging.ui.TreeNodePresentation;
28 import com.intellij.ui.treeStructure.SimpleNode;
29 import org.jetbrains.annotations.Nullable;
31 import java.util.ArrayList;
32 import java.util.Collection;
33 import java.util.List;
35 /**
36 * @author nik
38 public abstract class SourceItemNodeBase extends ArtifactsTreeNode {
39 private Artifact myArtifact;
40 private final ArtifactEditorEx myArtifactEditor;
42 public SourceItemNodeBase(ArtifactEditorContext context, NodeDescriptor parentDescriptor, final TreeNodePresentation presentation,
43 ArtifactEditorEx artifactEditor) {
44 super(context, parentDescriptor, presentation);
45 myArtifact = artifactEditor.getArtifact();
46 myArtifactEditor = artifactEditor;
49 protected ArtifactEditorEx getArtifactEditor() {
50 return myArtifactEditor;
53 @Override
54 protected void update(PresentationData presentation) {
55 final Artifact artifact = myArtifactEditor.getArtifact();
56 if (!myArtifact.equals(artifact)) {
57 myArtifact = artifact;
59 super.update(presentation);
62 @Override
63 protected SimpleNode[] buildChildren() {
64 final PackagingSourceItemsProvider[] providers = Extensions.getExtensions(PackagingSourceItemsProvider.EP_NAME);
65 List<SimpleNode> children = new ArrayList<SimpleNode>();
66 for (PackagingSourceItemsProvider provider : providers) {
67 final Collection<? extends PackagingSourceItem> items = provider.getSourceItems(myContext, myArtifact, getSourceItem());
68 for (PackagingSourceItem item : items) {
69 if (myArtifact.getArtifactType().isSuitableItem(item)) {
70 children.add(new SourceItemNode(myContext, this, item, myArtifactEditor));
74 return children.toArray(new SimpleNode[children.size()]);
77 @Nullable
78 protected abstract PackagingSourceItem getSourceItem();