[Yanel-commits] rev 54594 - public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client

michi at wyona.com michi at wyona.com
Thu Nov 11 13:30:07 CET 2010


Author: michi
Date: 2010-11-11 13:30:07 +0100 (Thu, 11 Nov 2010)
New Revision: 54594

Added:
   public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AlphabeticalFilterButton.java
Modified:
   public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AccessPolicyEditor.java
   public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AddRemoveIdentitiesWidget.java
   public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/I18n.java
   public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/IdentitiesListBoxWidget.java
Log:
alphabetical filter buttons added

Modified: public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AccessPolicyEditor.java
===================================================================
--- public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AccessPolicyEditor.java	2010-11-11 11:48:48 UTC (rev 54593)
+++ public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AccessPolicyEditor.java	2010-11-11 12:30:07 UTC (rev 54594)
@@ -53,8 +53,6 @@
     PolicyListBoxWidget policyLBW;
     Button saveButton;
 
-    String[] identitiesAllUsers;
-    String[] identitiesAllGroups;
     Right[] allRights;
     boolean rightsIdentitiesRetrievalCompleted = false;
     boolean policyRetrievalCompleted = false;
@@ -114,34 +112,11 @@
         searchTB.setVisibleLength(30);
         searchFilterPanel.add(searchTB);
 
+        // Search functionality
         searchTB.addKeyboardListener(
                 new KeyboardListenerAdapter() {
                     public void onKeyUp(Widget sender, char keyCode, int modifiers) {
-                        //ListBox identitiesLB = identitiesLBW.getListBox();
-                        //identitiesLB.clear();
-
-                        ArrayList resultUsers = new ArrayList();
-                        for (int i = 0; i < identitiesAllUsers.length; i++) {
-                            String itemText = identitiesAllUsers[i];
-                            if (itemText.indexOf(searchTB.getText()) >= 0) {
-                                resultUsers.add(itemText);
-                            }
-                        }
-                        ArrayList resultGroups = new ArrayList();
-                        for (int i = 0; i < identitiesAllGroups.length; i++) {
-                            String itemText = identitiesAllGroups[i];
-                            if (itemText.indexOf(searchTB.getText()) >= 0) {
-                                resultGroups.add(itemText);
-                            }
-                        }
-                        
-                        String tmpUsersStr [] = new String [resultUsers.size()];
-                        resultUsers.toArray(tmpUsersStr);
-                        String tmpGroupStr [] = new String [resultGroups.size()];
-                        resultGroups.toArray(tmpGroupStr);
-                        
-                        identitiesLBW.set(visibleItemCount, tmpUsersStr, tmpGroupStr);
-                        // filterList(list, filter.getText());
+                        identitiesLBW.listBySearchMatch(searchTB.getText());
                     }
                 });
 
@@ -211,11 +186,12 @@
         
 
         
-        AddRemoveIdentitiesWidget ariw = new AddRemoveIdentitiesWidget(identitiesLBW.getListBox(), policyLBW.getListBox(), policyLBW);
+        AddRemoveIdentitiesWidget ariw = new AddRemoveIdentitiesWidget(identitiesLBW, policyLBW.getListBox(), policyLBW);
         ariw.setStyleName("gwt-wyona-AddRemoveWidget");
 
         //Button removeIdentityButton = new Button("DEBUG", new AddRemoveClickListener(identitiesLB));
 
+        hp.add(getFilterUsersAndGroupsButtonsWidget(language));
         hp.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
         hp.add(identitiesLBW);
         hp.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
