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;
}
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());
}
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);
}
}
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);
}
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());
}
Aggregations