Search in sources :

Example 1 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 2 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 3 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)

Example 4 with RadRootContainer

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

the class ButtonGroupProperty method setValueImpl.

protected void setValueImpl(RadComponent component, RadButtonGroup value) throws Exception {
    final RadRootContainer radRootContainer = (RadRootContainer) FormEditingUtil.getRoot(component);
    assert radRootContainer != null;
    radRootContainer.setGroupForComponent(component, value);
}
Also used : RadRootContainer(com.intellij.uiDesigner.radComponents.RadRootContainer)

Example 5 with RadRootContainer

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

the class IntRegexEditor method setValueFromComponent.

@Override
protected void setValueFromComponent(final RadComponent component, final T value) {
    RadRootContainer root = (RadRootContainer) FormEditingUtil.getRoot(component);
    JLabel label = myRenderer.getComponent(root, value, false, false);
    myTf.setText(label.getText());
}
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