Search in sources :

Example 1 with NlProperty

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

the class BrowsePanel method createDesignAction.

private AnAction createDesignAction() {
    return new AnAction() {

        @Override
        public void update(AnActionEvent event) {
            Presentation presentation = event.getPresentation();
            switch(checkDesignState()) {
                case MISSING_DESIGN_PROPERTY:
                    presentation.setIcon(AndroidIcons.NeleIcons.DesignProperty);
                    presentation.setText("Specify Design Property");
                    presentation.setVisible(true);
                    presentation.setEnabled(true);
                    break;
                case IS_REMOVABLE_DESIGN_PROPERTY:
                    presentation.setIcon(AllIcons.Actions.Delete);
                    presentation.setText("Remove this Design Property");
                    presentation.setVisible(true);
                    presentation.setEnabled(true);
                    break;
                default:
                    presentation.setIcon(null);
                    presentation.setText(null);
                    presentation.setVisible(false);
                    presentation.setEnabled(false);
                    break;
            }
        }

        @Override
        public void actionPerformed(AnActionEvent event) {
            switch(checkDesignState()) {
                case MISSING_DESIGN_PROPERTY:
                    myContext.addDesignProperty();
                    break;
                case IS_REMOVABLE_DESIGN_PROPERTY:
                    myContext.removeDesignProperty();
                    break;
                default:
            }
        }

        private DesignState checkDesignState() {
            NlProperty property = myContext.getProperty();
            if (property == null || myDesignButton == null) {
                return DesignState.NOT_APPLICABLE;
            }
            if (TOOLS_URI.equals(property.getNamespace())) {
                NlProperty runtimeProperty = myContext.getRuntimeProperty();
                return runtimeProperty != null ? DesignState.IS_REMOVABLE_DESIGN_PROPERTY : DesignState.NOT_APPLICABLE;
            } else {
                NlProperty designProperty = myContext.getDesignProperty();
                return designProperty != null ? DesignState.HAS_DESIGN_PROPERTY : DesignState.MISSING_DESIGN_PROPERTY;
            }
        }
    };
}
Also used : NlProperty(com.android.tools.idea.uibuilder.property.NlProperty)

Example 2 with NlProperty

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

the class NlBaseComponentEditor method displayResourcePicker.

protected void displayResourcePicker() {
    NlProperty property = getProperty();
    if (property == null) {
        return;
    }
    ChooseResourceDialog dialog = BrowsePanel.showResourceChooser(property);
    if (dialog.showAndGet()) {
        stopEditing(dialog.getResourceName());
    } else {
        cancelEditing();
    }
}
Also used : NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) ChooseResourceDialog(com.android.tools.idea.ui.resourcechooser.ChooseResourceDialog)

Example 3 with NlProperty

use of com.android.tools.idea.uibuilder.property.NlProperty 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 4 with NlProperty

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

the class ProgressBarInspectorProviderTest method testChangingIndeterminateChangesVisibilityOfEditors.

public void testChangingIndeterminateChangesVisibilityOfEditors() {
    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);
    inspector.refresh();
    assertThat(isEditorVisible(inspector, ATTR_STYLE, "")).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_PROGRESS_DRAWABLE)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_INDETERMINATE_DRAWABLE)).isFalse();
    assertThat(isEditorVisible(inspector, ATTR_PROGRESS_TINT)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_INDETERMINATE_TINT)).isFalse();
    assertThat(isEditorVisible(inspector, ATTR_MAXIMUM)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_PROGRESS)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_VISIBILITY)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_VISIBILITY, TOOLS_URI)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_INDETERMINATE)).isTrue();
    NlBaseComponentEditor indeterminateEditor = (NlBaseComponentEditor) getEditor(inspector, ATTR_INDETERMINATE, ANDROID_URI);
    indeterminateEditor.stopEditing("true");
    assertThat(isEditorVisible(inspector, ATTR_STYLE, "")).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_PROGRESS_DRAWABLE)).isFalse();
    assertThat(isEditorVisible(inspector, ATTR_INDETERMINATE_DRAWABLE)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_PROGRESS_TINT)).isFalse();
    assertThat(isEditorVisible(inspector, ATTR_INDETERMINATE_TINT)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_MAXIMUM)).isFalse();
    assertThat(isEditorVisible(inspector, ATTR_PROGRESS)).isFalse();
    assertThat(isEditorVisible(inspector, ATTR_VISIBILITY)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_VISIBILITY, TOOLS_URI)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_INDETERMINATE)).isTrue();
    indeterminateEditor.stopEditing("false");
    assertThat(isEditorVisible(inspector, ATTR_STYLE, "")).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_PROGRESS_DRAWABLE)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_INDETERMINATE_DRAWABLE)).isFalse();
    assertThat(isEditorVisible(inspector, ATTR_PROGRESS_TINT)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_INDETERMINATE_TINT)).isFalse();
    assertThat(isEditorVisible(inspector, ATTR_MAXIMUM)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_PROGRESS)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_VISIBILITY)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_VISIBILITY, TOOLS_URI)).isTrue();
    assertThat(isEditorVisible(inspector, ATTR_INDETERMINATE)).isTrue();
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) Matchers.anyString(org.mockito.Matchers.anyString) NlBaseComponentEditor(com.android.tools.idea.uibuilder.property.editors.NlBaseComponentEditor)

Example 5 with NlProperty

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

the class ProgressBarInspectorProviderTest method hasProperty.

private static boolean hasProperty(@NotNull NlComponentEditor editor, @NotNull String attributeName, @NotNull String namespace) {
    NlProperty property = editor.getProperty();
    assertThat(property).isNotNull();
    return property.getName().equals(attributeName) && namespace.equals(property.getNamespace());
}
Also used : NlProperty(com.android.tools.idea.uibuilder.property.NlProperty)

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