Search in sources :

Example 26 with NlModel

use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.

the class NlComponentTreeTest method createModelWithAppBar.

@NotNull
private NlModel createModelWithAppBar() {
    ModelBuilder builder = model("coordinator.xml", component(COORDINATOR_LAYOUT).withBounds(0, 0, 1000, 1000).matchParentWidth().matchParentHeight().children(component(APP_BAR_LAYOUT).withBounds(0, 0, 1000, 192).matchParentWidth().height("192dp").children(component(COLLAPSING_TOOLBAR_LAYOUT).withBounds(0, 0, 1000, 192).matchParentHeight().matchParentWidth().children(component(IMAGE_VIEW).withBounds(0, 0, 1000, 192).matchParentWidth().matchParentHeight(), component("android.support.v7.widget.Toolbar").withBounds(0, 0, 1000, 18).height("?attr/actionBarSize").matchParentWidth())), component(CLASS_NESTED_SCROLL_VIEW).withBounds(0, 192, 1000, 808).matchParentWidth().matchParentHeight().withAttribute(AUTO_URI, "layout_behavior", "android.support.design.widget.AppBarLayout$ScrollingViewBehavior").children(component(TEXT_VIEW).withBounds(0, 192, 1000, 808).matchParentWidth().wrapContentHeight().text("@string/stuff"))));
    final NlModel model = builder.build();
    assertEquals(1, model.getComponents().size());
    assertEquals("NlComponent{tag=<android.support.design.widget.CoordinatorLayout>, bounds=[0,0:1000x1000}\n" + "    NlComponent{tag=<android.support.design.widget.AppBarLayout>, bounds=[0,0:1000x192}\n" + "        NlComponent{tag=<android.support.design.widget.CollapsingToolbarLayout>, bounds=[0,0:1000x192}\n" + "            NlComponent{tag=<ImageView>, bounds=[0,0:1000x192}\n" + "            NlComponent{tag=<android.support.v7.widget.Toolbar>, bounds=[0,0:1000x18}\n" + "    NlComponent{tag=<android.support.v4.widget.NestedScrollView>, bounds=[0,192:1000x808}\n" + "        NlComponent{tag=<TextView>, bounds=[0,192:1000x808}", NlTreeDumper.dumpTree(model.getComponents()));
    return model;
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) NlModel(com.android.tools.idea.uibuilder.model.NlModel) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with NlModel

use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.

the class NlComponentTreeTest method testTreeStructureOfAppBar.

public void testTreeStructureOfAppBar() {
    NlModel model = createModelWithAppBar();
    when(myScreen.getModel()).thenReturn(model);
    when(myScreen.getSelectionModel()).thenReturn(model.getSelectionModel());
    myTree.setDesignSurface(mySurface);
    UIUtil.dispatchAllInvocationEvents();
    assertEquals("<android.support.design.widget.CoordinatorLayout>  [expanded]\n" + "    <android.support.design.widget.AppBarLayout>  [expanded]\n" + "        <android.support.design.widget.CollapsingToolbarLayout>  [expanded]\n" + "            <ImageView>\n" + "            <android.support.v7.widget.Toolbar>\n" + "    <android.support.v4.widget.NestedScrollView>  [expanded]\n" + "        <TextView>\n", toTree());
}
Also used : NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 28 with NlModel

use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.

the class WidgetConstraintPanel method setAttribute.

private void setAttribute(String nameSpace, String attribute, String value) {
    if (mConfiguringUI) {
        return;
    }
    NlModel model = mComponent.getModel();
    AttributesTransaction transaction = mComponent.startAttributeTransaction();
    transaction.setAttribute(nameSpace, attribute, value);
    transaction.apply();
    model.requestLayout(false);
    myTimer.setRepeats(false);
    Project project = model.getProject();
    XmlFile file = model.getFile();
    String label = "Change Widget";
    myWriteAction = new WriteCommandAction(project, label, file) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            AttributesTransaction transaction = mComponent.startAttributeTransaction();
            transaction.setAttribute(nameSpace, attribute, value);
            transaction.commit();
        }
    };
    myTimer.restart();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) XmlFile(com.intellij.psi.xml.XmlFile) NlModel(com.android.tools.idea.uibuilder.model.NlModel) AttributesTransaction(com.android.tools.idea.uibuilder.model.AttributesTransaction) Result(com.intellij.openapi.application.Result)

Example 29 with NlModel

use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.

the class ConstraintComponentUtilities method clearAttributes.

public static void clearAttributes(SceneComponent component) {
    AttributesTransaction transaction = component.getNlComponent().startAttributeTransaction();
    clearAllAttributes(component, transaction);
    transaction.apply();
    NlModel nlModel = component.getNlComponent().getModel();
    Project project = nlModel.getProject();
    XmlFile file = nlModel.getFile();
    String label = "Cleared all constraints";
    WriteCommandAction action = new WriteCommandAction(project, label, file) {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            transaction.commit();
        }
    };
    action.execute();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) XmlFile(com.intellij.psi.xml.XmlFile) NlModel(com.android.tools.idea.uibuilder.model.NlModel) NotNull(org.jetbrains.annotations.NotNull) AttributesTransaction(com.android.tools.idea.uibuilder.model.AttributesTransaction) Result(com.intellij.openapi.application.Result)

Example 30 with NlModel

use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.

the class ConstraintComponentUtilities method updateOnDelete.

public static void updateOnDelete(NlComponent component, String targetId) {
    AttributesTransaction transaction = null;
    transaction = updateOnDelete(component, ourLeftAttributes, transaction, targetId);
    transaction = updateOnDelete(component, ourTopAttributes, transaction, targetId);
    transaction = updateOnDelete(component, ourRightAttributes, transaction, targetId);
    transaction = updateOnDelete(component, ourBottomAttributes, transaction, targetId);
    transaction = updateOnDelete(component, ourBaselineAttributes, transaction, targetId);
    if (transaction != null) {
        transaction.apply();
        NlModel nlModel = component.getModel();
        Project project = nlModel.getProject();
        XmlFile file = nlModel.getFile();
        String label = "Remove constraints pointing to a deleted component";
        AttributesTransaction finalTransaction = transaction;
        WriteCommandAction action = new WriteCommandAction(project, label, file) {

            @Override
            protected void run(@NotNull Result result) throws Throwable {
                finalTransaction.commit();
            }
        };
        action.execute();
    }
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) XmlFile(com.intellij.psi.xml.XmlFile) NlModel(com.android.tools.idea.uibuilder.model.NlModel) NotNull(org.jetbrains.annotations.NotNull) AttributesTransaction(com.android.tools.idea.uibuilder.model.AttributesTransaction) Result(com.intellij.openapi.application.Result)

Aggregations

NlModel (com.android.tools.idea.uibuilder.model.NlModel)71 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)33 ModelBuilder (com.android.tools.idea.uibuilder.fixtures.ModelBuilder)19 NotNull (org.jetbrains.annotations.NotNull)18 XmlFile (com.intellij.psi.xml.XmlFile)14 Project (com.intellij.openapi.project.Project)12 AttributesTransaction (com.android.tools.idea.uibuilder.model.AttributesTransaction)11 Result (com.intellij.openapi.application.Result)11 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)11 ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)6 ComponentDescriptor (com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor)5 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 Configuration (com.android.tools.idea.configurations.Configuration)4 DesignSurface (com.android.tools.idea.uibuilder.surface.DesignSurface)3 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)3 SelectionModel (com.android.tools.idea.uibuilder.model.SelectionModel)2 XmlTag (com.intellij.psi.xml.XmlTag)2 BufferedImage (java.awt.image.BufferedImage)2