Skip to content

Commit

Permalink
Provide "size" to layout element #411
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed May 23, 2017
1 parent 8464925 commit 41d7664
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import de.metas.ui.web.window.descriptor.ButtonFieldActionDescriptor.ButtonFieldActionType;
import de.metas.ui.web.window.descriptor.DocumentFieldWidgetType;
import de.metas.ui.web.window.descriptor.DocumentLayoutElementDescriptor;
import de.metas.ui.web.window.descriptor.WidgetSize;
import io.swagger.annotations.ApiModel;
import lombok.ToString;

Expand Down Expand Up @@ -96,6 +97,11 @@ public static JSONDocumentLayoutElement debuggingField(final String fieldName, f
@JsonInclude(JsonInclude.Include.NON_NULL)
private final JSONLayoutType type;

/** Widget size (see https://github.com/metasfresh/metasfresh-webui-api/issues/411). */
@JsonProperty("size")
@JsonInclude(JsonInclude.Include.NON_NULL)
private final WidgetSize size;

@JsonProperty("gridAlign")
@JsonInclude(JsonInclude.Include.NON_NULL)
private final JSONLayoutAlign gridAlign;
Expand Down Expand Up @@ -135,6 +141,7 @@ private JSONDocumentLayoutElement(final DocumentLayoutElementDescriptor element,
}

type = JSONLayoutType.fromNullable(element.getLayoutType());
size = element.getWidgetSize();
gridAlign = JSONLayoutAlign.fromNullable(element.getGridAlign());

fields = JSONDocumentLayoutElementField.ofSet(element.getFields(), jsonOpts);
Expand All @@ -151,6 +158,7 @@ private JSONDocumentLayoutElement(final String fieldName, final DocumentFieldWid
precision = null;

type = null;
size = null;
gridAlign = JSONLayoutAlign.right;

fields = ImmutableSet.of(new JSONDocumentLayoutElementField( //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public static final Builder builder(final DocumentFieldDescriptor... fields)
private final ButtonFieldActionDescriptor buttonActionDescriptor;

private final LayoutType layoutType;
private final WidgetSize widgetSize;
private final LayoutAlign gridAlign;
private final boolean advancedField;

Expand All @@ -106,6 +107,7 @@ private DocumentLayoutElementDescriptor(final Builder builder)
buttonActionDescriptor = builder.getButtonActionDescriptor();

layoutType = builder.getLayoutType();
widgetSize = builder.getWidgetSize();
gridAlign = builder.getGridAlign();

advancedField = builder.isAdvancedField();
Expand Down Expand Up @@ -164,6 +166,11 @@ public LayoutType getLayoutType()
{
return layoutType;
}

public WidgetSize getWidgetSize()
{
return widgetSize;
}

public LayoutAlign getGridAlign()
{
Expand All @@ -184,7 +191,7 @@ public boolean hasFields()
{
return !fields.isEmpty();
}

public ButtonFieldActionDescriptor getButtonActionDescriptor()
{
return buttonActionDescriptor;
Expand All @@ -200,6 +207,7 @@ public static final class Builder
private DocumentFieldWidgetType _widgetType;
private ButtonFieldActionDescriptor buttonActionDescriptor = null;
private LayoutType _layoutType;
private WidgetSize _widgetSize;
private boolean _gridElement = false;
private boolean _advancedField = false;
private final LinkedHashMap<String, DocumentLayoutElementFieldDescriptor.Builder> _fieldsBuilders = new LinkedHashMap<>();
Expand Down Expand Up @@ -375,6 +383,17 @@ private LayoutType getLayoutType()
return _layoutType;
}

public Builder setWidgetSize(final WidgetSize widgetSize)
{
_widgetSize = widgetSize;
return this;
}

private WidgetSize getWidgetSize()
{
return _widgetSize;
}

public Builder setAdvancedField(final boolean advancedField)
{
_advancedField = advancedField;
Expand Down Expand Up @@ -466,13 +485,13 @@ private LayoutAlign getGridAlign()
{
return _gridElement ? getWidgetType().getGridAlign() : null;
}
public Builder setButtonActionDescriptor(ButtonFieldActionDescriptor buttonActionDescriptor)

public Builder setButtonActionDescriptor(final ButtonFieldActionDescriptor buttonActionDescriptor)
{
this.buttonActionDescriptor = buttonActionDescriptor;
return this;
}

/* package */ ButtonFieldActionDescriptor getButtonActionDescriptor()
{
return buttonActionDescriptor;
Expand Down
77 changes: 77 additions & 0 deletions src/main/java/de/metas/ui/web/window/descriptor/WidgetSize.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package de.metas.ui.web.window.descriptor;

import java.util.NoSuchElementException;
import java.util.stream.Stream;

import org.adempiere.util.GuavaCollectors;
import org.compiere.model.X_AD_UI_Element;

import com.fasterxml.jackson.annotation.JsonValue;
import com.google.common.collect.ImmutableMap;

/*
* #%L
* metasfresh-webui-api
* %%
* Copyright (C) 2017 metas GmbH
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
* 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
* 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
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/

public enum WidgetSize
{
Small("S", X_AD_UI_Element.WIDGETSIZE_Small), //
Medium("M", X_AD_UI_Element.WIDGETSIZE_Medium), //
Large("L", X_AD_UI_Element.WIDGETSIZE_Large);

private final String json;
private final String adRefListValue;

private WidgetSize(final String json, final String adRefListValue)
{
this.json = json;
this.adRefListValue = adRefListValue;
}

@JsonValue
public String toJson()
{
return json;
}

public static WidgetSize fromNullableADRefListValue(final String adRefListValue)
{
if (adRefListValue == null || adRefListValue.trim().isEmpty())
{
return null;
}

final WidgetSize widgetSize = adRefListValue2widgetType.get(adRefListValue);
if (widgetSize == null)
{
throw new NoSuchElementException(adRefListValue);
}
return widgetSize;
}

private String getAD_Ref_List_Value()
{
return adRefListValue;
}

private static final ImmutableMap<String, WidgetSize> adRefListValue2widgetType = Stream.of(values())
.collect(GuavaCollectors.toImmutableMapByKey(WidgetSize::getAD_Ref_List_Value));
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import de.metas.ui.web.window.descriptor.DocumentLayoutHeader;
import de.metas.ui.web.window.descriptor.DocumentLayoutSectionDescriptor;
import de.metas.ui.web.window.descriptor.LayoutType;
import de.metas.ui.web.window.descriptor.WidgetSize;

/*
* #%L
Expand Down Expand Up @@ -359,6 +360,7 @@ private DocumentLayoutElementDescriptor.Builder layoutElement(final I_AD_UI_Elem
final DocumentLayoutElementDescriptor.Builder layoutElementBuilder = DocumentLayoutElementDescriptor.builder()
.setInternalName(uiElement.toString())
.setLayoutType(layoutType)
.setWidgetSize(WidgetSize.fromNullableADRefListValue(uiElement.getWidgetSize()))
.setAdvancedField(uiElement.isAdvancedField());

//
Expand Down

0 comments on commit 41d7664

Please sign in to comment.