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

michi at wyona.com michi at wyona.com
Fri Nov 12 10:52:47 CET 2010


Author: michi
Date: 2010-11-12 10:52:46 +0100 (Fri, 12 Nov 2010)
New Revision: 54613

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/CutPasteListOrderWidget.java
   public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/PolicyListBoxWidget.java
Log:
cut and paste finished

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-12 09:44:45 UTC (rev 54612)
+++ public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AccessPolicyEditor.java	2010-11-12 09:52:46 UTC (rev 54613)
@@ -185,11 +185,11 @@
         vp.add(new Label("Wyona Access Control Policy (GWT) Editor version 1.0-dev-rREVISION"));
         
 
-        
         AddRemoveIdentitiesWidget ariw = new AddRemoveIdentitiesWidget(identitiesLBW, policyLBW.getListBox(), policyLBW);
         ariw.setStyleName("gwt-wyona-AddRemoveWidget");
 
-        //Button removeIdentityButton = new Button("DEBUG", new AddRemoveClickListener(identitiesLB));
+        CutPasteListOrderWidget cutPasteWidget = new CutPasteListOrderWidget(policyLBW);
+        cutPasteWidget.setStyleName("gwt-wyona-CutPasteListOrderWidget");
 
         hp.add(getFilterUsersAndGroupsButtonsWidget(language));
         hp.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
@@ -198,6 +198,7 @@
         hp.add(ariw);
         hp.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
         hp.add(policyLBW);
