Search in sources :

Example 1 with QuickFix

use of com.intellij.uiDesigner.quickFixes.QuickFix in project intellij-community by JetBrains.

the class FormSpellCheckingInspection method checkStringDescriptor.

@Override
protected void checkStringDescriptor(Module module, final IComponent component, final IProperty prop, final StringDescriptor descriptor, final FormErrorCollector collector) {
    final String value = descriptor.getResolvedValue();
    if (value == null) {
        return;
    }
    final SpellCheckerManager manager = SpellCheckerManager.getInstance(module.getProject());
    PlainTextSplitter.getInstance().split(value, TextRange.allOf(value), textRange -> {
        final String word = textRange.substring(value);
        if (manager.hasProblem(word)) {
            final List<String> suggestions = manager.getSuggestions(word);
            if (!suggestions.isEmpty() && prop instanceof IntroStringProperty) {
                EditorQuickFixProvider changeToProvider = new EditorQuickFixProvider() {

                    @Override
                    public QuickFix createQuickFix(final GuiEditor editor, final RadComponent component1) {
                        return new PopupQuickFix<String>(editor, "Change to...", component1) {

                            @Override
                            public void run() {
                                ListPopup popup = JBPopupFactory.getInstance().createListPopup(getPopupStep());
                                popup.showUnderneathOf(component1.getDelegee());
                            }

                            @Override
                            public ListPopupStep<String> getPopupStep() {
                                return new BaseListPopupStep<String>("Select Replacement", suggestions) {

                                    @Override
                                    public PopupStep onChosen(String selectedValue, boolean finalChoice) {
                                        FormInspectionUtil.updateStringPropertyValue(editor, component1, (IntroStringProperty) prop, descriptor, selectedValue);
                                        return FINAL_CHOICE;
                                    }
                                };
                            }
                        };
                    }
                };
                EditorQuickFixProvider acceptProvider = new EditorQuickFixProvider() {

                    @Override
                    public QuickFix createQuickFix(final GuiEditor editor, RadComponent component1) {
                        return new QuickFix(editor, "Save '" + word + "' to dictionary", component1) {

                            @Override
                            public void run() {
                                manager.acceptWordAsCorrect(word, editor.getProject());
                            }
                        };
                    }
                };
                collector.addError(getID(), component, prop, "Typo in word '" + word + "'", changeToProvider, acceptProvider);
            } else {
                collector.addError(getID(), component, prop, "Typo in word '" + word + "'");
            }
        }
    });
}
Also used : QuickFix(com.intellij.uiDesigner.quickFixes.QuickFix) PopupQuickFix(com.intellij.uiDesigner.quickFixes.PopupQuickFix) PopupQuickFix(com.intellij.uiDesigner.quickFixes.PopupQuickFix) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) SpellCheckerManager(com.intellij.spellchecker.SpellCheckerManager) IntroStringProperty(com.intellij.uiDesigner.propertyInspector.properties.IntroStringProperty) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) ListPopup(com.intellij.openapi.ui.popup.ListPopup) GuiEditor(com.intellij.uiDesigner.designSurface.GuiEditor)

Example 2 with QuickFix

use of com.intellij.uiDesigner.quickFixes.QuickFix in project intellij-community by JetBrains.

the class NoButtonGroupInspection method checkComponentProperties.

@Override
protected void checkComponentProperties(Module module, IComponent component, FormErrorCollector collector) {
    if (FormInspectionUtil.isComponentClass(module, component, JRadioButton.class)) {
        final IRootContainer root = FormEditingUtil.getRoot(component);
        if (root == null)
            return;
        if (root.getButtonGroupName(component) == null) {
            EditorQuickFixProvider quickFixProvider = null;
            IContainer parent = component.getParentContainer();
            for (int i = 0; i < parent.getComponentCount(); i++) {
                IComponent child = parent.getComponent(i);
                if (child != component && FormInspectionUtil.isComponentClass(module, child, JRadioButton.class)) {
                    final GridConstraints c1 = component.getConstraints();
                    final GridConstraints c2 = child.getConstraints();
                    if (areCellsAdjacent(parent, c1, c2)) {
                        final String groupName = root.getButtonGroupName(child);
                        if (groupName == null) {
                            quickFixProvider = new EditorQuickFixProvider() {

                                @Override
                                public QuickFix createQuickFix(GuiEditor editor, RadComponent component) {
                                    return new CreateGroupQuickFix(editor, component, c1.getColumn() == c2.getColumn());
                                }
                            };
                            break;
                        } else {
                            quickFixProvider = new EditorQuickFixProvider() {

                                @Override
                                public QuickFix createQuickFix(GuiEditor editor, RadComponent component) {
                                    return new AddToGroupQuickFix(editor, component, groupName);
                                }
                            };
                        }
                    }
                }
            }
            collector.addError(getID(), component, null, UIDesignerBundle.message("inspection.no.button.group.error"), quickFixProvider);
        }
    }
}
Also used : QuickFix(com.intellij.uiDesigner.quickFixes.QuickFix) IComponent(com.intellij.uiDesigner.lw.IComponent) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) GuiEditor(com.intellij.uiDesigner.designSurface.GuiEditor) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) IRootContainer(com.intellij.uiDesigner.lw.IRootContainer) IContainer(com.intellij.uiDesigner.lw.IContainer)

