Search in sources :

Example 6 with RadRootContainer

use of com.intellij.uiDesigner.radComponents.RadRootContainer in project intellij-community by JetBrains.

the class ComponentTreeStructure method getChildElements.

public Object[] getChildElements(final Object element) {
    if (element == myRootElement) {
        ArrayList<Object> elements = new ArrayList<>();
        final RadRootContainer rootContainer = myEditor.getRootContainer();
        elements.add(new ComponentPtr(myEditor, rootContainer));
        final LwInspectionSuppression[] suppressions = rootContainer.getInspectionSuppressions();
        if (suppressions.length > 0) {
            elements.add(suppressions);
        }
        RadButtonGroup[] buttonGroups = rootContainer.getButtonGroups();
        if (buttonGroups.length > 0) {
            elements.add(buttonGroups);
        }
        return elements.toArray();
    } else if (element instanceof ComponentPtr) {
        final ComponentPtr ptr = (ComponentPtr) element;
        // pointer must be valid
        LOG.assertTrue(ptr.isValid());
        final RadComponent component = ptr.getComponent();
        if (component instanceof RadContainer) {
            final RadContainer container = (RadContainer) component;
            final ComponentPtr[] ptrs = new ComponentPtr[container.getComponentCount()];
            for (int i = 0; i < ptrs.length; i++) {
                ptrs[i] = new ComponentPtr(myEditor, container.getComponent(i));
            }
            return ptrs;
        } else {
            return ourEmptyObjectArray;
        }
    } else if (element instanceof LwInspectionSuppression[]) {
        ArrayList<LwInspectionSuppression> result = new ArrayList<>();
        for (LwInspectionSuppression suppression : (LwInspectionSuppression[]) element) {
            if (suppression.getComponentId() == null || FormEditingUtil.findComponent(myEditor.getRootContainer(), suppression.getComponentId()) != null) {
                result.add(suppression);
            }
        }
        return ArrayUtil.toObjectArray(result);
    } else if (element instanceof RadButtonGroup[]) {
        return (RadButtonGroup[]) element;
    } else if (element instanceof LwInspectionSuppression || element instanceof RadButtonGroup) {
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    } else {
        throw new IllegalArgumentException("unknown element: " + element);
    }
}
Also used : LwInspectionSuppression(com.intellij.uiDesigner.lw.LwInspectionSuppression) ArrayList(java.util.ArrayList) RadRootContainer(com.intellij.uiDesigner.radComponents.RadRootContainer) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) RadButtonGroup(com.intellij.uiDesigner.radComponents.RadButtonGroup) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

Example 7 with RadRootContainer

use of com.intellij.uiDesigner.radComponents.RadRootContainer in project intellij-community by JetBrains.

the class ComponentTreeStructure method getParentElement.

public Object getParentElement(final Object element) {
    if (element instanceof ComponentTreeStructureRoot) {
        return null;
    } else if (element instanceof LwInspectionSuppression[] || element instanceof RadButtonGroup[]) {
        return myRootElement;
    } else if (element instanceof LwInspectionSuppression) {
        return myEditor.getRootContainer().getInspectionSuppressions();
    } else if (element instanceof RadButtonGroup) {
        return myEditor.getRootContainer().getButtonGroups();
    } else if (element instanceof ComponentPtr) {
        // RadContainer is also RadComponent
        final ComponentPtr ptr = (ComponentPtr) element;
        if (!ptr.isValid())
            return myRootElement;
        final RadComponent component = ptr.getComponent();
        if (component instanceof RadRootContainer) {
            return myRootElement;
        } else {
            return component.getParent() != null ? new ComponentPtr(myEditor, component.getParent(), false) : null;
        }
    } else {
        throw new IllegalArgumentException("unknown element: " + element);
    }
}
Also used : RadButtonGroup(com.intellij.uiDesigner.radComponents.RadButtonGroup) LwInspectionSuppression(com.intellij.uiDesigner.lw.LwInspectionSuppression) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) RadRootContainer(com.intellij.uiDesigner.radComponents.RadRootContainer)

Example 8 with RadRootContainer

use of com.intellij.uiDesigner.radComponents.RadRootContainer in project intellij-community by JetBrains.

the class BindingProperty method suggestBindingFromText.