+        hp.add(cutPasteWidget);
     }
 
     /**

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-12 09:44:45 UTC (rev 54612)
+++ public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/AddRemoveIdentitiesWidget.java	2010-11-12 09:52:46 UTC (rev 54613)
@@ -81,7 +81,7 @@
                     String type = selectedIdentity.substring(0, 1); // e.g. 'g' or 'u'
                     String name = selectedIdentity.substring(2).trim(); // e.g. 'lenya'
                     //Window.alert("Add selected identity " + selectedIdentity + " (" + item + ", " + value + ") to policy");
-                    policyLBW.addItem(type, name, true);
+                    policyLBW.insertItemAtTop(type, name, true);
                     noItemSelected = false;
                 }
             }

Modified: public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/CutPasteListOrderWidget.java
===================================================================
--- public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/CutPasteListOrderWidget.java	2010-11-12 09:44:45 UTC (rev 54612)
+++ public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/CutPasteListOrderWidget.java	2010-11-12 09:52:46 UTC (rev 54613)
@@ -42,6 +42,7 @@
     private Button pasteBelowButton;
 
     private String selectedCutItem = null;
+    private Right[] selectedCutRights = null;
     private String selectedPasteAboveItem = null;
     private String selectedPasteBelowItem = null;
 
@@ -76,8 +77,13 @@
                 if (policyLB.isItemSelected(i)) {
                     selectedCutItem = policyLB.getValue(i);
                     Window.alert("INFO: Item '" + selectedCutItem + "' has been selected to be moved within policy. Select now another item and click either the 'Paste above' or 'Paste below' button.");
-                    // TODO: Cut only when pasted!
+
+                    //Window.alert("DEBUG: Selected item text: " + policyLB.getItemText(i));
+                    selectedCutRights = policyLBW.getRights(policyLB.getItemText(i));
+
+                    // TODO: Discuss of "Cut" only when pasted!
                     policyLB.removeItem(i);
+
                     noItemSelected = false;
                     break;
                 }
@@ -99,21 +105,23 @@
                 if (policyLB.isItemSelected(i)) {
                     selectedPasteAboveItem = policyLB.getValue(i);
                     if (selectedCutItem.equals(selectedPasteAboveItem)) {
-                        Window.alert("The paste above identity selected is the same as the cut identity! Please select another identity from 'Policy' list and click the 'Paste above' button again.");
+                        Window.alert("WARN: The paste above identity selected is the same as the cut identity! Please select another identity from 'Policy' list and click the 'Paste above' button again.");
                         return;
                     }
 
-                    Window.alert("DEBUG: Paste the item '" + selectedCutItem + "' above the selected identity '" + selectedPasteAboveItem + "'.");
+                    //Window.alert("DEBUG: Paste the item '" + selectedCutItem + "' above the selected identity '" + selectedPasteAboveItem + "'.");
                     String type = selectedCutItem.substring(0, 1);
                     String name = selectedCutItem.substring(2).trim();
                     String typeInsertBefore = selectedPasteAboveItem.substring(0, 1);
                     String nameInsertBefore = selectedPasteAboveItem.substring(2).trim();
-                    // TODO: Copy rights ...
-                    // TODO: Insert at right position
-                    policyLBW.insertItemBefore(type, name, true, typeInsertBefore, nameInsertBefore); // TODO: Discuss whether item should be selected (see e-mail ...)
+                    boolean keepItemSelected = true; // TODO: Discuss whether item should be selected (see e-mail ...)
+                    policyLBW.insertItemBefore(type, name, selectedCutRights, keepItemSelected, typeInsertBefore, nameInsertBefore);
 
+                    //Window.alert("DEBUG: Paste above is completed.");
+
                     // Reset temporary variables
                     selectedCutItem = null;
+                    selectedCutRights = null;
                     selectedPasteAboveItem = null;
                     selectedPasteBelowItem = null;
 
@@ -126,7 +134,6 @@
                 Window.alert("No identity selected yet! Please select an identity from 'Policy' list in order to paste above.");
             }
         } else if (sender == pasteBelowButton) {
-            Window.alert("WARN: Paste below user or group implementation not finished yet!");
             boolean noItemSelected = true;
 
             if (selectedCutItem == null) {
@@ -138,17 +145,27 @@
                 if (policyLB.isItemSelected(i)) {
                     selectedPasteBelowItem = policyLB.getValue(i);
                     if (selectedCutItem.equals(selectedPasteBelowItem)) {
-                        Window.alert("The paste below identity selected is the same as the cut identity! Please select another identity from 'Policy' list and click the 'Paste below' button again.");
+                        Window.alert("WARN: The paste below identity selected is the same as the cut identity! Please select another identity from 'Policy' list and click the 'Paste below' button again.");
                         return;
                     }
 
-                    Window.alert("DEBUG: Paste the item '" + selectedCutItem + "' below the selected identity '" + selectedPasteBelowItem + "'.");
-/*
-                    policyLB.addItem(TODO);
-*/
+                    //Window.alert("DEBUG: Paste the item '" + selectedCutItem + "' below the selected identity '" + selectedPasteBelowItem + "'.");
+
+                    String type = selectedCutItem.substring(0, 1);
+                    String name = selectedCutItem.substring(2).trim();
+                    String typeInsertAfter = selectedPasteBelowItem.substring(0, 1);
+                    String nameInsertAfter = selectedPasteBelowItem.substring(2).trim();
+                    boolean keepItemSelected = true; // TODO: Discuss whether item should be selected (see e-mail ...)
+                    policyLBW.insertItemAfter(type, name, selectedCutRights, keepItemSelected, typeInsertAfter, nameInsertAfter);
+
+                    //Window.alert("DEBUG: Paste below is completed.");
+
+                    // Reset temporary variables
                     selectedCutItem = null;
+                    selectedCutRights = null;
                     selectedPasteAboveItem = null;
                     selectedPasteBelowItem = null;
+
                     noItemSelected = false;
                     break;
                 }

Modified: public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/PolicyListBoxWidget.java
===================================================================
--- public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/PolicyListBoxWidget.java	2010-11-12 09:44:45 UTC (rev 54612)
+++ public/yanel/contributions/ajax-components/src/access-policy-editor/java/org/wyona/security/gwt/accesspolicyeditor/client/PolicyListBoxWidget.java	2010-11-12 09:52:46 UTC (rev 54613)
@@ -90,8 +90,7 @@
                     String id = users[i].getId();
                     Right[] rights = users[i].getRights();
                     //Window.alert("User: " + users[i].getId() + " (Number of rights: " + rights.length + ")");