@@ -226,10 +202,10 @@
 
     /**
      * Get identities and rights
-     * @param url URL to request identities (users and groups) as XML
+     * @param url URL to request identities (users and groups) as XML (also see src/contributions/resources/policymanager/src/java/org/wyona/yanel/impl/resources/policymanager/PolicyManagerResource.java, identities-url)
      */
     private void getIdentitiesAndRights(String url) {
-        if (identitiesAllUsers == null || identitiesAllGroups == null || allRights == null) {
+        if (allRights == null) {
             //Window.alert("Load users and groups as XML: " + url);
             url = GWT.getHostPageBaseURL() + url.replaceAll("&amp;", "&");
             //Window.alert("Load IdentitiesAndRights: "+ url);
@@ -243,19 +219,19 @@
                     public void run() {
                         if (request.isPending()) {
                             rightsIdentitiesRetrievalCompleted = false;
-                            identitiesLBW.displayLoadingIdentities(visibleItemCount);
+                            identitiesLBW.displayLoadingMessage();
                             scheduleRepeating(10);
                         } else {
                             rightsIdentitiesRetrievalCompleted = true;
                             
                             allRights = ag.getRights();
-                            identitiesAllUsers = ag.getUsers();
-                            identitiesAllGroups = ag.getGroups();
+                            String[] identitiesAllUsers = ag.getUsers();
+                            String[] identitiesAllGroups = ag.getGroups();
                             this.cancel();
                             // NOTE: Please note that the server might not provide any groups and hence the OR instead the AND!
                             if (allRights.length > 0 && (identitiesAllUsers.length > 0 || identitiesAllGroups.length > 0)) {
                                 policyLBW.set(allRights);
-                                identitiesLBW.set(visibleItemCount, identitiesAllUsers, identitiesAllGroups);
+                                identitiesLBW.setUsersAndGroups(identitiesAllUsers, identitiesAllGroups);
                                 //Window.alert("Rights and identities have been loaded!" + allRights.length + " " + identitiesAllUsers.length + " " + identitiesAllGroups.length);
                             } else {
                                 Window.alert("Rights and identities have not been loaded yet!");
@@ -270,6 +246,8 @@
                 e.printStackTrace();
                 //}
             }
+        } else {
+            Window.alert("Rights are already set!");
         }
     }
 
@@ -306,32 +284,19 @@
                         this.cancel();
                         
                         // Remove/Subtract policy-users/groups from "Identities"
-                        ArrayList tmpUsers = new ArrayList(Arrays.asList(identitiesAllUsers));
-                        ArrayList tmpGroups = new ArrayList(Arrays.asList(identitiesAllGroups));
                         
                         // Remove all users from identities list, which already exist within the policy
-                        int itemCountUP = policyUsers.length;
-                        for (int i = 0; i < itemCountUP; i++) {
-                            String itemText = policyUsers[i].getId();
-                            tmpUsers.remove(itemText);
+                        for (int i = 0; i < policyUsers.length; i++) {
+                            identitiesLBW.removeUser(policyUsers[i].getId());
                         }
 
                         // Remove all groups from identities list, which already exist within the policy
-                        int itemCountGP = policyGroups.length;
-                        for (int i = 0; i < itemCountGP; i++) {
-                            String itemText = policyGroups[i].getId();
-                            tmpGroups.remove(itemText);
+                        for (int i = 0; i < policyGroups.length; i++) {
+                            identitiesLBW.removeGroup(policyGroups[i].getId());
                         }
-                        
-                        String tmpUsersStr [] = new String [tmpUsers.size ()];
-                        tmpUsers.toArray(tmpUsersStr);
-                        identitiesAllUsers = tmpUsersStr;
-                        
-                        String tmpGroupStr [] = new String [tmpGroups.size ()];
-                        tmpGroups.toArray(tmpGroupStr);
-                        identitiesAllGroups = tmpGroupStr;
-                        
-                        identitiesLBW.set(visibleItemCount, identitiesAllUsers, identitiesAllGroups);
+
+                        identitiesLBW.listAll(); // TODO: Update display inside removeUser() and removeGroup()
+
                         //Window.alert("Policy has been loaded!");
                     }
                 }
@@ -345,10 +310,38 @@
              //}
         }
     }
-    
 
+    /**
+     * Get filter users and groups buttons widget
+     * @param language I18n language
+     */
+    private Widget getFilterUsersAndGroupsButtonsWidget(String language) {
+        VerticalPanel vp = new VerticalPanel();
+        vp.setStyleName("gwt-wyona-identity-initials-search");
+        vp.addStyleName("gwt-wyona-users-and-groups-buttons-vp");
+
+        Button allButton = new Button(I18n.getLabel("button-all", language), new ClickListener() {
+                public void onClick(Widget sender) {
+                    //Window.alert("DEBUG: Widget clicked with title: " + sender.getTitle());
+                    identitiesLBW.listAll();
+                }
+        });
+        allButton.setTitle("All groups button");
+        vp.add(allButton);
+
+        vp.add(new AlphabeticalFilterButton('a', 'd', identitiesLBW));
+        vp.add(new AlphabeticalFilterButton('e', 'i', identitiesLBW));
+        vp.add(new AlphabeticalFilterButton('j', 'm', identitiesLBW));
+        vp.add(new AlphabeticalFilterButton('n', 'q', identitiesLBW));
+        vp.add(new AlphabeticalFilterButton('r', 'u', identitiesLBW));
+        vp.add(new AlphabeticalFilterButton('v', 'z', identitiesLBW));
+
+        return vp;
+    }
 }
 
