Skip to content

Commit

Permalink
JSONLayout.expanded
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Jun 8, 2017
1 parent e768de1 commit 8c72aec
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
4 changes: 2 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 @@ -84,14 +84,14 @@ private static final class SqlViewBindingKey
public ViewLayout getViewLayout(final WindowId windowId, final JSONViewDataType viewDataType)
{
final Collection<DocumentFilterDescriptor> filters = getViewFilterDescriptors(windowId, viewDataType);

final SqlViewBindingKey sqlViewBindingKey = new SqlViewBindingKey(windowId, viewDataType.getRequiredFieldCharacteristic());
final SqlViewBinding sqlViewBinding = getViewBinding(sqlViewBindingKey);
final boolean hasTreeSupport = sqlViewBinding.hasGroupingFields();

return documentDescriptorFactory.getDocumentDescriptor(windowId)
.getViewLayout(viewDataType)
.withFiltersAndTreeSupport(filters, hasTreeSupport);
.withFiltersAndTreeSupport(filters, hasTreeSupport, false/* treeExpanded */);
}

@Override
Expand Down
29 changes: 24 additions & 5 deletions src/main/java/de/metas/ui/web/view/descriptor/ViewLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public static final Builder builder()
private final boolean hasAttributesSupport;
private final boolean hasTreeSupport;
private final boolean hasIncludedViewSupport;
private final boolean treeExpanded;
private final String allowNewCaption;

// ETag support
Expand All @@ -93,15 +94,18 @@ private ViewLayout(final Builder builder)
idFieldName = builder.getIdFieldName();

hasAttributesSupport = builder.hasAttributesSupport;

hasTreeSupport = builder.hasTreeSupport;
treeExpanded = builder.treeExpanded;

hasIncludedViewSupport = builder.hasIncludedViewSupport;
allowNewCaption = null;

eTag = ETag.of(nextETagVersionSupplier.getAndIncrement(), extractETagAttributes(filters, allowNewCaption));
}

/** copy and override constructor */
private ViewLayout(final ViewLayout from, final ImmutableList<DocumentFilterDescriptor> filters, final String allowNewCaption, final boolean hasTreeSupport)
private ViewLayout(final ViewLayout from, final ImmutableList<DocumentFilterDescriptor> filters, final String allowNewCaption, final boolean hasTreeSupport, final boolean treeExpanded)
{
super();
windowId = from.windowId;
Expand All @@ -119,6 +123,7 @@ private ViewLayout(final ViewLayout from, final ImmutableList<DocumentFilterDesc

hasAttributesSupport = from.hasAttributesSupport;
this.hasTreeSupport = hasTreeSupport;
this.treeExpanded = treeExpanded;
hasIncludedViewSupport = from.hasIncludedViewSupport;
this.allowNewCaption = allowNewCaption;

Expand Down Expand Up @@ -179,16 +184,18 @@ public List<DocumentFilterDescriptor> getFilters()
return filters;
}

public ViewLayout withFiltersAndTreeSupport(final Collection<DocumentFilterDescriptor> filtersToSet, final boolean hasTreeSupportToSet)
public ViewLayout withFiltersAndTreeSupport(final Collection<DocumentFilterDescriptor> filtersToSet, final boolean hasTreeSupportToSet, final Boolean treeExpanded)
{
final ImmutableList<DocumentFilterDescriptor> filtersToSetEffective = filtersToSet != null ? ImmutableList.copyOf(filtersToSet) : ImmutableList.of();
final boolean treeExpandedEffective = treeExpanded != null ? treeExpanded.booleanValue() : this.treeExpanded;
if (Objects.equals(filters, filtersToSetEffective)
&& this.hasTreeSupport == hasTreeSupportToSet)
&& this.hasTreeSupport == hasTreeSupportToSet
&& this.treeExpanded == treeExpandedEffective)
{
return this;
}

return new ViewLayout(this, filtersToSetEffective, allowNewCaption, hasTreeSupportToSet);
return new ViewLayout(this, filtersToSetEffective, allowNewCaption, hasTreeSupportToSet, treeExpandedEffective);
}

public ViewLayout withAllowNewRecordIfPresent(final Optional<String> allowNewCaption)
Expand All @@ -204,7 +211,7 @@ public ViewLayout withAllowNewRecordIfPresent(final Optional<String> allowNewCap
return this;
}

return new ViewLayout(this, filters, allowNewCaptionToSet, hasTreeSupport);
return new ViewLayout(this, filters, allowNewCaptionToSet, hasTreeSupport, treeExpanded);
}

public List<DocumentLayoutElementDescriptor> getElements()
Expand All @@ -231,6 +238,11 @@ public boolean isTreeSupport()
{
return hasTreeSupport;
}

public boolean isTreeExpanded()
{
return treeExpanded;
}

public boolean isIncludedViewSupport()
{
Expand Down Expand Up @@ -269,6 +281,7 @@ public static final class Builder

private boolean hasAttributesSupport = false;
private boolean hasTreeSupport = false;
private boolean treeExpanded = true;
private boolean hasIncludedViewSupport = false;

private final List<DocumentLayoutElementDescriptor.Builder> elementBuilders = new ArrayList<>();
Expand Down Expand Up @@ -420,6 +433,12 @@ public Builder setHasTreeSupport(final boolean hasTreeSupport)
this.hasTreeSupport = hasTreeSupport;
return this;
}

public Builder setTreeExpanded(boolean treeExpanded)
{
this.treeExpanded = treeExpanded;
return this;
}

public Builder setHasIncludedViewSupport(final boolean hasIncludedViewSupport)
{
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/de/metas/ui/web/view/json/JSONViewLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public static JSONViewLayout of(
//
@JsonProperty("supportTree")
private final boolean supportTree;
@JsonProperty("expanded")
private final boolean expanded;
//
@JsonProperty("supportIncludedView")
private final boolean supportIncludedView;
Expand Down Expand Up @@ -135,7 +137,10 @@ private JSONViewLayout(final ViewLayout layout, final JSONOptions jsonOpts)
this.filters = JSONDocumentFilterDescriptor.ofCollection(layout.getFilters(), jsonOpts);

supportAttributes = layout.isAttributesSupport();

supportTree = layout.isTreeSupport();
expanded = layout.isTreeExpanded();

supportIncludedView = layout.isIncludedViewSupport();
}

Expand All @@ -150,6 +155,7 @@ private JSONViewLayout(
, @JsonProperty("filters") final List<JSONDocumentFilterDescriptor> filters //
, @JsonProperty(value = PROPERTY_supportAttributes) final boolean supportAttributes //
, @JsonProperty(value = "supportTree") final boolean supportTree //
, @JsonProperty(value = "expanded") final boolean expanded //
, @JsonProperty(value = "supportIncludedView") final boolean supportIncludedView //
//
, @JsonProperty("newRecordCaption") final String newRecordCaption //
Expand All @@ -169,7 +175,10 @@ private JSONViewLayout(
this.filters = filters == null ? ImmutableList.of() : ImmutableList.copyOf(filters);

this.supportAttributes = supportAttributes;

this.supportTree = supportTree;
this.expanded = expanded;

this.supportIncludedView = supportIncludedView;

//
Expand Down

0 comments on commit 8c72aec

Please sign in to comment.