Search in sources :

Example 6 with IProperty

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

the class DuplicateComponentsAction method adjustDuplicates.

private static void adjustDuplicates(final Map<RadComponent, RadComponent> duplicates) {
    for (RadComponent c : duplicates.keySet()) {
        RadComponent copy = duplicates.get(c);
        if (c.getBinding() != null) {
            String binding = BindingProperty.getDefaultBinding(copy);
            new BindingProperty(c.getProject()).setValueEx(copy, binding);
            copy.setDefaultBinding(true);
        }
        for (IProperty prop : copy.getModifiedProperties()) {
            if (prop instanceof IntroComponentProperty) {
                final IntroComponentProperty componentProperty = (IntroComponentProperty) prop;
                String copyValue = componentProperty.getValue(copy);
                for (RadComponent original : duplicates.keySet()) {
                    if (original.getId().equals(copyValue)) {
                        componentProperty.setValueEx(copy, duplicates.get(original).getId());
                    }
                }
            }
        }
    }
}
Also used : IntroComponentProperty(com.intellij.uiDesigner.propertyInspector.properties.IntroComponentProperty) IProperty(com.intellij.uiDesigner.lw.IProperty) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) BindingProperty(com.intellij.uiDesigner.propertyInspector.properties.BindingProperty)

Example 7 with IProperty

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

the class MorphAction method morphComponent.

private static boolean morphComponent(final GuiEditor editor, final RadComponent oldComponent, ComponentItem targetItem) {
    targetItem = InsertComponentProcessor.replaceAnyComponentItem(editor, targetItem, "Morph to Non-Palette Component");
    if (targetItem == null) {
        return false;
    }
    final RadComponent newComponent = InsertComponentProcessor.createInsertedComponent(editor, targetItem);
    if (newComponent == null)
        return false;
    newComponent.setBinding(oldComponent.getBinding());
    newComponent.setCustomLayoutConstraints(oldComponent.getCustomLayoutConstraints());
    newComponent.getConstraints().restore(oldComponent.getConstraints());
    updateBoundFieldType(editor, oldComponent, targetItem);
    final IProperty[] oldProperties = oldComponent.getModifiedProperties();
    final Palette palette = Palette.getInstance(editor.getProject());
    for (IProperty prop : oldProperties) {
        IntrospectedProperty newProp = palette.getIntrospectedProperty(newComponent, prop.getName());
        if (newProp == null || !prop.getClass().equals(newProp.getClass()))
            continue;
        Object oldValue = prop.getPropertyValue(oldComponent);
        try {
            //noinspection unchecked
            newProp.setValue(newComponent, oldValue);
        } catch (Exception e) {
        // ignore
        }
    }
    retargetComponentProperties(editor, oldComponent, newComponent);
    final RadContainer parent = oldComponent.getParent();
    int index = parent.indexOfComponent(oldComponent);
    parent.removeComponent(oldComponent);
    parent.addComponent(newComponent, index);
    newComponent.setSelected(true);
    if (oldComponent.isDefaultBinding()) {
        final String text = FormInspectionUtil.getText(newComponent.getModule(), newComponent);
        if (text != null) {
            String binding = BindingProperty.suggestBindingFromText(newComponent, text);
            if (binding != null) {
                new BindingProperty(newComponent.getProject()).setValueEx(newComponent, binding);
            }
        }
        newComponent.setDefaultBinding(true);
    }
    return true;
}
Also used : Palette(com.intellij.uiDesigner.palette.Palette) IProperty(com.intellij.uiDesigner.lw.IProperty) IntrospectedProperty(com.intellij.uiDesigner.propertyInspector.IntrospectedProperty) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) BindingProperty(com.intellij.uiDesigner.propertyInspector.properties.BindingProperty) IncorrectOperationException(com.intellij.util.IncorrectOperationException) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

Example 8 with IProperty

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

the class MissingMnemonicInspection method checkComponentProperties.

