Skip to content

Commit

Permalink
picking prototype; ViewColumn functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Jun 23, 2017
1 parent fc5edb3 commit 68b6383
Show file tree
Hide file tree
Showing 17 changed files with 268 additions and 336 deletions.
98 changes: 60 additions & 38 deletions src/main/java/de/metas/ui/web/handlingunits/HUEditorRow.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

import de.metas.adempiere.model.I_M_Product;
import de.metas.handlingunits.model.I_M_HU;
Expand All @@ -28,13 +27,18 @@
import de.metas.handlingunits.storage.IHUProductStorage;
import de.metas.ui.web.exceptions.EntityNotFoundException;
import de.metas.ui.web.view.IViewRow;
import de.metas.ui.web.view.descriptor.annotation.ViewColumn;
import de.metas.ui.web.view.descriptor.annotation.ViewColumn.ViewColumnLayout;
import de.metas.ui.web.view.descriptor.annotation.ViewColumnHelper;
import de.metas.ui.web.view.json.JSONViewDataType;
import de.metas.ui.web.window.datatypes.DocumentId;
import de.metas.ui.web.window.datatypes.DocumentIdsSelection;
import de.metas.ui.web.window.datatypes.DocumentPath;
import de.metas.ui.web.window.datatypes.LookupValue;
import de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue;
import de.metas.ui.web.window.datatypes.WindowId;
import de.metas.ui.web.window.datatypes.json.JSONLookupValue;
import de.metas.ui.web.window.descriptor.DocumentFieldWidgetType;
import lombok.NonNull;