-                    String value = type+": " + id;
-                    lb.addItem(getListItemLabel(type, id, rights), value);
+                    lb.addItem(getListItemLabel(type, id, rights), getListItemValue(type, id));
                 }
             }
             if (groups != null) {
@@ -100,8 +99,7 @@
                     String id = groups[i].getId();
                     Right[] rights = groups[i].getRights();
                     //Window.alert("Group: " + groups[i].getId() + " (Number of rights: " + rights.length + ")");
-                    String value = type+": " + id;
-                    lb.addItem(getListItemLabel(type, id, rights), value);
+                    lb.addItem(getListItemLabel(type, id, rights), getListItemValue(type, id));
                 }
             } else {
                 Window.alert("No groups!");
@@ -177,9 +175,11 @@
     }
 
     /**
-     * Get rights from identity string, e.g. "u: (r,w) alice"
+     * Get rights from identity string
+     *
+     * @param identity Item label containing type, rights and name, e.g. 'u:() alice'
      */
-    private Right[] getRights(String identity) {
+    Right[] getRights(String identity) {
         if (identity.indexOf("(") > 0) {
             String[] rightsString = identity.substring(identity.indexOf("(") + 1, identity.indexOf(")")).split(",");
 
@@ -278,6 +278,8 @@
 
     /**
      * Set rights for selected users/groups
+     * 
+     * @param rights New rights
      */
     private void setRightsForSelectedListItem(String[] rights) {
         boolean noItemSelected = true;
@@ -323,12 +325,50 @@
     }
 
     /**
-     * Generate list item label, e.g. "u: (view, -, toolbar) user-foo-bar"
+     * Get list label, e.g. 'u:(r,-) alice'
      *
      * @param type u for user and g for group
      * @param id
      * @param rights Rights
      */
+    private String getListLabel(String type, String id, Right[] rights) {
+        StringBuffer sb = new StringBuffer(type + ":");
+
+        if (rights[0].getPermission()) {
+            sb.append("(" + rights[0].getId());
+        } else {
+            sb.append("(" + "-");
+        }
+        for (int i = 1; i < rights.length; i ++) {
+            if (rights[i].getPermission()) {
+                sb.append("," + rights[i].getId());
+            } else {
+                sb.append("," + "-");
+            }
+        }
+        sb.append(")");
+        sb.append(" " + id);
+        return sb.toString();
+    }
+
+
+    /**
+     * Generate list item value, e.g. "u: user-foo-bar"
+     *
+     * @param type u for user and g for group
+     * @param id
+     */
+    private String getListItemValue(String type, String id) {
+        return type + ": " + id;
+    }
+
+    /**
+     * Generate list item label, e.g. "u:(view, -, toolbar) user-foo-bar"
+     *
+     * @param type u for user and g for group
+     * @param id
+     * @param rights Rights
+     */
     private String getListItemLabel(String type, String id, Right[] rights) {
 
 /*
@@ -437,36 +477,98 @@
 
     /**
      * Append either user or group to policy list
-     * @param type User or Group
+     *
+     * @param type Type of user or group
      * @param name Name of user or group
      * @param selected Sets whether list item is selected. True to select the item.
      */
     public void addItem(String type, String name, boolean selected) {
-        StringBuffer emptyRights = new StringBuffer("(-");
-        for (int i = 1; i < availableRightsCB.length; i++) {
-            emptyRights.append(",-");
-        }
-        emptyRights.append(")");
-
-        lb.addItem(type + ": " + emptyRights + " " + name, type + ": " + name);
+        lb.addItem(type + ":" + getEmptyRights() + " " + name, getListItemValue(type, name));
         lb.setItemSelected(lb.getItemCount() - 1, selected);
     }
 
     /**
-     * Append either user or group to policy list
-     * @param type User or Group
+     * Insert either user or group at top of policy list
+     *
+     * @param type Type of user or group
      * @param name Name of user or group
      * @param selected Sets whether list item is selected. True to select the item.
      */
-    public void insertItemBefore(String type, String name, boolean selected, String typeInsertBefore, String nameInsertBefore) {
-        Window.alert("DEBUG: Insert before ...");
+    public void insertItemAtTop(String type, String name, boolean selected) {
+        // TOOD: If selected is true, then unselect all other items!
+        lb.insertItem(type + ":" + getEmptyRights() + " " + name, getListItemValue(type, name), 0);
+        lb.setItemSelected(0, selected);
+    }
+
+    /**
+     * Insert either user or group to policy list before an existing list item
+     *
+     * @param type Type of user or group which will be inserted
+     * @param name Name of user or group which will be inserted
+     * @param rights Rights of user or group which will be inserted
+     * @param selected Sets whether list item is selected. True to select the item.
+     * @param typeInsertBefore Type of user or group which is referenced as the target to insert before
+     * @param nameInsertBefore Name of user or group which is referenced as the target to insert before
+     */
+    public void insertItemBefore(String type, String name, Right[] rights, boolean selected, String typeInsertBefore, String nameInsertBefore) {
+        //Window.alert("DEBUG: Insert before ...");
+
+        boolean targetItemExists = false;
+        for (int i = lb.getItemCount() -1; i >= 0; i--) {
+            //Window.alert("DEBUG: Item value: " + lb.getValue(i));
+            if (lb.getValue(i).equals(getListItemValue(typeInsertBefore, nameInsertBefore))) {
+                targetItemExists = true;
+                lb.insertItem(getListLabel(type, name, rights), getListItemValue(type, name), i);
+                break;
+            }
+        }
+
+        if (!targetItemExists) {
+            Window.alert("ERROR: No such item: " + getListItemValue(typeInsertBefore, nameInsertBefore));
+        }
+    }
+
+    /**
+     * Insert either user or group to policy list after an existing list item
+     *
+     * @param type Type of user or group which will be inserted
+     * @param name Name of user or group which will be inserted
+     * @param rights Rights of user or group which will be inserted
+     * @param selected Sets whether list item is selected. True to select the item.
+     * @param typeInsertBefore Type of user or group which is referenced as the target to insert before
+     * @param nameInsertBefore Name of user or group which is referenced as the target to insert before
+     */
+    public void insertItemAfter(String type, String name, Right[] rights, boolean selected, String typeInsertBefore, String nameInsertBefore) {
+        //Window.alert("DEBUG: Insert before ...");
+
+        boolean targetItemExists = false;
+        for (int i = lb.getItemCount() -1; i >= 0; i--) {
+            //Window.alert("DEBUG: Item value: " + lb.getValue(i));
+            if (lb.getValue(i).equals(getListItemValue(typeInsertBefore, nameInsertBefore))) {
+                targetItemExists = true;
+                if (i + 1 < lb.getItemCount()) {
+                    lb.insertItem(getListLabel(type, name, rights), getListItemValue(type, name), i + 1);
+                } else {
+                    lb.addItem(getListLabel(type, name, rights), getListItemValue(type, name));
+                }
+                break;
+            }
+        }
+
+        if (!targetItemExists) {
+            Window.alert("ERROR: No such item: " + getListItemValue(typeInsertBefore, nameInsertBefore));
+        }
+    }
+
+    /**
+     * Generate an empty rights string
+     */
+    private String getEmptyRights() {
         StringBuffer emptyRights = new StringBuffer("(-");
         for (int i = 1; i < availableRightsCB.length; i++) {
             emptyRights.append(",-");
         }
         emptyRights.append(")");
-
-        lb.addItem(type + ": " + emptyRights + " " + name, type + ": " + name);
-        lb.setItemSelected(lb.getItemCount() - 1, selected);
+        return emptyRights.toString();
     }
 }



More information about the Yanel-commits mailing list