aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorHenri Sara <hesara@vaadin.com>2012-12-17 10:26:50 +0000
committerVaadin Code Review <review@vaadin.com>2012-12-17 10:26:50 +0000
commitc7070fc5754213b5d55c3db2d0fa52917f3bb544 (patch)
treeea267dff483cce4436925d2bbe509ce813452ab3 /server
parent8b7491d05c037205e31f182acf671f1ddd1ad380 (diff)
parent53c2e014976d8b45b4633e6d3f1d54a2147048a2 (diff)
downloadvaadin-framework-c7070fc5754213b5d55c3db2d0fa52917f3bb544.tar.gz
vaadin-framework-c7070fc5754213b5d55c3db2d0fa52917f3bb544.zip
Merge "Added method setContainerDataSource(Container newDataSource, Collection<?> visibleIds) to Table. (#10419)"
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/ui/Table.java68
1 files changed, 59 insertions, 9 deletions
diff --git a/server/src/com/vaadin/ui/Table.java b/server/src/com/vaadin/ui/Table.java
index c0814b8481..65dea7594b 100644
--- a/server/src/com/vaadin/ui/Table.java
+++ b/server/src/com/vaadin/ui/Table.java
@@ -2070,7 +2070,7 @@ public class Table extends AbstractSelect implements Action.Container,
value = generatedRow.getText()[j];
}
} else {
- // check in current pageBuffer already has row
+ // check if current pageBuffer already has row
int index = firstIndex + i;
if (p != null || isGenerated) {
int indexInOldBuffer = index - pageBufferFirstIndex;
@@ -2395,14 +2395,69 @@ public class Table extends AbstractSelect implements Action.Container,
refreshRenderedCells();
}
+ /**
+ * Sets the Container that serves as the data source of the viewer. As a
+ * side-effect the table's selection value is set to null as the old
+ * selection might not exist in new Container.<br>
+ * <br>
+ * All rows and columns are generated as visible using this method. If the
+ * new container contains properties that are not meant to be shown you
+ * should use {@link Table#setContainerDataSource(Container, Collection)}
+ * instead, especially if the table is editable.
+ *
+ * @param newDataSource
+ * the new data source.
+ */
@Override
public void setContainerDataSource(Container newDataSource) {
+ if (newDataSource == null) {
+ newDataSource = new IndexedContainer();
+ }
+ Collection<Object> generated;
+ if (columnGenerators != null) {
+ generated = columnGenerators.keySet();
+ } else {
+ generated = Collections.emptyList();
+ }
+ List<Object> visibleIds = new ArrayList<Object>();
+ if (generated.isEmpty()) {
+ visibleIds.addAll(newDataSource.getContainerPropertyIds());
+ } else {
+ for (Object id : newDataSource.getContainerPropertyIds()) {
+ // don't add duplicates
+ if (!generated.contains(id)) {
+ visibleIds.add(id);
+ }
+ }
+ // generated columns to the end
+ visibleIds.addAll(generated);
+ }
+ setContainerDataSource(newDataSource, visibleIds);
+ }
+
+ /**
+ * Sets the container data source and the columns that will be visible.
+ * Columns are shown in the collection's iteration order.
+ *
+ * @see Table#setContainerDataSource(Container)
+ * @see Table#setVisibleColumns(Object[])
+ *
+ * @param newDataSource
+ * the new data source.
+ * @param visibleIds
+ * IDs of the visible columns
+ */
+ public void setContainerDataSource(Container newDataSource,
+ Collection<?> visibleIds) {
disableContentRefreshing();
if (newDataSource == null) {
newDataSource = new IndexedContainer();
}
+ if (visibleIds == null) {
+ visibleIds = new ArrayList<Object>();
+ }
// Assures that the data source is ordered by making unordered
// containers ordered by wrapping them
@@ -2422,19 +2477,14 @@ public class Table extends AbstractSelect implements Action.Container,
collapsedColumns.clear();
}
- // columnGenerators 'override' properties, don't add the same id twice
+ // don't add the same id twice
Collection<Object> col = new LinkedList<Object>();
- for (Iterator<?> it = getContainerPropertyIds().iterator(); it
- .hasNext();) {
+ for (Iterator<?> it = visibleIds.iterator(); it.hasNext();) {
Object id = it.next();
- if (columnGenerators == null || !columnGenerators.containsKey(id)) {
+ if (!col.contains(id)) {
col.add(id);
}
}
- // generators added last
- if (columnGenerators != null && columnGenerators.size() > 0) {
- col.addAll(columnGenerators.keySet());
- }
setVisibleColumns(col.toArray());