Alexander Wels has uploaded a new change for review.

Change subject: webadmin,userportal: Synchronize refresh.
......................................................................

webadmin,userportal: Synchronize refresh.

- Added logic to automatically refresh the current active
  model when an action completes or when an event is found
  during the event query (webadmin).

Change-Id: Iaa59712f8f74426b0ca6a132664167f42fb8d7b2
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=858166
Signed-off-by: Alexander Wels <[email protected]>
---
M frontend/webadmin/modules/frontend/pom.xml
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/VdcOperationComplete.java
M 
frontend/webadmin/modules/frontend/src/test/java/org/ovirt/engine/ui/frontend/FrontendActionTest.java
M 
frontend/webadmin/modules/frontend/src/test/java/org/ovirt/engine/ui/frontend/FrontendTest.java
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/CommonModelManager.java
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/TabModelProvider.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/CommonModel.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/ListModel.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/SearchableListModel.java
M 
frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/uicommon/model/UserPortalDataBoundModelProvider.java
11 files changed, 201 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/57/21057/1

diff --git a/frontend/webadmin/modules/frontend/pom.xml 
b/frontend/webadmin/modules/frontend/pom.xml
index e9229a8..981ccfd 100644
--- a/frontend/webadmin/modules/frontend/pom.xml
+++ b/frontend/webadmin/modules/frontend/pom.xml
@@ -42,6 +42,12 @@
       <artifactId>gwt-dev</artifactId>
     </dependency>
     <dependency>
+      <groupId>com.gwtplatform</groupId>
+      <artifactId>gwtp-processors</artifactId>
+      <version>${gwtp.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
       <groupId>org.jboss.spec.javax.servlet</groupId>
       <artifactId>jboss-servlet-api_3.0_spec</artifactId>
       <scope>provided</scope>
@@ -111,6 +117,19 @@
         </executions>
       </plugin>
       <plugin>
+        <groupId>org.bsc.maven</groupId>
+        <artifactId>maven-processor-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>process</id>
+            <goals>
+              <goal>process</goal>
+            </goals>
+            <phase>generate-sources</phase>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
         <artifactId>maven-checkstyle-plugin</artifactId>
         <configuration>
           <propertyExpansion>runNlsCheck=true</propertyExpansion>
@@ -137,7 +156,25 @@
           </execution>
         </executions>
       </plugin>
-
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>build-helper-maven-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>add-apt-sources</id>
+            <phase>generate-sources</phase>
+            <goals>
+              <goal>add-source</goal>
+            </goals>
+            <configuration>
+              <sources>
+                
<source>${project.build.directory}/${generatedSourcesDirectory}</source>
+                
<source>${project.build.directory}/generated-sources/gwt</source>
+              </sources>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
     </plugins>
   </build>
   <profiles>
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 73b320f..bf928ef 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
@@ -16,6 +16,8 @@
 import org.ovirt.engine.core.common.action.VdcReturnValueBase;
 import org.ovirt.engine.core.common.businessentities.DbUser;
 import org.ovirt.engine.core.common.errors.VdcFault;
+import org.ovirt.engine.core.common.interfaces.SearchType;
+import org.ovirt.engine.core.common.queries.SearchParameters;
 import org.ovirt.engine.core.common.queries.VdcQueryParametersBase;
 import org.ovirt.engine.core.common.queries.VdcQueryReturnValue;
 import org.ovirt.engine.core.common.queries.VdcQueryType;
@@ -23,6 +25,7 @@
 import org.ovirt.engine.ui.frontend.communication.VdcOperation;
 import org.ovirt.engine.ui.frontend.communication.VdcOperationCallback;
 import org.ovirt.engine.ui.frontend.communication.VdcOperationCallbackList;
+import org.ovirt.engine.ui.frontend.communication.VdcOperationCompleteEvent;
 import org.ovirt.engine.ui.frontend.communication.VdcOperationManager;
 import org.ovirt.engine.ui.uicompat.ConstantsManager;
 import org.ovirt.engine.ui.uicompat.Event;
@@ -38,6 +41,9 @@
 
 import com.google.gwt.core.client.Scheduler;
 import com.google.gwt.core.client.Scheduler.ScheduledCommand;
+import com.google.gwt.event.shared.EventBus;
+import com.google.gwt.event.shared.GwtEvent;
+import com.google.gwt.event.shared.HasHandlers;
 import com.google.gwt.user.client.rpc.StatusCodeException;
 import com.google.inject.Inject;
 /**
@@ -48,7 +54,7 @@
  * There are several deprecated static methods that allow static access to the 
singleton, usage of those methods is
  * purely for legacy purposes and is discouraged for new development.
  */
-public class Frontend {
+public class Frontend implements HasHandlers {
     /**
      * The logger.
      */
@@ -146,6 +152,11 @@
     private Scheduler scheduler;
 
     /**
+     * GWT event bus.
+     */
+    private final EventBus eventBus;
+
+    /**
      * The instance of the {@code Frontend} class.
      */
     private static Frontend instance;
@@ -158,10 +169,11 @@
      */
     @Inject
     public Frontend(final VdcOperationManager manager, final AppErrors 
applicationErrors,
-            final VdsmErrors vdsmErrors) {
+            final VdsmErrors vdsmErrors, final EventBus gwtEventBus) {
         this.operationManager = manager;
         setAppErrorsTranslator(new ErrorTranslator(applicationErrors));
         setVdsmErrorsTranslator(new ErrorTranslator(vdsmErrors));
+        eventBus = gwtEventBus;
         instance = this;
     }
 
@@ -258,6 +270,9 @@
                     }
                 } finally {
                     raiseQueryCompleteEvent(queryType, callback.getContext());
+                    if (isEventQuery(queryType, parameters) && 
!((List<?>)result.getReturnValue()).isEmpty()) {
+                        raiseOperationCompleteEvent(operation);
+                    }
                 }
             }
 
