empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1382497 - in /empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements: BeanListPageElement.java ListPageElement.java
Date Sun, 09 Sep 2012 13:37:38 GMT
Author: doebele
Date: Sun Sep  9 13:37:38 2012
New Revision: 1382497

URL: http://svn.apache.org/viewvc?rev=1382497&view=rev
Log:
EMPIREDB-157 
ListPageElement allow single selection of items

Modified:
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/BeanListPageElement.java
    empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/ListPageElement.java

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/BeanListPageElement.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/BeanListPageElement.java?rev=1382497&r1=1382496&r2=1382497&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/BeanListPageElement.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/BeanListPageElement.java
Sun Sep  9 13:37:38 2012
@@ -458,8 +458,8 @@ public class BeanListPageElement<T> exte
         lti.setPosition((pos > 0 ? pos : 0));
     }
 
-    @Override
-    public Set<Object[]> getSelectedItems()
+    // @Override
+    public Set<Object[]> getSelectedItemKeys()
     {
         if (selectedItems == null)
             return null;
@@ -555,7 +555,7 @@ public class BeanListPageElement<T> exte
         BeanListTableInfo lti = (BeanListTableInfo) getTableInfo();
         DBCommand cmd = lti.getQueryCmd().clone();
         
-        Set<Object[]> items = getSelectedItems();
+        Set<Object[]> items = getSelectedItemKeys();
         if (items.size()>0)
         {
             DBColumn[] pk = rowset.getKeyColumns();

Modified: empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/ListPageElement.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/ListPageElement.java?rev=1382497&r1=1382496&r2=1382497&view=diff
==============================================================================
--- empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/ListPageElement.java
(original)
+++ empire-db/trunk/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/pageelements/ListPageElement.java
Sun Sep  9 13:37:38 2012
@@ -19,9 +19,9 @@
 package org.apache.empire.jsf2.pageelements;
 
 import java.io.Serializable;
+import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
-import java.util.Set;
 
 import javax.faces.event.ActionEvent;
 
@@ -49,6 +49,7 @@ public abstract class ListPageElement<T>
     {
         private static final long serialVersionUID = 1L;
         
+        private boolean singleSelection = false;
         private boolean invertSelection = false;
         
         public SelectionSet()
@@ -61,11 +62,44 @@ public abstract class ListPageElement<T>
             super(size);
         }
     
+        public boolean isSingleSelection()
+        {
+            return singleSelection;
+        }
+
+        public void setSingleSelection(boolean singleSelection)
+        {
+            this.singleSelection = singleSelection;
+            clear();
+        }
+
         public boolean isInvertSelection()
         {
             return invertSelection;
         }
 
+        public boolean set(String e)
+        {
+            clear();
+            return super.add(e);
+        }
+
+        @Override
+        public boolean add(String e)
+        {
+            if (singleSelection)
+                return false;
+            return super.add(e);
+        }
+
+        @Override
+        public boolean remove(Object o)
+        {
+            if (singleSelection)
+                return false;
+            return super.remove(o);
+        }
+
         public void setInvertSelection(boolean invertSelection)
         {
             if (this.invertSelection==invertSelection)
@@ -432,10 +466,18 @@ public abstract class ListPageElement<T>
         return this.selectedItems.size();
     }
 
-    public Set<Object[]> getSelectedItems()
+    public List<T> getSelectedItems()
     {
-        // if (this.selectedItems==null)
-        throw new NotSupportedException(this, "getSelectedItems");
+        if (this.selectedItems==null)
+            throw new NotSupportedException(this, "getSelectedItems");
+        // find all items
+        List<T> selection = new ArrayList<T>(this.selectedItems.size());
+        for (T item : getItems())
+        {
+            if (((SelectableItem)item).isSelected())
+                selection.add(item);
+        }
+        return selection;
     }
     
     public boolean isInvertSelection()
@@ -453,6 +495,43 @@ public abstract class ListPageElement<T>
         // Invert
         this.selectedItems.setInvertSelection(invertSelection);
     }
+    
+    public boolean isSingleSelection()
+    {
+        if (this.selectedItems==null)
+            return false;
+        // Invert selection
+        return this.selectedItems.isSingleSelection();
+    }
+
+    public void setSingleSelection(boolean singleSelection)
+    {
+        if (this.selectedItems==null)
+            throw new NotSupportedException(this, "setSingleSelection");
+        // Invert
+        this.selectedItems.setSingleSelection(singleSelection);
+    }
+
+    public void setSelection(SelectableItem item)
+    {
+        if (this.selectedItems==null)
+            throw new NotSupportedException(this, "setInvertSelection");
+        // Invert
+        if (item!=null)
+            this.selectedItems.set(item.getIdParam());
+        else
+            this.selectedItems.clear();
+    }
+
+    public void setSelection(SelectableItem[] items)
+    {
+        if (this.selectedItems==null)
+            throw new NotSupportedException(this, "setInvertSelection");
+        // Invert
+        this.selectedItems.clear();
+        for (SelectableItem item : items)
+            this.selectedItems.add(item.getIdParam());
+    }
 
     protected void assignSelectionMap(List<?> items)
     {



Mime
View raw message