use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class Palette method getIntrospectedProperties.
/**
* @return arrays of all properties that can be introspected from the
* specified class. Only properties with getter and setter methods are
* returned.
*/
@NotNull
public IntrospectedProperty[] getIntrospectedProperties(@NotNull final Class aClass, @NotNull final Class delegeeClass) {
// TODO[vova, anton] update cache after class reloading (its properties could be hanged).
if (myClass2Properties.containsKey(aClass)) {
return myClass2Properties.get(aClass);
}
final ArrayList<IntrospectedProperty> result = new ArrayList<>();
try {
final BeanInfo beanInfo = Introspector.getBeanInfo(aClass);
final PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
for (final PropertyDescriptor descriptor : descriptors) {
Method readMethod = descriptor.getReadMethod();
Method writeMethod = descriptor.getWriteMethod();
Class propertyType = descriptor.getPropertyType();
if (writeMethod == null || readMethod == null || propertyType == null) {
continue;
}
boolean storeAsClient = false;
try {
delegeeClass.getMethod(readMethod.getName(), readMethod.getParameterTypes());
delegeeClass.getMethod(writeMethod.getName(), writeMethod.getParameterTypes());
} catch (NoSuchMethodException e) {
storeAsClient = true;
}
@NonNls final String name = descriptor.getName();
final IntrospectedProperty property;
final Properties properties = (myProject == null) ? new Properties() : Properties.getInstance();
if (int.class.equals(propertyType)) {
// int
IntEnumEditor.Pair[] enumPairs = properties.getEnumPairs(aClass, name);
if (enumPairs != null) {
property = createIntEnumProperty(name, readMethod, writeMethod, enumPairs);
} else if (JLabel.class.isAssignableFrom(aClass)) {
// special handling for javax.swing.JLabel
if (JLabel.class.isAssignableFrom(aClass) && ("displayedMnemonic".equals(name) || "displayedMnemonicIndex".equals(name))) {
// skip JLabel#displayedMnemonic and JLabel#displayedMnemonicIndex
continue;
} else {
property = new IntroIntProperty(name, readMethod, writeMethod, storeAsClient);
}
} else if (AbstractButton.class.isAssignableFrom(aClass)) {
// special handling AbstractButton subclasses
if ("mnemonic".equals(name) || "displayedMnemonicIndex".equals(name)) {
// AbstractButton#mnemonic
continue;
} else {
property = new IntroIntProperty(name, readMethod, writeMethod, storeAsClient);
}
} else if (JTabbedPane.class.isAssignableFrom(aClass)) {
if (SwingProperties.SELECTED_INDEX.equals(name)) {
continue;
}
property = new IntroIntProperty(name, readMethod, writeMethod, storeAsClient);
} else {
property = new IntroIntProperty(name, readMethod, writeMethod, storeAsClient);
}
} else if (boolean.class.equals(propertyType)) {
// boolean
property = new IntroBooleanProperty(name, readMethod, writeMethod, storeAsClient);
} else if (double.class.equals(propertyType)) {
property = new IntroPrimitiveTypeProperty(name, readMethod, writeMethod, storeAsClient, Double.class);
} else if (float.class.equals(propertyType)) {
property = new IntroPrimitiveTypeProperty(name, readMethod, writeMethod, storeAsClient, Float.class);
} else if (long.class.equals(propertyType)) {
property = new IntroPrimitiveTypeProperty(name, readMethod, writeMethod, storeAsClient, Long.class);
} else if (byte.class.equals(propertyType)) {
property = new IntroPrimitiveTypeProperty(name, readMethod, writeMethod, storeAsClient, Byte.class);
} else if (short.class.equals(propertyType)) {
property = new IntroPrimitiveTypeProperty(name, readMethod, writeMethod, storeAsClient, Short.class);
} else if (char.class.equals(propertyType)) {
// java.lang.String
property = new IntroCharProperty(name, readMethod, writeMethod, storeAsClient);
} else if (String.class.equals(propertyType)) {
// java.lang.String
property = new IntroStringProperty(name, readMethod, writeMethod, myProject, storeAsClient);
} else if (Insets.class.equals(propertyType)) {
// java.awt.Insets
property = new IntroInsetsProperty(name, readMethod, writeMethod, storeAsClient);
} else if (Dimension.class.equals(propertyType)) {
// java.awt.Dimension
property = new IntroDimensionProperty(name, readMethod, writeMethod, storeAsClient);
} else if (Rectangle.class.equals(propertyType)) {
// java.awt.Rectangle
property = new IntroRectangleProperty(name, readMethod, writeMethod, storeAsClient);
} else if (Component.class.isAssignableFrom(propertyType)) {
if (JSplitPane.class.isAssignableFrom(aClass) && (name.equals("leftComponent") || name.equals("rightComponent") || name.equals("topComponent") || name.equals("bottomComponent"))) {
// these properties are set through layout
continue;
}
if (JTabbedPane.class.isAssignableFrom(aClass) && name.equals(SwingProperties.SELECTED_COMPONENT)) {
// can't set selectedComponent because of set property / add child sequence
continue;
}
if (JMenuBar.class.isAssignableFrom(propertyType) || JPopupMenu.class.isAssignableFrom(propertyType)) {
// no menu editing yet
continue;
}
Condition<RadComponent> filter = null;
if (name.equals(SwingProperties.LABEL_FOR)) {
filter = t -> {
ComponentItem item = getItem(t.getComponentClassName());
return item != null && item.isCanAttachLabel();
};
}
property = new IntroComponentProperty(name, readMethod, writeMethod, propertyType, filter, storeAsClient);
} else if (Color.class.equals(propertyType)) {
property = new IntroColorProperty(name, readMethod, writeMethod, storeAsClient);
} else if (Font.class.equals(propertyType)) {
property = new IntroFontProperty(name, readMethod, writeMethod, storeAsClient);
} else if (Icon.class.equals(propertyType)) {
property = new IntroIconProperty(name, readMethod, writeMethod, storeAsClient);
} else if (ListModel.class.isAssignableFrom(propertyType)) {
property = new IntroListModelProperty(name, readMethod, writeMethod, storeAsClient);
} else if (Enum.class.isAssignableFrom(propertyType)) {
property = new IntroEnumProperty(name, readMethod, writeMethod, storeAsClient, propertyType);
} else {
// other types are not supported (yet?)
continue;
}
result.add(property);
}
} catch (IntrospectionException e) {
throw new RuntimeException(e);
}
final IntrospectedProperty[] properties = result.toArray(new IntrospectedProperty[result.size()]);
myClass2Properties.put(aClass, properties);
return properties;
}
use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class I18nFormInspection method checkStringDescriptor.
@Override
protected void checkStringDescriptor(final Module module, final IComponent component, final IProperty prop, final StringDescriptor descriptor, final FormErrorCollector collector) {
if (isHardCodedStringDescriptor(descriptor)) {
if (isPropertyDescriptor(prop)) {
if (isSetterNonNls(module.getProject(), GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module), component.getComponentClassName(), prop.getName())) {
return;
}
}
EditorQuickFixProvider provider;
if (prop.getName().equals(BorderProperty.NAME)) {
provider = new EditorQuickFixProvider() {
@Override
public QuickFix createQuickFix(GuiEditor editor, RadComponent component) {
return new I18nizeFormBorderQuickFix(editor, UIDesignerBundle.message("i18n.quickfix.border.title"), (RadContainer) component);
}
};
} else if (prop.getName().equals(ITabbedPane.TAB_TITLE_PROPERTY) || prop.getName().equals(ITabbedPane.TAB_TOOLTIP_PROPERTY)) {
provider = new EditorQuickFixProvider() {
@Override
public QuickFix createQuickFix(GuiEditor editor, RadComponent component) {
return new I18nizeTabTitleQuickFix(editor, UIDesignerBundle.message("i18n.quickfix.tab.title", prop.getName()), component, prop.getName());
}
};
} else {
provider = new EditorQuickFixProvider() {
@Override
public QuickFix createQuickFix(GuiEditor editor, RadComponent component) {
return new I18nizeFormPropertyQuickFix(editor, UIDesignerBundle.message("i18n.quickfix.property", prop.getName()), component, (IntrospectedProperty) prop);
}
};
}
collector.addError(getID(), component, prop, UIDesignerBundle.message("inspection.i18n.message.in.form", descriptor.getValue()), provider);
}
}
use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class MorphAction method actionPerformed.
protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) {
Processor<ComponentItem> processor = selectedValue -> {
Runnable runnable = () -> {
for (RadComponent c : selection) {
if (!morphComponent(editor, c, selectedValue))
break;
}
editor.refreshAndSave(true);
};
CommandProcessor.getInstance().executeCommand(editor.getProject(), runnable, UIDesignerBundle.message("morph.component.command"), null);
IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
IdeFocusManager.getGlobalInstance().requestFocus(editor.getGlassLayer(), true);
});
return true;
};
PaletteListPopupStep step = new PaletteListPopupStep(editor, myLastMorphComponent, processor, UIDesignerBundle.message("morph.component.title"));
step.hideNonAtomic();
if (selection.size() == 1) {
step.hideComponentClass(selection.get(0).getComponentClassName());
}
final ListPopup listPopup = JBPopupFactory.getInstance().createListPopup(step);
FormEditingUtil.showPopupUnderComponent(listPopup, selection.get(0));
}
use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class CreateListenerAction method canCreateListener.
private static boolean canCreateListener(final ArrayList<RadComponent> selection) {
if (selection.size() == 0)
return false;
final RadRootContainer root = (RadRootContainer) FormEditingUtil.getRoot(selection.get(0));
if (root.getClassToBind() == null)
return false;
String componentClass = selection.get(0).getComponentClassName();
for (RadComponent c : selection) {
if (!c.getComponentClassName().equals(componentClass) || c.getBinding() == null)
return false;
if (BindingProperty.findBoundField(root, c.getBinding()) == null)
return false;
}
return true;
}
use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class DuplicateComponentsAction method actionPerformed.
protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) {
FormEditingUtil.remapToActionTargets(selection);
RadContainer parent = FormEditingUtil.getSelectionParent(selection);
assert parent != null;
List<RadComponent> duplicates = new ArrayList<>();
Map<RadComponent, RadComponent> duplicateMap = new HashMap<>();
TIntHashSet insertedRows = new TIntHashSet();
boolean incrementRow = true;
if (selection.size() > 1 && canDuplicate(selection, false) && FormEditingUtil.getSelectionBounds(selection).width == 1) {
incrementRow = false;
}
for (RadComponent c : selection) {
final int row = c.getConstraints().getCell(incrementRow);
int rowSpan = c.getConstraints().getSpan(incrementRow);
int insertIndex = parent.indexOfComponent(c);
if (parent.getLayoutManager().isGrid()) {
if (!insertedRows.contains(row) && !isSpaceBelowEmpty(c, incrementRow)) {
insertedRows.add(row);
parent.getGridLayoutManager().copyGridCells(parent, parent, incrementRow, row, rowSpan, row + rowSpan);
}
}
List<RadComponent> copyList = CutCopyPasteSupport.copyComponents(editor, Collections.singletonList(c));
if (copyList != null) {
RadComponent copy = copyList.get(0);
if (parent.getLayoutManager().isGrid()) {
copy.getConstraints().setCell(incrementRow, row + rowSpan + parent.getGridLayoutManager().getGapCellCount());
copy.getConstraints().setSpan(incrementRow, rowSpan);
}
parent.addComponent(copy, insertIndex + 1);
fillDuplicateMap(duplicateMap, c, copy);
duplicates.add(copy);
}
}
adjustDuplicates(duplicateMap);
FormEditingUtil.selectComponents(editor, duplicates);
}
Aggregations