Search in sources :

Example 6 with SmartPsiElementPointer

use of com.intellij.psi.SmartPsiElementPointer in project intellij-community by JetBrains.

the class DocumentationComponent method setData.

public void setData(PsiElement _element, String text, final boolean clearHistory, String effectiveExternalUrl, String ref) {
    if (myElement != null) {
        myBackStack.push(saveContext());
        myForwardStack.clear();
    }
    myEffectiveExternalUrl = effectiveExternalUrl;
    final SmartPsiElementPointer element = _element != null && _element.isValid() ? SmartPointerManager.getInstance(_element.getProject()).createSmartPsiElementPointer(_element) : null;
    if (element != null) {
        setElement(element);
    }
    myIsEmpty = false;
    updateControlState();
    setDataInternal(element, text, new Rectangle(0, 0), ref);
    if (clearHistory)
        clearHistory();
}
Also used : SmartPsiElementPointer(com.intellij.psi.SmartPsiElementPointer)

Example 7 with SmartPsiElementPointer

use of com.intellij.psi.SmartPsiElementPointer in project intellij-community by JetBrains.

the class FavoritesPanel method setupDnD.

private void setupDnD() {
    DnDSupport.createBuilder(myTree).setBeanProvider(info -> {
        final TreePath path = myTree.getPathForLocation(info.getPoint().x, info.getPoint().y);
        if (path != null && path.getPathCount() == 3) {
            Object o = path.getLastPathComponent();
            if (o instanceof DefaultMutableTreeNode) {
                o = ((DefaultMutableTreeNode) o).getUserObject();
                if (o instanceof FavoritesTreeNodeDescriptor) {
                    FavoritesTreeNodeDescriptor root = ((FavoritesTreeNodeDescriptor) o).getFavoritesRoot();
                    if (root != null && root != o) {
                        o = root.getElement();
                        if (o instanceof FavoritesListNode && ((FavoritesListNode) o).getProvider() == null) {
                            return new DnDDragStartBean(path);
                        }
                    }
                }
            }
        }
        if (path != null && path.getPathCount() == 2) {
            Object o = path.getLastPathComponent();
            if (o instanceof DefaultMutableTreeNode) {
                o = ((DefaultMutableTreeNode) o).getUserObject();
                if (o instanceof FavoritesTreeNodeDescriptor) {
                    FavoritesTreeNodeDescriptor root = ((FavoritesTreeNodeDescriptor) o).getFavoritesRoot();
                    if (root == o) {
                        return new DnDDragStartBean(path);
                    }
                }
            }
        }
        return new DnDDragStartBean("") {

            @Override
            public boolean isEmpty() {
                return true;
            }
        };
    }).setTargetChecker(new DnDTargetChecker() {

        @Override
        public boolean update(DnDEvent event) {
            final Object obj = event.getAttachedObject();
            if ("".equals(obj)) {
                event.setDropPossible(false);
                return false;
            }
            int pathCount = 0;
            if (obj instanceof TreePath) {
                pathCount = ((TreePath) obj).getPathCount();
                if (pathCount < 2) {
                    event.setDropPossible(false);
                    return true;
                }
            }
            FavoritesListNode node = myViewPanel.findFavoritesListNode(event.getPoint());
            if ((obj instanceof TreePath && pathCount == 3 && myViewPanel.myTree.getPath(node).isDescendant((TreePath) obj)) || (node != null && node.getProvider() != null)) {
                event.setDropPossible(false);
                return false;
            }
            highlight(node, event);
            if (obj instanceof TreePath && pathCount == 2 && node != null && node.getProvider() == null) {
                event.setDropPossible(true);
                return true;
            }
            if (node != null) {
                event.setDropPossible(true);
                return true;
            }
            event.setDropPossible(false);
            return false;
        }
    }).setDropHandler(new DnDDropHandler() {

        @Override
        public void drop(DnDEvent event) {
            final FavoritesListNode node = myViewPanel.findFavoritesListNode(event.getPoint());
            final FavoritesManager mgr = FavoritesManager.getInstance(myProject);
            if (node == null)
                return;
            final String listTo = node.getValue();
            final Object obj = event.getAttachedObject();
            if (obj instanceof TreePath) {
                final TreePath path = (TreePath) obj;
                final String listFrom = FavoritesTreeViewPanel.getListNodeFromPath(path).getValue();
                if (listTo.equals(listFrom))
                    return;
                if (path.getPathCount() == 3) {
                    final AbstractTreeNode abstractTreeNode = ((FavoritesTreeNodeDescriptor) ((DefaultMutableTreeNode) path.getLastPathComponent()).getUserObject()).getElement();
                    Object element = abstractTreeNode.getValue();
                    mgr.removeRoot(listFrom, Collections.singletonList(abstractTreeNode));
                    if (element instanceof SmartPsiElementPointer) {
                        element = ((SmartPsiElementPointer) element).getElement();
                    }
                    mgr.addRoots(listTo, null, element);
                }
                if (path.getPathCount() == 2) {
                    //favorites lists manual sorting
                    Rectangle bounds = myTree.getPathBounds(myTree.getPath(node));
                    if (bounds != null) {
                        mgr.setOrder(listFrom, listTo, event.getPoint().y < bounds.y + bounds.height / 2);
                    }
                }
            } else if (obj instanceof TransferableWrapper) {
                myViewPanel.dropPsiElements(mgr, node, ((TransferableWrapper) obj).getPsiElements());
            } else if (obj instanceof DnDNativeTarget.EventInfo) {
                myViewPanel.dropPsiElements(mgr, node, getPsiFiles(FileCopyPasteUtil.getFileList(((DnDNativeTarget.EventInfo) obj).getTransferable())));
            }
        }
    }).setImageProvider(info -> new DnDImage(myFavoritesImage, new Point(-myFavoritesImage.getWidth(null) / 2, -myFavoritesImage.getHeight(null) / 2))).enableAsNativeTarget().setDisposableParent(myProject).install();
}
Also used : AllIcons(com.intellij.icons.AllIcons) TreePath(javax.swing.tree.TreePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) AbstractTreeBuilder(com.intellij.ide.util.treeView.AbstractTreeBuilder) DnDAwareTree(com.intellij.ide.dnd.aware.DnDAwareTree) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) File(java.io.File) PsiManager(com.intellij.psi.PsiManager) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ArrayList(java.util.ArrayList) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) RelativeRectangle(com.intellij.ui.awt.RelativeRectangle) SmartPsiElementPointer(com.intellij.psi.SmartPsiElementPointer) Disposer(com.intellij.openapi.util.Disposer) Project(com.intellij.openapi.project.Project) com.intellij.ide.dnd(com.intellij.ide.dnd) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) Collections(java.util.Collections) IconUtil(com.intellij.util.IconUtil) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) RelativeRectangle(com.intellij.ui.awt.RelativeRectangle) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) TreePath(javax.swing.tree.TreePath) SmartPsiElementPointer(com.intellij.psi.SmartPsiElementPointer)

