Search in sources :

Example 1 with LwInspectionSuppression

use of com.intellij.uiDesigner.lw.LwInspectionSuppression 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);
    }
}
Also used : LwInspectionSuppression(com.intellij.uiDesigner.lw.LwInspectionSuppression) ArrayList(java.util.ArrayList) RadRootContainer(com.intellij.uiDesigner.radComponents.RadRootContainer) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) RadButtonGroup(com.intellij.uiDesigner.radComponents.RadButtonGroup) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

Example 2 with LwInspectionSuppression

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

Example 3 with LwInspectionSuppression

use of com.intellij.uiDesigner.lw.LwInspectionSuppression in project intellij-community by JetBrains.

the class RadRootContainer method writeInspectionSuppressions.

private void writeInspectionSuppressions(final XmlWriter writer) {
    if (myInspectionSuppressions.size() > 0) {
        writer.startElement(UIFormXmlConstants.ELEMENT_INSPECTION_SUPPRESSIONS);
        for (LwInspectionSuppression suppression : myInspectionSuppressions) {
            writer.startElement(UIFormXmlConstants.ELEMENT_SUPPRESS);
            writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_INSPECTION, suppression.getInspectionId());
            if (suppression.getComponentId() != null) {
                writer.addAttribute(UIFormXmlConstants.ATTRIBUTE_ID, suppression.getComponentId());
            }
            writer.endElement();
        }
        writer.endElement();
    }
}
Also used : LwInspectionSuppression(com.intellij.uiDesigner.lw.LwInspectionSuppression)

Example 4 with LwInspectionSuppression

use of com.intellij.uiDesigner.lw.LwInspectionSuppression in project intellij-community by JetBrains.

the class ComponentTree method getData.

/**
   * Provides {@link PlatformDataKeys#NAVIGATABLE} to navigate to
   * binding of currently selected component (if any)
   */
public Object getData(final String dataId) {
    if (GuiEditor.DATA_KEY.is(dataId)) {
        return myEditor;
    }
    if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
        return myDeleteProvider;
    }
    if (PlatformDataKeys.COPY_PROVIDER.is(dataId) || PlatformDataKeys.CUT_PROVIDER.is(dataId) || PlatformDataKeys.PASTE_PROVIDER.is(dataId)) {
        return myEditor == null ? null : myEditor.getData(dataId);
    }
    if (LW_INSPECTION_SUPPRESSION_ARRAY_DATA_KEY.is(dataId)) {
        Collection<LwInspectionSuppression> elements = getSelectedElements(LwInspectionSuppression.class);
        return elements.size() == 0 ? null : elements.toArray(new LwInspectionSuppression[elements.size()]);
    }
    if (PlatformDataKeys.HELP_ID.is(dataId)) {
        return ourHelpID;
    }
    if (PlatformDataKeys.FILE_EDITOR.is(dataId)) {
        return myFormEditor;
    }
    if (!CommonDataKeys.NAVIGATABLE.is(dataId)) {
        return null;
    }
    final RadComponent selectedComponent = getSelectedComponent();
    if (selectedComponent == null) {
        return null;
    }
    final String classToBind = myEditor.getRootContainer().getClassToBind();
    if (classToBind == null) {
        return null;
    }
    final PsiClass aClass = FormEditingUtil.findClassToBind(myEditor.getModule(), classToBind);
    if (aClass == null) {
        return null;
    }
    if (selectedComponent instanceof RadRootContainer) {
        return EditSourceUtil.getDescriptor(aClass);
    }
    final String binding = selectedComponent.getBinding();
    if (binding == null) {
        return null;
    }
    final PsiField[] fields = aClass.getFields();
    for (final PsiField field : fields) {
        if (binding.equals(field.getName())) {
            return EditSourceUtil.getDescriptor(field);
        }
    }
    return null;
}
Also used : LwInspectionSuppression(com.intellij.uiDesigner.lw.LwInspectionSuppression) PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass)

Aggregations

LwInspectionSuppression (com.intellij.uiDesigner.lw.LwInspectionSuppression)4 RadButtonGroup (com.intellij.uiDesigner.radComponents.RadButtonGroup)2 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)2 RadRootContainer (com.intellij.uiDesigner.radComponents.RadRootContainer)2 PsiClass (com.intellij.psi.PsiClass)1 PsiField (com.intellij.psi.PsiField)1 RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)1 ArrayList (java.util.ArrayList)1