@Override
protected void checkComponentProperties(Module module, IComponent component, FormErrorCollector collector) {
    String value = FormInspectionUtil.getText(module, component);
    if (value == null) {
        return;
    }
    IProperty textProperty = FormInspectionUtil.findProperty(component, SwingProperties.TEXT);
    SupportCode.TextWithMnemonic twm = SupportCode.parseText(value);
    if (twm.myMnemonicIndex < 0 && !twm.myText.isEmpty()) {
        if (FormInspectionUtil.isComponentClass(module, component, AbstractButton.class)) {
            collector.addError(getID(), component, textProperty, UIDesignerBundle.message("inspection.missing.mnemonics.message", value), new MyEditorQuickFixProvider());
        } else if (FormInspectionUtil.isComponentClass(module, component, JLabel.class)) {
            IProperty labelForProperty = FormInspectionUtil.findProperty(component, SwingProperties.LABEL_FOR);
            if (labelForProperty != null && !StringUtil.isEmpty((String) labelForProperty.getPropertyValue(component))) {
                collector.addError(getID(), component, textProperty, UIDesignerBundle.message("inspection.missing.mnemonics.message", value), new MyEditorQuickFixProvider());
            }
        }
    }
}
Also used : IProperty(com.intellij.uiDesigner.lw.IProperty) SupportCode(com.intellij.uiDesigner.core.SupportCode)

Example 9 with IProperty

use of com.intellij.uiDesigner.lw.IProperty 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)

Example 10 with IProperty

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

the class GuiEditor method refreshProperties.

private void refreshProperties() {
    final Ref<Boolean> anythingModified = new Ref<>();
    FormEditingUtil.iterate(myRootContainer, new FormEditingUtil.ComponentVisitor() {

        public boolean visit(final IComponent component) {
            final RadComponent radComponent = (RadComponent) component;
            boolean componentModified = false;
            for (IProperty prop : component.getModifiedProperties()) {
                if (prop instanceof IntroStringProperty) {
                    IntroStringProperty strProp = (IntroStringProperty) prop;
                    componentModified = strProp.refreshValue(radComponent) || componentModified;
                }
            }
            if (component instanceof RadContainer) {
                componentModified = ((RadContainer) component).updateBorder() || componentModified;
            }
            if (component.getParentContainer() instanceof RadTabbedPane) {
                componentModified = ((RadTabbedPane) component.getParentContainer()).refreshChildTitle(radComponent) || componentModified;
            }
            if (componentModified) {
                anythingModified.set(Boolean.TRUE);
            }
            return true;
        }
    });
    if (!anythingModified.isNull()) {
        refresh();
        DesignerToolWindow designerToolWindow = DesignerToolWindowManager.getInstance(this);
        ComponentTree tree = designerToolWindow.getComponentTree();
        if (tree != null)
            tree.repaint();
        PropertyInspector inspector = designerToolWindow.getPropertyInspector();
        if (inspector != null)
            inspector.synchWithTree(true);
    }
}
Also used : IComponent(com.intellij.uiDesigner.lw.IComponent) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) DesignerToolWindow(com.intellij.uiDesigner.propertyInspector.DesignerToolWindow) PropertyInspector(com.intellij.uiDesigner.propertyInspector.PropertyInspector) ComponentTree(com.intellij.uiDesigner.componentTree.ComponentTree) Ref(com.intellij.openapi.util.Ref) RadTabbedPane(com.intellij.uiDesigner.radComponents.RadTabbedPane) IProperty(com.intellij.uiDesigner.lw.IProperty) IntroStringProperty(com.intellij.uiDesigner.propertyInspector.properties.IntroStringProperty) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

Aggregations

IProperty (com.intellij.uiDesigner.lw.IProperty)10 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)5 StringDescriptor (com.intellij.uiDesigner.lw.StringDescriptor)3 Ref (com.intellij.openapi.util.Ref)2 IComponent (com.intellij.uiDesigner.lw.IComponent)2 BindingProperty (com.intellij.uiDesigner.propertyInspector.properties.BindingProperty)2 RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)2 LanguageLevel (com.intellij.pom.java.LanguageLevel)1 PsiClass (com.intellij.psi.PsiClass)1 PsiManager (com.intellij.psi.PsiManager)1 PsiMethod (com.intellij.psi.PsiMethod)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 FormEditingUtil (com.intellij.uiDesigner.FormEditingUtil)1 ComponentTree (com.intellij.uiDesigner.componentTree.ComponentTree)1 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)1 SupportCode (com.intellij.uiDesigner.core.SupportCode)1 GuiEditor (com.intellij.uiDesigner.designSurface.GuiEditor)1 ComponentItem (com.intellij.uiDesigner.palette.ComponentItem)1 Palette (com.intellij.uiDesigner.palette.Palette)1 DesignerToolWindow (com.intellij.uiDesigner.propertyInspector.DesignerToolWindow)1