Example 8 with SmartPsiElementPointer

use of com.intellij.psi.SmartPsiElementPointer in project intellij-community by JetBrains.

the class FavoritesTreeStructure method getChildElements.

@Override
public Object[] getChildElements(Object element) {
    if (!(element instanceof AbstractTreeNode)) {
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    final AbstractTreeNode favTreeElement = (AbstractTreeNode) element;
    try {
        if (!(element instanceof FavoritesListNode)) {
            Object[] elements = super.getChildElements(favTreeElement);
            if (elements.length > 0)
                return elements;
            ViewSettings settings = favTreeElement instanceof SettingsProvider ? ((SettingsProvider) favTreeElement).getSettings() : ViewSettings.DEFAULT;
            return ArrayUtil.toObjectArray(myNonProjectProvider.modify(favTreeElement, new ArrayList<>(), settings));
        }
        final List<AbstractTreeNode> result = new ArrayList<>();
        final FavoritesListNode listNode = (FavoritesListNode) element;
        if (listNode.getProvider() != null) {
            return ArrayUtil.toObjectArray(listNode.getChildren());
        }
        final Collection<AbstractTreeNode> roots = FavoritesListNode.getFavoritesRoots(myProject, listNode.getName(), listNode);
        for (AbstractTreeNode<?> abstractTreeNode : roots) {
            final Object value = abstractTreeNode.getValue();
            if (value == null)
                continue;
            if (value instanceof PsiElement && !((PsiElement) value).isValid())
                continue;
            if (value instanceof SmartPsiElementPointer && ((SmartPsiElementPointer) value).getElement() == null)
                continue;
            boolean invalid = false;
            for (FavoriteNodeProvider nodeProvider : Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, myProject)) {
                if (nodeProvider.isInvalidElement(value)) {
                    invalid = true;
                    break;
                }
            }
            if (invalid)
                continue;
            result.add(abstractTreeNode);
        }
        //}
        return ArrayUtil.toObjectArray(result);
    } catch (Exception e) {
        LOGGER.error(e);
    }
    return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
Also used : ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) ViewSettings(com.intellij.ide.projectView.ViewSettings) SettingsProvider(com.intellij.ide.projectView.SettingsProvider) SmartPsiElementPointer(com.intellij.psi.SmartPsiElementPointer) PsiElement(com.intellij.psi.PsiElement)

