summaryrefslogtreecommitdiffstats
path: root/src/com/vaadin
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-07-30 10:31:26 +0000
committerLeif Åstrand <leif@vaadin.com>2012-07-30 10:31:26 +0000
commit7635949eb052473472fbe9a50e563f6ef8730e2f (patch)
treec7d11f3ab72386247edeb976dbe82eeef20eb37f /src/com/vaadin
parentcc65635fe483cba01d718a152f77e4d5be91c162 (diff)
downloadvaadin-framework-7635949eb052473472fbe9a50e563f6ef8730e2f.tar.gz
vaadin-framework-7635949eb052473472fbe9a50e563f6ef8730e2f.zip
Improved code readability based on review (#8109)
svn changeset:24033/svn branch:6.8
Diffstat (limited to 'src/com/vaadin')
-rw-r--r--src/com/vaadin/ui/AbstractSelect.java34
-rw-r--r--src/com/vaadin/ui/Table.java17
2 files changed, 28 insertions, 23 deletions
diff --git a/src/com/vaadin/ui/AbstractSelect.java b/src/com/vaadin/ui/AbstractSelect.java
index 1a781dd4f3..e0d1f4e3f2 100644
--- a/src/com/vaadin/ui/AbstractSelect.java
+++ b/src/com/vaadin/ui/AbstractSelect.java
@@ -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
diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java
index c4d90d7790..e96636dd70 100644
--- a/src/com/vaadin/ui/Table.java
+++ b/src/com/vaadin/ui/Table.java
@@ -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