Example 3 with QuickFix

use of com.intellij.uiDesigner.quickFixes.QuickFix in project intellij-community by JetBrains.

the class I18nFormInspection method checkStringDescriptor.

@Override
protected void checkStringDescriptor(final Module module, final IComponent component, final IProperty prop, final StringDescriptor descriptor, final FormErrorCollector collector) {
    if (isHardCodedStringDescriptor(descriptor)) {
        if (isPropertyDescriptor(prop)) {
            if (isSetterNonNls(module.getProject(), GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module), component.getComponentClassName(), prop.getName())) {
                return;
            }
        }
        EditorQuickFixProvider provider;
        if (prop.getName().equals(BorderProperty.NAME)) {
            provider = new EditorQuickFixProvider() {

                @Override
                public QuickFix createQuickFix(GuiEditor editor, RadComponent component) {
                    return new I18nizeFormBorderQuickFix(editor, UIDesignerBundle.message("i18n.quickfix.border.title"), (RadContainer) component);
                }
            };
        } else if (prop.getName().equals(ITabbedPane.TAB_TITLE_PROPERTY) || prop.getName().equals(ITabbedPane.TAB_TOOLTIP_PROPERTY)) {
            provider = new EditorQuickFixProvider() {

                @Override
                public QuickFix createQuickFix(GuiEditor editor, RadComponent component) {
                    return new I18nizeTabTitleQuickFix(editor, UIDesignerBundle.message("i18n.quickfix.tab.title", prop.getName()), component, prop.getName());
                }
            };
        } else {
            provider = new EditorQuickFixProvider() {

                @Override
                public QuickFix createQuickFix(GuiEditor editor, RadComponent component) {
                    return new I18nizeFormPropertyQuickFix(editor, UIDesignerBundle.message("i18n.quickfix.property", prop.getName()), component, (IntrospectedProperty) prop);
                }
            };
        }
        collector.addError(getID(), component, prop, UIDesignerBundle.message("inspection.i18n.message.in.form", descriptor.getValue()), provider);
    }
}
Also used : QuickFix(com.intellij.uiDesigner.quickFixes.QuickFix) EditorQuickFixProvider(com.intellij.uiDesigner.inspections.EditorQuickFixProvider) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) GuiEditor(com.intellij.uiDesigner.designSurface.GuiEditor) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

Example 4 with QuickFix

use of com.intellij.uiDesigner.quickFixes.QuickFix in project intellij-community by JetBrains.

the class FormEditorErrorCollector method addError.

public void addError(@NotNull final String inspectionId, final IComponent component, @Nullable IProperty prop, @NotNull String errorMessage, EditorQuickFixProvider... editorQuickFixProviders) {
    if (myResults == null) {
        myResults = new ArrayList<>();
    }
    List<QuickFix> quickFixes = new ArrayList<>();
    for (EditorQuickFixProvider provider : editorQuickFixProviders) {
        if (provider != null) {
            quickFixes.add(provider.createQuickFix(myEditor, myComponent));
        }
    }
    final ErrorInfo errorInfo = new ErrorInfo(myComponent, prop == null ? null : prop.getName(), errorMessage, myProfile.getErrorLevel(HighlightDisplayKey.find(inspectionId), myFormPsiFile), quickFixes.toArray(new QuickFix[quickFixes.size()]));
    errorInfo.setInspectionId(inspectionId);
    myResults.add(errorInfo);
}
Also used : QuickFix(com.intellij.uiDesigner.quickFixes.QuickFix) ErrorInfo(com.intellij.uiDesigner.ErrorInfo) ArrayList(java.util.ArrayList)

Example 5 with QuickFix

use of com.intellij.uiDesigner.quickFixes.QuickFix 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

QuickFix (com.intellij.uiDesigner.quickFixes.QuickFix)5 GuiEditor (com.intellij.uiDesigner.designSurface.GuiEditor)4 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)4 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)2 IComponent (com.intellij.uiDesigner.lw.IComponent)2 ArrayList (java.util.ArrayList)2 ListPopup (com.intellij.openapi.ui.popup.ListPopup)1 BaseListPopupStep (com.intellij.openapi.ui.popup.util.BaseListPopupStep)1 Ref (com.intellij.openapi.util.Ref)1 SpellCheckerManager (com.intellij.spellchecker.SpellCheckerManager)1 ErrorInfo (com.intellij.uiDesigner.ErrorInfo)1 FormEditingUtil (com.intellij.uiDesigner.FormEditingUtil)1 EditorQuickFixProvider (com.intellij.uiDesigner.inspections.EditorQuickFixProvider)1 IContainer (com.intellij.uiDesigner.lw.IContainer)1 IProperty (com.intellij.uiDesigner.lw.IProperty)1 IRootContainer (com.intellij.uiDesigner.lw.IRootContainer)1 ComponentItem (com.intellij.uiDesigner.palette.ComponentItem)1 IntroStringProperty (com.intellij.uiDesigner.propertyInspector.properties.IntroStringProperty)1 PopupQuickFix (com.intellij.uiDesigner.quickFixes.PopupQuickFix)1 RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)1