@@ -493,6 +508,7 @@
                 logger.finer("Frontend: sucessfully executed runAction, 
determining result!"); //$NON-NLS-1$
                 handleActionResult(actionType, parameters, result,
                         callback != null ? callback : NULLABLE_ASYNC_CALLBACK, 
state, showErrorDialog);
+                raiseOperationCompleteEvent(operation);
             }
 
             @Override
@@ -608,6 +624,7 @@
                     callback.executed(new 
FrontendMultipleActionAsyncResult(actionType,
                             parameters, resultObject, state));
                 }
+                raiseOperationCompleteEvent(operationList.get(0));
             }
 
             @Override
@@ -1053,6 +1070,31 @@
     }
 
     /**
+     * Determine if a query is an event query. The following factors make a 
query an event query.
+     * <ul>
+     *   <li>The {@code VdcQueryType} is 'Search'</li>
+     *   <li>The {@code VdcQueryParametersBase} is a {@code SearchParameter}
+     *   <li>The {@code SearchType} of the parameter is 'AuditLog'
+     * </ul>
+     * @param queryType The query type.
+     * @param parameters The parameter type.
+     * @return {@code true} if the query is an event query, {@code false} 
otherwise.
+     */
+    private boolean isEventQuery(final VdcQueryType queryType, final 
VdcQueryParametersBase parameters) {
+        return queryType == VdcQueryType.Search && parameters instanceof 
SearchParameters
+                && ((SearchParameters) parameters).getSearchTypeValue() == 
SearchType.AuditLog;
+    }
+
+    private void raiseOperationCompleteEvent(final VdcOperation<?, ?> 
operation) {
+        VdcOperationCompleteEvent.fire(this, new 
VdcOperationCompleteEvent(operation));
+    }
+
+    @Override
+    public void fireEvent(GwtEvent<?> event) {
+        eventBus.fireEvent(event);
+    }
+
+    /**
      * Raise a query event.
      * @param queryEvent The event to raise.
      * @param queryType The query type of the event.
diff --git 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/communication/VdcOperationComplete.java
 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/communication/VdcOperationComplete.java
new file mode 100644
index 0000000..120400a
--- /dev/null
+++ 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/communication/VdcOperationComplete.java
@@ -0,0 +1,14 @@
+package org.ovirt.engine.ui.frontend.communication;
+
+import com.gwtplatform.dispatch.annotation.GenEvent;
+import com.gwtplatform.dispatch.annotation.Order;
+
+/**
+ * Event triggered when a VdcOperationCompletes. The typical use case is when 
a {@code VdcAction} completes
+ * and needs to inform models to refresh themselves.
+ */
+@GenEvent
+public class VdcOperationComplete {
+    @Order(1)
+    VdcOperation<?, ?> operation;
+}
diff --git 
a/frontend/webadmin/modules/frontend/src/test/java/org/ovirt/engine/ui/frontend/FrontendActionTest.java
 
