use of com.android.tools.idea.uibuilder.model.ModelListener in project android by JetBrains.
the class IncludeTagCreator method createNewIncludedLayout.
/**
* Create a new layout that will be included as a child of the mockup component
*/
private String createNewIncludedLayout() {
AndroidFacet facet = getMockup().getComponent().getModel().getFacet();
ResourceFolderType folderType = AndroidResourceUtil.XML_FILE_RESOURCE_TYPES.get(ResourceType.LAYOUT);
XmlFile newFile = CreateResourceFileAction.createFileResource(facet, folderType, null, null, null, true, null, null, null, false);
if (newFile == null) {
return null;
}
XmlTag rootTag = newFile.getRootTag();
if (rootTag == null) {
return null;
}
NlModel nlModel = NlModel.create(getScreenView().getSurface(), newFile.getProject(), facet, newFile);
ModelListener listener = new ModelListener() {
@Override
public void modelChanged(@NotNull NlModel model) {
}
@Override
public void modelRendered(@NotNull NlModel model) {
model.removeListener(this);
if (model.getComponents().isEmpty()) {
return;
}
NlComponent component = model.getComponents().get(0);
final AttributesTransaction transaction = component.startAttributeTransaction();
addShowInAttribute(transaction);
addSizeAttributes(transaction, getAndroidBounds());
addMockupAttributes(transaction, getSelectionBounds());
WriteCommandAction.runWriteCommandAction(model.getProject(), (Computable) transaction::commit);
}
@Override
public void modelChangedOnLayout(@NotNull NlModel model, boolean animate) {
// Do nothing
}
};
nlModel.addListener(listener);
nlModel.requestRender();
return getResourceName(newFile);
}
Aggregations