Skip to content

Commit

Permalink
JSONViewLayout.collapsible and expandedDepth
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Jun 9, 2017
1 parent 45fc4c1 commit 560cdcc
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 76 deletions.
2 changes: 1 addition & 1 deletion src/main/java/de/metas/ui/web/view/SqlViewFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public ViewLayout getViewLayout(final WindowId windowId, final JSONViewDataType

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

@Override
Expand Down
86 changes: 61 additions & 25 deletions src/main/java/de/metas/ui/web/view/descriptor/ViewLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,16 @@ public static final Builder builder()
private final String idFieldName;

private final boolean hasAttributesSupport;
private final boolean hasTreeSupport;
private final boolean hasIncludedViewSupport;
private final boolean treeExpanded;
private final String allowNewCaption;

private final boolean hasTreeSupport;
private final boolean treeCollapsible;
private final int treeExpandedDepth;
public static final int TreeExpandedDepth_AllCollapsed = 0;
public static final int TreeExpandedDepth_ExpandedFirstLevel = 1;
public static final int TreeExpandedDepth_AllExpanded = 100;

// ETag support
private static final AtomicInteger nextETagVersionSupplier = new AtomicInteger(1);
private final ETag eTag;
Expand All @@ -94,18 +99,22 @@ private ViewLayout(final Builder builder)
idFieldName = builder.getIdFieldName();

hasAttributesSupport = builder.hasAttributesSupport;

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

treeCollapsible = builder.treeCollapsible;
treeExpandedDepth = builder.treeExpandedDepth;

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, final boolean treeExpanded)
private ViewLayout(final ViewLayout from,
final ImmutableList<DocumentFilterDescriptor> filters,
final String allowNewCaption,
final boolean hasTreeSupport, final boolean treeCollapsible, final int treeExpandedDepth)
{
super();
windowId = from.windowId;
Expand All @@ -123,7 +132,8 @@ private ViewLayout(final ViewLayout from, final ImmutableList<DocumentFilterDesc

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

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

public ViewLayout withFiltersAndTreeSupport(final Collection<DocumentFilterDescriptor> filtersToSet, final boolean hasTreeSupportToSet, final Boolean treeExpanded)
public ViewLayout withFiltersAndTreeSupport(final Collection<DocumentFilterDescriptor> filtersToSet,
final boolean hasTreeSupportToSet, final Boolean treeCollapsibleToSet, final Integer treeExpandedDepthToSet)
{
final ImmutableList<DocumentFilterDescriptor> filtersToSetEffective = filtersToSet != null ? ImmutableList.copyOf(filtersToSet) : ImmutableList.of();
final boolean treeExpandedEffective = treeExpanded != null ? treeExpanded.booleanValue() : this.treeExpanded;
final boolean treeCollapsibleEffective = treeCollapsibleToSet != null ? treeCollapsibleToSet.booleanValue() : treeCollapsible;
final int treeExpandedDepthEffective = treeExpandedDepthToSet != null ? treeExpandedDepthToSet.intValue() : treeExpandedDepth;

// If there will be no change then return this
if (Objects.equals(filters, filtersToSetEffective)
&& this.hasTreeSupport == hasTreeSupportToSet
&& this.treeExpanded == treeExpandedEffective)
&& hasTreeSupport == hasTreeSupportToSet
&& treeCollapsible == treeCollapsibleEffective
&& treeExpandedDepth == treeExpandedDepthEffective)
{
return this;
}

return new ViewLayout(this, filtersToSetEffective, allowNewCaption, hasTreeSupportToSet, treeExpandedEffective);
// Create a copy of this layout and override what was required
return new ViewLayout(this,
filtersToSetEffective,
allowNewCaption,
hasTreeSupportToSet, treeCollapsibleEffective, treeExpandedDepthEffective);
}

public ViewLayout withAllowNewRecordIfPresent(final Optional<String> allowNewCaption)
Expand All @@ -205,13 +224,16 @@ public ViewLayout withAllowNewRecordIfPresent(final Optional<String> allowNewCap
return this;
}

final String allowNewCaptionToSet = allowNewCaption.get();
if (Objects.equals(this.allowNewCaption, allowNewCaptionToSet))
final String allowNewCaptionEffective = allowNewCaption.get();
if (Objects.equals(this.allowNewCaption, allowNewCaptionEffective))
{
return this;
}

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

public List<DocumentLayoutElementDescriptor> getElements()
Expand All @@ -238,10 +260,15 @@ public boolean isTreeSupport()
{
return hasTreeSupport;
}

public boolean isTreeExpanded()

public boolean isTreeCollapsible()
{
return treeCollapsible;
}

public int getTreeExpandedDepth()
{
return treeExpanded;
return treeExpandedDepth;
}

public boolean isIncludedViewSupport()
Expand Down Expand Up @@ -280,10 +307,12 @@ public static final class Builder
private Collection<DocumentFilterDescriptor> filters = null;

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

private boolean hasTreeSupport = false;
private boolean treeCollapsible = false;
private int treeExpandedDepth = TreeExpandedDepth_AllExpanded;

private final List<DocumentLayoutElementDescriptor.Builder> elementBuilders = new ArrayList<>();

private String idFieldName;
Expand Down Expand Up @@ -428,22 +457,29 @@ public Builder setHasAttributesSupport(final boolean hasAttributesSupport)
return this;
}

