Search in sources :

Example 1 with ProjectViewNode

use of com.intellij.ide.projectView.ProjectViewNode in project intellij-community by JetBrains.

the class FormMergerTreeStructureProvider method modify.

@NotNull
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
    if (parent.getValue() instanceof Form)
        return children;
    // Optimization. Check if there are any forms at all.
    boolean formsFound = false;
    for (AbstractTreeNode node : children) {
        if (node.getValue() instanceof PsiFile) {
            PsiFile file = (PsiFile) node.getValue();
            if (file.getFileType() == StdFileTypes.GUI_DESIGNER_FORM) {
                formsFound = true;
                break;
            }
        }
    }
    if (!formsFound)
        return children;
    Collection<AbstractTreeNode> result = new LinkedHashSet<>(children);
    ProjectViewNode[] copy = children.toArray(new ProjectViewNode[children.size()]);
    for (ProjectViewNode element : copy) {
        PsiClass psiClass = null;
        if (element.getValue() instanceof PsiClass) {
            psiClass = (PsiClass) element.getValue();
        } else if (element.getValue() instanceof PsiClassOwner) {
            final PsiClass[] psiClasses = ((PsiClassOwner) element.getValue()).getClasses();
            if (psiClasses.length == 1) {
                psiClass = psiClasses[0];
            }
        }
        if (psiClass == null)
            continue;
        String qName = psiClass.getQualifiedName();
        if (qName == null)
            continue;
        List<PsiFile> forms;
        try {
            forms = FormClassIndex.findFormsBoundToClass(myProject, qName);
        } catch (ProcessCanceledException e) {
            continue;
        }
        Collection<BasePsiNode<? extends PsiElement>> formNodes = findFormsIn(children, forms);
        if (!formNodes.isEmpty()) {
            Collection<PsiFile> formFiles = convertToFiles(formNodes);
            Collection<BasePsiNode<? extends PsiElement>> subNodes = new ArrayList<>();
            //noinspection unchecked
            subNodes.add((BasePsiNode<? extends PsiElement>) element);
            subNodes.addAll(formNodes);
            result.add(new FormNode(myProject, new Form(psiClass, formFiles), settings, subNodes));
            result.remove(element);
            result.removeAll(formNodes);
        }
    }
    return result;
}
Also used : AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) BasePsiNode(com.intellij.ide.projectView.impl.nodes.BasePsiNode) ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ProjectViewNode

use of com.intellij.ide.projectView.ProjectViewNode in project intellij-community by JetBrains.

the class XsltTreeStructureProvider method modify.

@NotNull
@SuppressWarnings({ "RawUseOfParameterizedType", "unchecked" })
public Collection<AbstractTreeNode> modify(@NotNull AbstractTreeNode parent, @NotNull Collection<AbstractTreeNode> children, ViewSettings settings) {
    Collection<AbstractTreeNode> l = children;
    int i = 0;
    for (AbstractTreeNode o : children) {
        if (o instanceof ProjectViewNode) {
            final ProjectViewNode node = (ProjectViewNode) o;
            final Object element = node.getValue();
            if (element instanceof PsiFile) {
                if (XsltSupport.isXsltFile((PsiFile) element)) {
                    if (l == children && l.getClass() != ArrayList.class) {
                        l = new ArrayList<>(children);
                    }
                    final XsltFileNode fileNode = new XsltFileNode(myProject, (PsiFile) element, settings);
                    ((List<AbstractTreeNode>) l).set(i, fileNode);
                }
            }
        }
        i++;
    }
    return l;
}
Also used : ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiFile(com.intellij.psi.PsiFile) ArrayList(java.util.ArrayList) List(java.util.List) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ProjectViewNode

use of com.intellij.ide.projectView.ProjectViewNode in project intellij-community by JetBrains.

the class AssociationsEditor method getObject.

