Lior Vernia has uploaded a new change for review. Change subject: webadmin: Start/stop progress on async operations ......................................................................
webadmin: Start/stop progress on async operations Implemented some infrastructure to automatically trigger loading animation whenever an async operation is invoked, and cancel the animation whenever the operations returns. This only happens if upon initialization of the operation, the source model is "properly" passed. For a single query, the model should be passed as the target of its AsyncQuery callback. Otherwise (multiple queries, single/multiple actions), the model should be passed as the "state" argument. Also, this only happens in case progress wasn't manually set; if it had been, then this would override the automatic infrastructure altogether. Change-Id: I24ed80a5453668b37f488e0226f7bdfbf36e503d Bug-Url: https://bugzilla.redhat.com/1167327 Signed-off-by: Lior Vernia <[email protected]> --- M frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/Frontend.java A frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/communication/AsyncOperationComplete.java A frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/communication/AsyncOperationStarted.java M frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/presenter/AbstractModelBoundPopupPresenterWidget.java 4 files changed, 82 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/64/35964/1 diff --git a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/Frontend.java b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/Frontend.java index 740fcaf..5a29227 100644 --- a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/Frontend.java +++ b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/Frontend.java @@ -19,6 +19,8 @@ import org.ovirt.engine.core.common.queries.VdcQueryParametersBase; import org.ovirt.engine.core.common.queries.VdcQueryReturnValue; import org.ovirt.engine.core.common.queries.VdcQueryType; +import org.ovirt.engine.ui.frontend.communication.AsyncOperationCompleteEvent; +import org.ovirt.engine.ui.frontend.communication.AsyncOperationStartedEvent; import org.ovirt.engine.ui.frontend.communication.RefreshActiveModelEvent; import org.ovirt.engine.ui.frontend.communication.StorageCallback; import org.ovirt.engine.ui.frontend.communication.UserCallback; @@ -285,6 +287,7 @@ } } } finally { + AsyncOperationCompleteEvent.fire(Frontend.this, callback.getModel()); raiseQueryCompleteEvent(queryType, callback.getContext()); } } @@ -303,6 +306,7 @@ callback.getDel().onSuccess(callback.getModel(), null); } } finally { + AsyncOperationCompleteEvent.fire(Frontend.this, callback.getModel()); raiseQueryCompleteEvent(queryType, callback.getContext()); } } @@ -310,6 +314,7 @@ // raise the query started event. raiseQueryStartedEvent(queryType, callback.getContext()); + AsyncOperationStartedEvent.fire(Frontend.this, callback.getModel()); if (isPublic) { getOperationManager().addPublicOperation(operation); } else { @@ -362,6 +367,7 @@ FrontendMultipleQueryAsyncResult f = new FrontendMultipleQueryAsyncResult(queryTypeList, queryParamsList, resultObject); callback.executed(f); + AsyncOperationCompleteEvent.fire(Frontend.this, state); raiseQueryCompleteEvent(queryTypeList, state); } @@ -378,6 +384,7 @@ failureEventHandler(caught); callback.executed(f); } finally { + AsyncOperationCompleteEvent.fire(Frontend.this, state); raiseQueryCompleteEvent(queryTypeList, state); } } @@ -392,6 +399,7 @@ parameters, true, multiCallback)); } + AsyncOperationStartedEvent.fire(Frontend.this, state); raiseQueryStartedEvent(queryTypeList, state); getOperationManager().addOperationList(operationList); } @@ -464,6 +472,7 @@ logger.finer("Frontend: sucessfully executed runAction, determining result!"); //$NON-NLS-1$ handleActionResult(actionType, parameters, result, callback != null ? callback : NULLABLE_ASYNC_CALLBACK, state, showErrorDialog); + AsyncOperationCompleteEvent.fire(Frontend.this, state); RefreshActiveModelEvent.fire(Frontend.this, true); } @@ -479,9 +488,11 @@ if (callback != null) { callback.executed(f); } + AsyncOperationCompleteEvent.fire(Frontend.this, state); } }); + AsyncOperationStartedEvent.fire(Frontend.this, state); getOperationManager().addOperation(operation); } @@ -558,6 +569,7 @@ callback.executed(new FrontendMultipleActionAsyncResult(actionType, parameters, resultObject, state)); } + AsyncOperationCompleteEvent.fire(Frontend.this, state); RefreshActiveModelEvent.fire(Frontend.this, true); } @@ -574,6 +586,7 @@ callback.executed(new FrontendMultipleActionAsyncResult(actionType, parameters, null, state)); } + AsyncOperationCompleteEvent.fire(Frontend.this, state); } }; @@ -583,6 +596,7 @@ VdcActionParametersBase>(actionType, parameter, true, multiCallback); operationList.add(operation); } + AsyncOperationStartedEvent.fire(Frontend.this, state); if (operationList.isEmpty()) { //Someone called run multiple actions with a single action without parameters. The backend will return //an empty return value as there are no parameters, so we can skip the round trip to the server and return diff --git a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/communication/AsyncOperationComplete.java b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/communication/AsyncOperationComplete.java new file mode 100644 index 0000000..fc314be --- /dev/null +++ b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/communication/AsyncOperationComplete.java @@ -0,0 +1,14 @@ +package org.ovirt.engine.ui.frontend.communication; + +import com.gwtplatform.dispatch.annotation.GenEvent; + +/** + * Event triggered when VdcOperation completes. Used primarily to monitor progress display in dialogs. + */ +@GenEvent +public class AsyncOperationComplete { + /** + * the model to which this operation is relevant. + */ + Object target; +} diff --git a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/communication/AsyncOperationStarted.java b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/communication/AsyncOperationStarted.java new file mode 100644 index 0000000..857bfb2 --- /dev/null +++ b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/communication/AsyncOperationStarted.java @@ -0,0 +1,14 @@ +package org.ovirt.engine.ui.frontend.communication; + +import com.gwtplatform.dispatch.annotation.GenEvent; + +/** + * Event triggered when VdcOperation starts. Used primarily to monitor progress display in dialogs. + */ +@GenEvent +public class AsyncOperationStarted { + /** + * the model to which this operation is relevant. + */ + Object target; +} diff --git a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/presenter/AbstractModelBoundPopupPresenterWidget.java b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/presenter/AbstractModelBoundPopupPresenterWidget.java index 806d995..31c6dee 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/presenter/AbstractModelBoundPopupPresenterWidget.java +++ b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/presenter/AbstractModelBoundPopupPresenterWidget.java @@ -8,6 +8,10 @@ import org.ovirt.engine.ui.common.utils.WebUtils; import org.ovirt.engine.ui.common.widget.HasEditorDriver; import org.ovirt.engine.ui.common.widget.HasUiCommandClickHandlers; +import org.ovirt.engine.ui.frontend.communication.AsyncOperationCompleteEvent; +import org.ovirt.engine.ui.frontend.communication.AsyncOperationCompleteEvent.AsyncOperationCompleteHandler; +import org.ovirt.engine.ui.frontend.communication.AsyncOperationStartedEvent; +import org.ovirt.engine.ui.frontend.communication.AsyncOperationStartedEvent.AsyncOperationStartedHandler; import org.ovirt.engine.ui.uicommonweb.UICommand; import org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel; import org.ovirt.engine.ui.uicommonweb.models.ListModel; @@ -66,6 +70,9 @@ private T model; private DeferredModelCommandInvoker modelCommandInvoker; + + private int asyncOperationCounter; + private boolean manageProgress; public AbstractModelBoundPopupPresenterWidget(EventBus eventBus, V view) { super(eventBus, view); @@ -128,6 +135,39 @@ public void init(final T model) { this.model = model; + // Set up async operation listeners to automatically display/hide progress bar + asyncOperationCounter = 0; + manageProgress = false; + addRegisteredHandler(AsyncOperationStartedEvent.getType(), new AsyncOperationStartedHandler() { + @Override + public void onAsyncOperationStarted(AsyncOperationStartedEvent event) { + if (event.getTarget() != model) { + return; + } + + if (model.getProgress() == null) { + manageProgress = true; + } + + if (manageProgress && asyncOperationCounter++ == 0) { + model.startProgress(null); + } + } + }); + addRegisteredHandler(AsyncOperationCompleteEvent.getType(), new AsyncOperationCompleteHandler() { + @Override + public void onAsyncOperationComplete(AsyncOperationCompleteEvent event) { + if (event.getTarget() != model) { + return; + } + + if (manageProgress && --asyncOperationCounter == 0) { + manageProgress = false; + model.stopProgress(); + } + } + }); + // Set up model command invoker this.modelCommandInvoker = new DeferredModelCommandInvoker(model) { @Override -- To view, visit http://gerrit.ovirt.org/35964 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I24ed80a5453668b37f488e0226f7bdfbf36e503d Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Lior Vernia <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
