Search in sources :

Example 6 with IntrospectedProperty

use of com.intellij.uiDesigner.propertyInspector.IntrospectedProperty 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 7 with IntrospectedProperty

use of com.intellij.uiDesigner.propertyInspector.IntrospectedProperty in project intellij-community by JetBrains.

the class MorphAction method morphComponent.

private static boolean morphComponent(final GuiEditor editor, final RadComponent oldComponent, ComponentItem targetItem) {
    targetItem = InsertComponentProcessor.replaceAnyComponentItem(editor, targetItem, "Morph to Non-Palette Component");
    if (targetItem == null) {
        return false;
    }
    final RadComponent newComponent = InsertComponentProcessor.createInsertedComponent(editor, targetItem);
    if (newComponent == null)
        return false;
    newComponent.setBinding(oldComponent.getBinding());
    newComponent.setCustomLayoutConstraints(oldComponent.getCustomLayoutConstraints());
    newComponent.getConstraints().restore(oldComponent.getConstraints());
    updateBoundFieldType(editor, oldComponent, targetItem);
    final IProperty[] oldProperties = oldComponent.getModifiedProperties();
    final Palette palette = Palette.getInstance(editor.getProject());
    for (IProperty prop : oldProperties) {
        IntrospectedProperty newProp = palette.getIntrospectedProperty(newComponent, prop.getName());
        if (newProp == null || !prop.getClass().equals(newProp.getClass()))
            continue;
        Object oldValue = prop.getPropertyValue(oldComponent);
        try {
            //noinspection unchecked
            newProp.setValue(newComponent, oldValue);
        } catch (Exception e) {
        // ignore
        }
    }
    retargetComponentProperties(editor, oldComponent, newComponent);
    final RadContainer parent = oldComponent.getParent();
    int index = parent.indexOfComponent(oldComponent);
    parent.removeComponent(oldComponent);
    parent.addComponent(newComponent, index);
    newComponent.setSelected(true);
    if (oldComponent.isDefaultBinding()) {
        final String text = FormInspectionUtil.getText(newComponent.getModule(), newComponent);
        if (text != null) {
            String binding = BindingProperty.suggestBindingFromText(newComponent, text);
            if (binding != null) {
                new BindingProperty(newComponent.getProject()).setValueEx(newComponent, binding);
            }
        }
        newComponent.setDefaultBinding(true);
    }
    return true;
}
Also used : Palette(com.intellij.uiDesigner.palette.Palette) IProperty(com.intellij.uiDesigner.lw.IProperty) IntrospectedProperty(com.intellij.uiDesigner.propertyInspector.IntrospectedProperty) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) BindingProperty(com.intellij.uiDesigner.propertyInspector.properties.BindingProperty) IncorrectOperationException(com.intellij.util.IncorrectOperationException) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

Example 8 with IntrospectedProperty

use of com.intellij.uiDesigner.propertyInspector.IntrospectedProperty in project intellij-community by JetBrains.

the class ShowJavadocAction method actionPerformed.

public void actionPerformed(final AnActionEvent e) {
    final PropertyInspectorTable inspector = PropertyInspectorTable.DATA_KEY.getData(e.getDataContext());
    final IntrospectedProperty introspectedProperty = inspector.getSelectedIntrospectedProperty();
    final PsiClass aClass = inspector.getComponentClass();
    final PsiMethod getter = PropertyUtil.findPropertyGetter(aClass, introspectedProperty.getName(), false, true);
    LOG.assertTrue(getter != null);
    final PsiMethod setter = PropertyUtil.findPropertySetter(aClass, introspectedProperty.getName(), false, true);
    LOG.assertTrue(setter != null);
    final DocumentationManager documentationManager = DocumentationManager.getInstance(aClass.getProject());
    final DocumentationComponent component1 = new DocumentationComponent(documentationManager);
    final DocumentationComponent component2 = new DocumentationComponent(documentationManager);
    final Disposable disposable = Disposer.newDisposable();
    final TabbedPaneWrapper tabbedPane = new TabbedPaneWrapper(disposable);
    tabbedPane.addTab(UIDesignerBundle.message("tab.getter"), component1);
    tabbedPane.addTab(UIDesignerBundle.message("tab.setter"), component2);
    documentationManager.fetchDocInfo(getter, component1);
    documentationManager.queueFetchDocInfo(setter, component2).doWhenProcessed(() -> {
        final JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(tabbedPane.getComponent(), component1).setDimensionServiceKey(aClass.getProject(), DocumentationManager.JAVADOC_LOCATION_AND_SIZE, false).setResizable(true).setMovable(true).setRequestFocus(true).setTitle(UIDesignerBundle.message("property.javadoc.title", introspectedProperty.getName())).createPopup();
        component1.setHint(hint);
        component2.setHint(hint);
        Disposer.register(hint, component1);
        Disposer.register(hint, component2);
        Disposer.register(hint, disposable);
        hint.show(new RelativePoint(inspector, new Point(0, 0)));
    //component1.requestFocus();
    });
}
Also used : Disposable(com.intellij.openapi.Disposable) DocumentationManager(com.intellij.codeInsight.documentation.DocumentationManager) PropertyInspectorTable(com.intellij.uiDesigner.propertyInspector.PropertyInspectorTable) PsiMethod(com.intellij.psi.PsiMethod) DocumentationComponent(com.intellij.codeInsight.documentation.DocumentationComponent) TabbedPaneWrapper(com.intellij.ui.TabbedPaneWrapper) IntrospectedProperty(com.intellij.uiDesigner.propertyInspector.IntrospectedProperty) PsiClass(com.intellij.psi.PsiClass) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 9 with IntrospectedProperty