public Builder setHasIncludedViewSupport(final boolean hasIncludedViewSupport)
{
this.hasIncludedViewSupport = hasIncludedViewSupport;
return this;
}

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

public Builder setTreeCollapsible(final boolean treeCollapsible)
{
this.treeExpanded = treeExpanded;
this.treeCollapsible = treeCollapsible;
return this;
}

public Builder setHasIncludedViewSupport(final boolean hasIncludedViewSupport)
public Builder setTreeExpandedDepth(final int treeExpandedDepth)
{
this.hasIncludedViewSupport = hasIncludedViewSupport;
this.treeExpandedDepth = treeExpandedDepth;
return this;
}

}
}
76 changes: 26 additions & 50 deletions src/main/java/de/metas/ui/web/view/json/JSONViewLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
Expand Down Expand Up @@ -65,7 +64,6 @@ public static JSONViewLayout of(
@JsonInclude(JsonInclude.Include.NON_NULL)
private final WindowId windowId;


@JsonProperty("caption")
@JsonInclude(JsonInclude.Include.NON_NULL)
private final String caption;
Expand Down Expand Up @@ -96,8 +94,12 @@ public static JSONViewLayout of(
//
@JsonProperty("supportTree")
private final boolean supportTree;
@JsonProperty("expanded")
private final boolean expanded;
@JsonProperty("collapsible")
@JsonInclude(JsonInclude.Include.NON_NULL)
private final Boolean collapsible;
@JsonProperty("expandedDepth")
@JsonInclude(JsonInclude.Include.NON_NULL)
private final Integer expandedDepth;
//
@JsonProperty("supportIncludedView")
private final boolean supportIncludedView;
Expand Down Expand Up @@ -137,54 +139,28 @@ 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();
}

@JsonCreator
private JSONViewLayout(
@JsonProperty("windowId") final WindowId windowId //
, @JsonProperty("caption") final String caption //
, @JsonProperty("description") final String description //
, @JsonProperty("emptyResultText") final String emptyResultText //
, @JsonProperty("emptyResultHint") final String emptyResultHint //
, @JsonProperty("elements") final List<JSONDocumentLayoutElement> elements //
, @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 //
, @JsonProperty("supportNewRecord") final boolean supportNewRecord //
)
{
super();
this.windowId = windowId;
this.type = windowId;

this.caption = caption;
this.description = description;
this.emptyResultText = emptyResultText;
this.emptyResultHint = emptyResultHint;

this.elements = elements == null ? ImmutableList.of() : ImmutableList.copyOf(elements);
this.filters = filters == null ? ImmutableList.of() : ImmutableList.copyOf(filters);

this.supportAttributes = supportAttributes;

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

this.supportIncludedView = supportIncludedView;

//
// New record support
this.supportNewRecord = supportNewRecord;
this.newRecordCaption = newRecordCaption;
// Tree
supportTree = layout.isTreeSupport();
if (supportTree)
{
collapsible = layout.isTreeCollapsible();
if (collapsible)
{
expandedDepth = layout.getTreeExpandedDepth();
}
else
{
expandedDepth = null;
}
}
else
{
collapsible = null;
expandedDepth = null;
}
}

@Override
Expand Down Expand Up @@ -254,7 +230,7 @@ public void enableNewRecord(final String newRecordCaption)
supportNewRecord = true;
this.newRecordCaption = newRecordCaption;
}

public void setViewId(final String viewId)
{
this.viewId = viewId;
Expand Down

0 comments on commit 560cdcc

Please sign in to comment.