Search in sources :

Example 21 with NlProperty

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

the class TextInspectorProviderTest method propertyPanelHasAllComponents.

private static void propertyPanelHasAllComponents(@NotNull InspectorPanel panel, @NotNull String propertyName, @NotNull Map<String, NlProperty> properties, @NotNull List<NlBooleanIconEditor> editors) {
    List<Component> components = editors.stream().map(NlBooleanIconEditor::getComponent).collect(Collectors.toList());
    ArgumentCaptor<JPanel> panelCaptor = ArgumentCaptor.forClass(JPanel.class);
    NlProperty property = properties.get(propertyName);
    verify(panel).addComponent(eq(propertyName), eq(property.getTooltipText()), panelCaptor.capture());
    JPanel propertyPanel = panelCaptor.getValue();
    assertThat(propertyPanel.getComponents()).asList().containsAllIn(components);
}
Also used : NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) TextInspectorComponent(com.android.tools.idea.uibuilder.property.inspector.TextInspectorProvider.TextInspectorComponent)

Example 22 with NlProperty

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

the class IdAnalyzerTest method testConstraintLayout.

public void testConstraintLayout() {
    ModelBuilder modelBuilder = createConstraintLayout();
    NlModel model = modelBuilder.build();
    NlComponent button2 = findById(model, "button3");
    NlProperty property = new NlPropertyItem(ImmutableList.of(button2), AUTO_URI, new AttributeDefinition(ATTR_LAYOUT_TOP_TO_TOP_OF));
    IdAnalyzer analyzer = new IdAnalyzer(property);
    List<String> ids = analyzer.findIds();
    assertEquals(ImmutableList.of("button4", "button5"), ids);
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) NlModel(com.android.tools.idea.uibuilder.model.NlModel) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) NlPropertyItem(com.android.tools.idea.uibuilder.property.NlPropertyItem)

Example 23 with NlProperty

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

the class IdAnalyzerTest method testRelativeLayout.

public void testRelativeLayout() {
    ModelBuilder modelBuilder = createRelativeLayout();
    NlModel model = modelBuilder.build();
    NlComponent button2 = findById(model, "button3");
    NlProperty property = new NlPropertyItem(ImmutableList.of(button2), ANDROID_URI, new AttributeDefinition(ATTR_LAYOUT_ALIGN_START));
    IdAnalyzer analyzer = new IdAnalyzer(property);
    List<String> ids = analyzer.findIds();
    assertEquals(ImmutableList.of("button4", "button5", "group1"), ids);
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) NlModel(com.android.tools.idea.uibuilder.model.NlModel) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) NlPropertyItem(com.android.tools.idea.uibuilder.property.NlPropertyItem)

Example 24 with NlProperty

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

the class IdAnalyzerTest method testButton1.

public void testButton1() {
    ModelBuilder modelBuilder = createRelativeLayout();
    NlModel model = modelBuilder.build();
    NlComponent button1 = findById(model, "button1");
    NlProperty labelFor = new NlPropertyItem(ImmutableList.of(button1), ANDROID_URI, new AttributeDefinition(ATTR_LABEL_FOR));
    IdAnalyzer analyzer = new IdAnalyzer(labelFor);
    List<String> ids = analyzer.findIds();
    assertEquals(ImmutableList.of("button2", "button3", "button4", "button5", "group1", "radio_button1", "radio_button2", "radio_button3", "text_view1"), ids);
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) NlModel(com.android.tools.idea.uibuilder.model.NlModel) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) NlPropertyItem(com.android.tools.idea.uibuilder.property.NlPropertyItem)

Example 25 with NlProperty

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

the class InspectorPanel method setComponent.

public void setComponent(@NotNull List<NlComponent> components, @NotNull Table<String, String, ? extends NlProperty> properties, @NotNull NlPropertiesManager propertiesManager) {
    myInspector.setLayout(null);
    myInspector.removeAll();
    mySource2GroupMap.clear();
    myLabel2GroupMap.clear();
    myLabel2ComponentMap.clear();
    myRow = 0;
    if (!components.isEmpty()) {
        Map<String, NlProperty> propertiesByName = Maps.newHashMapWithExpectedSize(properties.size());
        for (NlProperty property : properties.row(ANDROID_URI).values()) {
            propertiesByName.put(property.getName(), property);
        }
        for (NlProperty property : properties.row(AUTO_URI).values()) {
            propertiesByName.put(property.getName(), property);
        }
        for (NlProperty property : properties.row("").values()) {
            propertiesByName.put(property.getName(), property);
        }
        // Add access to known design properties
        for (NlProperty property : myDesignProperties.getKnownProperties(components)) {
            propertiesByName.putIfAbsent(property.getName(), property);
        }
        myInspectors = myProviders.createInspectorComponents(components, propertiesByName, propertiesManager);
        int rows = 0;
        for (InspectorComponent inspector : myInspectors) {
            rows += inspector.getMaxNumberOfRows();
        }
        // 1 row for each divider (including 1 after the last property)
        rows += myInspectors.size();
        // 1 Line with a link to all properties + 1 row with a spacer on the bottom
        rows += 2;
        myInspector.setLayout(createLayoutManager(rows, 2));
        for (InspectorComponent inspector : myInspectors) {
            addSeparator();
            inspector.attachToInspector(this);
        }
        endGroup();
        addSeparator();
        // Add a vertical spacer
        myInspector.add(new Spacer(), new GridConstraints(myRow++, 0, 1, 2, ANCHOR_CENTER, FILL_HORIZONTAL, SIZEPOLICY_CAN_GROW, SIZEPOLICY_CAN_GROW | SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
        // Add link to all properties table
        addLineComponent(myAllPropertiesLink, myRow++);
    }
    // These are both important to render the controls correctly the first time:
    ApplicationManager.getApplication().invokeLater(() -> {
        updateAfterFilterChange();
        if (myActivateEditorAfterLoad) {
            activatePreferredEditor(myPropertyNameForActivation);
        }
    });
}
Also used : NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) Spacer(com.intellij.uiDesigner.core.Spacer)

Aggregations

NlProperty (com.android.tools.idea.uibuilder.property.NlProperty)25 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)17 Matchers.anyString (org.mockito.Matchers.anyString)12 NlPropertyItem (com.android.tools.idea.uibuilder.property.NlPropertyItem)7 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)7 NlComponentEditor (com.android.tools.idea.uibuilder.property.editors.NlComponentEditor)6 ModelBuilder (com.android.tools.idea.uibuilder.fixtures.ModelBuilder)5 NlModel (com.android.tools.idea.uibuilder.model.NlModel)5 TextInspectorComponent (com.android.tools.idea.uibuilder.property.inspector.TextInspectorProvider.TextInspectorComponent)3 IdInspectorComponent (com.android.tools.idea.uibuilder.property.inspector.IdInspectorProvider.IdInspectorComponent)2 HashMap (java.util.HashMap)2 SdkConstants (com.android.SdkConstants)1 ChooseResourceDialog (com.android.tools.idea.ui.resourcechooser.ChooseResourceDialog)1 SwitchHandler (com.android.tools.idea.uibuilder.handlers.SwitchHandler)1 PreferenceUtils (com.android.tools.idea.uibuilder.model.PreferenceUtils)1 PropertyTestCase (com.android.tools.idea.uibuilder.property.PropertyTestCase)1 com.android.tools.idea.uibuilder.property.editors (com.android.tools.idea.uibuilder.property.editors)1 NlBaseComponentEditor (com.android.tools.idea.uibuilder.property.editors.NlBaseComponentEditor)1 ImmutableList (com.google.common.collect.ImmutableList)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1