aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/main/java/com/vaadin/ui/components
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>2016-12-15 13:58:55 +0200
committerGitHub <noreply@github.com>2016-12-15 13:58:55 +0200
commit9d35813566e8f64b8ef80ad3ad764ed1eae807c4 (patch)
tree08ced01b1533e352890606cc68f230696f5fe5a3 /server/src/main/java/com/vaadin/ui/components
parent04f30c6892c8ddf8794ed8561fa6f00beefeec28 (diff)
downloadvaadin-framework-9d35813566e8f64b8ef80ad3ad764ed1eae807c4.tar.gz
vaadin-framework-9d35813566e8f64b8ef80ad3ad764ed1eae807c4.zip
Redesign user-defined column identifiers for Grid (#7983)
Closes vaadin/framework8-issues#494
Diffstat (limited to 'server/src/main/java/com/vaadin/ui/components')
-rw-r--r--server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java5
-rw-r--r--server/src/main/java/com/vaadin/ui/components/grid/Header.java6
-rw-r--r--server/src/main/java/com/vaadin/ui/components/grid/StaticSection.java92
3 files changed, 85 insertions, 18 deletions
diff --git a/server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java b/server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java
index 44471d2806..7aa3920c3c 100644
--- a/server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java
+++ b/server/src/main/java/com/vaadin/ui/components/grid/EditorImpl.java
@@ -78,7 +78,8 @@ public class EditorImpl<T> extends AbstractGridExtension<T>
String message = errorGenerator.apply(fieldToColumn, status);
List<String> columnIds = fieldToColumn.values().stream()
- .map(Column::getId).collect(Collectors.toList());
+ .map(column -> getInternalIdForColumn(column))
+ .collect(Collectors.toList());
rpc.setErrorMessage(message, columnIds);
}
@@ -221,7 +222,7 @@ public class EditorImpl<T> extends AbstractGridExtension<T>
.apply(edited);
addComponentToGrid(component);
columnFields.put(c, component);
- getState().columnFields.put(c.getId(),
+ getState().columnFields.put(getInternalIdForColumn(c),
component.getConnectorId());
});
}
diff --git a/server/src/main/java/com/vaadin/ui/components/grid/Header.java b/server/src/main/java/com/vaadin/ui/components/grid/Header.java
index d1d369a9c8..0991069487 100644
--- a/server/src/main/java/com/vaadin/ui/components/grid/Header.java
+++ b/server/src/main/java/com/vaadin/ui/components/grid/Header.java
@@ -1,12 +1,12 @@
/*
* Copyright 2000-2016 Vaadin Ltd.
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
diff --git a/server/src/main/java/com/vaadin/ui/components/grid/StaticSection.java b/server/src/main/java/com/vaadin/ui/components/grid/StaticSection.java
index 3edb4fecc9..a28b971d7a 100644
--- a/server/src/main/java/com/vaadin/ui/components/grid/StaticSection.java
+++ b/server/src/main/java/com/vaadin/ui/components/grid/StaticSection.java
@@ -17,7 +17,6 @@ package com.vaadin.ui.components.grid;
import java.io.Serializable;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
@@ -98,16 +97,45 @@ public abstract class StaticSection<ROW extends StaticSection.StaticRow<?>>
protected abstract String getCellTagName();
/**
- * Adds a cell to this section, corresponding to the given column id.
+ * Adds a cell to this section, corresponding to the given user-defined
+ * column id.
*
* @param columnId
* the id of the column for which to add a cell
*/
protected void addCell(String columnId) {
+ Column<?, ?> column = section.getGrid().getColumn(columnId);
+ Objects.requireNonNull(column,
+ "No column matching given identifier");
+ addCell(column);
+ }
+
+ /**
+ * Adds a cell to this section for given column.
+ *
+ * @param column
+ * the column for which to add a cell
+ */
+ protected void addCell(Column<?, ?> column) {
+ if (!section.getGrid().getColumns().contains(column)) {
+ throw new IllegalArgumentException(
+ "Given column does not exist in this Grid");
+ }
+ internalAddCell(section.getInternalIdForColumn(column));
+ }
+
+ /**
+ * Adds a cell to this section, corresponding to the given internal
+ * column id.
+ *
+ * @param internalId
+ * the internal id of the column for which to add a cell
+ */
+ protected void internalAddCell(String internalId) {
CELL cell = createCell();
- cell.setColumnId(columnId);
- cells.put(columnId, cell);
- rowState.cells.put(columnId, cell.getCellState());
+ cell.setColumnId(internalId);
+ cells.put(internalId, cell);
+ rowState.cells.put(internalId, cell.getCellState());
}
/**
@@ -153,10 +181,43 @@ public abstract class StaticSection<ROW extends StaticSection.StaticRow<?>>
* if no cell was found for the column id
*/
public CELL getCell(String columnId) {
- CELL cell = cells.get(columnId);
+ Column<?, ?> column = section.getGrid().getColumn(columnId);
+ Objects.requireNonNull(column,
+ "No column matching given identifier");
+ return getCell(column);
+ }
+
+ /**
+ * Returns the cell in this section that corresponds to the given
+ * column.
+ *
+ * @param column
+ * the column
+ * @return the cell for the given column
+ *
+ * @throws IllegalArgumentException
+ * if no cell was found for the column
+ */
+ public CELL getCell(Column<?, ?> column) {
+ return internalGetCell(section.getInternalIdForColumn(column));
+ }
+
+ /**
+ * Returns the cell in this section that corresponds to the given
+ * internal column id.
+ *
+ * @param internalId
+ * the internal id of the column
+ * @return the cell for the given column
+ *
+ * @throws IllegalArgumentException
+ * if no cell was found for the column id
+ */
+ protected CELL internalGetCell(String internalId) {
+ CELL cell = cells.get(internalId);
if (cell == null) {
throw new IllegalArgumentException(
- "No cell found for column id " + columnId);
+ "No cell found for column id " + internalId);
}
return cell;
}
@@ -245,6 +306,7 @@ public abstract class StaticSection<ROW extends StaticSection.StaticRow<?>>
.getValue().contains(entry.getKey()))
.findFirst();
Stream<String> columnIds = Stream.of(entry.getKey());
+
if (groupCell.isPresent()) {
Set<String> orderedSet = new LinkedHashSet<>(
cells.keySet());
@@ -259,12 +321,14 @@ public abstract class StaticSection<ROW extends StaticSection.StaticRow<?>>
entry.getValue().getCellState());
}
cellElement.attr("column-ids",
- columnIds.collect(Collectors.joining(",")));
+ columnIds.map(section::getColumnByInternalId)
+ .map(Column::getId)
+ .collect(Collectors.joining(",")));
}
}
/**
- *
+ *
* Writes declarative design for the cell using its {@code state} to the
* given table cell element.
* <p>
@@ -272,7 +336,7 @@ public abstract class StaticSection<ROW extends StaticSection.StaticRow<?>>
* sometimes there is no a reference to the cell which should be written
* (merged cell) but only its state is available (the cell is virtual
* and is not stored).
- *
+ *
* @param cellElement
* Element to write design to
* @param context
@@ -509,7 +573,9 @@ public abstract class StaticSection<ROW extends StaticSection.StaticRow<?>>
protected abstract Grid<?> getGrid();
- protected abstract Collection<? extends Column<?, ?>> getColumns();
+ protected abstract Column<?, ?> getColumnByInternalId(String internalId);
+
+ protected abstract String getInternalIdForColumn(Column<?, ?> column);
/**
* Marks the state of this section as modified.
@@ -532,7 +598,7 @@ public abstract class StaticSection<ROW extends StaticSection.StaticRow<?>>
rows.add(index, row);
getState(true).rows.add(index, row.getRowState());
- getColumns().stream().forEach(column -> row.addCell(column.getId()));
+ getGrid().getColumns().stream().forEach(row::addCell);
return row;
}
@@ -599,7 +665,7 @@ public abstract class StaticSection<ROW extends StaticSection.StaticRow<?>>
*/
public void addColumn(String columnId) {
for (ROW row : rows) {
- row.addCell(columnId);
+ row.internalAddCell(columnId);
}
}