Search in sources :

Example 1 with DomElementsProblemsHolder

use of com.intellij.util.xml.highlighting.DomElementsProblemsHolder in project intellij-community by JetBrains.

the class EditorTextFieldControl method updateComponent.

@Override
protected void updateComponent() {
    final DomElement domElement = getDomElement();
    if (domElement == null || !domElement.isValid())
        return;
    final EditorTextField textField = getEditorTextField(getComponent());
    final Project project = getProject();
    ApplicationManager.getApplication().invokeLater(() -> {
        if (!project.isOpen())
            return;
        if (!getDomWrapper().isValid())
            return;
        final DomElement domElement1 = getDomElement();
        if (domElement1 == null || !domElement1.isValid())
            return;
        final DomElementAnnotationsManager manager = DomElementAnnotationsManager.getInstance(project);
        final DomElementsProblemsHolder holder = manager.getCachedProblemHolder(domElement1);
        final List<DomElementProblemDescriptor> errorProblems = holder.getProblems(domElement1);
        final List<DomElementProblemDescriptor> warningProblems = new ArrayList<>(holder.getProblems(domElement1, true, HighlightSeverity.WARNING));
        warningProblems.removeAll(errorProblems);
        Color background = getDefaultBackground();
        if (errorProblems.size() > 0 && textField.getText().trim().length() == 0) {
            background = getErrorBackground();
        } else if (warningProblems.size() > 0) {
            background = getWarningBackground();
        }
        final Editor editor = textField.getEditor();
        if (editor != null) {
            final MarkupModel markupModel = editor.getMarkupModel();
            markupModel.removeAllHighlighters();
            if (!errorProblems.isEmpty() && editor.getDocument().getLineCount() > 0) {
                final TextAttributes attributes = SimpleTextAttributes.ERROR_ATTRIBUTES.toTextAttributes();
                attributes.setEffectType(EffectType.WAVE_UNDERSCORE);
                attributes.setEffectColor(attributes.getForegroundColor());
                markupModel.addLineHighlighter(0, 0, attributes);
                editor.getContentComponent().setToolTipText(errorProblems.get(0).getDescriptionTemplate());
            }
        }
        textField.setBackground(background);
    });
}
Also used : Project(com.intellij.openapi.project.Project) DomElementsProblemsHolder(com.intellij.util.xml.highlighting.DomElementsProblemsHolder) DomElement(com.intellij.util.xml.DomElement) EditorTextField(com.intellij.ui.EditorTextField) DomElementProblemDescriptor(com.intellij.util.xml.highlighting.DomElementProblemDescriptor) ArrayList(java.util.ArrayList) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Editor(com.intellij.openapi.editor.Editor) MarkupModel(com.intellij.openapi.editor.markup.MarkupModel) DomElementAnnotationsManager(com.intellij.util.xml.highlighting.DomElementAnnotationsManager)

Example 2 with DomElementsProblemsHolder

use of com.intellij.util.xml.highlighting.DomElementsProblemsHolder in project intellij-community by JetBrains.

