update copyright
[fedora-idea.git] / plugins / ui-designer / src / com / intellij / uiDesigner / projectView / FormNode.java
blob40eb488f99b0149e4ee1a43bdcb7e6d530b01b05
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.uiDesigner.projectView;
18 import com.intellij.ide.IdeBundle;
19 import com.intellij.ide.projectView.PresentationData;
20 import com.intellij.ide.projectView.ProjectViewNode;
21 import com.intellij.ide.projectView.ViewSettings;
22 import com.intellij.ide.projectView.impl.nodes.BasePsiNode;
23 import com.intellij.ide.projectView.impl.nodes.ClassTreeNode;
24 import com.intellij.ide.projectView.impl.nodes.PsiFileNode;
25 import com.intellij.ide.util.treeView.AbstractTreeNode;
26 import com.intellij.openapi.fileTypes.StdFileTypes;
27 import com.intellij.openapi.project.Project;
28 import com.intellij.openapi.vcs.FileStatus;
29 import com.intellij.openapi.vfs.VirtualFile;
30 import com.intellij.openapi.util.Condition;
31 import com.intellij.psi.PsiClass;
32 import com.intellij.psi.PsiElement;
33 import com.intellij.psi.PsiFile;
34 import org.jetbrains.annotations.NotNull;
36 import java.util.Collection;
37 import java.util.LinkedHashSet;
38 import java.util.Set;
40 public class FormNode extends ProjectViewNode<Form>{
41 private final Collection<BasePsiNode<? extends PsiElement>> myChildren;
43 public FormNode(Project project, Object value, ViewSettings viewSettings) {
44 this(project, (Form)value, viewSettings, getChildren(project, (Form) value, viewSettings));
47 public FormNode(Project project, Form value, ViewSettings viewSettings, Collection<BasePsiNode<? extends PsiElement>> children) {
48 super(project, value, viewSettings);
49 myChildren = children;
52 @NotNull
53 public Collection<BasePsiNode<? extends PsiElement>> getChildren() {
54 return myChildren;
57 public String getTestPresentation() {
58 return "Form:" + getValue().getName();
61 public boolean contains(@NotNull VirtualFile file) {
62 for (final AbstractTreeNode aMyChildren : myChildren) {
63 ProjectViewNode treeNode = (ProjectViewNode)aMyChildren;
64 if (treeNode.contains(file)) return true;
66 return false;
69 public void update(PresentationData presentation) {
70 if (getValue() == null || !getValue().isValid()) {
71 setValue(null);
72 } else {
73 presentation.setPresentableText(getValue().getName());
74 presentation.setIcons(StdFileTypes.GUI_DESIGNER_FORM.getIcon());
78 public void navigate(final boolean requestFocus) {
79 getValue().navigate(requestFocus);
82 public boolean canNavigate() {
83 return getValue().canNavigate();
86 public boolean canNavigateToSource() {
87 return getValue().canNavigateToSource();
90 public String getToolTip() {
91 return IdeBundle.message("tooltip.ui.designer.form");
94 @Override
95 public FileStatus getFileStatus() {
96 for(BasePsiNode<? extends PsiElement> child: myChildren) {
97 final PsiElement value = child.getValue();
98 if (value == null || !value.isValid()) continue;
99 final FileStatus fileStatus = child.getFileStatus();
100 if (fileStatus != FileStatus.NOT_CHANGED) {
101 return fileStatus;
104 return FileStatus.NOT_CHANGED;
107 @Override
108 public boolean canHaveChildrenMatching(final Condition<PsiFile> condition) {
109 for(BasePsiNode<? extends PsiElement> child: myChildren) {
110 if (condition.value(child.getValue().getContainingFile())) {
111 return true;
114 return false;
117 public static AbstractTreeNode constructFormNode(final PsiClass classToBind, final Project project, final ViewSettings settings) {
118 final Form form = new Form(classToBind);
119 final Collection<BasePsiNode<? extends PsiElement>> children = getChildren(project, form, settings);
120 return new FormNode(project, form, settings, children);
123 private static Collection<BasePsiNode<? extends PsiElement>> getChildren(final Project project, final Form form, final ViewSettings settings) {
124 final Set<BasePsiNode<? extends PsiElement>> children = new LinkedHashSet<BasePsiNode<? extends PsiElement>>();
125 children.add(new ClassTreeNode(project, form.getClassToBind(), settings));
126 for (PsiFile formBoundToClass : form.getFormFiles()) {
127 children.add(new PsiFileNode(project, formBoundToClass, settings));
129 return children;