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());
}
use of com.intellij.uiDesigner.radComponents.RadRootContainer in project intellij-community by JetBrains.
the class IntroStringProperty method setValueImpl.
protected void setValueImpl(final RadComponent component, final StringDescriptor value) throws Exception {
// 1. Put value into map
if (value == null || (value.getBundleName() == null && !value.isNoI18n())) {
getName2Descriptor(component).remove(getName());
} else {
getName2Descriptor(component).put(getName(), value);
}
// 2. Apply real string value to JComponent peer
final JComponent delegee = component.getDelegee();
Locale locale = (Locale) component.getClientProperty(RadComponent.CLIENT_PROP_LOAD_TIME_LOCALE);
if (locale == null) {
RadRootContainer root = (RadRootContainer) FormEditingUtil.getRoot(component);
if (root != null) {
locale = root.getStringDescriptorLocale();
}
}
final String resolvedValue = (value != null && value.getValue() != null) ? value.getValue() : StringDescriptorManager.getInstance(component.getModule()).resolve(value, locale);
if (value != null) {
value.setResolvedValue(resolvedValue);
}
if (SwingProperties.TEXT.equals(getName())) {
final SupportCode.TextWithMnemonic textWithMnemonic = SupportCode.parseText(resolvedValue);
if (delegee instanceof JLabel) {
final JLabel label = (JLabel) delegee;
label.setText(textWithMnemonic.myText);
if (textWithMnemonic.myMnemonicIndex != -1) {
label.setDisplayedMnemonic(textWithMnemonic.getMnemonicChar());
label.setDisplayedMnemonicIndex(textWithMnemonic.myMnemonicIndex);
} else {
label.setDisplayedMnemonic(0);
}
} else if (delegee instanceof AbstractButton) {
final AbstractButton button = (AbstractButton) delegee;
button.setText(textWithMnemonic.myText);
if (textWithMnemonic.myMnemonicIndex != -1) {
button.setMnemonic(textWithMnemonic.getMnemonicChar());
button.setDisplayedMnemonicIndex(textWithMnemonic.myMnemonicIndex);
} else {
button.setMnemonic(0);
}
} else {
invokeSetter(component, resolvedValue);
}
checkUpdateBindingFromText(component, value, textWithMnemonic);
} else {
invokeSetter(component, resolvedValue);
}
}
use of com.intellij.uiDesigner.radComponents.RadRootContainer in project intellij-community by JetBrains.
the class IntroStringProperty method checkUpdateBindingFromText.
private static void checkUpdateBindingFromText(final RadComponent component, final StringDescriptor value, final SupportCode.TextWithMnemonic textWithMnemonic) {
if (component.isLoadingProperties()) {
return;
}
// only generate binding from text if default locale is active (IDEADEV-9427)
if (value.getValue() == null) {
RadRootContainer root = (RadRootContainer) FormEditingUtil.getRoot(component);
Locale locale = root.getStringDescriptorLocale();
if (locale != null && locale.getDisplayName().length() > 0) {
return;
}
}
BindingProperty.checkCreateBindingFromText(component, textWithMnemonic.myText);
if (component.getDelegee() instanceof JLabel) {
for (IProperty prop : component.getModifiedProperties()) {
if (prop.getName().equals(SwingProperties.LABEL_FOR) && prop instanceof IntroComponentProperty) {
((IntroComponentProperty) prop).updateLabelForBinding(component);
}
}
}
}
use of com.intellij.uiDesigner.radComponents.RadRootContainer in project intellij-community by JetBrains.
the class ErrorAnalyzer method analyzeErrors.
/**
* @param editor if null, no quick fixes are created. This is used in form to source compiler.
*/
public static void analyzeErrors(@NotNull final Module module, @NotNull final VirtualFile formFile, @Nullable final GuiEditor editor, @NotNull final IRootContainer rootContainer, @Nullable final ProgressIndicator progress) {
if (module.isDisposed()) {
return;
}
// 1. Validate class to bind
final String classToBind = rootContainer.getClassToBind();
final PsiClass psiClass;
if (classToBind != null) {
psiClass = FormEditingUtil.findClassToBind(module, classToBind);
if (psiClass == null) {
final QuickFix[] fixes = editor != null ? new QuickFix[] { new CreateClassToBindFix(editor, classToBind) } : QuickFix.EMPTY_ARRAY;
final ErrorInfo errorInfo = new ErrorInfo(null, null, UIDesignerBundle.message("error.class.does.not.exist", classToBind), HighlightDisplayLevel.ERROR, fixes);
rootContainer.putClientProperty(CLIENT_PROP_CLASS_TO_BIND_ERROR, errorInfo);
} else {
rootContainer.putClientProperty(CLIENT_PROP_CLASS_TO_BIND_ERROR, null);
}
} else {
rootContainer.putClientProperty(CLIENT_PROP_CLASS_TO_BIND_ERROR, null);
psiClass = null;
}
// 2. Validate bindings to fields
// field name -> error message
// for performance reasons
final ArrayList<String> usedBindings = new ArrayList<>();
final Set<IButtonGroup> processedGroups = new HashSet<>();
FormEditingUtil.iterate(rootContainer, new FormEditingUtil.ComponentVisitor<IComponent>() {
public boolean visit(final IComponent component) {
if (progress != null && progress.isCanceled())
return false;
// Reset previous error (if any)
component.putClientProperty(CLIENT_PROP_BINDING_ERROR, null);
final String binding = component.getBinding();
// a. Check that field exists and field is not static
if (psiClass != null && binding != null) {
if (validateFieldInClass(component, binding, component.getComponentClassName(), psiClass, editor, module))
return true;
}
// b. Check that binding is unique
if (binding != null) {
if (usedBindings.contains(binding)) {
// TODO[vova] implement
component.putClientProperty(CLIENT_PROP_BINDING_ERROR, new ErrorInfo(component, null, UIDesignerBundle.message("error.binding.already.exists", binding), HighlightDisplayLevel.ERROR, QuickFix.EMPTY_ARRAY));
return true;
}
usedBindings.add(binding);
}
IButtonGroup group = FormEditingUtil.findGroupForComponent(rootContainer, component);
if (group != null && !processedGroups.contains(group)) {
processedGroups.add(group);
if (group.isBound()) {
validateFieldInClass(component, group.getName(), ButtonGroup.class.getName(), psiClass, editor, module);
}
}
return true;
}
});
if (progress != null)
progress.checkCanceled();
// Check that there are no panels in XY with children
FormEditingUtil.iterate(rootContainer, new FormEditingUtil.ComponentVisitor<IComponent>() {
public boolean visit(final IComponent component) {
if (progress != null && progress.isCanceled())
return false;
// Clear previous error (if any)
component.putClientProperty(CLIENT_PROP_ERROR_ARRAY, null);
if (!(component instanceof IContainer)) {
return true;
}
final IContainer container = (IContainer) component;
if (container instanceof IRootContainer) {
final IRootContainer rootContainer = (IRootContainer) container;
if (rootContainer.getComponentCount() > 1) {
// TODO[vova] implement
putError(component, new ErrorInfo(component, null, UIDesignerBundle.message("error.multiple.toplevel.components"), HighlightDisplayLevel.ERROR, QuickFix.EMPTY_ARRAY));
}
} else if (container.isXY() && container.getComponentCount() > 0) {
// TODO[vova] implement
putError(component, new ErrorInfo(component, null, UIDesignerBundle.message("error.panel.not.laid.out"), HighlightDisplayLevel.ERROR, QuickFix.EMPTY_ARRAY));
}
return true;
}
});
if (progress != null)
progress.checkCanceled();
try {
// Run inspections for form elements
final PsiFile formPsiFile = PsiManager.getInstance(module.getProject()).findFile(formFile);
if (formPsiFile != null && rootContainer instanceof RadRootContainer) {
final List<FormInspectionTool> formInspectionTools = new ArrayList<>();
final FormInspectionTool[] registeredFormInspections = Extensions.getExtensions(FormInspectionTool.EP_NAME);
for (FormInspectionTool formInspectionTool : registeredFormInspections) {
if (formInspectionTool.isActive(formPsiFile) && !rootContainer.isInspectionSuppressed(formInspectionTool.getShortName(), null)) {
formInspectionTools.add(formInspectionTool);
}
}
if (formInspectionTools.size() > 0 && editor != null) {
for (FormInspectionTool tool : formInspectionTools) {
tool.startCheckForm(rootContainer);
}
FormEditingUtil.iterate(rootContainer, new FormEditingUtil.ComponentVisitor<RadComponent>() {
public boolean visit(final RadComponent component) {
if (progress != null && progress.isCanceled())
return false;
for (FormInspectionTool tool : formInspectionTools) {
if (rootContainer.isInspectionSuppressed(tool.getShortName(), component.getId()))
continue;
ErrorInfo[] errorInfos = tool.checkComponent(editor, component);
if (errorInfos != null) {
ArrayList<ErrorInfo> errorList = getErrorInfos(component);
if (errorList == null) {
errorList = new ArrayList<>();
component.putClientProperty(CLIENT_PROP_ERROR_ARRAY, errorList);
}
Collections.addAll(errorList, errorInfos);
}
}
return true;
}
});
for (FormInspectionTool tool : formInspectionTools) {
tool.doneCheckForm(rootContainer);
}
}
}
} catch (Exception e) {
LOG.error(e);
}
}
Aggregations