Search in sources :

Example 1 with BindingProperty

use of com.intellij.uiDesigner.propertyInspector.properties.BindingProperty 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 2 with BindingProperty

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

Aggregations

IProperty (com.intellij.uiDesigner.lw.IProperty)2 BindingProperty (com.intellij.uiDesigner.propertyInspector.properties.BindingProperty)2 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)2 Palette (com.intellij.uiDesigner.palette.Palette)1 IntrospectedProperty (com.intellij.uiDesigner.propertyInspector.IntrospectedProperty)1 IntroComponentProperty (com.intellij.uiDesigner.propertyInspector.properties.IntroComponentProperty)1 RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1