Search in sources :

Example 26 with ModelBuilder

use of com.android.tools.idea.uibuilder.fixtures.ModelBuilder in project android by JetBrains.

the class NlModelTest method testChangeSingleProperty.

@SuppressWarnings("ConstantConditions")
public void testChangeSingleProperty() throws Exception {
    boolean preserveXmlTags = false;
    boolean includeIds = false;
    ModelBuilder modelBuilder = createDefaultModelBuilder(includeIds);
    NlModel model = modelBuilder.build();
    assertEquals("NlComponent{tag=<LinearLayout>, bounds=[0,0:1000x1000, instance=0}\n" + "    NlComponent{tag=<TextView>, bounds=[100,100:100x100, instance=1}\n" + "    NlComponent{tag=<Button>, bounds=[100,200:100x100, instance=2}", myTreeDumper.toTree(model.getComponents()));
    // Change a single attribute in an element without id's.
    ComponentDescriptor layout = modelBuilder.findByPath(LINEAR_LAYOUT);
    assertThat(layout).isNotNull();
    layout.withAttribute("style", "@style/Foo");
    modelBuilder.updateModel(model, preserveXmlTags);
    assertEquals("NlComponent{tag=<LinearLayout>, bounds=[0,0:1000x1000, instance=0}\n" + "    NlComponent{tag=<TextView>, bounds=[100,100:100x100, instance=1}\n" + "    NlComponent{tag=<Button>, bounds=[100,200:100x100, instance=2}", myTreeDumper.toTree(model.getComponents()));
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) ComponentDescriptor(com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor)

Example 27 with ModelBuilder

use of com.android.tools.idea.uibuilder.fixtures.ModelBuilder in project android by JetBrains.

the class NlModelTest method testMoveInHierarchy.

public void testMoveInHierarchy() throws Exception {
    ModelBuilder modelBuilder = createDefaultModelBuilder(false);
    NlModel model = modelBuilder.build();
    assertEquals("NlComponent{tag=<LinearLayout>, bounds=[0,0:1000x1000, instance=0}\n" + "    NlComponent{tag=<TextView>, bounds=[100,100:100x100, instance=1}\n" + "    NlComponent{tag=<Button>, bounds=[100,200:100x100, instance=2}", myTreeDumper.toTree(model.getComponents()));
    // Move button to be child of the text view instead
    ComponentDescriptor parent = modelBuilder.findByPath(LINEAR_LAYOUT);
    assertThat(parent).isNotNull();
    ComponentDescriptor textView = modelBuilder.findByPath(LINEAR_LAYOUT, TEXT_VIEW);
    assertThat(textView).isNotNull();
    ComponentDescriptor button = modelBuilder.findByPath(LINEAR_LAYOUT, BUTTON);
    assertThat(button).isNotNull();
    parent.removeChild(button);
    textView.addChild(button, null);
    modelBuilder.updateModel(model, false);
    assertEquals("NlComponent{tag=<LinearLayout>, bounds=[0,0:1000x1000, instance=0}\n" + "    NlComponent{tag=<TextView>, bounds=[100,100:100x100, instance=1}\n" + "        NlComponent{tag=<Button>, bounds=[100,200:100x100, instance=2}", myTreeDumper.toTree(model.getComponents()));
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) ComponentDescriptor(com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor)

Example 28 with ModelBuilder

use of com.android.tools.idea.uibuilder.fixtures.ModelBuilder in project android by JetBrains.

the class NlModelTest method testAddRemove.

