Search in sources :

Example 6 with AttributesTransaction

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();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) XmlFile(com.intellij.psi.xml.XmlFile) NlModel(com.android.tools.idea.uibuilder.model.NlModel) NotNull(org.jetbrains.annotations.NotNull) AttributesTransaction(com.android.tools.idea.uibuilder.model.AttributesTransaction) Result(com.intellij.openapi.application.Result)

Example 7 with AttributesTransaction

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();
    }
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) XmlFile(com.intellij.psi.xml.XmlFile) NlModel(com.android.tools.idea.uibuilder.model.NlModel) NotNull(org.jetbrains.annotations.NotNull) AttributesTransaction(com.android.tools.idea.uibuilder.model.AttributesTransaction) Result(com.intellij.openapi.application.Result)

Example 8 with AttributesTransaction

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();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) XmlFile(com.intellij.psi.xml.XmlFile) NlModel(com.android.tools.idea.uibuilder.model.NlModel) NotNull(org.jetbrains.annotations.NotNull) AttributesTransaction(com.android.tools.idea.uibuilder.model.AttributesTransaction) Result(com.intellij.openapi.application.Result)

Example 9 with AttributesTransaction

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);
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) ResourceFolderType(com.android.resources.ResourceFolderType) ModelListener(com.android.tools.idea.uibuilder.model.ModelListener) NlModel(com.android.tools.idea.uibuilder.model.NlModel) NotNull(org.jetbrains.annotations.NotNull) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) AttributesTransaction(com.android.tools.idea.uibuilder.model.AttributesTransaction) XmlTag(com.intellij.psi.xml.XmlTag)

Example 10 with AttributesTransaction

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);
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) AttributesTransaction(com.android.tools.idea.uibuilder.model.AttributesTransaction)

Aggregations

AttributesTransaction (com.android.tools.idea.uibuilder.model.AttributesTransaction)17 NlModel (com.android.tools.idea.uibuilder.model.NlModel)11 XmlFile (com.intellij.psi.xml.XmlFile)11 Result (com.intellij.openapi.application.Result)10 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)10 Project (com.intellij.openapi.project.Project)10 NotNull (org.jetbrains.annotations.NotNull)10 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)9 ResourceFolderType (com.android.resources.ResourceFolderType)1 ModelListener (com.android.tools.idea.uibuilder.model.ModelListener)1 Scene (com.android.tools.idea.uibuilder.scene.Scene)1 SceneComponent (com.android.tools.idea.uibuilder.scene.SceneComponent)1 XmlTag (com.intellij.psi.xml.XmlTag)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1