the class ErrorableTableCellRenderer method getTableCellRendererComponent.

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    final Component component = myRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    if (!myRoot.isValid()) {
        return component;
    }
    final DomElementAnnotationsManager annotationsManager = DomElementAnnotationsManager.getInstance(myRowDomElement.getManager().getProject());
    final DomElementsProblemsHolder holder = annotationsManager.getCachedProblemHolder(myRoot);
    final List<DomElementProblemDescriptor> errorProblems = holder.getProblems(myCellValueDomElement);
    final List<DomElementProblemDescriptor> warningProblems = new ArrayList<>(holder.getProblems(myCellValueDomElement, true, HighlightSeverity.WARNING));
    warningProblems.removeAll(errorProblems);
    final boolean hasErrors = errorProblems.size() > 0;
    if (hasErrors) {
        component.setForeground(JBColor.RED);
        if (component instanceof JComponent) {
            ((JComponent) component).setToolTipText(TooltipUtils.getTooltipText(errorProblems));
        }
    } else {
        component.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
        if (component instanceof JComponent) {
            ((JComponent) component).setToolTipText(null);
        }
    }
    // highlight empty cell with errors
    if (hasErrors && (value == null || value.toString().trim().length() == 0)) {
        component.setBackground(BaseControl.ERROR_BACKGROUND);
    } else if (warningProblems.size() > 0) {
        component.setBackground(BaseControl.WARNING_BACKGROUND);
        if (isSelected)
            component.setForeground(JBColor.foreground());
    }
    final List<DomElementProblemDescriptor> errorDescriptors = annotationsManager.getCachedProblemHolder(myRowDomElement).getProblems(myRowDomElement, true, true);
    if (table.getModel().getColumnCount() - 1 == column) {
        if (errorDescriptors.size() > 0) {
            final JPanel wrapper = new JPanel(new BorderLayout());
            wrapper.add(component, BorderLayout.CENTER);
            wrapper.setBackground(component.getBackground());
            final JLabel errorLabel = new JLabel(getErrorIcon());
            wrapper.setToolTipText(TooltipUtils.getTooltipText(errorDescriptors));
            wrapper.add(errorLabel, BorderLayout.EAST);
            if (component instanceof JComponent) {
                final JComponent jComponent = (JComponent) component;
                wrapper.setBorder(jComponent.getBorder());
                jComponent.setBorder(BorderFactory.createEmptyBorder());
                jComponent.setToolTipText(TooltipUtils.getTooltipText(errorDescriptors));
            }
            return wrapper;
        } else {
            if (component instanceof JComponent) {
                ((JComponent) component).setToolTipText(null);
            }
        }
    }
    return component;
}
Also used : DomElementsProblemsHolder(com.intellij.util.xml.highlighting.DomElementsProblemsHolder) DomElementProblemDescriptor(com.intellij.util.xml.highlighting.DomElementProblemDescriptor) ArrayList(java.util.ArrayList) DomElementAnnotationsManager(com.intellij.util.xml.highlighting.DomElementAnnotationsManager)

Example 3 with DomElementsProblemsHolder

use of com.intellij.util.xml.highlighting.DomElementsProblemsHolder in project intellij-community by JetBrains.

the class DomElementsGroupNode method hasErrors.

private boolean hasErrors() {
    if (!myParentElement.isValid())
        return false;
    for (DomElement domElement : myChildDescription.getStableValues(myParentElement)) {
        final DomElementAnnotationsManager annotationsManager = DomElementAnnotationsManager.getInstance(getProject());
        final DomElementsProblemsHolder holder = annotationsManager.getCachedProblemHolder(domElement);
        final List<DomElementProblemDescriptor> problems = holder.getProblems(domElement, true, HighlightSeverity.ERROR);
        if (problems.size() > 0)
            return true;
    }
    return false;
}
Also used : DomElementsProblemsHolder(com.intellij.util.xml.highlighting.DomElementsProblemsHolder) DomElement(com.intellij.util.xml.DomElement) DomElementProblemDescriptor(com.intellij.util.xml.highlighting.DomElementProblemDescriptor) DomElementAnnotationsManager(com.intellij.util.xml.highlighting.DomElementAnnotationsManager)

Example 4 with DomElementsProblemsHolder

use of com.intellij.util.xml.highlighting.DomElementsProblemsHolder in project intellij-community by JetBrains.

the class ComboControl method updateComponent.

@Override
protected void updateComponent() {
    final DomElement domElement = getDomElement();
    if (domElement == null || !domElement.isValid())
        return;
    final JComboBox comboBox = getComponent();
    final Project project = getProject();
    ApplicationManager.getApplication().invokeLater(() -> {
        if (!project.isOpen())
            return;
        if (!getDomWrapper().isValid())
            return;
        final DomElement domElement1 = getDomElement();
        if (domElement1 == null || !domElement1.isValid())
            return;
        final DomElementAnnotationsManager manager = DomElementAnnotationsManager.getInstance(project);
        final DomElementsProblemsHolder holder = manager.getCachedProblemHolder(domElement1);
        final List<DomElementProblemDescriptor> errorProblems = holder.getProblems(domElement1);
        final List<DomElementProblemDescriptor> warningProblems = holder.getProblems(domElement1, true, HighlightSeverity.WARNING);
        Color background = getDefaultBackground();
        comboBox.setToolTipText(null);
        if (errorProblems.size() > 0) {
            background = getErrorBackground();
            comboBox.setToolTipText(TooltipUtils.getTooltipText(errorProblems));
        } else if (warningProblems.size() > 0) {
            background = getWarningBackground();
            comboBox.setToolTipText(TooltipUtils.getTooltipText(warningProblems));
        }
        final Pair<String, Icon> pair = (Pair<String, Icon>) comboBox.getSelectedItem();
        final String s = pair == null ? null : pair.first;
        background = s != null && s.trim().length() > 0 ? getDefaultBackground() : background;
        comboBox.setBackground(background);
        comboBox.getEditor().getEditorComponent().setBackground(background);
    });
}
Also used : Project(com.intellij.openapi.project.Project) DomElementsProblemsHolder(com.intellij.util.xml.highlighting.DomElementsProblemsHolder) DomElementProblemDescriptor(com.intellij.util.xml.highlighting.DomElementProblemDescriptor) JBColor(com.intellij.ui.JBColor) DomElementAnnotationsManager(com.intellij.util.xml.highlighting.DomElementAnnotationsManager) Pair(com.intellij.openapi.util.Pair)