public void testAddRemove() throws Exception {
    // Test removing one child and adding another one. Check that we don't
    // preserve component identity across two separate tag names.
    ModelBuilder modelBuilder = createDefaultModelBuilder(false);
    NlModel model = modelBuilder.build();
    assertEquals("NlComponent{tag=<LinearLayout>, bounds=[0,0:1000x1000, instance=0}\n" + "    NlComponent{tag=<TextView>, bounds=[100,100:100x100, instance=1}\n" + "    NlComponent{tag=<Button>, bounds=[100,200:100x100, instance=2}", myTreeDumper.toTree(model.getComponents()));
    // Add child
    ComponentDescriptor parent = modelBuilder.findByPath(LINEAR_LAYOUT);
    assertThat(parent).isNotNull();
    ComponentDescriptor button = modelBuilder.findByPath(LINEAR_LAYOUT, BUTTON);
    assertThat(button).isNotNull();
    ComponentDescriptor textView = modelBuilder.findByPath(LINEAR_LAYOUT, TEXT_VIEW);
    assertThat(textView).isNotNull();
    parent.addChild(component(EDIT_TEXT).withBounds(100, 100, 100, 100).width("100dp").height("100dp"), textView);
    parent.removeChild(button);
    modelBuilder.updateModel(model, false);
    assertEquals("NlComponent{tag=<LinearLayout>, bounds=[0,0:1000x1000, instance=0}\n" + "    NlComponent{tag=<EditText>, bounds=[100,100:100x100, instance=3}\n" + "    NlComponent{tag=<TextView>, bounds=[100,100:100x100, instance=1}", myTreeDumper.toTree(model.getComponents()));
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) ComponentDescriptor(com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor)

Example 29 with ModelBuilder

use of com.android.tools.idea.uibuilder.fixtures.ModelBuilder in project android by JetBrains.

the class NlModelTest method testSync.

@SuppressWarnings("ConstantConditions")
public void testSync() throws Exception {
    // Whether we include id's in the components or not. Id's help
    // associate id's with before/after versions; they're conditionally
    // added such that we can test the model handler with and without this
    // aid.
    boolean includeIds = false;
    ModelBuilder modelBuilder = createDefaultModelBuilder(includeIds);
    NlModel model = modelBuilder.build();
    assertEquals("NlComponent{tag=<LinearLayout>, bounds=[0,0:1000x1000, instance=0}\n" + "    NlComponent{tag=<TextView>, bounds=[100,100:100x100, instance=1}\n" + "    NlComponent{tag=<Button>, bounds=[100,200:100x100, instance=2}", myTreeDumper.toTree(model.getComponents()));
    // Same hierarchy; preserveXmlTags means that all the XmlTags in the view hiearchy
    // will be different than in the existing model (simulating a completely separate
    // PSI parse)
    boolean preserveXmlTags = false;
    modelBuilder.updateModel(model, preserveXmlTags);
    // Everything should be identical
    assertEquals("NlComponent{tag=<LinearLayout>, bounds=[0,0:1000x1000, instance=0}\n" + "    NlComponent{tag=<TextView>, bounds=[100,100:100x100, instance=1}\n" + "    NlComponent{tag=<Button>, bounds=[100,200:100x100, instance=2}", myTreeDumper.toTree(model.getComponents()));
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder)

Aggregations

ModelBuilder (com.android.tools.idea.uibuilder.fixtures.ModelBuilder)29 NlModel (com.android.tools.idea.uibuilder.model.NlModel)19 ComponentDescriptor (com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor)12 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)6 NotNull (org.jetbrains.annotations.NotNull)6 NlProperty (com.android.tools.idea.uibuilder.property.NlProperty)5 NlPropertyItem (com.android.tools.idea.uibuilder.property.NlPropertyItem)5 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)5 ABSOLUTE_LAYOUT (com.android.SdkConstants.ABSOLUTE_LAYOUT)1 ViewInfo (com.android.ide.common.rendering.api.ViewInfo)1 Configuration (com.android.tools.idea.configurations.Configuration)1 BuildSettings (com.android.tools.idea.gradle.project.BuildSettings)1 BuildMode (com.android.tools.idea.gradle.util.BuildMode)1 TagSnapshot (com.android.tools.idea.rendering.TagSnapshot)1 LayoutTestCase (com.android.tools.idea.uibuilder.LayoutTestCase)1 IdeEventQueue (com.intellij.ide.IdeEventQueue)1 Document (com.intellij.openapi.editor.Document)1 Project (com.intellij.openapi.project.Project)1 Disposer (com.intellij.openapi.util.Disposer)1 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)1