This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/causeway.git
The following commit(s) were added to refs/heads/master by this push:
new 008da0c45d CAUSEWAY-3415: adds section separator in coll. present.
dropdown
008da0c45d is described below
commit 008da0c45db0a9e0ae45192b2f5c04911cdab254
Author: Andi Huber <[email protected]>
AuthorDate: Thu Jun 29 07:09:34 2023 +0200
CAUSEWAY-3415: adds section separator in coll. present. dropdown
- for UI consistency
---
.../CollectionPresentationSelectorPanel.html | 7 +-
.../CollectionPresentationSelectorPanel.java | 118 +++++++++++++++------
2 files changed, 90 insertions(+), 35 deletions(-)
diff --git
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/collection/selector/CollectionPresentationSelectorPanel.html
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/collection/selector/CollectionPresentationSelectorPanel.html
index eafbaef32d..949e0e73f5 100644
---
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/collection/selector/CollectionPresentationSelectorPanel.html
+++
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/collection/selector/CollectionPresentationSelectorPanel.html
@@ -24,14 +24,19 @@
<div class="viewLinks" wicket:id="views">
<button type="button" class="btn btn-link dropdown-toggle"
data-bs-toggle="dropdown" style="text-decoration: none">
<span wicket:id="viewButtonIcon" class="ViewLinkItem"></span>
-<!-- <span wicket:id="viewButtonTitle"
class="ViewLinkItemTitle"></span> -->
<span class="caret"></span>
</button>
<ul wicket:id="viewList" class="dropdown-menu dropdown-menu-right"
role="menu">
<li wicket:id="viewItem">
+
+ <!-- either horizontal bar -->
+ <div wicket:id="sectionSeparator"
class="list-separator"></div>
+
+ <!-- or section label -->
<span wicket:id="sectionLabel"
class="sectionLabel">[sectionLabel]</span>
+ <!-- or link entry -->
<a href="#" wicket:id="viewLink" class="dropdown-item">
<span wicket:id="viewItemIcon"
class="ViewLinkItem"></span>
<span wicket:id="viewItemTitle"
class="ViewLinkItemTitle">[link title]</span>
diff --git
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/collection/selector/CollectionPresentationSelectorPanel.java
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/collection/selector/CollectionPresentationSelectorPanel.java
index 3bd7b11d85..e8677ab22b 100644
---
a/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/collection/selector/CollectionPresentationSelectorPanel.java
+++
b/viewers/wicket/ui/src/main/java/org/apache/causeway/viewer/wicket/ui/components/collection/selector/CollectionPresentationSelectorPanel.java
@@ -47,7 +47,9 @@ import org.apache.causeway.viewer.wicket.ui.util.Wkt;
import org.apache.causeway.viewer.wicket.ui.util.WktComponents;
import org.apache.causeway.viewer.wicket.ui.util.WktLinks;
+import lombok.Getter;
import lombok.NonNull;
+import lombok.RequiredArgsConstructor;
import lombok.val;
/**
@@ -67,6 +69,7 @@ extends PanelAbstract<DataTableModel, EntityCollectionModel> {
private static final String ID_VIEW_ITEM_TITLE = "viewItemTitle";
private static final String ID_VIEW_ITEM_ICON = "viewItemIcon";
private static final String ID_VIEW_BUTTON_ICON = "viewButtonIcon";
+ private static final String ID_SECTION_SEPARATOR = "sectionSeparator";
private static final String ID_SECTION_LABEL = "sectionLabel";
private final CollectionPresentationSelectorHelper selectorHelper;
@@ -127,19 +130,31 @@ extends PanelAbstract<DataTableModel,
EntityCollectionModel> {
final Label viewButtonIcon = Wkt.labelAdd(views, ID_VIEW_BUTTON_ICON,
"");
Wkt.listViewAdd(container, ID_VIEW_ITEM, sorted(componentFactories),
item->{
- val eitherComponentFactoryOrSectionLabel = item.getModelObject();
+ val repeatedViewEntry = item.getModelObject();
+ val repeatedViewEntryKind =
repeatedViewEntry.repeatedViewEntryKind;
- if(eitherComponentFactoryOrSectionLabel.isSectionLabel()) {
- Wkt.cssAppend(item, "list-section-label");
- Wkt.labelAdd(item, ID_SECTION_LABEL,
eitherComponentFactoryOrSectionLabel.getSectionLabel());
+ Wkt.cssAppend(item,
repeatedViewEntryKind.getCssClassForLiElement());
+
+ switch(repeatedViewEntryKind) {
+ case SECTION_SEPARATOR:
+ WktComponents.permanentlyHide(item, ID_SECTION_LABEL);
+ WktComponents.permanentlyHide(item, ID_VIEW_LINK);
+ Wkt.labelAdd(item, ID_SECTION_SEPARATOR, "");
+ return;
+ case SECTION_LABEL:
+ WktComponents.permanentlyHide(item, ID_SECTION_SEPARATOR);
WktComponents.permanentlyHide(item, ID_VIEW_LINK);
+ Wkt.labelAdd(item, ID_SECTION_LABEL,
repeatedViewEntry.getSectionLabel());
+ return;
+ case LINK_ENTRY:
+ WktComponents.permanentlyHide(item, ID_SECTION_SEPARATOR);
+ WktComponents.permanentlyHide(item, ID_SECTION_LABEL);
+ break; // fall through
+ default:
return;
}
- Wkt.cssAppend(item, "viewItem");
- WktComponents.permanentlyHide(item, ID_SECTION_LABEL);
-
- final ComponentFactory componentFactory =
eitherComponentFactoryOrSectionLabel.getComponentFactory();
+ final ComponentFactory componentFactory =
repeatedViewEntry.getComponentFactory();
// add direct download link instead of a panel
if(componentFactory.getComponentType() ==
UiComponentType.COLLECTION_CONTENTS_EXPORT) {
@@ -150,7 +165,7 @@ extends PanelAbstract<DataTableModel,
EntityCollectionModel> {
item.addOrReplace(downloadLink);
// add title and icon to the link
-
EitherComponentFactoryOrSectionLabel.addLinkWithIconAndTitle(item,
downloadLink);
+ RepeatedViewEntry.addLinkWithIconAndTitle(item, downloadLink);
return;
}
@@ -166,7 +181,7 @@ extends PanelAbstract<DataTableModel,
EntityCollectionModel> {
/* [CAUSEWAY-3415] do a full page reload when required,
* to properly trigger all client side java-script, that
decorates HTML (datatable.net, vega, ...) */
-
if(eitherComponentFactoryOrSectionLabel.isPageReloadRequiredOnTableViewActivation())
{
+
if(repeatedViewEntry.isPageReloadRequiredOnTableViewActivation()) {
linksSelectorPanel.reloadPage();
} else {
target.add(linksSelectorPanel, views);
@@ -174,11 +189,11 @@ extends PanelAbstract<DataTableModel,
EntityCollectionModel> {
});
// add title and icon to the link
- EitherComponentFactoryOrSectionLabel.addLinkWithIconAndTitle(item,
link);
+ RepeatedViewEntry.addLinkWithIconAndTitle(item, link);
// mark the selected item as active
- if (eitherComponentFactoryOrSectionLabel.isSelectedIn(this)) {
-
eitherComponentFactoryOrSectionLabel.markAsActive(viewButtonIcon, link);
+ if (repeatedViewEntry.isSelectedIn(this)) {
+ repeatedViewEntry.markAsActive(viewButtonIcon, link);
}
});
@@ -192,31 +207,37 @@ extends PanelAbstract<DataTableModel,
EntityCollectionModel> {
* @param filter
* @see CollectionContentsAsFactory#orderOfAppearanceInUiDropdown()
*/
- private List<EitherComponentFactoryOrSectionLabel> sorted(final
Can<ComponentFactory> componentFactories) {
+ private List<RepeatedViewEntry> sorted(final Can<ComponentFactory>
componentFactories) {
val presentations = sorted(componentFactories,
_Util.filterTablePresentations());
val exports = sorted(componentFactories, _Util.filterTableExports());
- val sortedWithSeparators = new
ArrayList<EitherComponentFactoryOrSectionLabel>(
+ val sortedWithSeparators = new ArrayList<RepeatedViewEntry>(
presentations.size() + exports.size() + 2); // heap
optimization, not strictly required
+ boolean needsSpacer = false;
+
if(!presentations.isEmpty()) {
-
sortedWithSeparators.add(EitherComponentFactoryOrSectionLabel.of(translate("Presentations")));
+
sortedWithSeparators.add(RepeatedViewEntry.sectionLabel(translate("Presentations")));
sortedWithSeparators.addAll(presentations);
+ needsSpacer = true;
}
if(!exports.isEmpty()) {
-
sortedWithSeparators.add(EitherComponentFactoryOrSectionLabel.of(translate("Exports")));
+ if(needsSpacer) {
+ sortedWithSeparators.add(RepeatedViewEntry.sectionSeparator());
+ }
+
sortedWithSeparators.add(RepeatedViewEntry.sectionLabel(translate("Exports")));
sortedWithSeparators.addAll(exports);
}
return sortedWithSeparators;
}
- private List<EitherComponentFactoryOrSectionLabel> sorted(
+ private List<RepeatedViewEntry> sorted(
final Can<ComponentFactory> componentFactories,
final Predicate<? super ComponentFactory> filter) {
- final List<EitherComponentFactoryOrSectionLabel> sorted =
componentFactories.stream()
+ final List<RepeatedViewEntry> sorted = componentFactories.stream()
.filter(filter)
.sorted(_Util.orderByOrderOfAppearanceInUiDropdown())
- .map((final ComponentFactory
factory)->EitherComponentFactoryOrSectionLabel.of(factory))
+ .map((final ComponentFactory
factory)->RepeatedViewEntry.linkEntry(factory))
.collect(Collectors.toList());
return sorted;
}
@@ -227,47 +248,76 @@ extends PanelAbstract<DataTableModel,
EntityCollectionModel> {
new CausewaySelectorEvent(component,
CollectionPresentationSelectorHelper.UIHINT_EVENT_VIEW_KEY, viewName, target));
}
+ @RequiredArgsConstructor
+ enum RepeatedViewEntryKind {
+ SECTION_SEPARATOR("list-separator"),
+ SECTION_LABEL("list-section-label"),
+ LINK_ENTRY("viewItem");
+ @Getter private final String cssClassForLiElement;
+ boolean isSectionSeparator() { return this==SECTION_SEPARATOR;}
+ boolean isSectionLabel() { return this==SECTION_LABEL;}
+ boolean isLinkEntry() { return this==LINK_ENTRY;}
+ }
+
@lombok.Value
- static class EitherComponentFactoryOrSectionLabel implements Serializable {
+ static class RepeatedViewEntry implements Serializable {
private static final long serialVersionUID = 1L;
- public static EitherComponentFactoryOrSectionLabel of(final @NonNull
ComponentFactory componentFactory) {
- return new EitherComponentFactoryOrSectionLabel(componentFactory,
null);
+
+ // -- FACTORIES
+
+ public static RepeatedViewEntry sectionSeparator() {
+ return new
RepeatedViewEntry(RepeatedViewEntryKind.SECTION_SEPARATOR, null, null);
}
- public static EitherComponentFactoryOrSectionLabel of(final @NonNull
String sectionLabel) {
- return new EitherComponentFactoryOrSectionLabel(null,
sectionLabel);
+ public static RepeatedViewEntry sectionLabel(final @NonNull String
sectionLabel) {
+ return new RepeatedViewEntry(RepeatedViewEntryKind.SECTION_LABEL,
null, sectionLabel);
}
+ public static RepeatedViewEntry linkEntry(final @NonNull
ComponentFactory componentFactory) {
+ return new RepeatedViewEntry(RepeatedViewEntryKind.LINK_ENTRY,
componentFactory, null);
+ }
+
+ // -- CONSTRUCTION
+
+ final @NonNull RepeatedViewEntryKind repeatedViewEntryKind;
final ComponentFactory componentFactory;
final String sectionLabel;
- boolean isComponentFactory() { return componentFactory!=null; }
- boolean isSectionLabel() { return sectionLabel!=null; }
+
+ // -- PREDICATES
+
boolean isSelectedIn(final CollectionPresentationSelectorPanel panel) {
- return isComponentFactory()
+ return repeatedViewEntryKind.isLinkEntry()
&& componentFactory == panel.selectedComponentFactory;
}
boolean isPageReloadRequiredOnTableViewActivation() {
- return isComponentFactory()
+ return repeatedViewEntryKind.isLinkEntry()
&&
_Util.isPageReloadRequiredOnTableViewActivation(componentFactory);
}
+
+ // -- UPDATE STATE
+
void markAsActive(final Label viewButtonIcon, final
AjaxLinkNoPropagate link) {
final IModel<String> cssClass =
_Util.cssClassFor(componentFactory, viewButtonIcon);
Wkt.cssReplace(viewButtonIcon, "ViewLinkItem " +
cssClass.getObject());
Wkt.cssAppend(link, "active");
link.setEnabled(false);
}
+
// -- UTILITY
+
static void addLinkWithIconAndTitle(
- final @NonNull ListItem<EitherComponentFactoryOrSectionLabel>
item,
+ final @NonNull ListItem<RepeatedViewEntry> item,
final @NonNull MarkupContainer link) {
WktLinks.listItemAsDropdownLink(item, link,
- ID_VIEW_ITEM_TITLE,
EitherComponentFactoryOrSectionLabel::nameFor,
+ ID_VIEW_ITEM_TITLE, RepeatedViewEntry::nameFor,
ID_VIEW_ITEM_ICON, null,
- EitherComponentFactoryOrSectionLabel::cssClassFor);
+ RepeatedViewEntry::cssClassFor);
}
+
// -- HELPER
- private static IModel<String> nameFor(final
EitherComponentFactoryOrSectionLabel either) {
+
+ private static IModel<String> nameFor(final RepeatedViewEntry either) {
return _Util.nameFor(either.getComponentFactory());
}
- private static IModel<String> cssClassFor(final
EitherComponentFactoryOrSectionLabel either, final Label viewIcon) {
+ private static IModel<String> cssClassFor(final RepeatedViewEntry
either, final Label viewIcon) {
return _Util.cssClassFor(either.getComponentFactory(), viewIcon);
}
}