Search in sources :

Example 1 with PTableItem

use of com.android.tools.idea.uibuilder.property.ptable.PTableItem in project android by JetBrains.

the class NlPropertyOrderingTest method testGrouping.

public void testGrouping() {
    @Language("XML") String source = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\" >" + "  <TextView />" + "</RelativeLayout>";
    NlComponent component = getFirstComponent(source);
    Table<String, String, NlPropertyItem> properties = NlProperties.getInstance().getProperties(ImmutableList.of(component));
    List<NlPropertyItem> propertyList = new ArrayList<>(properties.values());
    List<PTableItem> items = new NlPropertiesGrouper().group(propertyList, ImmutableList.of(component));
    // assert that all padding related attributes are grouped together
    PTableItem padding = findItemByName(items, "Padding");
    assertNotNull(padding);
    assertNotNull("Attribute paddingStart missing inside padding attributes", findItemByName(padding.getChildren(), "paddingStart"));
    assertNotNull("Attribute paddingEnd missing inside padding attributes", findItemByName(padding.getChildren(), "paddingEnd"));
    // assert that textview attributes are grouped together (disabled for now)
    //PTableItem textView = findItemByName(items, "TextView");
    //assertNotNull("Missing group for TextView attributes", textView);
    //assertNotNull("Attribute capitalize missing inside textview attributes", findItemByName(textView.getChildren(), "capitalize"));
    //assertNotNull("Attribute password missing inside textview attributes", findItemByName(textView.getChildren(), "password"));
    // certain special attrs should be at the top level
    assertNotNull("Missing attribute id at the top level after grouping", findItemByName(items, "id"));
}
Also used : Language(org.intellij.lang.annotations.Language) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) ArrayList(java.util.ArrayList) PTableItem(com.android.tools.idea.uibuilder.property.ptable.PTableItem)

Example 2 with PTableItem

use of com.android.tools.idea.uibuilder.property.ptable.PTableItem in project android by JetBrains.

the class NlPropertyOrderingTest method testSorting.

public void testSorting() {
    @Language("XML") String source = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\" >" + "  <TextView android:text=\"Hello\" />" + "</RelativeLayout>";
    NlComponent component = getFirstComponent(source);
    Table<String, String, NlPropertyItem> properties = NlProperties.getInstance().getProperties(ImmutableList.of(component));
    List<NlPropertyItem> propertyList = new ArrayList<>(properties.values());
    List<NlPropertyItem> sortedList = new NlPropertiesSorter().sort(propertyList, ImmutableList.of(component));
    List<PTableItem> items = new NlPropertiesGrouper().group(sortedList, ImmutableList.of(component));
    assertEquals("id attribute is not the first item", "id", items.get(0).getName());
    assertEquals("Layout_width attribute is not the second item", "layout_width", items.get(1).getName());
    assertEquals("Layout_height attribute is not the third item", "layout_height", items.get(2).getName());
    assertEquals("Layout attributes group is not the fourth item", "Layout_Margin", items.get(3).getName());
    assertEquals("Padding attributes group is not the fifth item", "Padding", items.get(4).getName());
    assertTrue("TextView group not within the top 10 items", findItemIndex(items, "TextView") < 10);
    assertTrue("Modified attribute text not in the top 10 items", findItemIndex(items, "text") < 10);
}
Also used : Language(org.intellij.lang.annotations.Language) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) ArrayList(java.util.ArrayList) PTableItem(com.android.tools.idea.uibuilder.property.ptable.PTableItem)

Example 3 with PTableItem

use of com.android.tools.idea.uibuilder.property.ptable.PTableItem in project android by JetBrains.

the class NlPropertiesPanelTest method testFilterParentIsNotAMatch.