@Nullable
private static Object getObject(Object component) {
    if (!(component instanceof DefaultMutableTreeNode))
        return null;
    final DefaultMutableTreeNode node = ((DefaultMutableTreeNode) component);
    final Object userObject = node.getUserObject();
    if (!(userObject instanceof ProjectViewNode))
        return null;
    return ((ProjectViewNode<?>) userObject).getValue();
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with ProjectViewNode

use of com.intellij.ide.projectView.ProjectViewNode in project intellij-community by JetBrains.

the class TreeFileChooserDialog method filterFiles.

private Object[] filterFiles(final Object[] list) {
    Condition<PsiFile> condition = psiFile -> {
        if (myFilter != null && !myFilter.accept(psiFile)) {
            return false;
        }
        boolean accepted = myFileType == null || psiFile.getFileType() == myFileType;
        VirtualFile virtualFile = psiFile.getVirtualFile();
        if (virtualFile != null && !accepted) {
            accepted = virtualFile.getFileType() == myFileType;
        }
        return accepted;
    };
    final List<Object> result = new ArrayList<>(list.length);
    for (Object o : list) {
        final PsiFile psiFile;
        if (o instanceof PsiFile) {
            psiFile = (PsiFile) o;
        } else if (o instanceof PsiFileNode) {
            psiFile = ((PsiFileNode) o).getValue();
        } else {
            psiFile = null;
        }
        if (psiFile != null && !condition.value(psiFile)) {
            continue;
        } else {
            if (o instanceof ProjectViewNode) {
                final ProjectViewNode projectViewNode = (ProjectViewNode) o;
                if (!projectViewNode.canHaveChildrenMatching(condition)) {
                    continue;
                }
            }
        }
        result.add(o);
    }
    return ArrayUtil.toObjectArray(result);
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) FileTypeIndex(com.intellij.psi.search.FileTypeIndex) BaseProjectTreeBuilder(com.intellij.ide.projectView.BaseProjectTreeBuilder) ProjectTreeBuilder(com.intellij.ide.projectView.impl.ProjectTreeBuilder) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModalityState(com.intellij.openapi.application.ModalityState) THashSet(gnu.trove.THashSet) ChooseByNamePopupComponent(com.intellij.ide.util.gotoByName.ChooseByNamePopupComponent) ChooseByNamePanel(com.intellij.ide.util.gotoByName.ChooseByNamePanel) PsiManager(com.intellij.psi.PsiManager) TreeSpeedSearch(com.intellij.ui.TreeSpeedSearch) ProjectAbstractTreeStructureBase(com.intellij.ide.projectView.impl.ProjectAbstractTreeStructureBase) JBUI(com.intellij.util.ui.JBUI) Disposer(com.intellij.openapi.util.Disposer) ChangeListener(javax.swing.event.ChangeListener) PsiFileNode(com.intellij.ide.projectView.impl.nodes.PsiFileNode) AbstractProjectTreeStructure(com.intellij.ide.projectView.impl.AbstractProjectTreeStructure) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) ChangeEvent(javax.swing.event.ChangeEvent) TreePath(javax.swing.tree.TreePath) GotoFileCellRenderer(com.intellij.ide.util.gotoByName.GotoFileCellRenderer) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) KeyEvent(java.awt.event.KeyEvent) DoubleClickListener(com.intellij.ui.DoubleClickListener) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) IdeBundle(com.intellij.ide.IdeBundle) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Function(com.intellij.util.Function) ApplicationManager(com.intellij.openapi.application.ApplicationManager) WindowManagerEx(com.intellij.openapi.wm.ex.WindowManagerEx) NotNull(org.jetbrains.annotations.NotNull) TabbedPaneWrapper(com.intellij.ui.TabbedPaneWrapper) TreeStructureProvider(com.intellij.ide.projectView.TreeStructureProvider) java.util(java.util) ArrayUtil(com.intellij.util.ArrayUtil) FilenameIndex(com.intellij.psi.search.FilenameIndex) ContainerUtil(com.intellij.util.containers.ContainerUtil) KeyAdapter(java.awt.event.KeyAdapter) NodeRenderer(com.intellij.ide.util.treeView.NodeRenderer) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) ChooseByNameModel(com.intellij.ide.util.gotoByName.ChooseByNameModel) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) PsiElement(com.intellij.psi.PsiElement) AlphaComparator(com.intellij.ide.util.treeView.AlphaComparator) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Tree(com.intellij.ui.treeStructure.Tree) DumbAware(com.intellij.openapi.project.DumbAware) ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode) FileType(com.intellij.openapi.fileTypes.FileType) TreeSelectionModel(javax.swing.tree.TreeSelectionModel) MouseEvent(java.awt.event.MouseEvent) java.awt(java.awt) Condition(com.intellij.openapi.util.Condition) ScrollPaneFactory(com.intellij.ui.ScrollPaneFactory) javax.swing(javax.swing) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFileNode(com.intellij.ide.projectView.impl.nodes.PsiFileNode) ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode) PsiFile(com.intellij.psi.PsiFile)

Example 5 with ProjectViewNode

use of com.intellij.ide.projectView.ProjectViewNode in project intellij-community by JetBrains.

the class ProjectViewImpl method getParentOfCurrentSelection.

@Override
public PsiElement getParentOfCurrentSelection() {
    final AbstractProjectViewPane viewPane = getCurrentProjectViewPane();
    if (viewPane == null) {
        return null;
    }
    TreePath path = viewPane.getSelectedPath();
    if (path == null) {
        return null;
    }
    path = path.getParentPath();
    if (path == null) {
        return null;
    }
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
    Object userObject = node.getUserObject();
    if (userObject instanceof ProjectViewNode) {
        ProjectViewNode descriptor = (ProjectViewNode) userObject;
        Object element = descriptor.getValue();
        if (element instanceof PsiElement) {
            PsiElement psiElement = (PsiElement) element;
            if (!psiElement.isValid())
                return null;
            return psiElement;
        } else {
            return null;
        }
    }
    return null;
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode)

Aggregations

ProjectViewNode (com.intellij.ide.projectView.ProjectViewNode)17 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)9 NotNull (org.jetbrains.annotations.NotNull)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 PsiFile (com.intellij.psi.PsiFile)6 ArrayList (java.util.ArrayList)5 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)5 TreePath (javax.swing.tree.TreePath)3 Project (com.intellij.openapi.project.Project)2 PsiElement (com.intellij.psi.PsiElement)2 List (java.util.List)2 Nullable (org.jetbrains.annotations.Nullable)2 IdeBundle (com.intellij.ide.IdeBundle)1 BaseProjectTreeBuilder (com.intellij.ide.projectView.BaseProjectTreeBuilder)1 PresentationData (com.intellij.ide.projectView.PresentationData)1 ProjectView (com.intellij.ide.projectView.ProjectView)1 TreeStructureProvider (com.intellij.ide.projectView.TreeStructureProvider)1 ViewSettings (com.intellij.ide.projectView.ViewSettings)1 AbstractProjectTreeStructure (com.intellij.ide.projectView.impl.AbstractProjectTreeStructure)1 ProjectAbstractTreeStructureBase (com.intellij.ide.projectView.impl.ProjectAbstractTreeStructureBase)1