Lior Vernia has uploaded a new change for review.

Change subject: webadmin: Added sorting infrastructure to SearchableListModel
......................................................................

webadmin: Added sorting infrastructure to SearchableListModel

Added comparator to SearchableListModel, which if set slightly alters
the behaviour of setItems(). If it isn't set, then the behaviour should
not be altered at all.

Changed some dependent code that assumed that getItems() returned a
List, which was a breach of the SearchableListModel current
implementation anyway (as items is Iterable).

Change-Id: Idadafcb33979d85b7ca332cad717b7c1ceadec4b
Signed-off-by: Lior Vernia <lver...@redhat.com>
---
M 
frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/DataBoundTabModelProvider.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/SearchableListModel.java
2 files changed, 29 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/46/15846/1

diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/DataBoundTabModelProvider.java
 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/DataBoundTabModelProvider.java
index 27ed76e..d2ec7d0 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/DataBoundTabModelProvider.java
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/java/org/ovirt/engine/ui/common/uicommon/model/DataBoundTabModelProvider.java
@@ -1,5 +1,7 @@
 package org.ovirt.engine.ui.common.uicommon.model;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
 import org.ovirt.engine.core.common.businessentities.IVdcQueryable;
@@ -118,7 +120,7 @@
      */
     @SuppressWarnings("unchecked")
     protected void updateData() {
-        List<T> items = (List<T>) getModel().getItems();
+        List<T> items = getModel().getItems() == null ? null : new 
ArrayList<T>((Collection<T>) getModel().getItems());
 
         if (items != null) {
             updateDataProvider(items);
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 eee5fe4..2ce8b64 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
@@ -1,11 +1,14 @@
 package org.ovirt.engine.ui.uicommonweb.models;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.TreeSet;
 import java.util.logging.Logger;
 
 import org.ovirt.engine.core.common.businessentities.BusinessEntity;
@@ -228,7 +231,7 @@
             return ""; //$NON-NLS-1$
         }
         int fromItemCount = getSearchPageSize() * (getSearchPageNumber() - 1) 
+ 1;
-        int toItemCount = (fromItemCount - 1) + ((List) getItems()).size();
+        int toItemCount = (fromItemCount - 1) + ((Collection) 
getItems()).size();
 
         if (toItemCount == 0 || fromItemCount > toItemCount) {
             return ""; //$NON-NLS-1$
@@ -635,6 +638,12 @@
     {
     }
 
+    private Comparator comparator;
+
+    protected void setComparator(Comparator comparator) {
+        this.comparator = comparator;
+    }
+
     @Override
     public Iterable getItems()
     {
@@ -657,8 +666,20 @@
                 }
             }
 
-            itemsChanging(value, items);
-            items = value;
+            if (comparator == null) {
+                itemsChanging(value, items);
+                items = value;
+            } else {
+                TreeSet sortedValue = null;
+                if (value != null) {
+                    sortedValue = new TreeSet(comparator);
+                    for (Object item : value) {
+                        sortedValue.add(item);
+                    }
+                }
+                itemsChanging(sortedValue, items);
+                items = sortedValue;
+            }
             updatePagingAvailability();
             getItemsChangedEvent().raise(this, EventArgs.Empty);
             onPropertyChanged(new PropertyChangedEventArgs("Items")); 
//$NON-NLS-1$
@@ -670,12 +691,12 @@
                 getSelectedItems().clear();
             }
 
-            if (lastSelectedItem != null && value != null)
+            if (lastSelectedItem != null && items != null)
             {
                 IVdcQueryable newSelectedItem = null;
                 ArrayList<IVdcQueryable> newItems = new 
ArrayList<IVdcQueryable>();
 
-                for (Object item : value)
+                for (Object item : items)
                 {
                     newItems.add((IVdcQueryable) item);
                 }


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idadafcb33979d85b7ca332cad717b7c1ceadec4b
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Lior Vernia <lver...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to