Skip to content

Commit

Permalink
Merge branch 'master' of github.com:metasfresh/metasfresh-webui-api
Browse files Browse the repository at this point in the history
  • Loading branch information
metas-ts committed Sep 21, 2017
2 parents 89b3f45 + 443b4c3 commit 1c5418a
Show file tree
Hide file tree
Showing 21 changed files with 731 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import de.metas.ui.web.window.descriptor.DocumentEntityDescriptor;
import de.metas.ui.web.window.descriptor.DocumentFieldDescriptor;
import de.metas.ui.web.window.descriptor.DocumentFieldWidgetType;
import de.metas.ui.web.window.descriptor.LookupDescriptor;
import de.metas.ui.web.window.descriptor.LookupDescriptorProvider;
import de.metas.ui.web.window.descriptor.LookupDescriptorProvider.LookupScope;
import de.metas.ui.web.window.descriptor.factory.DocumentDescriptorFactory;
Expand Down Expand Up @@ -291,7 +292,8 @@ private final BoardCardFieldDescriptor createBoardCardFieldDescriptor(final I_WE
{
sqlSelectValues = ImmutableSet.of(fieldBinding.getSqlSelectValue());
final DocumentFieldValueLoader documentFieldValueLoader = fieldBinding.getDocumentFieldValueLoader();
fieldLoader = (rs, adLanguage) -> documentFieldValueLoader.retrieveFieldValue(rs, isDisplayColumnAvailable, adLanguage);
final LookupDescriptor lookupDescriptor = documentField.getLookupDescriptor(LookupScope.DocumentField);
fieldLoader = (rs, adLanguage) -> documentFieldValueLoader.retrieveFieldValue(rs, isDisplayColumnAvailable, adLanguage, lookupDescriptor);
}

return BoardCardFieldDescriptor.builder()
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/de/metas/ui/web/view/SqlViewFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import de.metas.ui.web.window.datatypes.WindowId;
import de.metas.ui.web.window.descriptor.DocumentEntityDescriptor;
import de.metas.ui.web.window.descriptor.DocumentFieldDescriptor.Characteristic;
import de.metas.ui.web.window.descriptor.LookupDescriptor;
import de.metas.ui.web.window.descriptor.factory.DocumentDescriptorFactory;
import de.metas.ui.web.window.descriptor.sql.DocumentFieldValueLoader;
import de.metas.ui.web.window.descriptor.sql.SqlDocumentEntityDataBindingDescriptor;
Expand Down Expand Up @@ -246,9 +247,9 @@ private static final class DocumentFieldValueLoaderAsSqlViewRowFieldLoader imple
private final boolean isDisplayColumnAvailable;

@Override
public Object retrieveValueAsJson(ResultSet rs, String adLanguage) throws SQLException
public Object retrieveValueAsJson(final ResultSet rs, final String adLanguage) throws SQLException
{
final Object fieldValue = fieldValueLoader.retrieveFieldValue(rs, isDisplayColumnAvailable, adLanguage);
final Object fieldValue = fieldValueLoader.retrieveFieldValue(rs, isDisplayColumnAvailable, adLanguage, (LookupDescriptor)null);
return Values.valueToJsonObject(fieldValue);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Function;
Expand Down Expand Up @@ -181,6 +182,11 @@ public boolean isEmpty()
{
return valuesById.isEmpty() && debugProperties.isEmpty();
}

public Set<Object> getKeys()
{
return valuesById.keySet();
}

/**
* @return lookup values, respecting the order in which they were initially created.
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/de/metas/ui/web/window/datatypes/Values.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import de.metas.ui.web.window.datatypes.json.JSONDate;
import de.metas.ui.web.window.datatypes.json.JSONLookupValue;
import de.metas.ui.web.window.datatypes.json.JSONLookupValuesList;
import de.metas.ui.web.window.datatypes.json.JSONRange;

/*
Expand Down Expand Up @@ -75,6 +76,11 @@ else if (value instanceof LookupValue)
final LookupValue lookupValue = (LookupValue)value;
return JSONLookupValue.ofLookupValue(lookupValue);
}
else if (value instanceof LookupValuesList)
{
final LookupValuesList lookupValues = (LookupValuesList)value;
return JSONLookupValuesList.ofLookupValuesList(lookupValues);
}
else if (value instanceof NamePair)
{
final NamePair lookupValue = (NamePair)value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public enum JSONLayoutWidgetType
, Integer, Number, Amount, Quantity, CostPrice

//
, List, Lookup, Address, ProductAttributes
, List, Lookup
, Labels
, Address, ProductAttributes

, YesNo, Switch

Expand Down Expand Up @@ -80,6 +82,7 @@ public static JSONLayoutWidgetType fromNullable(final DocumentFieldWidgetType wi
.put(DocumentFieldWidgetType.CostPrice, JSONLayoutWidgetType.CostPrice)
.put(DocumentFieldWidgetType.List, JSONLayoutWidgetType.List)
.put(DocumentFieldWidgetType.Lookup, JSONLayoutWidgetType.Lookup)
.put(DocumentFieldWidgetType.Labels, JSONLayoutWidgetType.Labels)
.put(DocumentFieldWidgetType.Address, JSONLayoutWidgetType.Address)
.put(DocumentFieldWidgetType.ProductAttributes, JSONLayoutWidgetType.ProductAttributes)
.put(DocumentFieldWidgetType.YesNo, JSONLayoutWidgetType.YesNo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/
Expand Down Expand Up @@ -93,6 +93,24 @@ private static final JSONLookupValuesList ofJSONLookupValuesList(@JsonProperty("
return Collector.of(supplier, accumulator, combiner, finisher);
}

public static final LookupValuesList lookupValuesListFromJsonMap(final Map<String, Object> map)
{
@SuppressWarnings("unchecked")
final List<Object> values = (List<Object>)map.get("values");
if (values == null || values.isEmpty())
{
return LookupValuesList.EMPTY;
}

return values.stream()
.map(valueObj -> {
@SuppressWarnings("unchecked")
final Map<String, String> valueAsMap = (Map<String, String>)valueObj;
return JSONLookupValue.stringLookupValueFromJsonMap(valueAsMap);
})
.collect(LookupValuesList.collect());
}

private static final JSONLookupValuesList EMPTY = new JSONLookupValuesList();

@JsonProperty("values")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
import de.metas.ui.web.window.datatypes.LookupValue;
import de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue;
import de.metas.ui.web.window.datatypes.LookupValue.StringLookupValue;
import de.metas.ui.web.window.datatypes.LookupValuesList;
import de.metas.ui.web.window.datatypes.json.JSONDate;
import de.metas.ui.web.window.datatypes.json.JSONLookupValue;
import de.metas.ui.web.window.datatypes.json.JSONLookupValuesList;
import de.metas.ui.web.window.datatypes.json.JSONRange;
import de.metas.ui.web.window.descriptor.DocumentFieldDependencyMap.DependencyType;
import de.metas.ui.web.window.descriptor.DocumentLayoutElementFieldDescriptor.LookupSource;
Expand Down Expand Up @@ -638,6 +640,17 @@ else if (IntegerLookupValue.class == fromType)
return valueConv;
}
}
else if(LookupValuesList.class == targetType)
{
if (Map.class.isAssignableFrom(fromType))
{
@SuppressWarnings("unchecked")
final Map<String, Object> map = (Map<String, Object>)value;
@SuppressWarnings("unchecked")
final T valueConv = (T)JSONLookupValuesList.lookupValuesListFromJsonMap(map);
return valueConv;
}
}
else if(DateRangeValue.class == targetType)
{
if (Map.class.isAssignableFrom(fromType))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import de.metas.ui.web.window.datatypes.DateRangeValue;
import de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue;
import de.metas.ui.web.window.datatypes.LookupValuesList;

/*
* #%L
Expand Down Expand Up @@ -60,6 +61,7 @@ public enum DocumentFieldWidgetType
// General Lookups
, List(LayoutAlign.Left, null, DisplayType.Search) //
, Lookup(LayoutAlign.Left, null, DisplayType.Search) //
, Labels(LayoutAlign.Left, LookupValuesList.class, -1) //

//
// Special lookups
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.compiere.model.I_AD_UI_ElementField;
import org.compiere.model.I_AD_UI_ElementGroup;
import org.compiere.model.I_AD_UI_Section;
import org.compiere.model.X_AD_UI_Element;
import org.compiere.util.Env;

/*
Expand All @@ -25,16 +26,15 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/


final class DAOWindowUIElementsProvider implements IWindowUIElementsProvider
{
private final transient IADWindowDAO windowDAO = Services.get(IADWindowDAO.class);
Expand Down Expand Up @@ -64,9 +64,18 @@ public List<I_AD_UI_Element> getUIElements(final I_AD_UI_ElementGroup uiElementG
return windowDAO.retrieveUIElements(uiElementGroup);
}

@Override
public List<I_AD_UI_Element> getUIElementsOfTypeLabels(final int adTabId)
{
return windowDAO.retrieveUIElementsQueryByTabId(adTabId)
.addEqualsFilter(I_AD_UI_Element.COLUMN_AD_UI_ElementType, X_AD_UI_Element.AD_UI_ELEMENTTYPE_Labels)
.create()
.list(I_AD_UI_Element.class);
}

@Override
public List<I_AD_UI_ElementField> getUIElementFields(final I_AD_UI_Element uiElement)
{
return windowDAO.retrieveUIElementFields(uiElement);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ public DocumentDescriptor load()
{
continue;
}

// Skip tabs which were already used/embedded in root layout
if(rootLayoutFactory.isSkipAD_Tab_ID(detailTabVO.getAD_Tab_ID()))
{
continue;
}

final LayoutFactory detailLayoutFactory = LayoutFactory.ofIncludedTab(gridWindowVO, mainTabVO, detailTabVO);
final DocumentLayoutDetailDescriptor.Builder layoutDetail = detailLayoutFactory.layoutDetail();
Expand Down
Loading

0 comments on commit 1c5418a

Please sign in to comment.