Search in sources :

Example 1 with UpdatePropertiesSuccess

use of com.willshex.blogwt.client.api.blog.event.UpdatePropertiesEventHandler.UpdatePropertiesSuccess in project blogwt by billy1380.

the class PropertyController method updateProperties.

public boolean updateProperties(Collection<Property> properties) {
    List<Property> changed = null;
    String existingPropertyValue;
    boolean addToChanged;
    for (Property property : properties) {
        addToChanged = false;
        existingPropertyValue = PropertyHelper.value(propertyLookup.get(property.name));
        if (!PropertyHelper.isEmpty(property)) {
            if (existingPropertyValue == null) {
                addToChanged = true;
            } else if (!property.value.equals(existingPropertyValue)) {
                addToChanged = true;
            }
        }
        if (addToChanged) {
            if (changed == null) {
                changed = new ArrayList<Property>();
            }
            changed.add(property);
        }
    }
    boolean updating = changed != null;
    if (updating) {
        final UpdatePropertiesRequest input = SessionController.get().setSession(ApiHelper.setAccessCode(new UpdatePropertiesRequest()).properties(changed));
        ApiHelper.createBlogClient().updateProperties(input, new AsyncCallback<UpdatePropertiesResponse>() {

            @Override
            public void onSuccess(UpdatePropertiesResponse output) {
                if (output != null && output.status == StatusType.StatusTypeSuccess) {
                    GWT.log("Properties have been updated successfully... reload to see the effects.");
                }
                DefaultEventBus.get().fireEventFromSource(new UpdatePropertiesSuccess(input, output), PropertyController.this);
            }

            @Override
            public void onFailure(Throwable caught) {
                DefaultEventBus.get().fireEventFromSource(new UpdatePropertiesFailure(input, caught), PropertyController.this);
            }
        });
    }
    return updating;
}
Also used : UpdatePropertiesSuccess(com.willshex.blogwt.client.api.blog.event.UpdatePropertiesEventHandler.UpdatePropertiesSuccess) UpdatePropertiesFailure(com.willshex.blogwt.client.api.blog.event.UpdatePropertiesEventHandler.UpdatePropertiesFailure) UpdatePropertiesResponse(com.willshex.blogwt.shared.api.blog.call.UpdatePropertiesResponse) UpdatePropertiesRequest(com.willshex.blogwt.shared.api.blog.call.UpdatePropertiesRequest) Property(com.willshex.blogwt.shared.api.datatype.Property)

Aggregations

UpdatePropertiesFailure (com.willshex.blogwt.client.api.blog.event.UpdatePropertiesEventHandler.UpdatePropertiesFailure)1 UpdatePropertiesSuccess (com.willshex.blogwt.client.api.blog.event.UpdatePropertiesEventHandler.UpdatePropertiesSuccess)1 UpdatePropertiesRequest (com.willshex.blogwt.shared.api.blog.call.UpdatePropertiesRequest)1 UpdatePropertiesResponse (com.willshex.blogwt.shared.api.blog.call.UpdatePropertiesResponse)1 Property (com.willshex.blogwt.shared.api.datatype.Property)1