/*
Expand Down Expand Up @@ -65,7 +69,7 @@
* @author metas-dev <dev@metasfresh.com>
*
*/
public final class HUEditorRow implements IViewRow, IHUEditorRow
public final class HUEditorRow implements IViewRow
{
public static final Builder builder(final WindowId windowId)
{
Expand Down Expand Up @@ -97,27 +101,66 @@ public static Set<Integer> rowIdsToM_HU_IDs(final Collection<DocumentId> rowIds)
return DocumentIdsSelection.of(rowIds).toIntSet();
}

static final int HUSTATUS_AD_Reference_ID = X_M_HU.HUSTATUS_AD_Reference_ID;

private final DocumentPath documentPath;
private final DocumentId rowId;
private final HUEditorRowType type;
private final boolean topLevel;
private final boolean processed;

private final Map<String, Object> values;
static final String COLUMNNAME_M_HU_ID = I_M_HU.COLUMNNAME_M_HU_ID;
@ViewColumn(fieldName = COLUMNNAME_M_HU_ID, widgetType = DocumentFieldWidgetType.Integer)
private final int huId;

@ViewColumn(captionKey = "HUCode", widgetType = DocumentFieldWidgetType.Text, layouts = {
@ViewColumnLayout(when = JSONViewDataType.grid, seqNo = 10),
@ViewColumnLayout(when = JSONViewDataType.includedView, seqNo = 10)
})
private final String code;
// private final JSONLookupValue huUnitType;
private final JSONLookupValue huStatus;
private final String packingInfo;

@ViewColumn(captionKey = "M_Product_ID", widgetType = DocumentFieldWidgetType.Lookup, layouts = {
@ViewColumnLayout(when = JSONViewDataType.grid, seqNo = 20),
@ViewColumnLayout(when = JSONViewDataType.includedView, seqNo = 20)
})
private final JSONLookupValue product;
private final JSONLookupValue uom;

@ViewColumn(captionKey = "HU_UnitType", widgetType = DocumentFieldWidgetType.Text, layouts = {
@ViewColumnLayout(when = JSONViewDataType.grid, seqNo = 30)
// @ViewColumnLayout(when = JSONViewDataType.includedView, seqNo = 30)
})
private final JSONLookupValue huUnitType;

@ViewColumn(captionKey = "M_HU_PI_Item_Product_ID", widgetType = DocumentFieldWidgetType.Text, layouts = {
@ViewColumnLayout(when = JSONViewDataType.grid, seqNo = 40),
@ViewColumnLayout(when = JSONViewDataType.includedView, seqNo = 40)
})
private final String packingInfo;

@ViewColumn(captionKey = "QtyCU", widgetType = DocumentFieldWidgetType.Quantity, layouts = {
@ViewColumnLayout(when = JSONViewDataType.grid, seqNo = 50),
@ViewColumnLayout(when = JSONViewDataType.includedView, seqNo = 50)
})
private final BigDecimal qtyCU;

@ViewColumn(captionKey = "C_UOM_ID", widgetType = DocumentFieldWidgetType.Lookup, layouts = {
@ViewColumnLayout(when = JSONViewDataType.grid, seqNo = 60),
// @ViewColumnLayout(when = JSONViewDataType.includedView, seqNo = 60)
})
private final JSONLookupValue uom;

@ViewColumn(captionKey = "HUStatus", widgetType = DocumentFieldWidgetType.Lookup, layouts = {
@ViewColumnLayout(when = JSONViewDataType.grid, seqNo = 70),
// @ViewColumnLayout(when = JSONViewDataType.includedView, seqNo = 70)
})
private final JSONLookupValue huStatus;

private final Supplier<HUEditorRowAttributes> attributesSupplier;

private final List<HUEditorRow> includedRows;

private transient String _summary; // lazy
private transient Map<String, Object> _values; // lazy

private HUEditorRow(final Builder builder)
{
Expand All @@ -128,10 +171,9 @@ private HUEditorRow(final Builder builder)
topLevel = builder.isTopLevel();
processed = builder.isProcessed();

values = builder.buildValuesMap();
huId = builder.huId;
code = builder.code;
// huUnitType = builder.huUnitType;
huUnitType = builder.huUnitType;
huStatus = builder.huStatus;
packingInfo = builder.packingInfo;
product = builder.product;
Expand Down Expand Up @@ -190,12 +232,17 @@ public boolean isProcessed()

Object getFieldValueAsJson(final String fieldName)
{
return values.get(fieldName);
return getFieldNameAndJsonValues().get(fieldName);
}

@Override
public Map<String, Object> getFieldNameAndJsonValues()
{
Map<String, Object> values = _values;
if (values == null)
{
values = _values = ViewColumnHelper.extractJsonMap(this);
}
return values;
}

Expand Down Expand Up @@ -326,7 +373,7 @@ public boolean isLU()
{
return getType() == HUEditorRowType.LU;
}

public boolean isTopLevel()
{
return topLevel;
Expand Down Expand Up @@ -473,31 +520,6 @@ public HUEditorRow build()
return new HUEditorRow(this);
}

private ImmutableMap<String, Object> buildValuesMap()
{
final ImmutableMap.Builder<String, Object> map = ImmutableMap.builder();
putIfNotNull(map, IHUEditorRow.COLUMNNAME_M_HU_ID, huId);
putIfNotNull(map, IHUEditorRow.COLUMNNAME_Value, code);
putIfNotNull(map, IHUEditorRow.COLUMNNAME_HU_UnitType, huUnitType);
putIfNotNull(map, IHUEditorRow.COLUMNNAME_HUStatus, huStatus);
putIfNotNull(map, IHUEditorRow.COLUMNNAME_PackingInfo, packingInfo);

putIfNotNull(map, IHUEditorRow.COLUMNNAME_M_Product_ID, product);
putIfNotNull(map, IHUEditorRow.COLUMNNAME_C_UOM_ID, uom);
putIfNotNull(map, IHUEditorRow.COLUMNNAME_QtyCU, qtyCU);

return map.build();
}

private static final void putIfNotNull(final ImmutableMap.Builder<String, Object> map, final String name, final Object value)
{
if (value == null)
{
return;
}
map.put(name, value);
}

private DocumentPath getDocumentPath()
{
final DocumentId rowId = getRowId();
Expand Down Expand Up @@ -528,13 +550,13 @@ public Builder setType(final HUEditorRowType type)
this.type = type;
return this;
}

public Builder setTopLevel(final boolean topLevel)
{
this.topLevel = topLevel;
return this;
}

private boolean isTopLevel()
{
Check.assumeNotNull(topLevel, "Parameter topLevel is not null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class HUEditorViewBuffer_FullyCached implements HUEditorViewBuffer
private final HUEditorViewRepository huEditorRepo;

private final ImmutableList<DocumentFilter> stickyFiltersWithoutHUIdsFilter;

private final HUIdsFilterData huIdsFilterData;
private final Supplier<Set<Integer>> huIdsSupplier;
private final ExtendedMemorizingSupplier<IndexedHUEditorRows> rowsSupplier = ExtendedMemorizingSupplier.of(() -> retrieveHUEditorRows());
Expand Down Expand Up @@ -107,7 +107,7 @@ public ViewId getViewId()
@Override
public List<DocumentFilter> getStickyFilters()
{
return ImmutableList.<DocumentFilter>builder()
return ImmutableList.<DocumentFilter> builder()
.add(HUIdsFilterHelper.createFilter(huIdsFilterData.copy()))
.addAll(stickyFiltersWithoutHUIdsFilter)
.build();
Expand Down Expand Up @@ -169,21 +169,10 @@ private static final Comparator<HUEditorRow> createComparatorOrNull(final List<D
return null;
}

Comparator<HUEditorRow> comparator = null;
for (final DocumentQueryOrderBy orderBy : orderBys)
{
final Comparator<HUEditorRow> orderByComparator = orderBy.<HUEditorRow> asComparator((row, fieldName) -> row.getFieldValueAsJson(fieldName));
if (comparator == null)
{
comparator = orderByComparator;
}
else
{
comparator = comparator.thenComparing(orderByComparator);
}
}

return comparator;
return orderBys.stream()
.map(orderBy -> orderBy.asComparator(HUEditorRow::getFieldValueAsJson))
.reduce((cmp1, cmp2) -> cmp1.thenComparing(cmp2))
.orElse(null);
}

@Override
Expand Down Expand Up @@ -260,7 +249,7 @@ public String getSqlWhereClause(final DocumentIdsSelection rowIds)
final String sqlKeyColumnNameFK = I_M_HU.Table_Name + "." + I_M_HU.COLUMNNAME_M_HU_ID;
return sqlKeyColumnNameFK + " IN " + DB.buildSqlList(rowIdsEffective.toIntSet());
}

//
//
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
import de.metas.ui.web.window.datatypes.WindowId;
import de.metas.ui.web.window.descriptor.DocumentEntityDescriptor;
import de.metas.ui.web.window.descriptor.DocumentFieldWidgetType;
import de.metas.ui.web.window.descriptor.DocumentLayoutElementDescriptor;
import de.metas.ui.web.window.descriptor.DocumentLayoutElementFieldDescriptor;
import de.metas.ui.web.window.descriptor.factory.DocumentDescriptorFactory;
import de.metas.ui.web.window.descriptor.factory.standard.LayoutFactory;
import de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor;
Expand Down Expand Up @@ -159,32 +157,13 @@ private final ViewLayout createHUViewLayout_IncludedView(final WindowId windowId
.setCaption("HU Editor")
.setEmptyResultText(LayoutFactory.HARDCODED_TAB_EMPTY_RESULT_TEXT)
.setEmptyResultHint(LayoutFactory.HARDCODED_TAB_EMPTY_RESULT_HINT)
.setIdFieldName(IHUEditorRow.COLUMNNAME_M_HU_ID)
.setIdFieldName(HUEditorRow.COLUMNNAME_M_HU_ID)
.setFilters(getSqlViewBinding().getViewFilterDescriptors().getAll())
//
.setHasAttributesSupport(true)
.setHasTreeSupport(true)
//
.addElement(DocumentLayoutElementDescriptor.builder()
.setCaption("Code")
.setWidgetType(DocumentFieldWidgetType.Text)
.setGridElement()
.addField(DocumentLayoutElementFieldDescriptor.builder(IHUEditorRow.COLUMNNAME_Value)))
.addElement(DocumentLayoutElementDescriptor.builder()
.setCaptionFromAD_Message("M_Product_ID")
.setWidgetType(DocumentFieldWidgetType.Lookup)
.setGridElement()
.addField(DocumentLayoutElementFieldDescriptor.builder(IHUEditorRow.COLUMNNAME_M_Product_ID)))
.addElement(DocumentLayoutElementDescriptor.builder()
.setCaptionFromAD_Message("M_HU_PI_Item_Product_ID")
.setWidgetType(DocumentFieldWidgetType.Text)
.setGridElement()
.addField(DocumentLayoutElementFieldDescriptor.builder(IHUEditorRow.COLUMNNAME_PackingInfo)))
.addElement(DocumentLayoutElementDescriptor.builder()
.setCaptionFromAD_Message("QtyCU")
.setWidgetType(DocumentFieldWidgetType.Quantity)
.setGridElement()
.addField(DocumentLayoutElementFieldDescriptor.builder(IHUEditorRow.COLUMNNAME_QtyCU)))
.addElementsFromViewRowClass(HUEditorRow.class, JSONViewDataType.includedView)
//
.build();
}
Expand All @@ -196,48 +175,13 @@ private final ViewLayout createHUViewLayout_Grid(final WindowId windowId)
.setCaption("HU Editor")
.setEmptyResultText(LayoutFactory.HARDCODED_TAB_EMPTY_RESULT_TEXT)
.setEmptyResultHint(LayoutFactory.HARDCODED_TAB_EMPTY_RESULT_HINT)
.setIdFieldName(IHUEditorRow.COLUMNNAME_M_HU_ID)
.setIdFieldName(HUEditorRow.COLUMNNAME_M_HU_ID)
.setFilters(getSqlViewBinding().getViewFilterDescriptors().getAll())
//
.setHasAttributesSupport(true)
.setHasTreeSupport(true)
//
.addElement(DocumentLayoutElementDescriptor.builder()
.setCaption("Code")
.setWidgetType(DocumentFieldWidgetType.Text)
.setGridElement()
.addField(DocumentLayoutElementFieldDescriptor.builder(IHUEditorRow.COLUMNNAME_Value)))
.addElement(DocumentLayoutElementDescriptor.builder()
.setCaptionFromAD_Message("M_Product_ID")
.setWidgetType(DocumentFieldWidgetType.Lookup)
.setGridElement()
.addField(DocumentLayoutElementFieldDescriptor.builder(IHUEditorRow.COLUMNNAME_M_Product_ID)))
.addElement(DocumentLayoutElementDescriptor.builder()
.setCaptionFromAD_Message("HU_UnitType")
.setWidgetType(DocumentFieldWidgetType.Text)
.setGridElement()
.addField(DocumentLayoutElementFieldDescriptor.builder(IHUEditorRow.COLUMNNAME_HU_UnitType)))
.addElement(DocumentLayoutElementDescriptor.builder()
.setCaptionFromAD_Message("M_HU_PI_Item_Product_ID")
.setWidgetType(DocumentFieldWidgetType.Text)
.setGridElement()
.addField(DocumentLayoutElementFieldDescriptor.builder(IHUEditorRow.COLUMNNAME_PackingInfo)))
.addElement(DocumentLayoutElementDescriptor.builder()
.setCaptionFromAD_Message("QtyCU")
.setWidgetType(DocumentFieldWidgetType.Quantity)
.setGridElement()
.addField(DocumentLayoutElementFieldDescriptor.builder(IHUEditorRow.COLUMNNAME_QtyCU)))
.addElement(DocumentLayoutElementDescriptor.builder()
.setCaptionFromAD_Message("C_UOM_ID")
.setWidgetType(DocumentFieldWidgetType.Lookup)
.setGridElement()
.addField(DocumentLayoutElementFieldDescriptor.builder(IHUEditorRow.COLUMNNAME_C_UOM_ID)))
//
.addElement(DocumentLayoutElementDescriptor.builder()
.setCaptionFromAD_Message(IHUEditorRow.COLUMNNAME_HUStatus)
.setWidgetType(DocumentFieldWidgetType.Lookup)
.setGridElement()
.addField(DocumentLayoutElementFieldDescriptor.builder(IHUEditorRow.COLUMNNAME_HUStatus)))
.addElementsFromViewRowClass(HUEditorRow.class, JSONViewDataType.grid)
//
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ private HUEditorRow createHUEditorRow(final int parent_HU_ID, final IHUProductSt
private static JSONLookupValue createHUStatusLookupValue(final I_M_HU hu)
{
final String huStatusKey = hu.getHUStatus();
final String huStatusDisplayName = Services.get(IADReferenceDAO.class).retrieveListNameTrl(IHUEditorRow.HUSTATUS_AD_Reference_ID, huStatusKey);
final String huStatusDisplayName = Services.get(IADReferenceDAO.class).retrieveListNameTrl(HUEditorRow.HUSTATUS_AD_Reference_ID, huStatusKey);
return JSONLookupValue.of(huStatusKey, huStatusDisplayName);
}

Expand Down
44 changes: 0 additions & 44 deletions src/main/java/de/metas/ui/web/handlingunits/IHUEditorRow.java

This file was deleted.

Loading

0 comments on commit 68b6383

Please sign in to comment.