Search in sources :

Example 21 with GuiEditor

use of com.intellij.uiDesigner.designSurface.GuiEditor in project intellij-community by JetBrains.

the class NoLabelForInspection method checkComponentProperties.

@Override
protected void checkComponentProperties(final Module module, final IComponent component, FormErrorCollector collector) {
    ComponentItem item = Palette.getInstance(module.getProject()).getItem(component.getComponentClassName());
    if (item != null && item.isCanAttachLabel()) {
        IComponent root = component;
        while (root.getParentContainer() != null) {
            root = root.getParentContainer();
        }
        final Ref<Boolean> found = new Ref<>(Boolean.FALSE);
        final Ref<RadComponent> candidateLabel = new Ref<>();
        final List<RadComponent> allLabels = new ArrayList<>();
        FormEditingUtil.iterate(root, new FormEditingUtil.ComponentVisitor() {

            @Override
            public boolean visit(final IComponent c2) {
                if (FormInspectionUtil.isComponentClass(module, c2, JLabel.class)) {
                    IProperty prop = FormInspectionUtil.findProperty(c2, SwingProperties.LABEL_FOR);
                    if (prop != null && component.getId().equals(prop.getPropertyValue(c2))) {
                        found.set(Boolean.TRUE);
                        return false;
                    } else if (component instanceof RadComponent && (prop == null || StringUtil.isEmpty((String) prop.getPropertyValue(c2)))) {
                        RadComponent radComponent = (RadComponent) component;
                        final RadComponent radComponent2 = (RadComponent) c2;
                        allLabels.add(radComponent2);
                        if (radComponent.getParent() == radComponent2.getParent() && radComponent.getParent().getLayoutManager().isGrid()) {
                            GridConstraints gc1 = radComponent.getConstraints();
                            GridConstraints gc2 = radComponent2.getConstraints();
                            int nextColumn = FormEditingUtil.nextCol(radComponent.getParent(), gc2.getColumn());
                            int nextRow = FormEditingUtil.nextRow(radComponent.getParent(), gc2.getRow());
                            if (gc1.getRow() == gc2.getRow() && nextColumn == gc1.getColumn() || gc1.getColumn() == gc2.getColumn() && nextRow == gc1.getRow()) {
                                candidateLabel.set(radComponent2);
                            }
                        }
                    }
                }
                return true;
            }
        });
        if (!found.get().booleanValue()) {
            if (!candidateLabel.isNull()) {
                allLabels.clear();
                allLabels.add(candidateLabel.get());
            }
            EditorQuickFixProvider[] quickFixProviders = new EditorQuickFixProvider[allLabels.size()];
            for (int i = 0; i < quickFixProviders.length; i++) {
                final RadComponent label = allLabels.get(i);
                quickFixProviders[i] = new EditorQuickFixProvider() {

                    @Override
                    public QuickFix createQuickFix(GuiEditor editor, RadComponent component) {
                        return new MyQuickFix(editor, component, label);
                    }
                };
            }
            collector.addError(getID(), component, null, UIDesignerBundle.message("inspection.no.label.for.error"), quickFixProviders);
        }
    }
}
Also used : ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) QuickFix(com.intellij.uiDesigner.quickFixes.QuickFix) IComponent(com.intellij.uiDesigner.lw.IComponent) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) ArrayList(java.util.ArrayList) GuiEditor(com.intellij.uiDesigner.designSurface.GuiEditor) Ref(com.intellij.openapi.util.Ref) IProperty(com.intellij.uiDesigner.lw.IProperty) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) FormEditingUtil(com.intellij.uiDesigner.FormEditingUtil)

Aggregations

GuiEditor (com.intellij.uiDesigner.designSurface.GuiEditor)21 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)8 QuickFix (com.intellij.uiDesigner.quickFixes.QuickFix)4 SelectionState (com.intellij.uiDesigner.SelectionState)3 IComponent (com.intellij.uiDesigner.lw.IComponent)3 RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)3 Presentation (com.intellij.openapi.actionSystem.Presentation)2 Project (com.intellij.openapi.project.Project)2 ListPopup (com.intellij.openapi.ui.popup.ListPopup)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 CaptionSelection (com.intellij.uiDesigner.CaptionSelection)2 FormEditingUtil (com.intellij.uiDesigner.FormEditingUtil)2 ComponentTreeBuilder (com.intellij.uiDesigner.componentTree.ComponentTreeBuilder)2 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)2 IProperty (com.intellij.uiDesigner.lw.IProperty)2 ComponentItem (com.intellij.uiDesigner.palette.ComponentItem)2 NotNull (org.jetbrains.annotations.NotNull)2 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 CommandProcessor (com.intellij.openapi.command.CommandProcessor)1