b/frontend/webadmin/modules/frontend/src/test/java/org/ovirt/engine/ui/frontend/FrontendActionTest.java
index 31bb937..056fd6b 100644
--- 
a/frontend/webadmin/modules/frontend/src/test/java/org/ovirt/engine/ui/frontend/FrontendActionTest.java
+++ 
b/frontend/webadmin/modules/frontend/src/test/java/org/ovirt/engine/ui/frontend/FrontendActionTest.java
@@ -40,6 +40,7 @@
 import org.ovirt.engine.ui.uicompat.IFrontendMultipleActionAsyncCallback;
 import org.ovirt.engine.ui.uicompat.UIConstants;
 
+import com.google.gwt.event.shared.EventBus;
 import com.google.gwt.user.client.rpc.AsyncCallback;
 import com.google.gwt.user.client.rpc.StatusCodeException;
 
@@ -83,6 +84,8 @@
     AsyncQuery mockAsyncQuery;
     @Mock
     INewAsyncCallback mockAsyncCallback;
+    @Mock
+    EventBus mockEventBus;
     @Captor
     ArgumentCaptor<AsyncCallback<ArrayList<VdcReturnValueBase>>> 
callbackMultipleActions;
     @Captor
@@ -100,7 +103,8 @@
         operationProcessor.setScheduler(fakeScheduler);
         VdcOperationManager operationsManager = new 
VdcOperationManager(operationProcessor);
         operationsManager.setLoggedIn(true);
-        frontend = new Frontend(operationsManager, 
mockCanDoActionErrorsTranslator, mockVdsmErrorsTranslator);
+        frontend = new Frontend(operationsManager, 
mockCanDoActionErrorsTranslator, mockVdsmErrorsTranslator,
+                mockEventBus);
         frontend.setEventsHandler(mockEventsHandler);
         frontend.setConstants(mockConstants);
         frontend.frontendFailureEvent = mockFrontendFailureEvent;
diff --git 
a/frontend/webadmin/modules/frontend/src/test/java/org/ovirt/engine/ui/frontend/FrontendTest.java
 
b/frontend/webadmin/modules/frontend/src/test/java/org/ovirt/engine/ui/frontend/FrontendTest.java
index a11df6d..e04d7d6 100644
--- 
a/frontend/webadmin/modules/frontend/src/test/java/org/ovirt/engine/ui/frontend/FrontendTest.java
+++ 
b/frontend/webadmin/modules/frontend/src/test/java/org/ovirt/engine/ui/frontend/FrontendTest.java
@@ -38,6 +38,7 @@
 import org.ovirt.engine.ui.uicompat.IFrontendMultipleQueryAsyncCallback;
 import org.ovirt.engine.ui.uicompat.UIConstants;
 
+import com.google.gwt.event.shared.EventBus;
 import com.google.gwt.user.client.rpc.AsyncCallback;
 import com.google.gwt.user.client.rpc.StatusCodeException;
 
@@ -80,6 +81,8 @@
     INewAsyncCallback mockAsyncCallback;
     @Mock
     IAsyncConverter mockConverter;
+    @Mock
+    EventBus mockEventBus;
     @Captor
     ArgumentCaptor<AsyncCallback<VdcQueryReturnValue>> callback;
     @Captor
@@ -93,7 +96,8 @@
         operationProcessor.setScheduler(fakeScheduler);
         VdcOperationManager operationsManager = new 
VdcOperationManager(operationProcessor);
         operationsManager.setLoggedIn(true);
