Skip to content

Commit

Permalink
ViewColumn.sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Dec 5, 2017
1 parent 3a8f0dc commit 3a8b18c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
*/
String captionKey() default "";

/** true if user is allowed to sort by this column */
boolean sorting() default true;

/**
* Column layout profiles.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ private static ClassViewColumnDescriptor createClassViewColumnDescriptor(final F
.caption(Services.get(IMsgBL.class).translatable(captionKey))
.widgetType(viewColumnAnn.widgetType())
.editorRenderMode(viewColumnAnn.editor())
.allowSorting(viewColumnAnn.sorting())
.fieldReference(FieldReference.of(field))
.layoutsByViewType(layoutsByViewType)
.build();
Expand All @@ -161,10 +162,11 @@ private static ClassViewColumnDescriptor createClassViewColumnDescriptor(final F
private static DocumentLayoutElementDescriptor.Builder createLayoutElement(final ClassViewColumnDescriptor column)
{
return DocumentLayoutElementDescriptor.builder()
.setGridElement()
.setCaption(column.getCaption())
.setWidgetType(column.getWidgetType())
.setGridElement()
.setViewEditorRenderMode(column.getEditorRenderMode())
.setViewAllowSorting(column.isAllowSorting())
.addField(DocumentLayoutElementFieldDescriptor.builder(column.getFieldName()));
}

Expand Down Expand Up @@ -249,6 +251,7 @@ private static final class ClassViewColumnDescriptor
private final DocumentFieldWidgetType widgetType;
@NonNull
private final ViewEditorRenderMode editorRenderMode;
private final boolean allowSorting;
@NonNull
private final FieldReference fieldReference;
@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ public static JSONDocumentLayoutElement debuggingField(final String fieldName, f
@JsonProperty("viewEditorRenderMode")
@JsonInclude(JsonInclude.Include.NON_NULL)
private final String viewEditorRenderMode;
@JsonProperty("sortable")
@JsonInclude(JsonInclude.Include.NON_NULL)
private final Boolean viewAllowSorting;


@JsonProperty("fields")
@JsonInclude(Include.NON_EMPTY)
Expand Down Expand Up @@ -155,6 +159,7 @@ private JSONDocumentLayoutElement(final DocumentLayoutElementDescriptor element,

gridAlign = JSONLayoutAlign.fromNullable(element.getGridAlign());
viewEditorRenderMode = element.getViewEditorRenderMode() != null ? element.getViewEditorRenderMode().toJson() : null;
viewAllowSorting = element.isGridElement() ? element.isViewAllowSorting() : null;

fields = JSONDocumentLayoutElementField.ofSet(element.getFields(), jsonOpts);
}
Expand All @@ -174,6 +179,7 @@ private JSONDocumentLayoutElement(final String fieldName, final DocumentFieldWid
size = null;
gridAlign = JSONLayoutAlign.right;
viewEditorRenderMode = null;
viewAllowSorting = null;

fields = ImmutableSet.of(new JSONDocumentLayoutElementField( //
fieldName, (JSONFieldType)null // type
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package de.metas.ui.web.window.descriptor;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -43,8 +42,7 @@
* #L%
*/

@SuppressWarnings("serial")
public final class DocumentLayoutElementDescriptor implements Serializable
public final class DocumentLayoutElementDescriptor
{
public static final Builder builder()
{
Expand Down Expand Up @@ -75,6 +73,7 @@ public static final Builder builder(final DocumentFieldDescriptor... fields)
}

private final String internalName;
private final boolean gridElement;

private final ITranslatableString caption;
private final ITranslatableString description;
Expand All @@ -90,6 +89,7 @@ public static final Builder builder(final DocumentFieldDescriptor... fields)

private final LayoutAlign gridAlign;
private final ViewEditorRenderMode viewEditorRenderMode;
private final boolean viewAllowSorting;

private final Set<DocumentLayoutElementFieldDescriptor> fields;

Expand All @@ -99,9 +99,9 @@ public static final Builder builder(final DocumentFieldDescriptor... fields)

private DocumentLayoutElementDescriptor(final Builder builder)
{
super();

internalName = builder.getInternalName();
gridElement = builder.isGridElement();

caption = builder.getCaption();
description = builder.getDescription();

Expand All @@ -115,6 +115,7 @@ private DocumentLayoutElementDescriptor(final Builder builder)

gridAlign = builder.getGridAlign();
viewEditorRenderMode = builder.getViewEditorRenderMode();
viewAllowSorting = builder.isViewAllowSorting();

advancedField = builder.isAdvancedField();

Expand All @@ -134,6 +135,11 @@ public String toString()
.add("fields", fields.isEmpty() ? null : fields)
.toString();
}

public boolean isGridElement()
{
return gridElement;
}

public String getCaption(final String adLanguage)
{
Expand Down Expand Up @@ -193,6 +199,11 @@ public ViewEditorRenderMode getViewEditorRenderMode()
return viewEditorRenderMode;
}

public boolean isViewAllowSorting()
{
return viewAllowSorting;
}

public boolean isAdvancedField()
{
return advancedField;
Expand Down Expand Up @@ -235,6 +246,7 @@ public static final class Builder

private boolean _gridElement = false;
private ViewEditorRenderMode viewEditorRenderMode = null;
private boolean viewAllowSorting = true;

private boolean _advancedField = false;
private final LinkedHashMap<String, DocumentLayoutElementFieldDescriptor.Builder> _fieldsBuilders = new LinkedHashMap<>();
Expand Down Expand Up @@ -497,6 +509,11 @@ public boolean isConsumed()
return consumed;
}

public boolean isGridElement()
{
return _gridElement;
}

/**
* Flags this element as a "grid element".
*/
Expand All @@ -505,7 +522,7 @@ public Builder setGridElement()
_gridElement = true;
return this;
}

/**
* Reset the "grid element" flag.
*
Expand All @@ -521,7 +538,7 @@ public Builder setNotGridElement()

private LayoutAlign getGridAlign()
{
return _gridElement ? getWidgetType().getGridAlign() : null;
return isGridElement() ? getWidgetType().getGridAlign() : null;
}

public Builder setViewEditorRenderMode(final ViewEditorRenderMode gridEditorRenderMode)
Expand All @@ -534,6 +551,17 @@ private ViewEditorRenderMode getViewEditorRenderMode()
{
return viewEditorRenderMode;
}

public Builder setViewAllowSorting(boolean viewAllowSorting)
{
this.viewAllowSorting = viewAllowSorting;
return this;
}

private boolean isViewAllowSorting()
{
return viewAllowSorting;
}

public Builder setButtonActionDescriptor(final ButtonFieldActionDescriptor buttonActionDescriptor)
{
Expand Down

0 comments on commit 3a8b18c

Please sign in to comment.