Search in sources :

Example 6 with NlPropertyItem

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

the class FavoritesInspectorProviderTest method testIsApplicableChangesWithStarSettings.

public void testIsApplicableChangesWithStarSettings() {
    NlPropertyItem elevation = createFrom(myTextView, ATTR_ELEVATION);
    NlPropertyItem visibility = createFrom(myTextView, ATTR_VISIBILITY);
    assertThat(myProvider.isApplicable(Collections.emptyList(), Collections.singletonMap(ATTR_ELEVATION, elevation), myPropertiesManager)).isFalse();
    assertThat(myProvider.isApplicable(Collections.emptyList(), Collections.singletonMap(ATTR_VISIBILITY, visibility), myPropertiesManager)).isTrue();
    myPropertiesComponent.setValue(STARRED_PROP, ATTR_ELEVATION);
    assertThat(myProvider.isApplicable(Collections.emptyList(), Collections.singletonMap(ATTR_ELEVATION, elevation), myPropertiesManager)).isTrue();
    assertThat(myProvider.isApplicable(Collections.emptyList(), Collections.singletonMap(ATTR_VISIBILITY, visibility), myPropertiesManager)).isFalse();
}
Also used : NlPropertyItem(com.android.tools.idea.uibuilder.property.NlPropertyItem)

Example 7 with NlPropertyItem

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

the class FavoritesInspectorProviderTest method testIsApplicable.

public void testIsApplicable() {
    NlPropertyItem elevation = createFrom(myTextView, ATTR_ELEVATION);
    NlPropertyItem visibility = createFrom(myTextView, ATTR_VISIBILITY);
    // If no starred properties are available for the current selection then this provider is not applicable:
    assertThat(myProvider.isApplicable(Collections.emptyList(), Collections.emptyMap(), myPropertiesManager)).isFalse();
    assertThat(myProvider.isApplicable(Collections.emptyList(), Collections.singletonMap(ATTR_ELEVATION, elevation), myPropertiesManager)).isFalse();
    assertThat(myProvider.isApplicable(Collections.emptyList(), Collections.singletonMap(ATTR_VISIBILITY, visibility), myPropertiesManager)).isTrue();
}
Also used : NlPropertyItem(com.android.tools.idea.uibuilder.property.NlPropertyItem)

Example 8 with NlPropertyItem

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

the class NlDefaultRendererTest method testSimple.

public void testSimple() {
    @Language("XML") String source = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\" >" + "  <TextView android:id=\"@+id/textView\"/>" + "</RelativeLayout>";
    XmlFile xmlFile = (XmlFile) myFixture.addFileToProject("res/layout/layout.xml", source);
    XmlTag[] subTags = xmlFile.getRootTag().getSubTags();
    assertEquals(1, subTags.length);
    Table<String, String, NlPropertyItem> properties = NlProperties.getInstance().getProperties(ImmutableList.of(MockNlComponent.create(subTags[0])));
    NlDefaultRenderer renderer = new NlDefaultRenderer();
    NlPropertyItem property = properties.get(SdkConstants.ANDROID_URI, "id");
    validateRendering(renderer, property, "id", "textView");
    property = properties.get(SdkConstants.ANDROID_URI, "text");
    validateRendering(renderer, property, "text", "");
    property = properties.get(SdkConstants.ANDROID_URI, "focusable");
    validateRendering(renderer, property, "focusable", "");
}
Also used : Language(org.intellij.lang.annotations.Language) XmlFile(com.intellij.psi.xml.XmlFile) XmlTag(com.intellij.psi.xml.XmlTag) NlPropertyItem(com.android.tools.idea.uibuilder.property.NlPropertyItem)

Example 9 with NlPropertyItem

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

the class ViewInspectorProviderTest method testUpdateProperties.

public void testUpdateProperties() {
    List<NlComponent> components = ImmutableList.of(myImageView);
    Map<String, NlProperty> properties = getPropertyMap(components);
    assertThat(myProvider.isApplicable(components, properties, myPropertiesManager)).isTrue();
    InspectorComponent inspector = myProvider.createCustomInspector(components, properties, myPropertiesManager);
    inspector.updateProperties(components, properties, myPropertiesManager);
    NlComponentEditor srcEditor = inspector.getEditors().get(0);
    assertThat(srcEditor.getProperty()).isNotNull();
    assertThat(srcEditor.getProperty().getName()).isEqualTo(ATTR_SRC);
    // Simulate the addition of appcompat library:
    AttributeDefinition srcCompatDefinition = new AttributeDefinition(ATTR_SRC_COMPAT);
    properties.put(ATTR_SRC_COMPAT, new NlPropertyItem(components, ANDROID_URI, srcCompatDefinition));
    // Check that an update will replace the ATTR_SRC with ATTR_SRC_COMPAT
    inspector.updateProperties(components, properties, myPropertiesManager);
    srcEditor = inspector.getEditors().get(0);
    assertThat(srcEditor.getProperty()).isNotNull();
    assertThat(srcEditor.getProperty().getName()).isEqualTo(ATTR_SRC_COMPAT);
    // Simulate the removal of appcompat library:
    properties.remove(ATTR_SRC_COMPAT);
    // Check that an update will replace the ATTR_SRC with ATTR_SRC_COMPAT
    inspector.updateProperties(components, properties, myPropertiesManager);
    srcEditor = inspector.getEditors().get(0);
    assertThat(srcEditor.getProperty()).isNotNull();
    assertThat(srcEditor.getProperty().getName()).isEqualTo(ATTR_SRC);
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) Matchers.anyString(org.mockito.Matchers.anyString) NlComponentEditor(com.android.tools.idea.uibuilder.property.editors.NlComponentEditor) NlPropertyItem(com.android.tools.idea.uibuilder.property.NlPropertyItem)

