Search in sources :

Example 31 with NlComponent

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

the class GenerateLayoutTestSkeletonAction method generateModelFixture.

@NotNull
private static String generateModelFixture(@NotNull NlModel model) {
    List<NlComponent> components = model.getComponents();
    StringBuilder builder = new StringBuilder();
    builder.append("import com.android.tools.idea.uibuilder.LayoutTestCase;\n").append("import com.android.tools.idea.uibuilder.fixtures.ModelBuilder;\n").append("import com.android.tools.idea.uibuilder.model.NlModel;\n").append("import com.android.tools.idea.uibuilder.util.NlTreeDumper;\n").append("import org.jetbrains.annotations.NotNull;\n").append("\n").append("import static com.android.SdkConstants.*;\n").append("\n").append("public class NewTest extends LayoutTestCase {\n").append("\n").append("  // TODO: Rename this test method\n").append("  public void testRenameThis() {\n").append("    NlModel model = createModel();\n").append("  }\n").append("\n").append("  @NotNull\n").append("  private NlModel createModel() {\n").append("    ModelBuilder builder = model(\"").append(model.getFile().getName()).append("\",\n");
    for (NlComponent component : components) {
        appendComponent(component, "\"    ModelBuilder builder = model(".length(), builder);
    }
    builder.append(");\n");
    builder.append("    NlModel model = builder.build();\n").append("    format(model.getFile());\n").append("    assertEquals(").append(components.size()).append(", model.getComponents().size());\n");
    appendTreeComparison(components, builder);
    appendXmlComparison(model, builder);
    builder.append("\n").append("    return model;\n").append("  }\n").append("}\n");
    return builder.toString();
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with NlComponent

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

the class NlPropertiesSorter method getModifiedAttributes.

@NotNull
public static Set<String> getModifiedAttributes(@NotNull List<NlComponent> components) {
    List<AttributeSnapshot> attrs = components.get(0).getAttributes();
    Set<String> modifiedAttrs = Sets.newHashSetWithExpectedSize(attrs.size());
    for (NlComponent component : components) {
        attrs = component.getAttributes();
        for (AttributeSnapshot snapshot : attrs) {
            modifiedAttrs.add(snapshot.name);
        }
    }
    return modifiedAttrs;
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) AttributeSnapshot(com.android.tools.idea.rendering.AttributeSnapshot) NotNull(org.jetbrains.annotations.NotNull)

Example 33 with NlComponent

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

the class NlPropertyItem method setValue.

@Override
public void setValue(Object value) {
    // TODO: Consider making getApplication() a field to avoid statics
    assert ApplicationManager.getApplication().isDispatchThread();
    if (getModel().getProject().isDisposed()) {
        return;
    }
    String strValue = value == null ? null : value.toString();
    if (StringUtil.isEmpty(strValue) || isDefaultValue(strValue)) {
        strValue = null;
    }
    final String attrValue = strValue;
    NlComponent first = myComponents.get(0);
    String componentName = myComponents.size() == 1 ? first.getTagName() : "Multiple";
    String msg = String.format("Set %1$s.%2$s to %3$s", componentName, myName, attrValue);
    new WriteCommandAction.Simple(getModel().getProject(), msg, getModel().getFile()) {

        @Override
        protected void run() throws Throwable {
            for (NlComponent component : myComponents) {
                String v = StringUtil.isEmpty(attrValue) ? null : attrValue;
                component.setAttribute(myNamespace, myName, v);
                TemplateUtils.reformatAndRearrange(getProject(), component.getTag());
            }
        }
    }.execute();
    if (SdkConstants.VIEW_MERGE.equals(componentName) && SdkConstants.TOOLS_URI.equals(getNamespace()) && SdkConstants.ATTR_PARENT_TAG.equals(getName())) {
        // Special case: When the tools:parentTag is updated on a <merge> tag, the set of attributes for
        // the <merge> tag may change e.g. if the value is set to "LinearLayout" the <merge> tag will
        // then have all attributes from a <LinearLayout>. Force an update of all properties:
        updateAllProperties();
    }
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 34 with NlComponent

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

the class NlPropertiesManager method setToolContext.

@Override
public void setToolContext(@Nullable DesignSurface designSurface) {
    if (designSurface == mySurface) {
        return;
    }
    if (mySurface != null) {
        mySurface.removeListener(this);
    }
    mySurface = designSurface;
    if (mySurface == null) {
        setScreenView(null);
    } else {
        mySurface.addListener(this);
        ScreenView screenView = mySurface.getCurrentScreenView();
        setScreenView(screenView);
        List<NlComponent> selection = screenView != null ? screenView.getSelectionModel().getSelection() : Collections.emptyList();
        componentSelectionChanged(mySurface, selection);
    }
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 35 with NlComponent

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

the class PreferenceScreenDragHandlerTest method newPreferenceScreen.

@NotNull
private static NlComponent newPreferenceScreen() {
    NlComponent screen = newPreferenceScreen(0, 162, 768, 755);
    screen.addChild(PreferenceScreenTestFactory.newCheckBoxPreference(0, 162, 768, 168));
    screen.addChild(PreferenceScreenTestFactory.newPreferenceCategory());
    screen.addChild(PreferenceScreenTestFactory.newCheckBoxPreference(0, 711, 768, 102));
    screen.addChild(PreferenceScreenTestFactory.newCheckBoxPreference(0, 815, 768, 102));
    return screen;
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)184 NlModel (com.android.tools.idea.uibuilder.model.NlModel)34 NotNull (org.jetbrains.annotations.NotNull)34 NlProperty (com.android.tools.idea.uibuilder.property.NlProperty)18 ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)17 Nullable (org.jetbrains.annotations.Nullable)14 Test (org.junit.Test)12 Matchers.anyString (org.mockito.Matchers.anyString)11 ViewGroupHandler (com.android.tools.idea.uibuilder.api.ViewGroupHandler)9 AttributesTransaction (com.android.tools.idea.uibuilder.model.AttributesTransaction)9 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)8 NlPropertyItem (com.android.tools.idea.uibuilder.property.NlPropertyItem)7 XmlFile (com.intellij.psi.xml.XmlFile)7 XmlTag (com.intellij.psi.xml.XmlTag)7 ArrayList (java.util.ArrayList)7 ModelBuilder (com.android.tools.idea.uibuilder.fixtures.ModelBuilder)6 NlGraphics (com.android.tools.idea.uibuilder.graphics.NlGraphics)6 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)6 Project (com.intellij.openapi.project.Project)6 List (java.util.List)6