Search in sources :

Example 6 with PsIssue

use of com.android.tools.idea.gradle.structure.model.PsIssue in project android by JetBrains.

the class NodeHyperlinkSupport method addHyperlinkBehaviorToSupportedNodes.

private void addHyperlinkBehaviorToSupportedNodes() {
    myTree.setCellRenderer(new NodeRenderer() {

        @NotNull
        @Override
        protected SimpleTextAttributes getSimpleTextAttributes(@NotNull PresentationData presentation, Color color, @NotNull Object node) {
            List<PsIssue> issues = Collections.emptyList();
            if (myShowIssues && node instanceof AbstractPsModelNode) {
                AbstractPsModelNode<? extends PsModel> modelNode = (AbstractPsModelNode<? extends PsModel>) node;
                issues = findIssues(modelNode, IssuesByTypeAndTextComparator.INSTANCE);
                presentation.setTooltip(getTooltipText(issues, false));
            }
            if (myHoveredNode != null && myHoveredNode == node) {
                return LINK_ATTRIBUTES;
            }
            SimpleTextAttributes textAttributes = super.getSimpleTextAttributes(presentation, color, node);
            if (!issues.isEmpty()) {
                PsIssue issue = issues.get(0);
                Color waveColor = issue.getSeverity().getColor();
                textAttributes = textAttributes.derive(STYLE_WAVED, null, null, waveColor);
            }
            return textAttributes;
        }

        @Override
        public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            if (myShowIssues) {
                AbstractPsModelNode<? extends PsModel> modelNode = findModelNode(value);
                if (modelNode != null) {
                    List<PsIssue> issues = findIssues(modelNode, null);
                    if (!issues.isEmpty()) {
                        // Force color change of the node.
                        modelNode.getPresentation().clearText();
                    }
                }
            }
            super.customizeCellRenderer(tree, value, selected, expanded, leaf, row, hasFocus);
            Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
            if (userObject instanceof CellAppearanceEx) {
                ((CellAppearanceEx) userObject).customize(this);
            }
        }

        @Nullable
        private AbstractPsModelNode<? extends PsModel> findModelNode(@Nullable Object value) {
            if (value instanceof DefaultMutableTreeNode) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
                Object userObject = node.getUserObject();
                if (userObject instanceof AbstractPsModelNode) {
                    return (AbstractPsModelNode<? extends PsModel>) userObject;
                }
            }
            return null;
        }
    });
    MouseAdapter mouseListener = new MouseAdapter() {

        @Override
        public void mouseMoved(MouseEvent e) {
            Cursor cursor = getDefaultCursor();
            T node = getIfHyperlink(e);
            if (node != null) {
                cursor = getPredefinedCursor(HAND_CURSOR);
            }
            setHoveredNode(node);
            myTree.setCursor(cursor);
        }
    };
    myTree.addMouseMotionListener(mouseListener);
    // Make the cursor change to 'hand' if the mouse pointer is over a supported node and the user presses Ctrl or Cmd.
    myKeyEventDispatcher = e -> {
        T node = null;
        if (e.getID() == KEY_PRESSED) {
            Cursor cursor = getDefaultCursor();
            if (isMetaOrCtrlKeyPressed(e)) {
                node = getNodeUnderMousePointer();
                if (node != null) {
                    cursor = getPredefinedCursor(HAND_CURSOR);
                }
            }
            setHoveredNode(node);
            myTree.setCursor(cursor);
        } else if (e.getID() == KEY_RELEASED) {
            if (isMetaOrCtrlKeyPressed(e)) {
                setHoveredNode(null);
            }
            myTree.setCursor(getDefaultCursor());
        }
        return false;
    };
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(myKeyEventDispatcher);
}
Also used : PresentationData(com.intellij.ide.projectView.PresentationData) CellAppearanceEx(com.intellij.openapi.roots.ui.CellAppearanceEx) MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) PsModel(com.android.tools.idea.gradle.structure.model.PsModel) MouseAdapter(java.awt.event.MouseAdapter) Cursor(java.awt.Cursor) NotNull(org.jetbrains.annotations.NotNull) NodeRenderer(com.intellij.ide.util.treeView.NodeRenderer) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) List(java.util.List) PsIssue(com.android.tools.idea.gradle.structure.model.PsIssue) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with PsIssue

use of com.android.tools.idea.gradle.structure.model.PsIssue in project android by JetBrains.

the class PsAndroidModuleAnalyzerTest method createIssueFrom.

