Search in sources :

Example 16 with RadComponent

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;
}
Also used : BeanInfo(java.beans.BeanInfo) ArrayList(java.util.ArrayList) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) IntrospectionException(java.beans.IntrospectionException) SwingProperties(com.intellij.uiDesigner.SwingProperties) Properties(com.intellij.uiDesigner.Properties) NonNls(org.jetbrains.annotations.NonNls) PropertyDescriptor(java.beans.PropertyDescriptor) Method(java.lang.reflect.Method) IntrospectedProperty(com.intellij.uiDesigner.propertyInspector.IntrospectedProperty) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with RadComponent

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);
    }
}
Also used : QuickFix(com.intellij.uiDesigner.quickFixes.QuickFix) EditorQuickFixProvider(com.intellij.uiDesigner.inspections.EditorQuickFixProvider) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) GuiEditor(com.intellij.uiDesigner.designSurface.GuiEditor) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

Example 18 with RadComponent

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));
}
Also used : PsiType(com.intellij.psi.PsiType) UIDesignerBundle(com.intellij.uiDesigner.UIDesignerBundle) RadAtomicComponent(com.intellij.uiDesigner.radComponents.RadAtomicComponent) JavaPsiFacade(com.intellij.psi.JavaPsiFacade) ChangeFieldTypeFix(com.intellij.uiDesigner.quickFixes.ChangeFieldTypeFix) ArrayList(java.util.ArrayList) GuiEditor(com.intellij.uiDesigner.designSurface.GuiEditor) Palette(com.intellij.uiDesigner.palette.Palette) PsiElementFactory(com.intellij.psi.PsiElementFactory) IProperty(com.intellij.uiDesigner.lw.IProperty) Logger(com.intellij.openapi.diagnostic.Logger) IntroComponentProperty(com.intellij.uiDesigner.propertyInspector.properties.IntroComponentProperty) IncorrectOperationException(com.intellij.util.IncorrectOperationException) ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) BindingProperty(com.intellij.uiDesigner.propertyInspector.properties.BindingProperty) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) FormEditingUtil(com.intellij.uiDesigner.FormEditingUtil) CommandProcessor(com.intellij.openapi.command.CommandProcessor) ListPopup(com.intellij.openapi.ui.popup.ListPopup) List(java.util.List) IComponent(com.intellij.uiDesigner.lw.IComponent) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) Processor(com.intellij.util.Processor) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) PsiField(com.intellij.psi.PsiField) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer) NotNull(org.jetbrains.annotations.NotNull) InsertComponentProcessor(com.intellij.uiDesigner.designSurface.InsertComponentProcessor) FormInspectionUtil(com.intellij.uiDesigner.inspections.FormInspectionUtil) IntrospectedProperty(com.intellij.uiDesigner.propertyInspector.IntrospectedProperty) ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) ListPopup(com.intellij.openapi.ui.popup.ListPopup)

Example 19 with RadComponent

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;
}
Also used : RadRootContainer(com.intellij.uiDesigner.radComponents.RadRootContainer) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent)

Example 20 with RadComponent

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);
}
Also used : RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer) TIntHashSet(gnu.trove.TIntHashSet)

Aggregations

RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)86 RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)22 RadRootContainer (com.intellij.uiDesigner.radComponents.RadRootContainer)18 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)15 ArrayList (java.util.ArrayList)12 FormEditingUtil (com.intellij.uiDesigner.FormEditingUtil)8 GuiEditor (com.intellij.uiDesigner.designSurface.GuiEditor)8 IComponent (com.intellij.uiDesigner.lw.IComponent)7 IProperty (com.intellij.uiDesigner.lw.IProperty)6 ComponentItem (com.intellij.uiDesigner.palette.ComponentItem)5 RadButtonGroup (com.intellij.uiDesigner.radComponents.RadButtonGroup)5 ListPopup (com.intellij.openapi.ui.popup.ListPopup)4 ComponentTree (com.intellij.uiDesigner.componentTree.ComponentTree)4 IntrospectedProperty (com.intellij.uiDesigner.propertyInspector.IntrospectedProperty)4 IntroComponentProperty (com.intellij.uiDesigner.propertyInspector.properties.IntroComponentProperty)4 QuickFix (com.intellij.uiDesigner.quickFixes.QuickFix)4 Nullable (org.jetbrains.annotations.Nullable)4 RelativePoint (com.intellij.ui.awt.RelativePoint)3 Palette (com.intellij.uiDesigner.palette.Palette)3 IncorrectOperationException (com.intellij.util.IncorrectOperationException)3