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;
}
}
}
}
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()));
}
}
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());
}
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);
}
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();
}
Aggregations