use of com.intellij.uiDesigner.propertyInspector.IntrospectedProperty in project intellij-community by JetBrains.

the class RadComponent method getComponentTitle.

@Nullable
public String getComponentTitle() {
    Palette palette = Palette.getInstance(getProject());
    IntrospectedProperty[] props = palette.getIntrospectedProperties(this);
    for (IntrospectedProperty prop : props) {
        if (prop.getName().equals(SwingProperties.TEXT) && prop instanceof IntroStringProperty) {
            StringDescriptor value = (StringDescriptor) prop.getValue(this);
            if (value != null) {
                return "\"" + value.getResolvedValue() + "\"";
            }
        }
    }
    if (this instanceof RadContainer) {
        RadContainer container = (RadContainer) this;
        StringDescriptor descriptor = container.getBorderTitle();
        if (descriptor != null) {
            if (descriptor.getResolvedValue() == null) {
                descriptor.setResolvedValue(StringDescriptorManager.getInstance(getModule()).resolve(this, descriptor));
            }
            return "\"" + descriptor.getResolvedValue() + "\"";
        }
    }
    if (getParent() instanceof RadTabbedPane) {
        RadTabbedPane parentTabbedPane = (RadTabbedPane) getParent();
        final StringDescriptor descriptor = parentTabbedPane.getChildTitle(this);
        if (descriptor != null) {
            if (descriptor.getResolvedValue() == null) {
                descriptor.setResolvedValue(StringDescriptorManager.getInstance(getModule()).resolve(this, descriptor));
            }
            return "\"" + descriptor.getResolvedValue() + "\"";
        } else {
            parentTabbedPane.getChildTitle(this);
        }
    }
    return null;
}
Also used : Palette(com.intellij.uiDesigner.palette.Palette) IntrospectedProperty(com.intellij.uiDesigner.propertyInspector.IntrospectedProperty) IntroStringProperty(com.intellij.uiDesigner.propertyInspector.properties.IntroStringProperty) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with IntrospectedProperty

use of com.intellij.uiDesigner.propertyInspector.IntrospectedProperty in project intellij-community by JetBrains.

the class SnapshotContext method postProcess.

public void postProcess() {
    for (ButtonGroup group : myButtonGroups) {
        RadButtonGroup radButtonGroup = myRootContainer.createGroup(myRootContainer.suggestGroupName());
        Enumeration<AbstractButton> elements = group.getElements();
        while (elements.hasMoreElements()) {
            AbstractButton btn = elements.nextElement();
            RadComponent c = myImportMap.get(btn);
            if (c != null) {
                radButtonGroup.add(c);
            }
        }
    }
    for (ComponentProperty prop : myComponentProperties) {
        RadComponent radOwner = myImportMap.get(prop.owner);
        RadComponent radValue = myImportMap.get(prop.value);
        if (radOwner != null && radValue != null) {
            final IntrospectedProperty property = radOwner.getPalette().getIntrospectedProperty(radOwner, prop.name);
            assert property != null;
            //noinspection unchecked
            IntroComponentProperty icp = (IntroComponentProperty) property;
            try {
                icp.setValue(radOwner, radValue.getId());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
}
Also used : IntroComponentProperty(com.intellij.uiDesigner.propertyInspector.properties.IntroComponentProperty) RadButtonGroup(com.intellij.uiDesigner.radComponents.RadButtonGroup) IntroComponentProperty(com.intellij.uiDesigner.propertyInspector.properties.IntroComponentProperty) RadButtonGroup(com.intellij.uiDesigner.radComponents.RadButtonGroup) IntrospectedProperty(com.intellij.uiDesigner.propertyInspector.IntrospectedProperty) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent)

Aggregations

IntrospectedProperty (com.intellij.uiDesigner.propertyInspector.IntrospectedProperty)11 Palette (com.intellij.uiDesigner.palette.Palette)3 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)3 Nullable (org.jetbrains.annotations.Nullable)3 ArrayList (java.util.ArrayList)2 NotNull (org.jetbrains.annotations.NotNull)2 DocumentationComponent (com.intellij.codeInsight.documentation.DocumentationComponent)1 DocumentationManager (com.intellij.codeInsight.documentation.DocumentationManager)1 Disposable (com.intellij.openapi.Disposable)1 JBPopup (com.intellij.openapi.ui.popup.JBPopup)1 PsiClass (com.intellij.psi.PsiClass)1 PsiMethod (com.intellij.psi.PsiMethod)1 JBColor (com.intellij.ui.JBColor)1 TabbedPaneWrapper (com.intellij.ui.TabbedPaneWrapper)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 Properties (com.intellij.uiDesigner.Properties)1 SwingProperties (com.intellij.uiDesigner.SwingProperties)1 RecursiveFormNestingException (com.intellij.uiDesigner.compiler.RecursiveFormNestingException)1 IProperty (com.intellij.uiDesigner.lw.IProperty)1 PsiNestedFormLoader (com.intellij.uiDesigner.make.PsiNestedFormLoader)1