-        frontend = new Frontend(operationsManager, 
mockCanDoActionErrorsTranslator, mockVdsmErrorsTranslator);
+        frontend = new Frontend(operationsManager, 
mockCanDoActionErrorsTranslator, mockVdsmErrorsTranslator,
+                mockEventBus);
         frontend.queryCompleteEvent = queryCompleteEvent;
         frontend.queryStartedEvent = queryStartEvent;
         frontend.frontendFailureEvent = mockFrontendFailureEvent;
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/CommonModelManager.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/CommonModelManager.java
index 18d353f..617a8c7 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/CommonModelManager.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/CommonModelManager.java
@@ -26,7 +26,15 @@
      */
     public static void init(final EventBus eventBus, final CurrentUser user, 
final LoginModel loginModel,
             final FrontendFailureEventListener frontendFailureEventListener) {
+        if (commonModel != null) {
+            //Unregister handlers
+            commonModel.unregisterHandlers();
+            //Unset the event bus on the old model, so they can be freed.
+            commonModel.setEventBus(null);
+        }
         commonModel = CommonModel.newInstance();
+        //Set the event bus so we can register listeners.
+        commonModel.setEventBus(eventBus);
 
         commonModel.getSelectedItemChangedEvent().addListener(new 
IEventListener() {
             @Override
diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/TabModelProvider.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/TabModelProvider.java
index 070315a..daedd57 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/TabModelProvider.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/TabModelProvider.java
@@ -9,7 +9,6 @@
 import org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel;
 import org.ovirt.engine.ui.uicommonweb.models.EntityModel;
 import org.ovirt.engine.ui.uicommonweb.models.Model;
-import org.ovirt.engine.ui.uicommonweb.models.SearchableListModel;
 import org.ovirt.engine.ui.uicompat.Event;
 import org.ovirt.engine.ui.uicompat.EventArgs;
 import org.ovirt.engine.ui.uicompat.IEventListener;
@@ -39,7 +38,6 @@
             @Override
             protected void 
hideAndClearPopup(AbstractModelBoundPopupPresenterWidget<?, ?> popup, boolean 
isConfirm) {
                 super.hideAndClearPopup(popup, isConfirm);
-                TabModelProvider.this.forceRefresh(getModel());
             }
         };
         
this.popupHandler.setDefaultConfirmPopupProvider(defaultConfirmPopupProvider);
@@ -137,17 +135,6 @@
     protected ModelBoundPresenterWidget<? extends Model> 
getModelBoundWidget(UICommand lastExecutedCommand) {
         // No-op, override as necessary
         return null;
-    }
-
-    void forceRefresh(M model) {
-        if (model instanceof SearchableListModel) {
-            UICommand lastExecutedCommand = model.getLastExecutedCommand();
-            if (lastExecutedCommand != null && 
!lastExecutedCommand.getIsCancel()) {
-                // Refresh grid after invoking non-cancel command
-                SearchableListModel searchableList = (SearchableListModel) 
model;
-                searchableList.forceRefresh();
-            }
-        }
     }
 
 }
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/CommonModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/CommonModel.java
index b0cdaad..01a92dc 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/CommonModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/CommonModel.java
@@ -2,6 +2,7 @@
 
 import java.util.ArrayList;
 import java.util.List;
+
 import org.ovirt.engine.core.common.businessentities.AuditLog;
 import org.ovirt.engine.core.common.businessentities.DbUser;
 import org.ovirt.engine.core.common.businessentities.StorageDomain;
@@ -50,6 +51,8 @@
 import org.ovirt.engine.ui.uicompat.ObservableCollection;
 import org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs;
 
+import com.google.gwt.event.shared.EventBus;
+
 @SuppressWarnings("unused")
 public class CommonModel extends ListModel
 {
@@ -93,7 +96,6 @@
     private SearchableListModel eventList;
     private ReportsListModel reportsList;
     private SearchableListModel quotaList;
-    private SearchableListModel monitor;
     private SearchableListModel volumeList;
     private SearchableListModel diskList;
     private SearchableListModel networkList;
@@ -148,6 +150,27 @@
         setLoggedInUser(Frontend.getInstance().getLoggedInUser());
     }
 
+    @Override
+    public void setEventBus(EventBus eventBus) {
+        //Assume none of these are null.
+        dataCenterList.setEventBus(eventBus);
+        clusterList.setEventBus(eventBus);
+        hostList.setEventBus(eventBus);
+        storageList.setEventBus(eventBus);
+        vmList.setEventBus(eventBus);
+        poolList.setEventBus(eventBus);
+        templateList.setEventBus(eventBus);
+        userList.setEventBus(eventBus);
+        eventList.setEventBus(eventBus);
+        reportsList.setEventBus(eventBus);
+        quotaList.setEventBus(eventBus);
+        volumeList.setEventBus(eventBus);
+        diskList.setEventBus(eventBus);
+        networkList.setEventBus(eventBus);
+        providerList.setEventBus(eventBus);
+        profileList.setEventBus(eventBus);
+    }
+
     private void initItems()
     {
         ObservableCollection<SearchableListModel> list = new 
ObservableCollection<SearchableListModel>();
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/ListModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/ListModel.java
index 8b1a4e5..6df6f95 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/ListModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/ListModel.java
@@ -14,9 +14,14 @@
 import org.ovirt.engine.ui.uicompat.ProvideCollectionChangedEvent;
 import org.ovirt.engine.ui.uicompat.ProvidePropertyChangedEvent;
 
-@SuppressWarnings("unused")
+import com.google.gwt.event.shared.EventBus;
+
 public class ListModel extends EntityModel
 {
+    /**
+     * The GWT event bus.
+     */
+    private EventBus eventBus;
 
     public static EventDefinition selectedItemChangedEventDefinition;
     private Event privateSelectedItemChangedEvent;
@@ -349,4 +354,24 @@
             }
         }
     }
