use of com.android.tools.idea.uibuilder.model.AttributesTransaction 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();
}
use of com.android.tools.idea.uibuilder.model.AttributesTransaction 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();
}
}
use of com.android.tools.idea.uibuilder.model.AttributesTransaction in project android by JetBrains.
the class WidgetConstraintPanel method removeAttribute.
private void removeAttribute(int type) {
String label = "Constraint Disconnected";
String[] attribute = ourDeleteAttributes[type];
String[] namespace = ourDeleteNamespace[type];
NlModel nlModel = mComponent.getModel();
Project project = nlModel.getProject();
XmlFile file = nlModel.getFile();
AttributesTransaction transaction = mComponent.startAttributeTransaction();
for (int i = 0; i < attribute.length; i++) {
transaction.setAttribute(namespace[i], attribute[i], null);
}
ConstraintComponentUtilities.ensureHorizontalPosition(mComponent, transaction);
ConstraintComponentUtilities.ensureVerticalPosition(mComponent, transaction);
transaction.apply();
WriteCommandAction action = new WriteCommandAction(project, label, file) {
@Override
protected void run(@NotNull Result result) throws Throwable {
transaction.commit();
}
};
action.execute();
}
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);
}
use of com.android.tools.idea.uibuilder.model.AttributesTransaction in project android by JetBrains.
the class ResizeTarget method mouseDrag.
@Override
public void mouseDrag(int x, int y, @Nullable Target closestTarget) {
NlComponent component = myComponent.getNlComponent();
AttributesTransaction attributes = component.startAttributeTransaction();
updateAttributes(attributes, x, y);
attributes.apply();
myComponent.getScene().needsLayout(Scene.IMMEDIATE_LAYOUT);
}
Aggregations