Search in sources :

Example 1 with NlComponentEditor

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

the class InspectorPanel method activatePreferredEditor.

private void activatePreferredEditor(@NotNull String propertyName) {
    myActivateEditorAfterLoad = false;
    myPropertyNameForActivation = null;
    boolean designPropertyRequired = propertyName.startsWith(TOOLS_NS_NAME_PREFIX);
    propertyName = StringUtil.trimStart(propertyName, TOOLS_NS_NAME_PREFIX);
    for (InspectorComponent component : myInspectors) {
        for (NlComponentEditor editor : component.getEditors()) {
            NlProperty property = editor.getProperty();
            if (property != null && propertyName.equals(property.getName()) && !(designPropertyRequired && !TOOLS_URI.equals(property.getNamespace()))) {
                editor.requestFocus();
                return;
            }
        }
    }
}
Also used : NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) NlComponentEditor(com.android.tools.idea.uibuilder.property.editors.NlComponentEditor)

Example 2 with NlComponentEditor

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

the class ProgressBarInspectorProviderTest method testInspectorComponent.

public void testInspectorComponent() {
    List<NlComponent> components = ImmutableList.of(myProgressBar);
    Map<String, NlProperty> properties = getPropertyMap(components);
    assertThat(myProvider.isApplicable(components, properties, myPropertiesManager)).isTrue();
    InspectorComponent inspector = myProvider.createCustomInspector(components, properties, myPropertiesManager);
    List<NlComponentEditor> editors = inspector.getEditors();
    assertThat(editors.size()).isEqualTo(10);
    assertThat(inspector.getMaxNumberOfRows()).isEqualTo(11);
    InspectorPanel panel = mock(InspectorPanel.class);
    when(panel.addComponent(anyString(), anyString(), any())).thenAnswer(invocation -> new JLabel());
    inspector.attachToInspector(panel);
    verify(panel).addTitle(eq(PROGRESS_BAR));
    for (NlComponentEditor editor : editors) {
        NlProperty property = editor.getProperty();
        assertThat(property).isNotNull();
        verify(panel).addComponent(eq(property.getName()), eq(property.getTooltipText()), eq(editor.getComponent()));
    }
}
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)

Example 3 with NlComponentEditor

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

the class IdInspectorProviderTest method testInspectorComponent.

public void testInspectorComponent() {
    List<NlComponent> components = ImmutableList.of(myTextView);
    Map<String, NlProperty> properties = getPropertyMap(components);
    assertThat(myProvider.isApplicable(components, properties, myPropertiesManager)).isTrue();
    IdInspectorComponent inspector = myProvider.createCustomInspector(components, properties, myPropertiesManager);
    List<NlComponentEditor> editors = inspector.getEditors();
    assertThat(editors.size()).isEqualTo(3);
    assertThat(inspector.getMaxNumberOfRows()).isEqualTo(4);
    InspectorPanel panel = mock(InspectorPanel.class);
    when(panel.addComponent(anyString(), anyString(), any())).thenAnswer(invocation -> new JLabel());
    inspector.attachToInspector(panel);
    for (NlComponentEditor editor : editors) {
        NlProperty property = editor.getProperty();
        assertThat(property).isNotNull();
        String propertyName = property.getName();
        if (propertyName.equals(ATTR_ID)) {
            propertyName = "ID";
        }
        verify(panel).addComponent(eq(propertyName), eq(null), eq(editor.getComponent()));
    }
    verify(panel, never()).addPanel(inspector.getConstraintPanel());
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) Matchers.anyString(org.mockito.Matchers.anyString) IdInspectorComponent(com.android.tools.idea.uibuilder.property.inspector.IdInspectorProvider.IdInspectorComponent) NlComponentEditor(com.android.tools.idea.uibuilder.property.editors.NlComponentEditor)

Example 4 with NlComponentEditor

use of com.android.tools.idea.uibuilder.property.editors.NlComponentEditor 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 5 with NlComponentEditor

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

the class ViewInspectorProviderTest method testInspectorComponent.

public void testInspectorComponent() {
    List<NlComponent> components = ImmutableList.of(mySwitch);
    Map<String, NlProperty> properties = getPropertyMap(components);
    assertThat(myProvider.isApplicable(components, properties, myPropertiesManager)).isTrue();
    InspectorComponent inspector = myProvider.createCustomInspector(components, properties, myPropertiesManager);
    List<NlComponentEditor> editors = inspector.getEditors();
    assertThat(editors.size()).isEqualTo(14);
    assertThat(inspector.getMaxNumberOfRows()).isEqualTo(editors.size() + 1);
    Set<String> inspectorProperties = new HashSet<>(new SwitchHandler().getInspectorProperties());
    InspectorPanel panel = mock(InspectorPanel.class);
    when(panel.addComponent(anyString(), anyString(), any())).thenAnswer(invocation -> new JLabel());
    inspector.attachToInspector(panel);
    verify(panel).addTitle(SWITCH);
    for (NlComponentEditor editor : editors) {
        NlProperty property = editor.getProperty();
        assertThat(property).isNotNull();
        verify(panel).addComponent(eq(property.getName()), eq(property.getTooltipText()), eq(editor.getComponent()));
        assertThat(editor.getLabel()).isNotNull();
        if (TOOLS_URI.equals(property.getNamespace())) {
            assertThat(editor.getLabel().getIcon()).isEqualTo(AndroidIcons.NeleIcons.DesignProperty);
            if (!inspectorProperties.remove(TOOLS_NS_NAME_PREFIX + property.getName())) {
                assertThat(inspectorProperties.remove(TOOLS_NS_NAME_PREFIX + property.getName())).named(property.getName()).isTrue();
            }
        } else {
            assertThat(editor.getLabel().getIcon()).isNull();
            assertThat(inspectorProperties.remove(property.getName())).named(property.getName()).isTrue();
        }
    }
    assertThat(inspectorProperties).isEmpty();
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) NlComponentEditor(com.android.tools.idea.uibuilder.property.editors.NlComponentEditor) SwitchHandler(com.android.tools.idea.uibuilder.handlers.SwitchHandler) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty)

Aggregations

NlProperty (com.android.tools.idea.uibuilder.property.NlProperty)6 NlComponentEditor (com.android.tools.idea.uibuilder.property.editors.NlComponentEditor)6 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)5 Matchers.anyString (org.mockito.Matchers.anyString)5 NlPropertyItem (com.android.tools.idea.uibuilder.property.NlPropertyItem)2 SwitchHandler (com.android.tools.idea.uibuilder.handlers.SwitchHandler)1 IdInspectorComponent (com.android.tools.idea.uibuilder.property.inspector.IdInspectorProvider.IdInspectorComponent)1 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)1