Example 5 with DomElementsProblemsHolder

use of com.intellij.util.xml.highlighting.DomElementsProblemsHolder in project intellij-community by JetBrains.

the class BaseDomElementNode method doUpdate.

@Override
protected void doUpdate() {
    if (!myDomElement.isValid())
        return;
    final Project project = myDomElement.getManager().getProject();
    if (project.isDisposed())
        return;
    setUniformIcon(getNodeIcon());
    clearColoredText();
    final DomElementAnnotationsManager manager = DomElementAnnotationsManager.getInstance(project);
    final DomElementsProblemsHolder holder = manager.getCachedProblemHolder(myDomElement);
    final List<DomElementProblemDescriptor> problems = holder.getProblems(myDomElement, highlightIfChildrenHaveProblems(), HighlightSeverity.ERROR);
    if (problems.size() > 0) {
        final String toolTip = TooltipUtils.getTooltipText(problems);
        addColoredFragment(getNodeName(), toolTip, getWavedAttributes(SimpleTextAttributes.STYLE_PLAIN));
        if (isShowContainingFileInfo()) {
            addColoredFragment(" (" + DomUtil.getFile(myDomElement).getName() + ")", toolTip, SimpleTextAttributes.GRAY_ATTRIBUTES);
        }
    } else if (myDomElement.getXmlTag() == null && !(myDomElement instanceof DomFileElement)) {
        addColoredFragment(getNodeName(), folder ? SimpleTextAttributes.GRAYED_BOLD_ATTRIBUTES : SimpleTextAttributes.GRAYED_ATTRIBUTES);
    } else if (folder) {
        addColoredFragment(getNodeName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
        final int childrenCount = getChildren().length;
        addColoredFragment(" (" + childrenCount + ')', SimpleTextAttributes.GRAY_ATTRIBUTES);
    } else {
        addColoredFragment(getNodeName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
        if (isShowContainingFileInfo()) {
            addColoredFragment(" (" + DomUtil.getFile(myDomElement).getName() + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) DomElementsProblemsHolder(com.intellij.util.xml.highlighting.DomElementsProblemsHolder) DomElementProblemDescriptor(com.intellij.util.xml.highlighting.DomElementProblemDescriptor) DomElementAnnotationsManager(com.intellij.util.xml.highlighting.DomElementAnnotationsManager)

Aggregations

DomElementProblemDescriptor (com.intellij.util.xml.highlighting.DomElementProblemDescriptor)6 DomElementsProblemsHolder (com.intellij.util.xml.highlighting.DomElementsProblemsHolder)6 DomElementAnnotationsManager (com.intellij.util.xml.highlighting.DomElementAnnotationsManager)5 Project (com.intellij.openapi.project.Project)3 DomElement (com.intellij.util.xml.DomElement)3 ArrayList (java.util.ArrayList)2 Editor (com.intellij.openapi.editor.Editor)1 MarkupModel (com.intellij.openapi.editor.markup.MarkupModel)1 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)1 Pair (com.intellij.openapi.util.Pair)1 XmlTag (com.intellij.psi.xml.XmlTag)1 EditorTextField (com.intellij.ui.EditorTextField)1 JBColor (com.intellij.ui.JBColor)1 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)1 Nullable (org.jetbrains.annotations.Nullable)1