Search in sources :

Example 11 with AttributeDefinition

use of org.jetbrains.android.dom.attrs.AttributeDefinition in project android by JetBrains.

the class NlDesignProperties method getDefinitionByName.

private static AttributeDefinition getDefinitionByName(@NotNull String name) {
    AttributeDefinition definition = ToolsAttributeUtil.getAttrDefByName(name);
    assert definition != null;
    ResolvingConverter converter = ToolsAttributeUtil.getConverter(definition);
    // TODO: Figure out how to provide the correct reference editor depending on the converter.
    if (converter instanceof StaticEnumConverter) {
        Collection variants = converter.getVariants(null);
        for (Object variant : variants) {
            definition.addValue(variant.toString());
        }
    }
    return definition;
}
Also used : ResolvingConverter(com.intellij.util.xml.ResolvingConverter) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) Collection(java.util.Collection) StaticEnumConverter(org.jetbrains.android.dom.converters.StaticEnumConverter)

Example 12 with AttributeDefinition

use of org.jetbrains.android.dom.attrs.AttributeDefinition in project android by JetBrains.

the class NlBooleanIconEditor method updateDescription.

private void updateDescription(@NotNull NlProperty property) {
    AttributeDefinition definition = property.getDefinition();
    if (definition != null) {
        String description = definition.getValueDoc(myAction.myTrueValue);
        if (description != null) {
            // TODO: Add a getter of the presentation instance in ActionButton. Then we can get rid of myPresentation.
            myPresentation.setDescription(description);
            myPresentation.setText(description);
        }
    }
}
Also used : AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition)

Example 13 with AttributeDefinition

use of org.jetbrains.android.dom.attrs.AttributeDefinition in project android by JetBrains.

the class NlPropertyEditors method getEditorType.

@NotNull
private static EditorType getEditorType(@NotNull NlProperty property) {
    AttributeDefinition definition = property.getDefinition();
    Set<AttributeFormat> formats = definition != null ? definition.getFormats() : Collections.emptySet();
    Boolean isBoolean = null;
    for (AttributeFormat format : formats) {
        switch(format) {
            case Boolean:
                if (isBoolean == null) {
                    isBoolean = Boolean.TRUE;
                }
                break;
            case String:
            case Color:
            case Dimension:
            case Integer:
            case Float:
            case Fraction:
                if (isBoolean == null) {
                    isBoolean = Boolean.FALSE;
                }
                break;
            case Enum:
                return EditorType.COMBO;
            case Flag:
                return EditorType.FLAG;
            default:
                break;
        }
    }
    // Do not inline this method. Other classes should not know about EnumSupportFactory.
    if (isBoolean == Boolean.TRUE) {
        return EditorType.BOOLEAN;
    } else if (EnumSupportFactory.supportsProperty(property)) {
        if (property.getName().equals(ATTR_STYLE)) {
            return EditorType.COMBO_WITH_BROWSE;
        }
        return EditorType.COMBO;
    }
    return EditorType.DEFAULT;
}
Also used : AttributeFormat(org.jetbrains.android.dom.attrs.AttributeFormat) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with AttributeDefinition

use of org.jetbrains.android.dom.attrs.AttributeDefinition in project android by JetBrains.

the class Quantity method addUnit.

@NotNull
public static String addUnit(@NotNull NlProperty property, @NotNull String value) {
    AttributeDefinition definition = property.getDefinition();
    boolean isDimension = definition != null && definition.getFormats().contains(AttributeFormat.Dimension);
    if (!isDimension) {
        return value;
    }
    Quantity quantity = parse(value);
    if (quantity == null || !quantity.myUnit.isEmpty()) {
        return value;
    }
    switch(property.getName()) {
        case SdkConstants.ATTR_TEXT_SIZE:
        case SdkConstants.ATTR_LINE_SPACING_EXTRA:
            return quantity.myValue + SdkConstants.UNIT_SP;
        default:
            return quantity.myValue + SdkConstants.UNIT_DP;
    }
}
Also used : AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with AttributeDefinition

use of org.jetbrains.android.dom.attrs.AttributeDefinition in project android by JetBrains.

the class NlEnumEditor method findBestInsertionPoint.

private int findBestInsertionPoint(@NotNull ValueWithDisplayString newValue) {
    AttributeDefinition definition = myProperty.getDefinition();
    boolean isDimension = definition != null && definition.getFormats().contains(AttributeFormat.Dimension);
    int startIndex = 1;
    if (!isDimension) {
        return startIndex;
    }
    String newTextValue = newValue.getDisplayString();
    if (StringUtil.isEmpty(newTextValue)) {
        return startIndex;
    }
    Quantity newQuantity = Quantity.parse(newTextValue);
    if (newQuantity == null) {
        return startIndex;
    }
    ComboBoxModel<ValueWithDisplayString> model = myCombo.getModel();
    for (int index = startIndex, size = model.getSize(); index < size; index++) {
        String textValue = model.getElementAt(index).getValue();
        if (textValue != null) {
            Quantity quantity = Quantity.parse(textValue);
            if (newQuantity.compareTo(quantity) <= 0) {
                return index;
            }
        }
    }
    return model.getSize();
}
Also used : ValueWithDisplayString(com.android.tools.idea.uibuilder.property.editors.support.ValueWithDisplayString) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) Quantity(com.android.tools.idea.uibuilder.property.editors.support.Quantity) ValueWithDisplayString(com.android.tools.idea.uibuilder.property.editors.support.ValueWithDisplayString)

Aggregations

AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)35 NotNull (org.jetbrains.annotations.NotNull)10 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)8 NlProperty (com.android.tools.idea.uibuilder.property.NlProperty)7 Nullable (org.jetbrains.annotations.Nullable)7 NlPropertyItem (com.android.tools.idea.uibuilder.property.NlPropertyItem)6 AttributeDefinitions (org.jetbrains.android.dom.attrs.AttributeDefinitions)6 ModelBuilder (com.android.tools.idea.uibuilder.fixtures.ModelBuilder)5 NlModel (com.android.tools.idea.uibuilder.model.NlModel)5 AttributeFormat (org.jetbrains.android.dom.attrs.AttributeFormat)5 ResourceType (com.android.resources.ResourceType)4 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)3 XmlTag (com.intellij.psi.xml.XmlTag)3 ResourceManager (org.jetbrains.android.resourceManagers.ResourceManager)3 HtmlBuilder (com.android.utils.HtmlBuilder)2 NamespaceAwareXmlAttributeDescriptor (com.intellij.xml.NamespaceAwareXmlAttributeDescriptor)2 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)2 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)2 ViewGroup (android.view.ViewGroup)1 LinearLayout (android.widget.LinearLayout)1