Search in sources :

Example 6 with IComponent

use of com.intellij.uiDesigner.lw.IComponent in project intellij-community by JetBrains.

the class SelectAllComponentsAction method actionPerformed.

protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) {
    final ComponentTreeBuilder builder = DesignerToolWindowManager.getInstance(editor).getComponentTreeBuilder();
    builder.beginUpdateSelection();
    try {
        FormEditingUtil.iterate(editor.getRootContainer(), new FormEditingUtil.ComponentVisitor() {

            public boolean visit(final IComponent component) {
                ((RadComponent) component).setSelected(true);
                return true;
            }
        });
    } finally {
        builder.endUpdateSelection();
    }
}
Also used : IComponent(com.intellij.uiDesigner.lw.IComponent) FormEditingUtil(com.intellij.uiDesigner.FormEditingUtil) ComponentTreeBuilder(com.intellij.uiDesigner.componentTree.ComponentTreeBuilder)

Example 7 with IComponent

use of com.intellij.uiDesigner.lw.IComponent in project intellij-community by JetBrains.

the class ComponentEditor method collectFilteredComponents.

protected RadComponent[] collectFilteredComponents(final RadComponent component) {
    final ArrayList<RadComponent> result = new ArrayList<>();
    result.add(null);
    RadContainer container = component.getParent();
    while (container.getParent() != null) {
        container = container.getParent();
    }
    FormEditingUtil.iterate(container, new FormEditingUtil.ComponentVisitor() {

        public boolean visit(final IComponent component) {
            RadComponent radComponent = (RadComponent) component;
            final JComponent delegee = radComponent.getDelegee();
            if (!myPropertyType.isInstance(delegee)) {
                return true;
            }
            if (myFilter == null || myFilter.value(radComponent)) {
                result.add(radComponent);
            }
            return true;
        }
    });
    return result.toArray(new RadComponent[result.size()]);
}
Also used : IComponent(com.intellij.uiDesigner.lw.IComponent) ArrayList(java.util.ArrayList) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) FormEditingUtil(com.intellij.uiDesigner.FormEditingUtil) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

Example 8 with IComponent

use of com.intellij.uiDesigner.lw.IComponent in project intellij-community by JetBrains.

the class AssignMnemonicFix method fillMnemonicVariants.

private String[] fillMnemonicVariants(final String value) {
    final StringBuffer usedMnemonics = new StringBuffer();
    RadContainer container = myComponent.getParent();
    if (container != null) {
        while (container.getParent() != null) {
            container = container.getParent();
        }
        FormEditingUtil.iterate(container, new FormEditingUtil.ComponentVisitor() {

            public boolean visit(final IComponent component) {
                SupportCode.TextWithMnemonic twm = DuplicateMnemonicInspection.getTextWithMnemonic(myEditor.getModule(), component);
                if (twm != null) {
                    usedMnemonics.append(twm.getMnemonicChar());
                }
                return true;
            }
        });
    }
    ArrayList<String> variants = new ArrayList<>();
    // try upper-case and word start characters
    for (int i = 0; i < value.length(); i++) {
        final char ch = value.charAt(i);
        if (i == 0 || Character.isUpperCase(ch) || (i > 0 && value.charAt(i - 1) == ' ')) {
            if (Character.isLetter(ch) && usedMnemonics.indexOf(String.valueOf(ch).toUpperCase()) < 0) {
                variants.add(value.substring(0, i) + "&" + value.substring(i));
            }
        }
    }
    if (variants.size() == 0) {
        // try any unused characters
        for (int i = 0; i < value.length(); i++) {
            final char ch = value.charAt(i);
            if (Character.isLetter(ch) && usedMnemonics.indexOf(String.valueOf(ch).toUpperCase()) < 0) {
                variants.add(value.substring(0, i) + "&" + value.substring(i));
            }
        }
    }
    if (variants.size() == 0) {
        variants.add(value);
    }
    return ArrayUtil.toStringArray(variants);
}
Also used : IComponent(com.intellij.uiDesigner.lw.IComponent) ArrayList(java.util.ArrayList) FormEditingUtil(com.intellij.uiDesigner.FormEditingUtil) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

Example 9 with IComponent

