]> source.dussan.org Git - vaadin-framework.git/commitdiff
Improved code readability based on review (#8109)
authorLeif Åstrand <leif@vaadin.com>
Mon, 30 Jul 2012 10:31:26 +0000 (10:31 +0000)
committerLeif Åstrand <leif@vaadin.com>
Mon, 30 Jul 2012 10:31:26 +0000 (10:31 +0000)
svn changeset:24033/svn branch:6.8

src/com/vaadin/ui/AbstractSelect.java
src/com/vaadin/ui/Table.java

index 1a781dd4f3947b782d1a0b446a348b18359f28b0..e0d1f4e3f2080617fad3331f644682583effe59a 100644 (file)
@@ -396,7 +396,8 @@ public abstract class AbstractSelect extends AbstractField implements
 
         // Selection change
         if (variables.containsKey("selected")) {
-            final String[] ka = (String[]) variables.get("selected");
+            final String[] clientSideSelectedKeys = (String[]) variables
+                    .get("selected");
 
             // Multiselect mode
             if (isMultiSelect()) {
@@ -404,19 +405,20 @@ public abstract class AbstractSelect extends AbstractField implements
                 // TODO Optimize by adding repaintNotNeeded when applicable
 
                 // Converts the key-array to id-set
-                final LinkedList<Object> s = new LinkedList<Object>();
-                for (int i = 0; i < ka.length; i++) {
-                    final Object id = itemIdMapper.get(ka[i]);
+                final LinkedList<Object> acceptedSelections = new LinkedList<Object>();
+                for (int i = 0; i < clientSideSelectedKeys.length; i++) {
+                    final Object id = itemIdMapper
+                            .get(clientSideSelectedKeys[i]);
                     if (!isNullSelectionAllowed()
                             && (id == null || id == getNullSelectionItemId())) {
                         // skip empty selection if nullselection is not allowed
                         requestRepaint();
                     } else if (id != null && containsId(id)) {
-                        s.add(id);
+                        acceptedSelections.add(id);
                     }
                 }
 
-                if (!isNullSelectionAllowed() && s.size() < 1) {
+                if (!isNullSelectionAllowed() && acceptedSelections.size() < 1) {
                     // empty selection not allowed, keep old value
                     requestRepaint();
                     return;
@@ -424,11 +426,11 @@ public abstract class AbstractSelect extends AbstractField implements
 
                 // Limits the deselection to the set of visible items
                 // (non-visible items can not be deselected)
-                Collection<?> visible = getVisibleItemIds();
-                if (visible != null) {
-                    visible = new HashSet<Object>(visible);
+                Collection<?> visibleNotSelected = getVisibleItemIds();
+                if (visibleNotSelected != null) {
+                    visibleNotSelected = new HashSet<Object>(visibleNotSelected);
                     // Don't remove those that will be added to preserve order
-                    visible.removeAll(s);
+                    visibleNotSelected.removeAll(acceptedSelections);
 
                     @SuppressWarnings("unchecked")
                     Set<Object> newsel = (Set<Object>) getValue();
@@ -437,18 +439,19 @@ public abstract class AbstractSelect extends AbstractField implements
                     } else {
                         newsel = new LinkedHashSet<Object>(newsel);
                     }
-                    newsel.removeAll(visible);
-                    newsel.addAll(s);
+                    newsel.removeAll(visibleNotSelected);
+                    newsel.addAll(acceptedSelections);
                     setValue(newsel, true);
                 }
             } else {
                 // Single select mode
                 if (!isNullSelectionAllowed()
-                        && (ka.length == 0 || ka[0] == null || ka[0] == getNullSelectionItemId())) {
+                        && (clientSideSelectedKeys.length == 0
+                                || clientSideSelectedKeys[0] == null || clientSideSelectedKeys[0] == getNullSelectionItemId())) {
                     requestRepaint();
                     return;
                 }
-                if (ka.length == 0) {
+                if (clientSideSelectedKeys.length == 0) {
                     // Allows deselection only if the deselected item is
                     // visible
                     final Object current = getValue();
@@ -457,7 +460,8 @@ public abstract class AbstractSelect extends AbstractField implements
                         setValue(null, true);
                     }
                 } else {
-                    final Object id = itemIdMapper.get(ka[0]);
+                    final Object id = itemIdMapper
+                            .get(clientSideSelectedKeys[0]);
                     if (!isNullSelectionAllowed() && id == null) {
                         requestRepaint();
                     } else if (id != null
index c4d90d7790df1b500c08361dfd2bfbfa122b92f2..e96636dd70c38c956c008af8fe3b0c5ba6dd04c1 100644 (file)
@@ -2294,8 +2294,9 @@ public class Table extends AbstractSelect implements Action.Container,
      *            The end key
      * @return
      */
-    private Set<Object> getItemIdsInRange(Object itemId, final int length) {
-        HashSet<Object> ids = new LinkedHashSet<Object>();
+    private LinkedHashSet<Object> getItemIdsInRange(Object itemId,
+            final int length) {
+        LinkedHashSet<Object> ids = new LinkedHashSet<Object>();
         for (int i = 0; i < length; i++) {
             assert itemId != null; // should not be null unless client-server
                                    // are out of sync
@@ -2315,7 +2316,7 @@ public class Table extends AbstractSelect implements Action.Container,
         final String[] ka = (String[]) variables.get("selected");
         final String[] ranges = (String[]) variables.get("selectedRanges");
 
-        Set<Object> renderedItemIds = getCurrentlyRenderedItemIds();
+        Set<Object> renderedButNotSelectedItemIds = getCurrentlyRenderedItemIds();
 
         @SuppressWarnings("unchecked")
         HashSet<Object> newValue = new LinkedHashSet<Object>(
@@ -2340,7 +2341,7 @@ public class Table extends AbstractSelect implements Action.Container,
                 requestRepaint();
             } else if (id != null && containsId(id)) {
                 newValue.add(id);
-                renderedItemIds.remove(id);
+                renderedButNotSelectedItemIds.remove(id);
             }
         }
 
@@ -2350,17 +2351,17 @@ public class Table extends AbstractSelect implements Action.Container,
                 String[] split = range.split("-");
                 Object startItemId = itemIdMapper.get(split[0]);
                 int length = Integer.valueOf(split[1]);
-                Set<Object> itemIdsInRange = getItemIdsInRange(startItemId,
-                        length);
+                LinkedHashSet<Object> itemIdsInRange = getItemIdsInRange(
+                        startItemId, length);
                 newValue.addAll(itemIdsInRange);
-                renderedItemIds.removeAll(itemIdsInRange);
+                renderedButNotSelectedItemIds.removeAll(itemIdsInRange);
             }
         }
         /*
          * finally clear all currently rendered rows (the ones that the client
          * side counterpart is aware of) that the client didn't send as selected
          */
-        newValue.removeAll(renderedItemIds);
+        newValue.removeAll(renderedButNotSelectedItemIds);
 
         if (!isNullSelectionAllowed() && newValue.isEmpty()) {
             // empty selection not allowed, keep old value