public void testFilterParentIsNotAMatch() {
    PTableItem item = mock(PTableItem.class);
    PTableGroupItem group = mock(PTableGroupItem.class);
    when(item.getName()).thenReturn("top");
    when(item.getParent()).thenReturn(group);
    when(group.getName()).thenReturn("padding");
    when(myEntry.getValue(0)).thenReturn(item);
    NlPropertiesPanel.MyFilter filter = new NlPropertiesPanel.MyFilter();
    filter.setPattern("constra");
    assertFalse(filter.include(myEntry));
}
Also used : PTableItem(com.android.tools.idea.uibuilder.property.ptable.PTableItem) PTableGroupItem(com.android.tools.idea.uibuilder.property.ptable.PTableGroupItem)

Example 4 with PTableItem

use of com.android.tools.idea.uibuilder.property.ptable.PTableItem in project android by JetBrains.

the class NlPropertiesPanelTest method testFilterSimpleMatch.

public void testFilterSimpleMatch() {
    PTableItem item = mock(PTableItem.class);
    when(item.getName()).thenReturn("layout_bottom_of");
    when(myEntry.getValue(0)).thenReturn(item);
    NlPropertiesPanel.MyFilter filter = new NlPropertiesPanel.MyFilter();
    filter.setPattern("bott");
    assertTrue(filter.include(myEntry));
}
Also used : PTableItem(com.android.tools.idea.uibuilder.property.ptable.PTableItem)

Example 5 with PTableItem

use of com.android.tools.idea.uibuilder.property.ptable.PTableItem in project android by JetBrains.

the class NlMarginPropertyAccumulator method createTableCellRenderer.

private static ColoredTableCellRenderer createTableCellRenderer() {
    return new ColoredTableCellRenderer() {

        @Override
        protected void customizeCellRenderer(JTable table, @Nullable Object value, boolean selected, boolean hasFocus, int row, int column) {
            assert value instanceof MarginGroupNode;
            MarginGroupNode node = (MarginGroupNode) value;
            NlMarginPropertyAccumulator accumulator = node.getAccumulator();
            append("[");
            append(node, accumulator.myAllMargin, null);
            append(", ");
            append(node, accumulator.myLeftMargin, accumulator.myStartMargin);
            append(", ");
            append(node, accumulator.myTopMargin, null);
            append(", ");
            append(node, accumulator.myRightMargin, accumulator.myEndMargin);
            append(", ");
            append(node, accumulator.myBottomMargin, null);
            append("]");
        }

        private void append(@NotNull MarginGroupNode node, @NotNull String propertyName, @Nullable String propertyOverride) {
            SimpleTextAttributes attributes = SimpleTextAttributes.REGULAR_ATTRIBUTES;
            PTableItem property = node.getItemByName(propertyName);
            PTableItem override = propertyOverride != null ? node.getItemByName(propertyOverride) : null;
            String value = null;
            if (override != null) {
                value = override.getResolvedValue();
                if (!override.isDefaultValue(value)) {
                    attributes = SimpleTextAttributes.SYNTHETIC_ATTRIBUTES;
                }
            }
            if (property != null && value == null) {
                value = property.getResolvedValue();
                if (!property.isDefaultValue(value)) {
                    attributes = SimpleTextAttributes.SYNTHETIC_ATTRIBUTES;
                }
            }
            if (value == null) {
                value = "?";
            }
            append(value, attributes);
        }
    };
}
Also used : SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) PTableItem(com.android.tools.idea.uibuilder.property.ptable.PTableItem) NotNull(org.jetbrains.annotations.NotNull) ColoredTableCellRenderer(com.intellij.ui.ColoredTableCellRenderer) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PTableItem (com.android.tools.idea.uibuilder.property.ptable.PTableItem)13 PTableGroupItem (com.android.tools.idea.uibuilder.property.ptable.PTableGroupItem)4 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)2 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)2 ArrayList (java.util.ArrayList)2 Language (org.intellij.lang.annotations.Language)2 PropertyNamePrefixAccumulator (com.android.tools.idea.uibuilder.property.NlPropertyAccumulator.PropertyNamePrefixAccumulator)1 PTable (com.android.tools.idea.uibuilder.property.ptable.PTable)1 ColoredTableCellRenderer (com.intellij.ui.ColoredTableCellRenderer)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1