Search in sources :

Example 1 with IntroComponentProperty

use of com.intellij.uiDesigner.propertyInspector.properties.IntroComponentProperty in project intellij-community by JetBrains.

the class FormEditingUtil method deleteComponents.

public static void deleteComponents(final Collection<? extends RadComponent> selection, boolean deleteEmptyCells) {
    if (selection.size() == 0) {
        return;
    }
    final RadRootContainer rootContainer = (RadRootContainer) getRoot(selection.iterator().next());
    final Set<String> deletedComponentIds = new HashSet<>();
    for (final RadComponent component : selection) {
        boolean wasSelected = component.isSelected();
        final RadContainer parent = component.getParent();
        boolean wasPackedHorz = false;
        boolean wasPackedVert = false;
        if (parent.getParent() != null && parent.getParent().isXY()) {
            final Dimension minSize = parent.getMinimumSize();
            wasPackedHorz = parent.getWidth() == minSize.width;
            wasPackedVert = parent.getHeight() == minSize.height;
        }
        iterate(component, new ComponentVisitor() {

            public boolean visit(final IComponent c) {
                RadComponent rc = (RadComponent) c;
                BindingProperty.checkRemoveUnusedField(rootContainer, rc.getBinding(), null);
                deletedComponentIds.add(rc.getId());
                return true;
            }
        });
        GridConstraints delConstraints = parent.getLayoutManager().isGrid() ? component.getConstraints() : null;
        int index = parent.indexOfComponent(component);
        parent.removeComponent(component);
        if (wasSelected) {
            if (parent.getComponentCount() > index) {
                parent.getComponent(index).setSelected(true);
            } else if (index > 0 && parent.getComponentCount() == index) {
                parent.getComponent(index - 1).setSelected(true);
            } else {
                parent.setSelected(true);
            }
        }
        if (delConstraints != null && deleteEmptyCells) {
            deleteEmptyGridCells(parent, delConstraints);
        }
        if (wasPackedHorz || wasPackedVert) {
            final Dimension minSize = parent.getMinimumSize();
            Dimension newSize = new Dimension(parent.getWidth(), parent.getHeight());
            if (wasPackedHorz) {
                newSize.width = minSize.width;
            }
            if (wasPackedVert) {
                newSize.height = minSize.height;
            }
            parent.setSize(newSize);
        }
    }
    iterate(rootContainer, new ComponentVisitor() {

        public boolean visit(final IComponent component) {
            RadComponent rc = (RadComponent) component;
            for (IProperty p : component.getModifiedProperties()) {
                if (p instanceof IntroComponentProperty) {
                    IntroComponentProperty icp = (IntroComponentProperty) p;
                    final String value = icp.getValue(rc);
                    if (deletedComponentIds.contains(value)) {
                        try {
                            icp.resetValue(rc);
                        } catch (Exception e) {
                        // ignore
                        }
                    }
                }
            }
            return true;
        }
    });
}
Also used : RadRootContainer(com.intellij.uiDesigner.radComponents.RadRootContainer) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) RelativePoint(com.intellij.ui.awt.RelativePoint) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) IncorrectOperationException(com.intellij.util.IncorrectOperationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IntroComponentProperty(com.intellij.uiDesigner.propertyInspector.properties.IntroComponentProperty) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer) HashSet(com.intellij.util.containers.HashSet)

Example 2 with IntroComponentProperty

use of com.intellij.uiDesigner.propertyInspector.properties.IntroComponentProperty in project intellij-community by JetBrains.

the class SnapshotContext method postProcess.

public void postProcess() {
    for (ButtonGroup group : myButtonGroups) {
        RadButtonGroup radButtonGroup = myRootContainer.createGroup(myRootContainer.suggestGroupName());
        Enumeration<AbstractButton> elements = group.getElements();
        while (elements.hasMoreElements()) {
            AbstractButton btn = elements.nextElement();
            RadComponent c = myImportMap.get(btn);
            if (c != null) {
                radButtonGroup.add(c);
            }
        }
    }
    for (ComponentProperty prop : myComponentProperties) {
        RadComponent radOwner = myImportMap.get(prop.owner);
        RadComponent radValue = myImportMap.get(prop.value);
        if (radOwner != null && radValue != null) {
            final IntrospectedProperty property = radOwner.getPalette().getIntrospectedProperty(radOwner, prop.name);
            assert property != null;
            //noinspection unchecked
            IntroComponentProperty icp = (IntroComponentProperty) property;
            try {
                icp.setValue(radOwner, radValue.getId());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
}
Also used : IntroComponentProperty(com.intellij.uiDesigner.propertyInspector.properties.IntroComponentProperty) RadButtonGroup(com.intellij.uiDesigner.radComponents.RadButtonGroup) IntroComponentProperty(com.intellij.uiDesigner.propertyInspector.properties.IntroComponentProperty) RadButtonGroup(com.intellij.uiDesigner.radComponents.RadButtonGroup) IntrospectedProperty(com.intellij.uiDesigner.propertyInspector.IntrospectedProperty) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent)

Example 3 with IntroComponentProperty

use of com.intellij.uiDesigner.propertyInspector.properties.IntroComponentProperty 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)

Aggregations

IntroComponentProperty (com.intellij.uiDesigner.propertyInspector.properties.IntroComponentProperty)3 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)3 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)1 IProperty (com.intellij.uiDesigner.lw.IProperty)1 IntrospectedProperty (com.intellij.uiDesigner.propertyInspector.IntrospectedProperty)1 BindingProperty (com.intellij.uiDesigner.propertyInspector.properties.BindingProperty)1 RadButtonGroup (com.intellij.uiDesigner.radComponents.RadButtonGroup)1 RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)1 RadRootContainer (com.intellij.uiDesigner.radComponents.RadRootContainer)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 HashSet (com.intellij.util.containers.HashSet)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1