summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin
diff options
context:
space:
mode:
authorJohannes Dahlström <johannesd@vaadin.com>2013-02-14 13:15:34 +0000
committerVaadin Code Review <review@vaadin.com>2013-02-14 13:15:34 +0000
commit655a44cadffb2fc0f4d94327582c6611126be8ad (patch)
tree9726648f7a025454bcd6259ed01f7ff72906784e /server/src/com/vaadin
parent35571f0f3e11595e0306cfbe158682f0c370ca4c (diff)
parent7a111fc541dcc507032cdad6799b477df6d4833f (diff)
downloadvaadin-framework-655a44cadffb2fc0f4d94327582c6611126be8ad.tar.gz
vaadin-framework-655a44cadffb2fc0f4d94327582c6611126be8ad.zip
Merge "Merge of (#6160) and (#10470) to Vaadin 7." into 7.0
Diffstat (limited to 'server/src/com/vaadin')
-rw-r--r--server/src/com/vaadin/data/util/IndexedContainer.java3
-rw-r--r--server/src/com/vaadin/server/VaadinPortletService.java7
-rw-r--r--server/src/com/vaadin/server/VaadinServletService.java7
-rw-r--r--server/src/com/vaadin/ui/AbstractField.java24
-rw-r--r--server/src/com/vaadin/ui/Label.java17
-rw-r--r--server/src/com/vaadin/ui/Table.java207
6 files changed, 159 insertions, 106 deletions
diff --git a/server/src/com/vaadin/data/util/IndexedContainer.java b/server/src/com/vaadin/data/util/IndexedContainer.java
index 1705365f60..306f9cf23b 100644
--- a/server/src/com/vaadin/data/util/IndexedContainer.java
+++ b/server/src/com/vaadin/data/util/IndexedContainer.java
@@ -166,7 +166,8 @@ public class IndexedContainer extends
public Property getContainerProperty(Object itemId, Object propertyId) {
// map lookup more efficient than propertyIds if there are many
// properties
- if (!containsId(itemId) || !types.containsKey(propertyId)) {
+ if (!containsId(itemId) || propertyId == null
+ || !types.containsKey(propertyId)) {
return null;
}
diff --git a/server/src/com/vaadin/server/VaadinPortletService.java b/server/src/com/vaadin/server/VaadinPortletService.java
index e59ea7fd5e..8c1e7af0fa 100644
--- a/server/src/com/vaadin/server/VaadinPortletService.java
+++ b/server/src/com/vaadin/server/VaadinPortletService.java
@@ -46,7 +46,12 @@ public class VaadinPortletService extends VaadinService {
}
}
- protected VaadinPortlet getPortlet() {
+ /**
+ * Retrieves a reference to the portlet associated with this service.
+ *
+ * @return A reference to the VaadinPortlet this service is using
+ */
+ public VaadinPortlet getPortlet() {
return portlet;
}
diff --git a/server/src/com/vaadin/server/VaadinServletService.java b/server/src/com/vaadin/server/VaadinServletService.java
index 71f47ea217..7120e3a5c5 100644
--- a/server/src/com/vaadin/server/VaadinServletService.java
+++ b/server/src/com/vaadin/server/VaadinServletService.java
@@ -44,7 +44,12 @@ public class VaadinServletService extends VaadinService {
}
}
- protected VaadinServlet getServlet() {
+ /**
+ * Retrieves a reference to the servlet associated with this service.
+ *
+ * @return A reference to the VaadinServlet this service is using
+ */
+ public VaadinServlet getServlet() {
return servlet;
}
diff --git a/server/src/com/vaadin/ui/AbstractField.java b/server/src/com/vaadin/ui/AbstractField.java
index 422e0a1796..619d717d97 100644
--- a/server/src/com/vaadin/ui/AbstractField.java
+++ b/server/src/com/vaadin/ui/AbstractField.java
@@ -373,30 +373,6 @@ public abstract class AbstractField<T> extends AbstractComponent implements
/* Property interface implementation */
/**
- * Returns the (field) value converted to a String using toString().
- *
- * @see java.lang.Object#toString()
- * @deprecated As of 7.0, use {@link #getValue()} to get the value of the
- * field, {@link #getConvertedValue()} to get the field value
- * converted to the data model type or
- * {@link #getPropertyDataSource()} .getValue() to get the value
- * of the data source.
- */
- @Deprecated
- @Override
- public String toString() {
- logger.warning("You are using AbstractField.toString() to get the value for a "
- + getClass().getSimpleName()
- + ". This will not be supported starting from Vaadin 7.1 "
- + "(your debugger might call toString() and cause this message to appear).");
- final Object value = getFieldValue();
- if (value == null) {
- return null;
- }
- return value.toString();
- }
-
- /**
* Gets the current value of the field.
*
* <p>
diff --git a/server/src/com/vaadin/ui/Label.java b/server/src/com/vaadin/ui/Label.java
index f49a1403cf..f413ea47f2 100644
--- a/server/src/com/vaadin/ui/Label.java
+++ b/server/src/com/vaadin/ui/Label.java
@@ -203,23 +203,6 @@ public class Label extends AbstractComponent implements Property<String>,
}
/**
- * Returns the value displayed by this label.
- *
- * @see java.lang.Object#toString()
- * @deprecated As of 7.0, use {@link #getValue()} to get the value of the
- * label or {@link #getPropertyDataSource()} .getValue() to get
- * the value of the data source.
- */
- @Deprecated
- @Override
- public String toString() {
- logger.warning("You are using Label.toString() to get the value for a "
- + getClass().getSimpleName()
- + ". This will not be supported starting from Vaadin 7.1 (your debugger might call toString() and cause this message to appear).");
- return getValue();
- }
-
- /**
* Gets the type of the Property.
*
* @see com.vaadin.data.Property#getType()
diff --git a/server/src/com/vaadin/ui/Table.java b/server/src/com/vaadin/ui/Table.java
index a9632da038..641c0ff1f6 100644
--- a/server/src/com/vaadin/ui/Table.java
+++ b/server/src/com/vaadin/ui/Table.java
@@ -1645,6 +1645,9 @@ public class Table extends AbstractSelect implements Action.Container,
if (rows > 0) {
pageBufferFirstIndex = firstIndex;
}
+ if (getPageLength() != 0) {
+ removeUnnecessaryRows();
+ }
setRowCacheInvalidated(true);
markAsDirty();
@@ -1711,6 +1714,47 @@ public class Table extends AbstractSelect implements Action.Container,
}
/**
+ * Removes rows that fall outside the required cache.
+ */
+ private void removeUnnecessaryRows() {
+ int minPageBufferIndex = getMinPageBufferIndex();
+ int maxPageBufferIndex = getMaxPageBufferIndex();
+
+ int maxBufferSize = maxPageBufferIndex - minPageBufferIndex + 1;
+
+ /*
+ * Number of rows that were previously cached. This is not necessarily
+ * the same as pageLength if we do not have enough rows in the
+ * container.
+ */
+ int currentlyCachedRowCount = pageBuffer[CELL_ITEMID].length;
+
+ if (currentlyCachedRowCount <= maxBufferSize) {
+ // removal unnecessary
+ return;
+ }
+
+ /* Figure out which rows to get rid of. */
+ int firstCacheRowToRemoveInPageBuffer = -1;
+ if (minPageBufferIndex > pageBufferFirstIndex) {
+ firstCacheRowToRemoveInPageBuffer = pageBufferFirstIndex;
+ } else if (maxPageBufferIndex < pageBufferFirstIndex
+ + currentlyCachedRowCount) {
+ firstCacheRowToRemoveInPageBuffer = maxPageBufferIndex + 1;
+ }
+
+ if (firstCacheRowToRemoveInPageBuffer - pageBufferFirstIndex < currentlyCachedRowCount) {
+ /*
+ * Unregister all components that fall beyond the cache limits after
+ * inserting the new rows.
+ */
+ unregisterComponentsAndPropertiesInRows(
+ firstCacheRowToRemoveInPageBuffer, currentlyCachedRowCount
+ - firstCacheRowToRemoveInPageBuffer);
+ }
+ }
+
+ /**
* Requests that the Table should be repainted as soon as possible.
*
* Note that a {@code Table} does not necessarily repaint its contents when
@@ -1856,41 +1900,24 @@ public class Table extends AbstractSelect implements Action.Container,
"Insert {0} rows at index {1} to existing page buffer requested",
new Object[] { rows, firstIndex });
- // Page buffer must not become larger than pageLength*cacheRate before
- // or after the current page
- int minPageBufferIndex = getCurrentPageFirstItemIndex()
- - (int) (getPageLength() * getCacheRate());
- if (minPageBufferIndex < 0) {
- minPageBufferIndex = 0;
- }
+ int minPageBufferIndex = getMinPageBufferIndex();
+ int maxPageBufferIndex = getMaxPageBufferIndex();
- int maxPageBufferIndex = getCurrentPageFirstItemIndex()
- + (int) (getPageLength() * (1 + getCacheRate()));
- int maxBufferSize = maxPageBufferIndex - minPageBufferIndex;
+ int maxBufferSize = maxPageBufferIndex - minPageBufferIndex + 1;
if (getPageLength() == 0) {
// If pageLength == 0 then all rows should be rendered
- maxBufferSize = pageBuffer[0].length + rows;
+ maxBufferSize = pageBuffer[CELL_ITEMID].length + rows;
}
/*
* Number of rows that were previously cached. This is not necessarily
- * the same as pageLength if we do not have enough rows in the
- * container.
+ * the same as maxBufferSize.
*/
int currentlyCachedRowCount = pageBuffer[CELL_ITEMID].length;
- /*
- * firstIndexInPageBuffer is the offset in pageBuffer where the new rows
- * will be inserted (firstIndex is the index in the whole table).
- *
- * E.g. scrolled down to row 1000: firstIndex==1010,
- * pageBufferFirstIndex==1000 -> cacheIx==10
- */
- int firstIndexInPageBuffer = firstIndex - pageBufferFirstIndex;
-
/* If rows > size available in page buffer */
- if (firstIndexInPageBuffer + rows > maxBufferSize) {
- rows = maxBufferSize - firstIndexInPageBuffer;
+ if (firstIndex + rows - 1 > maxPageBufferIndex) {
+ rows = maxPageBufferIndex - firstIndex + 1;
}
/*
@@ -1899,38 +1926,59 @@ public class Table extends AbstractSelect implements Action.Container,
* the cache.
*/
- /* All rows until the insertion point remain, always. */
- int firstCacheRowToRemoveInPageBuffer = firstIndexInPageBuffer;
+ /*
+ * if there are rows before the new pageBuffer limits they must be
+ * removed
+ */
+ int lastCacheRowToRemove = minPageBufferIndex - 1;
+ int rowsFromBeginning = lastCacheRowToRemove - pageBufferFirstIndex + 1;
+ if (lastCacheRowToRemove >= pageBufferFirstIndex) {
+ unregisterComponentsAndPropertiesInRows(pageBufferFirstIndex,
+ rowsFromBeginning);
+ } else {
+ rowsFromBeginning = 0;
+ }
/*
+ * the rows that fall outside of the new pageBuffer limits after the new
+ * rows are inserted must also be removed
+ */
+ int firstCacheRowToRemove = firstIndex;
+ /*
* IF there is space remaining in the buffer after the rows have been
* inserted, we can keep more rows.
*/
- int numberOfOldRowsAfterInsertedRows = maxBufferSize
- - firstIndexInPageBuffer - rows;
+ int numberOfOldRowsAfterInsertedRows = Math.min(pageBufferFirstIndex
+ + currentlyCachedRowCount + rows, maxPageBufferIndex + 1)
+ - (firstIndex + rows - 1);
if (numberOfOldRowsAfterInsertedRows > 0) {
- firstCacheRowToRemoveInPageBuffer += numberOfOldRowsAfterInsertedRows;
+ firstCacheRowToRemove += numberOfOldRowsAfterInsertedRows;
}
+ int rowsFromAfter = currentlyCachedRowCount
+ - (firstCacheRowToRemove - pageBufferFirstIndex);
- if (firstCacheRowToRemoveInPageBuffer <= currentlyCachedRowCount) {
+ if (rowsFromAfter > 0) {
/*
* Unregister all components that fall beyond the cache limits after
* inserting the new rows.
*/
- unregisterComponentsAndPropertiesInRows(
- firstCacheRowToRemoveInPageBuffer + pageBufferFirstIndex,
- currentlyCachedRowCount - firstCacheRowToRemoveInPageBuffer
- + pageBufferFirstIndex);
+ unregisterComponentsAndPropertiesInRows(firstCacheRowToRemove,
+ rowsFromAfter);
}
// Calculate the new cache size
- int newCachedRowCount = currentlyCachedRowCount;
- if (maxBufferSize == 0 || currentlyCachedRowCount < maxBufferSize) {
- newCachedRowCount = currentlyCachedRowCount + rows;
- if (maxBufferSize > 0 && newCachedRowCount > maxBufferSize) {
- newCachedRowCount = maxBufferSize;
- }
- }
+ int newCachedRowCount = maxBufferSize;
+ if (pageBufferFirstIndex + currentlyCachedRowCount + rows - 1 < maxPageBufferIndex) {
+ // there aren't enough rows to fill the whole potential -> use what
+ // there is
+ newCachedRowCount -= maxPageBufferIndex
+ - (pageBufferFirstIndex + currentlyCachedRowCount + rows - 1);
+ } else if (minPageBufferIndex < pageBufferFirstIndex) {
+ newCachedRowCount -= pageBufferFirstIndex - minPageBufferIndex;
+ }
+ /* calculate the internal location of the new rows within the new cache */
+ int firstIndexInNewPageBuffer = firstIndex - pageBufferFirstIndex
+ - rowsFromBeginning;
/* Paint the new rows into a separate buffer */
Object[][] cells = getVisibleCellsNoCache(firstIndex, rows, false);
@@ -1942,21 +1990,25 @@ public class Table extends AbstractSelect implements Action.Container,
Object[][] newPageBuffer = new Object[pageBuffer.length][newCachedRowCount];
for (int i = 0; i < pageBuffer.length; i++) {
- for (int row = 0; row < firstIndexInPageBuffer; row++) {
+ for (int row = 0; row < firstIndexInNewPageBuffer; row++) {
// Copy the first rows
- newPageBuffer[i][row] = pageBuffer[i][row];
+ newPageBuffer[i][row] = pageBuffer[i][rowsFromBeginning + row];
}
- for (int row = firstIndexInPageBuffer; row < firstIndexInPageBuffer
+ for (int row = firstIndexInNewPageBuffer; row < firstIndexInNewPageBuffer
+ rows; row++) {
// Copy the newly created rows
- newPageBuffer[i][row] = cells[i][row - firstIndexInPageBuffer];
+ newPageBuffer[i][row] = cells[i][row
+ - firstIndexInNewPageBuffer];
}
- for (int row = firstIndexInPageBuffer + rows; row < newCachedRowCount; row++) {
+ for (int row = firstIndexInNewPageBuffer + rows; row < newCachedRowCount; row++) {
// Move the old rows down below the newly inserted rows
- newPageBuffer[i][row] = pageBuffer[i][row - rows];
+ newPageBuffer[i][row] = pageBuffer[i][rowsFromBeginning + row
+ - rows];
}
}
pageBuffer = newPageBuffer;
+ pageBufferFirstIndex = Math.max(pageBufferFirstIndex
+ + rowsFromBeginning, minPageBufferIndex);
if (getLogger().isLoggable(Level.FINEST)) {
getLogger().log(
Level.FINEST,
@@ -1970,6 +2022,40 @@ public class Table extends AbstractSelect implements Action.Container,
return cells;
}
+ private int getMaxPageBufferIndex() {
+ int total = size();
+ if (getPageLength() == 0) {
+ // everything is shown at once, no caching
+ return total - 1;
+ }
+ // Page buffer must not become larger than pageLength*cacheRate after
+ // the current page
+ int maxPageBufferIndex = getCurrentPageFirstItemIndex()
+ + (int) (getPageLength() * (1 + getCacheRate()));
+ if (shouldHideNullSelectionItem()) {
+ --total;
+ }
+ if (maxPageBufferIndex >= total) {
+ maxPageBufferIndex = total - 1;
+ }
+ return maxPageBufferIndex;
+ }
+
+ private int getMinPageBufferIndex() {
+ if (getPageLength() == 0) {
+ // everything is shown at once, no caching
+ return 0;
+ }
+ // Page buffer must not become larger than pageLength*cacheRate before
+ // the current page
+ int minPageBufferIndex = getCurrentPageFirstItemIndex()
+ - (int) (getPageLength() * getCacheRate());
+ if (minPageBufferIndex < 0) {
+ minPageBufferIndex = 0;
+ }
+ return minPageBufferIndex;
+ }
+
/**
* Render rows with index "firstIndex" to "firstIndex+rows-1" to a new
* buffer.
@@ -3076,26 +3162,23 @@ public class Table extends AbstractSelect implements Action.Container,
// Rows
if (isPartialRowUpdate() && painted && !target.isFullRepaint()) {
paintPartialRowUpdate(target, actionSet);
- /*
- * Send the page buffer indexes to ensure that the client side stays
- * in sync. Otherwise we _might_ have the situation where the client
- * side discards too few or too many rows, causing out of sync
- * issues.
- *
- * This could probably be done for full repaints also to simplify
- * the client side.
- */
- int pageBufferLastIndex = pageBufferFirstIndex
- + pageBuffer[CELL_ITEMID].length - 1;
- target.addAttribute(TableConstants.ATTRIBUTE_PAGEBUFFER_FIRST,
- pageBufferFirstIndex);
- target.addAttribute(TableConstants.ATTRIBUTE_PAGEBUFFER_LAST,
- pageBufferLastIndex);
} else if (target.isFullRepaint() || isRowCacheInvalidated()) {
paintRows(target, cells, actionSet);
setRowCacheInvalidated(false);
}
+ /*
+ * Send the page buffer indexes to ensure that the client side stays in
+ * sync. Otherwise we _might_ have the situation where the client side
+ * discards too few or too many rows, causing out of sync issues.
+ */
+ int pageBufferLastIndex = pageBufferFirstIndex
+ + pageBuffer[CELL_ITEMID].length - 1;
+ target.addAttribute(TableConstants.ATTRIBUTE_PAGEBUFFER_FIRST,
+ pageBufferFirstIndex);
+ target.addAttribute(TableConstants.ATTRIBUTE_PAGEBUFFER_LAST,
+ pageBufferLastIndex);
+
paintSorting(target);
resetVariablesAndPageBuffer(target);