Skip to content

Commit

Permalink
MAJOR: Show value/ name in breadcrumb but edit in window
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Apr 23, 2017
1 parent b0980ad commit 4ce0c31
Show file tree
Hide file tree
Showing 19 changed files with 674 additions and 263 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,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 All @@ -66,9 +66,10 @@ public static final JSONDocumentLayout ofDetailTab(final DocumentLayoutDetailDes
@JsonInclude(Include.NON_NULL)
private final String tabid;

@JsonProperty("documentNoElement")
@JsonInclude(Include.NON_NULL)
private final JSONDocumentLayoutElement documentNoElement;
// NOTE: we are no longer using documentNoElement (see https://github.com/metasfresh/metasfresh-webui-api/issues/291 ).
// @JsonProperty("documentNoElement")
// @JsonInclude(Include.NON_NULL)
// private final JSONDocumentLayoutElement documentNoElement;

@JsonProperty("documentSummaryElement")
@JsonInclude(Include.NON_NULL)
Expand Down Expand Up @@ -113,7 +114,6 @@ private JSONDocumentLayout(final DocumentLayoutDescriptor layout, final JSONOpti

type = String.valueOf(layout.getAD_Window_ID());
tabid = null;
documentNoElement = JSONDocumentLayoutElement.fromNullable(layout.getDocumentNoElement(), jsonOpts);
documentSummaryElement = JSONDocumentLayoutElement.fromNullable(layout.getDocumentSummaryElement(), jsonOpts);
docActionElement = JSONDocumentLayoutElement.fromNullable(layout.getDocActionElement(), jsonOpts);

Expand Down Expand Up @@ -168,7 +168,6 @@ private JSONDocumentLayout(final DocumentLayoutDetailDescriptor detailLayout, fi
final DetailId detailId = detailLayout.getDetailId();
tabid = DetailId.toJson(detailId);

documentNoElement = null;
documentSummaryElement = null;
docActionElement = null;

Expand All @@ -190,7 +189,6 @@ private JSONDocumentLayout(final DocumentLayoutDetailDescriptor detailLayout, fi
private JSONDocumentLayout(
@JsonProperty("type") final String type//
, @JsonProperty("tabid") final String tabId //
, @JsonProperty("documentNoElement") final JSONDocumentLayoutElement documentNoElement//
, @JsonProperty("documentSummaryElement") final JSONDocumentLayoutElement documentSummaryElement //
, @JsonProperty("docActionElement") final JSONDocumentLayoutElement docActionElement//
, @JsonProperty("sections") final List<JSONDocumentLayoutSection> sections //
Expand All @@ -199,12 +197,11 @@ private JSONDocumentLayout(
, @JsonProperty("emptyResultText") final String emptyResultText //
, @JsonProperty("emptyResultHint") final String emptyResultHint //

)
)
{
super();
this.type = type;
tabid = Strings.emptyToNull(tabId);
this.documentNoElement = documentNoElement;
this.documentSummaryElement = documentSummaryElement;
this.docActionElement = docActionElement;
this.sections = sections == null ? ImmutableList.of() : ImmutableList.copyOf(sections);
Expand Down Expand Up @@ -237,11 +234,6 @@ public String getTabid()
return tabid;
}

public JSONDocumentLayoutElement getDocumentNoElement()
{
return documentNoElement;
}

public JSONDocumentLayoutElement getDocumentSummaryElement()
{
return documentSummaryElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,11 @@ public Collection<DocumentFieldDescriptor.Builder> getFieldBuilders()
return _fieldBuilders.values();
}

public boolean hasField(final String fieldName)
{
return getFieldBuilder(fieldName) != null;
}

public int getFieldsCount()
{
return _fieldBuilders.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.function.BiConsumer;

import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -50,10 +49,17 @@ public static final Builder builder()

public enum DependencyType
{
ReadonlyLogic, DisplayLogic, MandatoryLogic, LookupValues,
ReadonlyLogic, DisplayLogic, MandatoryLogic, LookupValues, FieldValue
};

@FunctionalInterface
public static interface IDependencyConsumer
{
void consume(String dependentFieldName, DependencyType dependencyType);
}

private final Map<DependencyType, Multimap<String, String>> type2name2dependencies;
/** Map: "dependency type" to "depends on field name" to list of "dependent field name" */
private final ImmutableMap<DependencyType, Multimap<String, String>> type2name2dependencies;

private DocumentFieldDependencyMap(final Builder builder)
{
Expand Down Expand Up @@ -100,22 +106,28 @@ public String toStringX()
return sb.toString();
}

public void consumeForChangedFieldName(final String changedFieldName, final BiConsumer<String, DependencyType> consumer)
public void consumeForChangedFieldName(final String changedFieldName, final IDependencyConsumer consumer)
{
for (final DependencyType dependencyType : DependencyType.values())
{
final Multimap<String, String> name2dependencies = type2name2dependencies.get(dependencyType);
if (name2dependencies == null)
if (name2dependencies == null || name2dependencies.isEmpty())
{
continue;
}

for (final String dependentFieldName : name2dependencies.get(changedFieldName))
{
consumer.accept(dependentFieldName, dependencyType);
consumer.consume(dependentFieldName, dependencyType);
}
}
}

//
//
//
//
//
public static final class Builder
{
private final Map<DependencyType, ImmutableSetMultimap.Builder<String, String>> type2name2dependencies = new HashMap<>();
Expand All @@ -134,7 +146,7 @@ public DocumentFieldDependencyMap build()
return new DocumentFieldDependencyMap(this);
}

private Map<DependencyType, Multimap<String, String>> getType2Name2DependenciesMap()
private ImmutableMap<DependencyType, Multimap<String, String>> getType2Name2DependenciesMap()
{
final ImmutableMap.Builder<DependencyType, Multimap<String, String>> builder = ImmutableMap.builder();
for (final Entry<DependencyType, ImmutableSetMultimap.Builder<String, String>> e : type2name2dependencies.entrySet())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@
import de.metas.ui.web.window.descriptor.DocumentFieldDependencyMap.DependencyType;
import de.metas.ui.web.window.descriptor.DocumentLayoutElementFieldDescriptor.LookupSource;
import de.metas.ui.web.window.descriptor.LookupDescriptorProvider.LookupScope;
import de.metas.ui.web.window.model.IDocumentFieldValueProvider;
import de.metas.ui.web.window.model.lookup.LookupDataSource;
import de.metas.ui.web.window.model.lookup.LookupDataSourceFactory;
import de.metas.ui.web.window.model.lookup.LookupValueByIdSupplier;
import lombok.NonNull;

/*
* #%L
Expand Down Expand Up @@ -87,17 +89,19 @@ public static final Builder builder(final String fieldName)
/** Is this the key field ? */
private final boolean key;
private final boolean parentLink;
private final boolean virtualField;
private final boolean calculated;

private final DocumentFieldWidgetType widgetType;

private final Class<?> valueClass;

private final LookupDescriptorProvider lookupDescriptorProvider;

private final boolean virtualField;
private final Optional<IDocumentFieldValueProvider> virtualFieldValueProvider;

private final Optional<IExpression<?>> defaultValueExpression;
private final List<IDocumentFieldCallout> callouts;
private final ImmutableList<IDocumentFieldCallout> callouts;

public static enum Characteristic
{
Expand All @@ -110,13 +114,13 @@ public static enum Characteristic
, SpecialField_DocumentNo //
, SpecialField_DocStatus //
, SpecialField_DocAction //
, SpecialField_DocumentSummary //
// , SpecialField_DocumentSummary //
;
};

private static final List<Characteristic> SPECIALFIELDS_ToExcludeFromLayout = ImmutableList.of(
Characteristic.SpecialField_DocumentNo //
, Characteristic.SpecialField_DocStatus //
// Characteristic.SpecialField_DocumentNo // NOP, don't exclude it (see https://github.com/metasfresh/metasfresh-webui-api/issues/291 )
Characteristic.SpecialField_DocStatus //
, Characteristic.SpecialField_DocAction //
// , SpecialField_DocumentSummary // NOP, don't exclude DocumentSummary because if it's layout it shall be editable at least when new (e.g. C_BPartner.Name)
);
Expand All @@ -142,15 +146,17 @@ private DocumentFieldDescriptor(final Builder builder)

key = builder.isKey();
parentLink = builder.parentLink;
virtualField = builder.virtualField;
calculated = builder.calculated;
calculated = builder.isCalculated();

widgetType = builder.getWidgetType();
valueClass = builder.getValueClass();

lookupDescriptorProvider = builder.getLookupDescriptorProvider();

defaultValueExpression = Preconditions.checkNotNull(builder.defaultValueExpression, "defaultValueExpression not null");

virtualField = builder.isVirtualField();
virtualFieldValueProvider = builder.getVirtualFieldValueProvider();

characteristics = Sets.immutableEnumSet(builder.characteristics);
readonlyLogic = builder.getReadonlyLogicEffective();
Expand All @@ -162,7 +168,7 @@ private DocumentFieldDescriptor(final Builder builder)

dependencies = builder.buildDependencies();

callouts = ImmutableList.copyOf(builder.getCallouts());
callouts = builder.buildCallouts();
}

@Override
Expand Down Expand Up @@ -212,6 +218,11 @@ public boolean isVirtualField()
{
return virtualField;
}

public Optional<IDocumentFieldValueProvider> getVirtualFieldValueProvider()
{
return virtualFieldValueProvider;
}

public boolean isCalculated()
{
Expand Down Expand Up @@ -603,6 +614,7 @@ public static final class Builder
private boolean key = false;
private boolean parentLink = false;
private boolean virtualField;
private Optional<IDocumentFieldValueProvider> virtualFieldValueProvider = Optional.empty();
private boolean calculated;

private DocumentFieldWidgetType _widgetType;
Expand All @@ -617,7 +629,7 @@ public static final class Builder
private ILogicExpression _entityReadonlyLogic = ILogicExpression.FALSE;
private ILogicExpression _readonlyLogic = ILogicExpression.FALSE;
private ILogicExpression _readonlyLogicEffective = null;
private boolean alwaysUpdateable;
private boolean alwaysUpdateable = false;
private ILogicExpression displayLogic = ILogicExpression.TRUE;
private ILogicExpression _mandatoryLogic = ILogicExpression.FALSE;
private ILogicExpression _mandatoryLogicEffective = null;
Expand Down Expand Up @@ -772,20 +784,43 @@ public Builder setVirtualField(final boolean virtualField)
{
assertNotBuilt();
this.virtualField = virtualField;
this.virtualFieldValueProvider = Optional.empty();
return this;
}

public Builder setVirtualField(@NonNull final IDocumentFieldValueProvider virtualFieldValueProvider)
{
assertNotBuilt();
this.virtualField = true;
this.virtualFieldValueProvider = Optional.of(virtualFieldValueProvider);
return this;
}

public boolean isVirtualField()
{
return virtualField;
}

private Optional<IDocumentFieldValueProvider> getVirtualFieldValueProvider()
{
return virtualFieldValueProvider;
}

public Builder setCalculated(final boolean calculated)
{
assertNotBuilt();
this.calculated = calculated;
return this;
}

private boolean isCalculated()
{
if(isVirtualField())
{
return true;
}
return calculated;
}

public Builder setWidgetType(final DocumentFieldWidgetType widgetType)
{
Expand Down Expand Up @@ -897,7 +932,7 @@ public Builder removeCharacteristic(final Characteristic c)
return this;
}

public boolean isSpecialField()
public boolean isSpecialFieldToExcludeFromLayout()
{
return !Collections.disjoint(characteristics, SPECIALFIELDS_ToExcludeFromLayout);
}
Expand Down Expand Up @@ -963,7 +998,7 @@ private ILogicExpression buildReadonlyLogicEffective()
return ILogicExpression.TRUE;
}

// Case: DocumentNo special field not be readonly
// Case: DocumentNo/Value special field not be readonly
if (hasCharacteristic(Characteristic.SpecialField_DocumentNo))
{
return LOGICEXPRESSION_NotActive.or(LOGICEXPRESSION_Processed);
Expand Down Expand Up @@ -1089,11 +1124,6 @@ public Builder setMandatoryLogic(final boolean mandatory)
return this;
}

public ILogicExpression getMandatoryLogic()
{
return _mandatoryLogic;
}

private ILogicExpression getMandatoryLogicEffective()
{
if (_mandatoryLogicEffective == null)
Expand Down Expand Up @@ -1135,7 +1165,7 @@ private final ILogicExpression buildMandatoryLogicEffective()
// => we need to NOT enforce setting it because it's not needed, user cannot change it and it might be no callouts to set it.
// Else, we won't be able to save our document.
final boolean publicField = hasCharacteristic(Characteristic.PublicField);
final ILogicExpression mandatoryLogic = getMandatoryLogic();
final ILogicExpression mandatoryLogic = _mandatoryLogic;
final boolean mandatory = mandatoryLogic.isConstantTrue();
final DocumentFieldDataBindingDescriptor fieldDataBinding = getDataBinding().orElse(null);
final boolean mandatoryDB = fieldDataBinding != null && fieldDataBinding.isMandatory();
Expand Down Expand Up @@ -1182,6 +1212,12 @@ private DocumentFieldDependencyMap buildDependencies()
{
dependencyMapBuilder.add(fieldName, lookupDescriptor.getDependsOnFieldNames(), DependencyType.LookupValues);
}

final IDocumentFieldValueProvider virtualFieldValueProvider = getVirtualFieldValueProvider().orElse(null);
if(virtualFieldValueProvider != null)
{
dependencyMapBuilder.add(fieldName, virtualFieldValueProvider.getDependsOnFieldNames(), DependencyType.FieldValue);
}

return dependencyMapBuilder.build();
}
Expand All @@ -1206,9 +1242,9 @@ public Builder addCallout(final ILambdaDocumentFieldCallout lambdaCallout)
return this;
}

/* package */List<IDocumentFieldCallout> getCallouts()
private ImmutableList<IDocumentFieldCallout> buildCallouts()
{
return callouts;
return ImmutableList.copyOf(callouts);
}

public Builder setButtonProcessId(final int buttonProcessId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ public final boolean isDateOrTime()
return TYPES_Date.contains(this);
}

public final boolean isNumeric()
{
return TYPES_Numeric.contains(this);
}

public final boolean isText()
{
return this == Text || this == LongText;
Expand Down
Loading

0 comments on commit 4ce0c31

Please sign in to comment.