use of com.intellij.uiDesigner.lw.IComponent in project intellij-community by JetBrains.

the class BaseFormInspection method checkFile.

@Override
@Nullable
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
    if (!file.getFileType().equals(StdFileTypes.GUI_DESIGNER_FORM)) {
        return null;
    }
    final VirtualFile virtualFile = file.getVirtualFile();
    if (virtualFile == null) {
        return null;
    }
    final Module module = ModuleUtil.findModuleForFile(virtualFile, file.getProject());
    if (module == null) {
        return null;
    }
    final LwRootContainer rootContainer;
    try {
        rootContainer = Utils.getRootContainer(file.getText(), new PsiPropertiesProvider(module));
    } catch (Exception e) {
        return null;
    }
    if (rootContainer.isInspectionSuppressed(getShortName(), null)) {
        return null;
    }
    final FormFileErrorCollector collector = new FormFileErrorCollector(file, manager, isOnTheFly);
    startCheckForm(rootContainer);
    FormEditingUtil.iterate(rootContainer, new FormEditingUtil.ComponentVisitor() {

        @Override
        public boolean visit(final IComponent component) {
            if (!rootContainer.isInspectionSuppressed(getShortName(), component.getId())) {
                checkComponentProperties(module, component, collector);
            }
            return true;
        }
    });
    doneCheckForm(rootContainer);
    return collector.result();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IComponent(com.intellij.uiDesigner.lw.IComponent) LwRootContainer(com.intellij.uiDesigner.lw.LwRootContainer) Module(com.intellij.openapi.module.Module) PsiPropertiesProvider(com.intellij.uiDesigner.PsiPropertiesProvider) FormEditingUtil(com.intellij.uiDesigner.FormEditingUtil) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with IComponent

use of com.intellij.uiDesigner.lw.IComponent in project intellij-community by JetBrains.

the class PasteProcessor method doPaste.

private void doPaste(final ComponentDropLocation location) {
    if (location.canDrop(myPastedComponentList) && myEditor.ensureEditable()) {
        final RadComponent[] componentsToPaste = myComponentsToPaste.toArray(new RadComponent[myComponentsToPaste.size()]);
        CommandProcessor.getInstance().executeCommand(myEditor.getProject(), () -> {
            location.processDrop(myEditor, componentsToPaste, null, myPastedComponentList);
            for (RadComponent c : componentsToPaste) {
                FormEditingUtil.iterate(c, new FormEditingUtil.ComponentVisitor() {

                    public boolean visit(final IComponent component) {
                        if (component.getBinding() != null) {
                            InsertComponentProcessor.createBindingField(myEditor, (RadComponent) component);
                        }
                        return true;
                    }
                });
            }
            FormEditingUtil.selectComponents(myEditor, myComponentsToPaste);
            myEditor.refreshAndSave(true);
        }, UIDesignerBundle.message("command.paste"), null);
        endPaste();
    }
}
Also used : IComponent(com.intellij.uiDesigner.lw.IComponent) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) FormEditingUtil(com.intellij.uiDesigner.FormEditingUtil)

Aggregations

IComponent (com.intellij.uiDesigner.lw.IComponent)12 FormEditingUtil (com.intellij.uiDesigner.FormEditingUtil)8 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)6 ArrayList (java.util.ArrayList)4 Ref (com.intellij.openapi.util.Ref)3 IRootContainer (com.intellij.uiDesigner.lw.IRootContainer)3 RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)3 Module (com.intellij.openapi.module.Module)2 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)2 GuiEditor (com.intellij.uiDesigner.designSurface.GuiEditor)2 IContainer (com.intellij.uiDesigner.lw.IContainer)2 IProperty (com.intellij.uiDesigner.lw.IProperty)2 LwRootContainer (com.intellij.uiDesigner.lw.LwRootContainer)2 QuickFix (com.intellij.uiDesigner.quickFixes.QuickFix)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 WordOccurrence (com.intellij.lang.cacheBuilder.WordOccurrence)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 PsiPropertiesProvider (com.intellij.uiDesigner.PsiPropertiesProvider)1 AlienFormFileException (com.intellij.uiDesigner.compiler.AlienFormFileException)1