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