+
+
 /**
  *
  */

Modified: public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AddRemoveIdentitiesWidget.java
===================================================================
--- public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AddRemoveIdentitiesWidget.java	2010-11-11 11:48:48 UTC (rev 54593)
+++ public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AddRemoveIdentitiesWidget.java	2010-11-11 12:30:07 UTC (rev 54594)
@@ -33,7 +33,7 @@
  */
 public class AddRemoveIdentitiesWidget extends Composite implements ClickListener {
 
-    private ListBox identitiesLB;
+    private IdentitiesListBoxWidget identitiesLBW;
     private ListBox policyLB;
     private PolicyListBoxWidget policyLBW;
 
@@ -45,7 +45,7 @@
     /**
      *
      */
-    public AddRemoveIdentitiesWidget(ListBox identitiesListBox, ListBox policyListBox, PolicyListBoxWidget policyLBW) {
+    public AddRemoveIdentitiesWidget(IdentitiesListBoxWidget identitiesListBox, ListBox policyListBox, PolicyListBoxWidget policyLBW) {
         initWidget(fp);
 
         addButton = new Button(">", this);
@@ -54,7 +54,7 @@
         removeButton = new Button("<", this);
         fp.add(removeButton);
 
-        this.identitiesLB = identitiesListBox;
+        this.identitiesLBW = identitiesListBox;
         this.policyLB = policyListBox;
         this.policyLBW = policyLBW;
     }
@@ -63,11 +63,20 @@
      * Move item from one list to the other
      */
     public void onClick(Widget sender) {
+        ListBox identitiesLB = identitiesLBW.getListBox();
         if (sender == addButton) {
             boolean noItemSelected = true;
             for (int i = identitiesLB.getItemCount() - 1; i >= 0; i--) { // INFO: One needs to step backwards, because the size of the list decreases, because items are being removed if selected
                 if (identitiesLB.isItemSelected(i)) {
                     String selectedIdentity = identitiesLB.getValue(i);
+                    //Window.alert("DEBUG: Move item: " + selectedIdentity);
+                    if (selectedIdentity.startsWith("u:")) {
+                        identitiesLBW.removeUser(selectedIdentity.substring(3));
+                    } else if (selectedIdentity.startsWith("g:")) {
+                        identitiesLBW.removeGroup(selectedIdentity.substring(3));
+                    } else {
+                        Window.alert("ERROR: Neither user nor group: " + selectedIdentity);
+                    }
                     identitiesLB.removeItem(i);
                     String type = selectedIdentity.substring(0, 1); // e.g. 'g' or 'u'
                     String name = selectedIdentity.substring(2).trim(); // e.g. 'lenya'
@@ -85,7 +94,14 @@
             for (int i = policyLB.getItemCount() - 1; i >= 0; i--) { // INFO: One needs to step backwards, because the size of the list decreases, because items are being removed if selected
                 if (policyLB.isItemSelected(i)) {
                     String selectedIdentity = policyLB.getValue(i);
-                    //Window.alert("Remove selected identity " + selectedIdentity + " from policy");
+                    //Window.alert("DEBUG: Remove selected identity " + selectedIdentity + " from policy");
+                    if (selectedIdentity.startsWith("u:")) {
+                        identitiesLBW.addUser(selectedIdentity.substring(3));
+                    } else if (selectedIdentity.startsWith("g:")) {
+                        identitiesLBW.addGroup(selectedIdentity.substring(3));
+                    } else {
+                        Window.alert("ERROR: Neither user nor group: " + selectedIdentity);
+                    }
                     policyLB.removeItem(i);
                     identitiesLB.addItem(removeRights(selectedIdentity));
                     noItemSelected = false;

Added: public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AlphabeticalFilterButton.java
===================================================================
--- public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AlphabeticalFilterButton.java	                        (rev 0)
+++ public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AlphabeticalFilterButton.java	2010-11-11 12:30:07 UTC (rev 54594)
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2010 Wyona
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.wyona.security.gwt.accesspolicyeditor.client;
+
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.ui.Button;
+import com.google.gwt.user.client.ui.ClickListener;
+import com.google.gwt.user.client.ui.Widget;
+
+/**
+ * Alphabetical filter button
+ */
+public class AlphabeticalFilterButton extends Button {
+
+    /**
+     *
+     */
+    public AlphabeticalFilterButton(char startRangeChar, char endRangeChar, IdentitiesListBoxWidget usersGroupsListBox) {
+        // Init button
+        super(Character.toUpperCase(startRangeChar) + "-" + Character.toUpperCase(endRangeChar));
+
+        // Add click listener
+        addClickListener(new UsersGroupsButtonClickListener(startRangeChar, endRangeChar, usersGroupsListBox));
+
+        // Set tool tip
+        setTitle(Character.toUpperCase(startRangeChar) + " - " + Character.toUpperCase(endRangeChar) + " filter button");
+    }
+}
+
+/**
+ *
+ */
+class UsersGroupsButtonClickListener implements ClickListener {
+
+    private IdentitiesListBoxWidget ugl;
+    private char startChar;
+    private char endChar;
+
+    /**
+     *
+     */
+    public UsersGroupsButtonClickListener(char startRangeChar, char endRangeChar, IdentitiesListBoxWidget usersGroupsListBox) {
+        this.ugl = usersGroupsListBox;
+        this.startChar = startRangeChar;
+        this.endChar = endRangeChar;
+    }
+
+    /**
+     *
+     */
+    public void onClick(Widget sender) {
+        //Window.alert("DEBUG: Button clicked ...");
+        ugl.listUsersAndGroups(startChar, endChar);
+    }
+}

Modified: public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/I18n.java
===================================================================
--- public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/I18n.java	2010-11-11 11:48:48 UTC (rev 54593)
+++ public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/I18n.java	2010-11-11 12:30:07 UTC (rev 54594)
@@ -31,6 +31,8 @@
                 return "Inherit rights from parent policies";
             } else if(key.equals("list-box-identities")) {
                 return "Identities (Users and Groups)";
+            } else if(key.equals("button-all")) {
+                return "All";
             }
         } else if (language.equals("de")) {
             if (key.equals("search-box-label")) {
@@ -39,6 +41,8 @@
                 return "Uebernehme vererbte Rechte der Eltern-Policies";
             } else if(key.equals("list-box-identities")) {
                 return "Identitäten (Benutzer und Gruppen)";
+            } else if(key.equals("button-all")) {
+                return "Alle";
             }
         } else {
             return "WARNING: No such language '" + language + "' implemented!";

Modified: public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/IdentitiesListBoxWidget.java
===================================================================
--- public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/IdentitiesListBoxWidget.java	2010-11-11 11:48:48 UTC (rev 54593)
+++ public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/IdentitiesListBoxWidget.java	2010-11-11 12:30:07 UTC (rev 54594)
@@ -30,6 +30,8 @@
 import com.google.gwt.user.client.ui.VerticalPanel;
 import com.google.gwt.user.client.ui.Widget;
 
+import java.util.List;
+
 /**
  * List box containing users and groups to choose/select from
  */
@@ -41,8 +43,12 @@
 
     private String language;
 
+    private List users;
+    private List groups;
+
     /**
-     *
+     * @param visibleItemCount Maximum number of users/groups which shall be displayed (all other users/groups can be accessed by scrolling up and down)
+     * @param language I18n language
      */
     public IdentitiesListBoxWidget(int visibleItemCount, String language) {
         this.language = language;
@@ -53,16 +59,19 @@
         boolean isMultipleSelect = true;
         lb = new ListBox(isMultipleSelect); // NOTE: ListBox#setMultipleSelect(true) can spuriously fail on IE 6.0
         lb.addClickListener(this);
-        set(visibleItemCount, null, null);
+
+        lb.clear();
+        lb.setVisibleItemCount(visibleItemCount);
+        displayLoadingMessage();
+
         vp.add(lb);
     }
 
     /**
-     *
+     * Display message that users and groups have not been loaded yet
      */
-    public void displayLoadingIdentities(int visibleItemCount) {
+    public void displayLoadingMessage() {
         lb.clear();
-        lb.setVisibleItemCount(visibleItemCount);
         lb.addItem("Loading users/groups ...");
         lb.addItem("Thanks for being patient!");
     }
@@ -70,24 +79,48 @@
     /**
      * Set users and groups as list items
      */
-    public void set(int visibleItemCount, String[] users, String[] groups) {
+    public void setUsersAndGroups(String[] users, String[] groups) {
         if (users == null && groups == null) {
-            displayLoadingIdentities(visibleItemCount);
+            Window.alert("ERROR: Neither users nor groups set!");
             return;
         }
 
-        lb.clear();
-        lb.setVisibleItemCount(visibleItemCount);
         if (users != null) {
+            this.users = new java.util.ArrayList();
             for (int i = 0; i < users.length; i++) {
-                lb.addItem("u: " + users[i]);
+                this.users.add(users[i]);
             }
+        }
+        if (groups != null) {
+            this.groups = new java.util.ArrayList();
+            for (int i = 0; i < groups.length; i++) {
+                this.groups.add(groups[i]);
+            }
+        }
+
+        listAll();
+    }
+
+    /**
+     * Display all users and all groups
+     */
+    public void listAll() {
+        if (users == null && groups == null) {
+            Window.alert("ERROR: Neither users nor groups have been set yet!");
+            return;
+        }
+
+        lb.clear();
+        if (users != null) {
+            for (int i = 0; i < users.size(); i++) {
+                lb.addItem("u: " + users.get(i));
+            }
         } else {
             lb.addItem("No users yet!");
         }
         if (groups != null) {
-            for (int i = 0; i < groups.length; i++) {
-                lb.addItem("g: " + groups[i]);
+            for (int i = 0; i < groups.size(); i++) {
+                lb.addItem("g: " + groups.get(i));
             }
         } else {
             lb.addItem("No groups yet!");
@@ -107,4 +140,94 @@
     public void onClick(Widget sender) {
         //Window.alert("An identity has been selected!");
     }
+
+    /**
+     * List all users and groups matching a particular search term
+     * @param searchTerm Search term
+     */
+    public void listBySearchMatch(String searchTerm) {
+        lb.clear();
+
+        for (int i = 0; i < users.size(); i++) {
+            String itemText = (String) users.get(i);
+            if (itemText.indexOf(searchTerm) >= 0) {
+                lb.addItem("u: " + itemText);
+            }
+        }
+        for (int i = 0; i < groups.size(); i++) {
+            String itemText = (String) groups.get(i);
+            if (itemText.indexOf(searchTerm) >= 0) {
+                lb.addItem("g: " + itemText);
+            }
+        }
+    }
+
+    /**
+     * Remove user
+     * @param id User ID
+     */
+    public void removeUser(String id) {
+        //Window.alert("DEBUG: Remove user: " + id);
+        users.remove(id);
+    }
+
+    /**
+     * Add user
+     * @param id User ID
+     */
+    public void addUser(String id) {
+        //Window.alert("DEBUG: Add user: " + id);
+        users.add(id);
+    }
+
+    /**
+     * Remove group
+     * @param id Group ID
+     */
+    public void removeGroup(String id) {
+        groups.remove(id);
+    }
+
+    /**
+     * Add group
+     * @param id Group ID
+     */
+    public void addGroup(String id) {
+        groups.add(id);
+    }
+
+    /**
+     * List users and groups within a specific range of the alphabet
+     * @param start Start of alphabet range
+     * @param end End of alphabet range
+     */
+    public void listUsersAndGroups(char start, char end) {
+        //Window.alert("DEBUG: List users and groups ...");
+
+        if (groups != null && users != null) {
+            lb.clear();
+
+            for (int i = 0; i < users.size(); i++) {
+                char firstChar = ((String)users.get(i)).charAt(0);
+                if (start <= firstChar && firstChar <= end) {
+                    lb.addItem("u: " + users.get(i));
+                }
+            }
+
+            for (int i = 0; i < groups.size(); i++) {
+                char firstChar = ((String)groups.get(i)).charAt(0);
+                if (start <= firstChar && firstChar <= end) {
+                    lb.addItem("g: " + groups.get(i));
+                }
+            }
+
+/*
+            if (lb.getItemCount() <= 0) {
+                lb.addItem("Neither users nor groups within range: " + start + " - " + end);
+            }
+*/
+        } else {
+            lb.addItem("Either users or groups not loaded yet!");
+        }
+    }
 }



More information about the Yanel-commits mailing list