@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); } } }
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; }
private void validate() { DomElement domElement = getDomElement(); final List<DomElementProblemDescriptor> list = DomElementAnnotationsManager.getInstance(getProject()).getCachedProblemHolder(domElement).getProblems(domElement); final List<String> messages = new ArrayList<String>(); for (final DomElementProblemDescriptor descriptor : list) { if (descriptor instanceof DomCollectionProblemDescriptor && myChildDescription.equals(((DomCollectionProblemDescriptor)descriptor).getChildDescription())) { messages.add(descriptor.getDescriptionTemplate()); } } myCollectionPanel.setErrorMessages(ArrayUtil.toStringArray(messages)); myCollectionPanel.repaint(); }
public DomFileEditor(final Project project, final VirtualFile file, final String name, final Factory<? extends T> component) { super(project, file); myComponentFactory = component; myName = name; DomElementAnnotationsManager.getInstance(project).addHighlightingListener(new DomElementAnnotationsManager.DomHighlightingListener() { @Override public void highlightingFinished(@NotNull DomFileElement element) { if (isInitialised() && getComponent().isShowing() && element.isValid()) { updateHighlighting(); } } }, this); }
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); } } }
public DomFileEditor(final Project project, final VirtualFile file, final String name, final Factory<? extends T> component) { super(project, file); myComponentFactory = component; myName = name; DomElementAnnotationsManager.getInstance(project).addHighlightingListener(new DomElementAnnotationsManager.DomHighlightingListener() { public void highlightingFinished(@NotNull DomFileElement element) { if (isInitialised() && getComponent().isShowing() && element.isValid()) { updateHighlighting(); } } }, this); }
public void testResolveProblemsAreReportedOnlyOnce() throws Throwable { final MyElement myElement = createElement("<a><my-class>abc</my-class></a>", MyElement.class); new MockDomInspection(MyElement.class).checkFile(DomUtil.getFile(myElement), InspectionManager.getInstance(getProject()), true); final DomElementsProblemsHolder holder = DomElementAnnotationsManager.getInstance(getProject()).getProblemHolder(myElement); final DomElement element = myElement.getMyClass(); assertEquals(0, holder.getProblems(myElement).size()); assertEquals(0, holder.getProblems(myElement).size()); assertEquals(1, holder.getProblems(element).size()); assertEquals(1, holder.getProblems(element).size()); assertEquals(1, holder.getProblems(myElement, true, true).size()); assertEquals(1, holder.getProblems(myElement, true, true).size()); }
@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<DomElementProblemDescriptor>(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; }
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<DomElementProblemDescriptor>(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; }