Example 10 with NlPropertyItem

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

the class FavoritesInspectorProviderTest method testInspectorComponent.

public void testInspectorComponent() {
    NlPropertyItem elevation = createFrom(myTextView, ATTR_ELEVATION);
    NlPropertyItem visibility = createFrom(myTextView, ATTR_VISIBILITY);
    NlPropertyItem text = createFrom(myTextView, ATTR_TEXT);
    myPropertiesComponent.setValue(STARRED_PROP, TOOLS_NS_NAME_PREFIX + ATTR_ELEVATION + ";" + ATTR_VISIBILITY);
    List<NlComponent> components = Collections.singletonList(myTextView);
    Map<String, NlProperty> properties = ImmutableMap.of(ATTR_TEXT, text, ATTR_ELEVATION, elevation, ATTR_VISIBILITY, visibility);
    assertThat(myProvider.isApplicable(components, properties, myPropertiesManager)).isTrue();
    InspectorComponent inspector = myProvider.createCustomInspector(components, properties, myPropertiesManager);
    List<NlComponentEditor> editors = inspector.getEditors();
    assertThat(editors.size()).isEqualTo(2);
    assertThat(inspector.getMaxNumberOfRows()).isEqualTo(3);
    InspectorPanel panel = mock(InspectorPanel.class);
    when(panel.addComponent(anyString(), anyString(), any())).thenAnswer(invocation -> new JLabel());
    inspector.attachToInspector(panel);
    verify(panel).addTitle(eq("Favorite Attributes"));
    NlComponentEditor visibilityEditor = editors.get(1);
    assertThat(visibilityEditor.getProperty()).isSameAs(visibility);
    verify(panel).addComponent(eq(visibility.getName()), eq(visibility.getTooltipText()), eq(visibilityEditor.getComponent()));
    JLabel visibilityLabel = visibilityEditor.getLabel();
    assertThat(visibilityLabel).isNotNull();
    assertThat(visibilityLabel.getIcon()).isNull();
    NlComponentEditor elevationEditor = editors.get(0);
    NlProperty elevationDesignProperty = elevationEditor.getProperty();
    assertThat(elevationDesignProperty.getName()).isEqualTo(elevation.getName());
    assertThat(elevationDesignProperty.getDefinition()).isSameAs(elevation.getDefinition());
    assertThat(elevationDesignProperty.getNamespace()).isEqualTo(TOOLS_URI);
    verify(panel).addComponent(eq(elevationDesignProperty.getName()), eq(elevationDesignProperty.getTooltipText()), eq(elevationEditor.getComponent()));
    JLabel elevationLabel = elevationEditor.getLabel();
    assertThat(elevationLabel).isNotNull();
    assertThat(elevationLabel.getIcon()).isSameAs(AndroidIcons.NeleIcons.DesignProperty);
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) Matchers.anyString(org.mockito.Matchers.anyString) NlComponentEditor(com.android.tools.idea.uibuilder.property.editors.NlComponentEditor) NlPropertyItem(com.android.tools.idea.uibuilder.property.NlPropertyItem)

Aggregations

NlPropertyItem (com.android.tools.idea.uibuilder.property.NlPropertyItem)14 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)7 NlProperty (com.android.tools.idea.uibuilder.property.NlProperty)7 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)6 ModelBuilder (com.android.tools.idea.uibuilder.fixtures.ModelBuilder)5 NlModel (com.android.tools.idea.uibuilder.model.NlModel)5 NlComponentEditor (com.android.tools.idea.uibuilder.property.editors.NlComponentEditor)2 PTableModel (com.android.tools.idea.uibuilder.property.ptable.PTableModel)2 Nullable (org.jetbrains.annotations.Nullable)2 Matchers.anyString (org.mockito.Matchers.anyString)2 XmlFile (com.intellij.psi.xml.XmlFile)1 XmlTag (com.intellij.psi.xml.XmlTag)1 Language (org.intellij.lang.annotations.Language)1