Example 9 with SmartPsiElementPointer

use of com.intellij.psi.SmartPsiElementPointer in project intellij-community by JetBrains.

the class FavoritesViewTreeBuilder method findSmartFirstLevelNodeByElement.

@Nullable
DefaultMutableTreeNode findSmartFirstLevelNodeByElement(final Object element) {
    for (Object child : getRoot().getChildren()) {
        AbstractTreeNode favorite = (AbstractTreeNode) child;
        Object currentValue = favorite.getValue();
        if (currentValue instanceof SmartPsiElementPointer) {
            currentValue = ((SmartPsiElementPointer) favorite.getValue()).getElement();
        }
        /*else if (currentValue instanceof PsiJavaFile) {
        final PsiClass[] classes = ((PsiJavaFile)currentValue).getClasses();
        if (classes.length > 0) {
          currentValue = classes[0];
        }
      }*/
        if (Comparing.equal(element, currentValue)) {
            final DefaultMutableTreeNode nodeWithObject = findFirstLevelNodeWithObject((DefaultMutableTreeNode) getTree().getModel().getRoot(), favorite);
            if (nodeWithObject != null) {
                return nodeWithObject;
            }
        }
    }
    return null;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) SmartPsiElementPointer(com.intellij.psi.SmartPsiElementPointer) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with SmartPsiElementPointer

use of com.intellij.psi.SmartPsiElementPointer in project intellij-plugins by JetBrains.

the class AngularUiRouterDiagramProvider method getExtras.

