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.ValueChangeEvent;
import org.adempiere.webui.event.ValueChangeListener; import org.adempiere.webui.event.ValueChangeListener;
import org.adempiere.webui.info.InfoWindow; import org.adempiere.webui.info.InfoWindow;
import org.compiere.minigrid.ColumnInfo;
import org.compiere.minigrid.IDColumn; import org.compiere.minigrid.IDColumn;
import org.compiere.model.GridField; import org.compiere.model.GridField;
import org.compiere.model.MInfoColumn; import org.compiere.model.MInfoColumn;
@ -36,58 +37,50 @@ import org.zkoss.zul.Listcell;
public class WInfoWindowListItemRenderer extends WListItemRenderer public class WInfoWindowListItemRenderer extends WListItemRenderer
{ {
private MInfoColumn[] infoColumns; private MInfoColumn[] gridDisplayedInfoColumns = null;
private GridField[] gridFields; private ColumnInfo[] gridDisplayedColumnInfos = null;
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 = null;
private InfoWindow infoWindow;
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; 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); super(columnNames);
this.infoColumns = infoColumns;
this.gridFields = gridFields.toArray(new GridField[infoColumns.length]);
this.infoWindow = infoWindow; 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 @Override
protected Listcell getCellComponent(WListbox table, Object field, protected Listcell getCellComponent(WListbox table, Object field,
final int rowIndex, final int columnIndex) final int rowIndex, final int columnIndex)
{ {
if(gridFieldsOffset < 0) // Just do it once, this assumes this rendered is not shared between grids if(gridDisplayedInfoColumns == null || gridDisplayedColumnInfos == null)
calculateFieldOffest(); {
return super.getCellComponent(table, field, rowIndex, columnIndex);
}
Listcell listcell = null; Listcell listcell = null;
ListModelTable model = table.getModel(); ListModelTable model = table.getModel();
Object obj = model.get(rowIndex); Object obj = model.get(rowIndex);
int effectiveFieldIndex = columnIndex - gridFieldsOffset; MInfoColumn infoColumn = gridDisplayedInfoColumns[columnIndex];
if(effectiveFieldIndex >= 0 if(model.isSelected(obj) && infoColumn != null) // First index may be null
&& model.isSelected(obj) )
{ {
MInfoColumn infoColumn = infoColumns[effectiveFieldIndex];
if(infoColumn.isReadOnly() == false if(infoColumn.isReadOnly() == false
&& columnIndex > 0) && columnIndex > 0)
{ {
ListCell listCell = new ListCell(); ListCell listCell = new ListCell();
final GridField gridField = gridFields[effectiveFieldIndex]; final GridField gridField = gridDisplayedColumnInfos[columnIndex].getGridField();
final WEditor editor = WebEditorFactory.getEditor(gridField, false); final WEditor editor = WebEditorFactory.getEditor(gridField, false);
// Set editor value // Set editor value

View File

@ -158,6 +158,7 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
private boolean hasEditable = false; private boolean hasEditable = false;
private Map<Integer, List<Object>> cacheOriginalValues = new HashMap<>(); 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 // F3P: export
@ -630,10 +631,10 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
if(hasEditable) if(hasEditable)
{ {
WInfoWindowListItemRenderer renderer = new WInfoWindowListItemRenderer(this, infoColumns, gridFields); infoWindowListItemRenderer = new WInfoWindowListItemRenderer(this);
contentPanel.setItemRenderer(renderer); contentPanel.setItemRenderer(infoWindowListItemRenderer);
contentPanel.setAllowIDColumnForReadWrite(true); 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; String keySelectClause = keyTableAlias+"."+p_keyColumn;
list.add(new ColumnInfo(" ", keySelectClause, IDColumn.class, true, false, null, 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 boolean haveNotProcess = !haveProcess; // A field is editabile only if is not readonly and theres a process
int i = 0; int i = 0;
@ -809,6 +813,7 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
columnInfo.setGridField(gridFields.get(i)); columnInfo.setGridField(gridFields.get(i));
columnInfo.setColumnName(infoColumn.getColumnName()); columnInfo.setColumnName(infoColumn.getColumnName());
list.add(columnInfo); list.add(columnInfo);
gridDisplayedIC.add(infoColumn);
if (keyColumnOfView == infoColumn){ if (keyColumnOfView == infoColumn){
if (columnInfo.getColClass().equals(IDColumn.class)) if (columnInfo.getColClass().equals(IDColumn.class))
@ -824,6 +829,10 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL
} }
columnInfos = list.toArray(new ColumnInfo[0]); 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()); prepareTable(columnInfos, infoWindow.getFromClause(), p_whereClause, infoWindow.getOrderByClause());
} }