Search in sources :

Example 1 with PropertyNamePrefixAccumulator

use of com.android.tools.idea.uibuilder.property.NlPropertyAccumulator.PropertyNamePrefixAccumulator in project android by JetBrains.

the class NlPropertiesGrouper method group.

public List<PTableItem> group(@NotNull List<NlPropertyItem> properties, @NotNull List<NlComponent> components) {
    String className = getCommonTagName(components);
    List<PTableItem> result = Lists.newArrayListWithExpectedSize(properties.size());
    // group theme attributes together
    NlPropertyAccumulator themePropertiesAccumulator = new NlPropertyAccumulator("Theme", p -> p != null && (p.getParentStylables().contains("Theme") || p.getName().equalsIgnoreCase("theme")));
    // Disable this for now...
    //
    // group attributes that correspond to this component together
    //NlPropertyAccumulator customViewPropertiesAccumulator = null;
    //if (className != null) {
    //  customViewPropertiesAccumulator = new NlPropertyAccumulator(className, p -> p != null && p.getParentStylables().contains(className));
    //}
    // group margin, padding and layout attributes together
    NlPropertyAccumulator paddingPropertiesAccumulator = new NlMarginPropertyAccumulator("Padding", ATTR_PADDING, ATTR_PADDING_LEFT, ATTR_PADDING_RIGHT, ATTR_PADDING_START, ATTR_PADDING_END, ATTR_PADDING_TOP, ATTR_PADDING_BOTTOM);
    NlPropertyAccumulator layoutViewPropertiesAccumulator = new NlMarginPropertyAccumulator("Layout_Margin", ATTR_LAYOUT_MARGIN, ATTR_LAYOUT_MARGIN_LEFT, ATTR_LAYOUT_MARGIN_RIGHT, ATTR_LAYOUT_MARGIN_START, ATTR_LAYOUT_MARGIN_END, ATTR_LAYOUT_MARGIN_TOP, ATTR_LAYOUT_MARGIN_BOTTOM);
    PropertyNamePrefixAccumulator constraintPropertiesAccumulator = new PropertyNamePrefixAccumulator("Constraints", "layout_constraint");
    List<NlPropertyAccumulator> accumulators = Lists.newArrayList(themePropertiesAccumulator, paddingPropertiesAccumulator, layoutViewPropertiesAccumulator, constraintPropertiesAccumulator);
    for (NlPropertyItem p : properties) {
        boolean added = false;
        for (NlPropertyAccumulator accumulator : accumulators) {
            added = accumulator.process(p);
            if (added) {
                break;
            }
        }
        if (!added) {
            result.add(p);
        }
    }
    int insertionPoint = findInsertionPoint(result);
    for (NlPropertyAccumulator accumulator : accumulators) {
        if (accumulator.hasItems()) {
            result.add(insertionPoint, accumulator.getGroupNode());
        }
    }
    return result;
}
Also used : PropertyNamePrefixAccumulator(com.android.tools.idea.uibuilder.property.NlPropertyAccumulator.PropertyNamePrefixAccumulator) PTableItem(com.android.tools.idea.uibuilder.property.ptable.PTableItem)

Aggregations

PropertyNamePrefixAccumulator (com.android.tools.idea.uibuilder.property.NlPropertyAccumulator.PropertyNamePrefixAccumulator)1 PTableItem (com.android.tools.idea.uibuilder.property.ptable.PTableItem)1