@NotNull
@Override
public DiagramExtras<DiagramObject> getExtras() {
    return new DiagramExtras<DiagramObject>() {

        @Override
        public List<AnAction> getExtraActions() {
            return Collections.singletonList(new MyEditSourceAction());
        }

        @Nullable
        @Override
        public Object getData(String dataId, List<DiagramNode<DiagramObject>> list, DiagramBuilder builder) {
            if (CommonDataKeys.PSI_ELEMENT.is(dataId) && list.size() == 1) {
                final SmartPsiElementPointer target = list.get(0).getIdentifyingElement().getNavigationTarget();
                return target == null ? null : target.getElement();
            } else if (JSModulesDiagramUtils.DIAGRAM_BUILDER.is(dataId)) {
                return builder;
            }
            return null;
        }

        @Nullable
        @Override
        public Layouter getCustomLayouter(Graph2D graph, Project project) {
            final GraphSettingsProvider settingsProvider = GraphSettingsProvider.getInstance(project);
            final GraphSettings settings = settingsProvider.getSettings(graph);
            final SmartOrganicLayouter layouter = settings.getOrganicLayouter();
            layouter.setNodeEdgeOverlapAvoided(true);
            layouter.setNodeSizeAware(true);
            layouter.setMinimalNodeDistance(60);
            layouter.setNodeOverlapsAllowed(false);
            layouter.setSmartComponentLayoutEnabled(true);
            layouter.setConsiderNodeLabelsEnabled(true);
            layouter.setDeterministic(true);
            final List<CanonicMultiStageLayouter> list = new ArrayList<>();
            list.add(layouter);
            list.add(settings.getBalloonLayouter());
            list.add(settings.getCircularLayouter());
            list.add(settings.getDirectedOrthogonalLayouter());
            //list.add(settings.getGroupLayouter());
            list.add(settings.getHVTreeLayouter());
            list.add(settings.getOrthogonalLayouter());
            for (CanonicMultiStageLayouter current : list) {
                final ParallelEdgeLayouter parallelEdgeLayouter = GraphManager.getGraphManager().createParallelEdgeLayouter();
                parallelEdgeLayouter.setLineDistance(40);
                parallelEdgeLayouter.setUsingAdaptiveLineDistances(false);
                current.appendStage(parallelEdgeLayouter);
                current.setParallelEdgeLayouterEnabled(false);
            }
            return layouter;
        }

        @NotNull
        @Override
        public JComponent createNodeComponent(DiagramNode<DiagramObject> node, DiagramBuilder builder, Point basePoint, JPanel wrapper) {
            final DiagramNodeContainer container = new DiagramNodeContainer(node, builder, basePoint);
            if (!GraphViewUtil.isPrintMode()) {
                if (!node.getIdentifyingElement().getErrors().isEmpty()) {
                    container.setBorder(ERROR_BORDER);
                } else if (!node.getIdentifyingElement().getWarnings().isEmpty()) {
                    container.setBorder(WARNING_BORDER);
                } else {
                    container.setBorder(NORMAL_BORDER);
                }
            }
            if (!node.getIdentifyingElement().getChildrenList().isEmpty())
                container.getHeader().setBorder(JBUI.Borders.customLine(Gray._190, 0, 0, 1, 0));
            return container;
        }
    };
}
Also used : CanonicMultiStageLayouter(com.intellij.openapi.graph.layout.CanonicMultiStageLayouter) GraphSettingsProvider(com.intellij.openapi.graph.settings.GraphSettingsProvider) ParallelEdgeLayouter(com.intellij.openapi.graph.layout.ParallelEdgeLayouter) YPoint(com.intellij.openapi.graph.geom.YPoint) Project(com.intellij.openapi.project.Project) GraphSettings(com.intellij.openapi.graph.settings.GraphSettings) SmartPsiElementPointer(com.intellij.psi.SmartPsiElementPointer) DiagramNodeContainer(com.intellij.diagram.components.DiagramNodeContainer) DiagramExtras(com.intellij.diagram.extras.DiagramExtras) List(java.util.List) SmartOrganicLayouter(com.intellij.openapi.graph.layout.organic.SmartOrganicLayouter) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SmartPsiElementPointer (com.intellij.psi.SmartPsiElementPointer)14 PsiElement (com.intellij.psi.PsiElement)7 Project (com.intellij.openapi.project.Project)4 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 ArrayList (java.util.ArrayList)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 PsiDirectory (com.intellij.psi.PsiDirectory)2 PsiFile (com.intellij.psi.PsiFile)2 MoveRenameUsageInfo (com.intellij.refactoring.util.MoveRenameUsageInfo)2 UsageInfo (com.intellij.usageView.UsageInfo)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 File (java.io.File)2 List (java.util.List)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 RefElement (com.intellij.codeInspection.reference.RefElement)1 RefFile (com.intellij.codeInspection.reference.RefFile)1 DiagramNodeContainer (com.intellij.diagram.components.DiagramNodeContainer)1 DiagramExtras (com.intellij.diagram.extras.DiagramExtras)1