@Nullable
public static String suggestBindingFromText(final RadComponent component, String text) {
    if (StringUtil.startsWithIgnoreCase(text, PREFIX_HTML)) {
        text = Pattern.compile("<.+?>").matcher(text).replaceAll("");
    }
    ArrayList<String> words = new ArrayList<>(StringUtil.getWordsIn(text));
    if (words.size() > 0) {
        StringBuilder nameBuilder = new StringBuilder(StringUtil.decapitalize(words.get(0)));
        for (int i = 1; i < words.size() && i < 4; i++) {
            nameBuilder.append(StringUtil.capitalize(words.get(i)));
        }
        final String shortClassName = StringUtil.capitalize(InsertComponentProcessor.getShortClassName(component.getComponentClassName()));
        if (shortClassName.equalsIgnoreCase(nameBuilder.toString())) {
            // avoid "buttonButton" case
            return null;
        }
        nameBuilder.append(shortClassName);
        RadRootContainer root = (RadRootContainer) FormEditingUtil.getRoot(component);
        Project project = root.getProject();
        String binding = JavaCodeStyleManager.getInstance(project).propertyNameToVariableName(nameBuilder.toString(), VariableKind.FIELD);
        if (FormEditingUtil.findComponentWithBinding(root, binding, component) != null) {
            binding = InsertComponentProcessor.getUniqueBinding(root, nameBuilder.toString());
        }
        return binding;
    }
    return null;
}
Also used : Project(com.intellij.openapi.project.Project) ArrayList(java.util.ArrayList) RadRootContainer(com.intellij.uiDesigner.radComponents.RadRootContainer) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with RadRootContainer

use of com.intellij.uiDesigner.radComponents.RadRootContainer in project intellij-community by JetBrains.

the class BindingProperty method setValueImpl.

protected void setValueImpl(final RadComponent component, final String value) throws Exception {
    if (Comparing.strEqual(value, component.getBinding(), true)) {
        return;
    }
    if (value.length() > 0 && !PsiNameHelper.getInstance(component.getProject()).isIdentifier(value)) {
        throw new Exception("Value '" + value + "' is not a valid identifier");
    }
    final RadRootContainer root = (RadRootContainer) FormEditingUtil.getRoot(component);
    final String oldBinding = getValue(component);
    if (value.length() > 0) {
        if (!FormEditingUtil.isBindingUnique(component, value, root)) {
            throw new Exception(UIDesignerBundle.message("error.binding.not.unique"));
        }
        component.setBinding(value);
        component.setDefaultBinding(false);
    } else {
        if (component.isCustomCreateRequired()) {
            throw new Exception(UIDesignerBundle.message("error.custom.create.binding.required"));
        }
        component.setBinding(null);
        component.setCustomCreate(false);
    }
    // Set new value or rename old one. It means that previous binding exists
    // and the new one doesn't exist we need to ask user to create new field
    // or rename old one.
    updateBoundFieldName(root, oldBinding, value, component.getComponentClassName());
}
Also used : RadRootContainer(com.intellij.uiDesigner.radComponents.RadRootContainer) IncorrectOperationException(com.intellij.util.IncorrectOperationException) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException)

Example 10 with RadRootContainer

use of com.intellij.uiDesigner.radComponents.RadRootContainer in project intellij-community by JetBrains.

the class BindingProperty method checkCreateBindingFromText.

public static void checkCreateBindingFromText(final RadComponent component, final String text) {
    if (!component.isDefaultBinding()) {
        return;
    }
    RadRootContainer root = (RadRootContainer) FormEditingUtil.getRoot(component);
    PsiField boundField = findBoundField(root, component.getBinding());
    if (boundField == null || !isFieldUnreferenced(boundField)) {
        return;
    }
    String binding = suggestBindingFromText(component, text);
    if (binding != null) {
        new BindingProperty(component.getProject()).setValueEx(component, binding);
        // keep the binding marked as default
        component.setDefaultBinding(true);
    }
}
Also used : RadRootContainer(com.intellij.uiDesigner.radComponents.RadRootContainer)

Aggregations

RadRootContainer (com.intellij.uiDesigner.radComponents.RadRootContainer)29 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)17 RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)6 RadButtonGroup (com.intellij.uiDesigner.radComponents.RadButtonGroup)4 Locale (java.util.Locale)4 IncorrectOperationException (com.intellij.util.IncorrectOperationException)3 HashSet (com.intellij.util.containers.HashSet)3 ArrayList (java.util.ArrayList)3 Nullable (org.jetbrains.annotations.Nullable)3 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)2 IButtonGroup (com.intellij.uiDesigner.lw.IButtonGroup)2 LwInspectionSuppression (com.intellij.uiDesigner.lw.LwInspectionSuppression)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)1 Project (com.intellij.openapi.project.Project)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 FormEditingUtil (com.intellij.uiDesigner.FormEditingUtil)1 ComponentPtr (com.intellij.uiDesigner.componentTree.ComponentPtr)1 ComponentTree (com.intellij.uiDesigner.componentTree.ComponentTree)1