Fix display errors with non-displayed columns

This commit is contained in:
Silvano Trinchero 2018-09-25 12:23:19 +02:00
parent f3403b3130
commit 4bad2e4a77
2 changed files with 32 additions and 30 deletions

View File

@ -28,6 +28,7 @@ import org.adempiere.webui.editor.WebEditorFactory;
import org.adempiere.webui.event.ValueChangeEvent;
import org.adempiere.webui.event.ValueChangeListener;
import org.adempiere.webui.info.InfoWindow;
import org.compiere.minigrid.ColumnInfo;
import org.compiere.minigrid.IDColumn;
import org.compiere.model.GridField;
import org.compiere.model.MInfoColumn;
@ -36,58 +37,50 @@ import org.zkoss.zul.Listcell;
public class WInfoWindowListItemRenderer extends WListItemRenderer
{
private MInfoColumn[] infoColumns;
private GridField[] gridFields;
private int gridFieldsOffset = -1; // There are added columns in front of the first real gridField, instead of a fixed +1 we use an offset
private InfoWindow infoWindow;
private MInfoColumn[] gridDisplayedInfoColumns = null;
private ColumnInfo[] gridDisplayedColumnInfos = null;
private InfoWindow infoWindow = null;
public WInfoWindowListItemRenderer(InfoWindow infoWindow, MInfoColumn[] infoColumns, List<GridField> gridFields)
public WInfoWindowListItemRenderer(InfoWindow infoWindow)
{
this.infoColumns = infoColumns;
this.gridFields = gridFields.toArray(new GridField[infoColumns.length]);
this.infoWindow = infoWindow;
}
public WInfoWindowListItemRenderer(InfoWindow infoWindow, MInfoColumn[] infoColumns, List<GridField> gridFields, List<? extends String> columnNames)
public WInfoWindowListItemRenderer(InfoWindow infoWindow, List<? extends String> columnNames)
{
super(columnNames);
this.infoColumns = infoColumns;
this.gridFields = gridFields.toArray(new GridField[infoColumns.length]);
this.infoWindow = infoWindow;
}
private void calculateFieldOffest()
public void setGridDisplaydInfoColumns(MInfoColumn[] infoColumns, ColumnInfo[] columnInfos)
{
int colCount = getTableColumns().size();
this.gridDisplayedInfoColumns = infoColumns;
this.gridDisplayedColumnInfos = columnInfos;
}
if(colCount > infoColumns.length) // Added columns: selecetion
gridFieldsOffset = colCount - infoColumns.length;
}
@Override
protected Listcell getCellComponent(WListbox table, Object field,
final int rowIndex, final int columnIndex)
{
if(gridFieldsOffset < 0) // Just do it once, this assumes this rendered is not shared between grids
calculateFieldOffest();
if(gridDisplayedInfoColumns == null || gridDisplayedColumnInfos == null)
{
return super.getCellComponent(table, field, rowIndex, columnIndex);
}
Listcell listcell = null;
ListModelTable model = table.getModel();
Object obj = model.get(rowIndex);
int effectiveFieldIndex = columnIndex - gridFieldsOffset;
if(effectiveFieldIndex >= 0
&& model.isSelected(obj) )
MInfoColumn infoColumn = gridDisplayedInfoColumns[columnIndex];
if(model.isSelected(obj) && infoColumn != null) // First index may be null
{
MInfoColumn infoColumn = infoColumns[effectiveFieldIndex];
if(infoColumn.isReadOnly() == false
&& columnIndex > 0)
{
ListCell listCell = new ListCell();
final GridField gridField = gridFields[effectiveFieldIndex];
final GridField gridField = gridDisplayedColumnInfos[columnIndex].getGridField();
final WEditor editor = WebEditorFactory.getEditor(gridField, false);
// Set editor value

View File

@ -157,7 +157,8 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
private boolean hasEditable = false;
private Map<Integer, List<Object>> cacheOriginalValues = new HashMap<>();
private Map<Integer, List<Object>> temporarySelectedData = new HashMap<>();
private Map<Integer, List<Object>> temporarySelectedData = new HashMap<>();
private WInfoWindowListItemRenderer infoWindowListItemRenderer = null;
// F3P: export
@ -630,10 +631,10 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
if(hasEditable)
{
WInfoWindowListItemRenderer renderer = new WInfoWindowListItemRenderer(this, infoColumns, gridFields);
contentPanel.setItemRenderer(renderer);
infoWindowListItemRenderer = new WInfoWindowListItemRenderer(this);
contentPanel.setItemRenderer(infoWindowListItemRenderer);
contentPanel.setAllowIDColumnForReadWrite(true);
renderer.addTableValueChangeListener(contentPanel); // Replicated from WListbox constructor
infoWindowListItemRenderer.addTableValueChangeListener(contentPanel); // Replicated from WListbox constructor
}
}
@ -766,6 +767,9 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
String keySelectClause = keyTableAlias+"."+p_keyColumn;
list.add(new ColumnInfo(" ", keySelectClause, IDColumn.class, true, false, null, p_keyColumn));
List<MInfoColumn> gridDisplayedIC = new ArrayList<>();
gridDisplayedIC.add(null); // First column does not have any matching info column
boolean haveNotProcess = !haveProcess; // A field is editabile only if is not readonly and theres a process
int i = 0;
@ -809,6 +813,7 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
columnInfo.setGridField(gridFields.get(i));
columnInfo.setColumnName(infoColumn.getColumnName());
list.add(columnInfo);
gridDisplayedIC.add(infoColumn);
if (keyColumnOfView == infoColumn){
if (columnInfo.getColClass().equals(IDColumn.class))
@ -824,6 +829,10 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
}
columnInfos = list.toArray(new ColumnInfo[0]);
MInfoColumn gridDisplayedInfoColumns[] = gridDisplayedIC.toArray(new MInfoColumn[gridDisplayedIC.size()]);
if(infoWindowListItemRenderer != null)
infoWindowListItemRenderer.setGridDisplaydInfoColumns(gridDisplayedInfoColumns,columnInfos);
prepareTable(columnInfos, infoWindow.getFromClause(), p_whereClause, infoWindow.getOrderByClause());
}