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