+
+    /**
+     * Get the GWT event bus.
+     * @return The {@code EventBus}, can be null.
+     */
+    public EventBus getEventBus() {
+        return eventBus;
+    }
+
+    /**
+     * Set the GWT event bus.
+     * @param eventBus The {@code EventBus}, can be null.
+     */
+    public void setEventBus(EventBus eventBus) {
+        this.eventBus = eventBus;
+    }
+
+    public void unregisterHandlers() {
+
+    }
 }
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/SearchableListModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/SearchableListModel.java
index 89b1443..a79f744 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/SearchableListModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/SearchableListModel.java
@@ -27,6 +27,8 @@
 import org.ovirt.engine.ui.frontend.Frontend;
 import org.ovirt.engine.ui.frontend.INewAsyncCallback;
 import org.ovirt.engine.ui.frontend.RegistrationResult;
+import org.ovirt.engine.ui.frontend.communication.VdcOperationCompleteEvent;
+import 
org.ovirt.engine.ui.frontend.communication.VdcOperationCompleteEvent.VdcOperationCompleteHandler;
 import org.ovirt.engine.ui.uicommonweb.Linq;
 import org.ovirt.engine.ui.uicommonweb.ProvideTickEvent;
 import org.ovirt.engine.ui.uicommonweb.ReportCommand;
@@ -40,6 +42,8 @@
 import org.ovirt.engine.ui.uicompat.NotifyCollectionChangedEventArgs;
 import org.ovirt.engine.ui.uicompat.PropertyChangedEventArgs;
 
+import com.google.gwt.event.shared.HandlerRegistration;
+
 /**
  * Represents a list model with ability to fetch items both sync and async.
  */
@@ -50,6 +54,8 @@
     private static Logger logger = 
Logger.getLogger(SearchableListModel.class.getName());
     private static final String PAGE_STRING_REGEX = 
"[\\s]+page[\\s]+[1-9]+[0-9]*[\\s]*$"; //$NON-NLS-1$
     private static final String PAGE_NUMBER_REGEX = "[1-9]+[0-9]*$"; 
//$NON-NLS-1$
+
+    private HandlerRegistration operationCompleteHandlerRegistration;
 
     private UICommand privateSearchCommand;
 
@@ -383,6 +389,19 @@
                 syncSearch();
                 setIsQueryFirstTime(false);
                 getTimer().start();
+                if (getEventBus() != null) {
+                    //Make sure to unregister any existing handler, before 
adding a new one.
+                    unregisterOperationCompleteHandler();
+                    //Register to listen for operation complete events.
+                    operationCompleteHandlerRegistration = 
getEventBus().addHandler(VdcOperationCompleteEvent.getType(),
+                            new VdcOperationCompleteHandler() {
+                        @Override
+                        public void 
onVdcOperationComplete(VdcOperationCompleteEvent event) {
+                            //This is an operation this model is interested 
in, refresh.
+                            getForceRefreshCommand().execute();
+                        }
+                    });
+                }
             }
             else
             {
@@ -772,6 +791,18 @@
     public void stopRefresh()
     {
         getTimer().stop();
+        unregisterOperationCompleteHandler();
+    }
+
+    @Override
+    public void unregisterHandlers() {
+        unregisterOperationCompleteHandler();
+    }
+
+    private void unregisterOperationCompleteHandler() {
+        if (operationCompleteHandlerRegistration != null) {
+            operationCompleteHandlerRegistration.removeHandler();
+        }
     }
 
     @Override
diff --git 
a/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/uicommon/model/UserPortalDataBoundModelProvider.java
 
b/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/uicommon/model/UserPortalDataBoundModelProvider.java
index c8b4e6b..9a1294e 100644
--- 
a/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/uicommon/model/UserPortalDataBoundModelProvider.java
+++ 
b/frontend/webadmin/modules/userportal-gwtp/src/main/java/org/ovirt/engine/ui/userportal/uicommon/model/UserPortalDataBoundModelProvider.java
@@ -66,7 +66,13 @@
 
     @Override
     public void onUserPortalModelInit(UserPortalModelInitEvent event) {
+        if (this.model != null) {
+            //Clear the event bus from original model if it still exists.
+            this.model.unregisterHandlers();
+            this.model.setEventBus(null);
+        }
         this.model = createModel();
+        this.model.setEventBus(getEventBus());
     }
 
     /**


-- 
To view, visit http://gerrit.ovirt.org/21057
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaa59712f8f74426b0ca6a132664167f42fb8d7b2
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Alexander Wels <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to