use of com.android.tools.idea.uibuilder.model.AttributesTransaction in project android by JetBrains.
the class ConstraintTarget method cycleChainStyle.
protected void cycleChainStyle(SceneComponent chainHeadComponent, String orientationStyle) {
NlComponent chainHead = chainHeadComponent.getNlComponent();
String chainStyle = chainHead.getLiveAttribute(SdkConstants.SHERPA_URI, orientationStyle);
if (chainStyle != null) {
if (chainStyle.equalsIgnoreCase(SdkConstants.ATTR_LAYOUT_CHAIN_SPREAD)) {
chainStyle = SdkConstants.ATTR_LAYOUT_CHAIN_SPREAD_INSIDE;
} else if (chainStyle.equalsIgnoreCase(SdkConstants.ATTR_LAYOUT_CHAIN_SPREAD_INSIDE)) {
chainStyle = SdkConstants.ATTR_LAYOUT_CHAIN_PACKED;
} else if (chainStyle.equalsIgnoreCase(SdkConstants.ATTR_LAYOUT_CHAIN_PACKED)) {
chainStyle = SdkConstants.ATTR_LAYOUT_CHAIN_SPREAD;
}
} else {
chainStyle = SdkConstants.ATTR_LAYOUT_CHAIN_SPREAD;
}
AttributesTransaction transaction = chainHead.startAttributeTransaction();
transaction.setAttribute(SdkConstants.SHERPA_URI, orientationStyle, chainStyle);
transaction.apply();
NlModel nlModel = chainHead.getModel();
Project project = nlModel.getProject();
XmlFile file = nlModel.getFile();
String label = "Cycle chain style";
WriteCommandAction action = new WriteCommandAction(project, label, file) {
@Override
protected void run(@NotNull Result result) throws Throwable {
transaction.commit();
}
};
action.execute();
myComponent.getScene().needsRebuildList();
}
use of com.android.tools.idea.uibuilder.model.AttributesTransaction 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