protected void populateItem(Item item) {
if(item.getIndex() % 2 == 1) {
item.add(CLASS_ALT);
}
item.add(new Label("index", item.getIndex() + 1 + ""));
Cell cell = (Cell) item.getModelObject();
Label label = new Label("cell", new PropertyModel(cell, "valueAsString"));
label.setEscapeModelStrings(false);
if(!cell.isValid(column.getColumnHeading())) {
label.add(CLASS_ERROR_BACK);
}
item.add(label);
if(mappedDisplayValues != null && distinctCellsContainer.isVisible() && cell.getKey() != null) {
String mapped = mappedDisplayValues.get(cell.getKey());
item.add(new Label("mapped", mapped));
} else {
item.add(new WebMarkupContainer("mapped"));
}
}
});
form.add(distinctCellsContainer);
distinctCellsContainer.add(new DistinctCellsView("rows"));
Button updateButton = new Button("update") {
@Override
public void onSubmit() {
if(distinctCellsContainer.isVisible()) {
ColumnHeading ch = column.getColumnHeading();
for(Cell cell : columnCells) {
IModel model = mappedKeys.get(cell.getValueAsString());
Object o = model.getObject();
cell.setKey(o);
}
}
}
@Override
public boolean isVisible() {
return distinctCellsContainer.isVisible();
}
};
form.add(updateButton);
Button submitButton = new Button("submit") {
@Override
public void onSubmit() {
ColumnHeading ch = column.getColumnHeading();
for(Cell cell : columnCells) {
if(!cell.isValid(ch)) {
error(localize("excel_view.error.invalidValue"));
return;
}
}
if(ch.isField()) {
column.setLabel(ch.getLabel());
} else {
column.setLabel(labelsMap.get(column.getColumnHeading().getName()));
}
excelFile.getColumns().set(index, column);
if(distinctCellsContainer.isVisible()) {
for(Cell cell : columnCells) {
cell.setValue(mappedDisplayValues.get(cell.getKey()));
}
excelFile.setColumnCells(index, columnCells);
}
setResponsePage(previous);
}