@Test
public void createIssueFrom() {
    SyncIssue syncIssue = mock(SyncIssue.class);
    when(syncIssue.getMessage()).thenReturn("Conflict with dependency 'com.google.guava:guava'. Resolved versions for app (16.0) " + "and test app (16.0.1) differ. See http://g.co/androidstudio/app-test-app-conflict for " + "details.");
    when(syncIssue.getSeverity()).thenReturn(SEVERITY_ERROR);
    PsPath path = mock(PsPath.class);
    PsIssue issue = PsAndroidModuleAnalyzer.createIssueFrom(syncIssue, path, null);
    assertThat(issue.getText()).isEqualTo("Conflict with dependency 'com.google.guava:guava'. Resolved versions for app (16.0) " + "and test app (16.0.1) differ. See " + "<a href='http://g.co/androidstudio/app-test-app-conflict'>http://g.co/androidstudio/app-test-app-conflict</a> " + "for details.");
    assertThat(issue.getSeverity()).isEqualTo(ERROR);
}
Also used : PsPath(com.android.tools.idea.gradle.structure.model.PsPath) SyncIssue(com.android.builder.model.SyncIssue) PsIssue(com.android.tools.idea.gradle.structure.model.PsIssue) Test(org.junit.Test)

Example 8 with PsIssue

use of com.android.tools.idea.gradle.structure.model.PsIssue in project android by JetBrains.

the class DependencyGraphPanel method updateIssues.

private void updateIssues(@NotNull List<AbstractDependencyNode<? extends PsAndroidDependency>> selection) {
    List<PsIssue> issues = Lists.newArrayList();
    for (AbstractDependencyNode<? extends PsAndroidDependency> node : selection) {
        for (PsAndroidDependency dependency : node.getModels()) {
            issues.addAll(myContext.getAnalyzerDaemon().getIssues().findIssues(dependency, null));
        }
    }
    displayIssues(issues);
}
Also used : PsAndroidDependency(com.android.tools.idea.gradle.structure.model.android.PsAndroidDependency) PsIssue(com.android.tools.idea.gradle.structure.model.PsIssue)

Example 9 with PsIssue

use of com.android.tools.idea.gradle.structure.model.PsIssue in project android by JetBrains.

the class NodeHyperlinkSupport method findIssues.

@NotNull
private List<PsIssue> findIssues(@NotNull AbstractPsModelNode<? extends PsModel> modelNode, @Nullable Comparator<PsIssue> comparator) {
    List<PsIssue> issues = Lists.newArrayList();
    PsIssueCollection issueCollection = myContext.getAnalyzerDaemon().getIssues();
    for (PsModel model : modelNode.getModels()) {
        issues.addAll(issueCollection.findIssues(model, null));
    }
    if (comparator != null && issues.size() > 1) {
        Collections.sort(issues, comparator);
    }
    return issues;
}
Also used : PsModel(com.android.tools.idea.gradle.structure.model.PsModel) PsIssueCollection(com.android.tools.idea.gradle.structure.model.PsIssueCollection) PsIssue(com.android.tools.idea.gradle.structure.model.PsIssue) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsIssue (com.android.tools.idea.gradle.structure.model.PsIssue)9 NotNull (org.jetbrains.annotations.NotNull)4 PsPath (com.android.tools.idea.gradle.structure.model.PsPath)3 List (java.util.List)3 PsModel (com.android.tools.idea.gradle.structure.model.PsModel)2 PsAndroidDependency (com.android.tools.idea.gradle.structure.model.android.PsAndroidDependency)2 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)2 SyncIssue (com.android.builder.model.SyncIssue)1 CollapsiblePanel (com.android.tools.idea.gradle.structure.configurables.ui.CollapsiblePanel)1 UiUtil.revalidateAndRepaint (com.android.tools.idea.gradle.structure.configurables.ui.UiUtil.revalidateAndRepaint)1 PsIssueCollection (com.android.tools.idea.gradle.structure.model.PsIssueCollection)1 PsModule (com.android.tools.idea.gradle.structure.model.PsModule)1 PresentationData (com.intellij.ide.projectView.PresentationData)1 NodeRenderer (com.intellij.ide.util.treeView.NodeRenderer)1 CellAppearanceEx (com.intellij.openapi.roots.ui.CellAppearanceEx)1 MasterDetailsComponent (com.intellij.openapi.ui.MasterDetailsComponent)1 NamedConfigurable (com.intellij.openapi.ui.NamedConfigurable)1 Cursor (java.awt.Cursor)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1