Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.causeway.applib.services.bookmark.BookmarkHolder_object;
import org.apache.causeway.applib.services.clock.ClockService;
import org.apache.causeway.applib.services.columnorder.Object_downloadColumnOrderTxtFilesAsZip;
import org.apache.causeway.applib.services.columnorder.Object_patchColumnOrder;
import org.apache.causeway.applib.services.commanddto.conmap.ContentMappingServiceForCommandDto;
import org.apache.causeway.applib.services.commanddto.conmap.ContentMappingServiceForCommandsDto;
import org.apache.causeway.applib.services.commanddto.processor.spi.CommandDtoProcessorServiceIdentity;
Expand Down Expand Up @@ -110,6 +111,7 @@
Dto_downloadXml.class,
Dto_downloadXsd.class,
Object_downloadColumnOrderTxtFilesAsZip.class,
Object_patchColumnOrder.class,
Object_downloadLayout.class,
Object_patchLayout.class,
Object_downloadMetamodelXml.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@

import java.util.Collection;
import java.util.Map;
import java.util.Optional;
import java.util.SortedSet;

import org.apache.causeway.applib.Identifier;
import org.apache.causeway.applib.id.LogicalType;
import org.springframework.lang.Nullable;

/**
* Provides the access to string representations of the packages, classes and
Expand Down Expand Up @@ -52,4 +55,6 @@ public interface ApplicationFeatureRepository {
Collection<ApplicationFeature> allMembers();

SortedSet<ApplicationFeatureId> propertyIdsFor(LogicalType logicalType);

Optional<Identifier> asIdentifier(@Nullable ApplicationFeatureId applicationFeatureId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.causeway.applib.services.columnorder;

import java.util.List;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.inject.Inject;

import org.apache.causeway.applib.Identifier;
import org.apache.causeway.applib.annotation.Action;
import org.apache.causeway.applib.annotation.ActionLayout;
import org.apache.causeway.applib.annotation.DomainObject;
import org.apache.causeway.applib.annotation.Introspection;
import org.apache.causeway.applib.annotation.MemberSupport;
import org.apache.causeway.applib.annotation.Nature;
import org.apache.causeway.applib.annotation.Parameter;
import org.apache.causeway.applib.annotation.ParameterLayout;
import org.apache.causeway.applib.annotation.PrecedingParamsPolicy;
import org.apache.causeway.applib.annotation.Publishing;
import org.apache.causeway.applib.annotation.RestrictTo;
import org.apache.causeway.applib.annotation.SemanticsOf;
import org.apache.causeway.applib.layout.LayoutConstants;
import org.apache.causeway.applib.services.appfeat.ApplicationFeatureId;
import org.apache.causeway.applib.services.appfeat.ApplicationFeatureRepository;
import org.apache.causeway.applib.services.metamodel.MetaModelService;
import org.apache.causeway.applib.services.metamodel.MetaModelService.AssociationsLookup;
import org.apache.causeway.applib.util.Listing;
import org.apache.causeway.applib.util.Listing.MergePolicy;
import org.apache.causeway.commons.collections.Can;
import org.apache.causeway.commons.internal.exceptions._Exceptions;
import org.springframework.lang.Nullable;

import lombok.RequiredArgsConstructor;

/**
* Allows uploading of column order definition, that overrules the default lookup for such information.
*
* @since 4.0 {@index}
*/
@Action(
domainEvent = Object_patchColumnOrder.ActionDomainEvent.class,
semantics = SemanticsOf.IDEMPOTENT,
commandPublishing = Publishing.DISABLED,
executionPublishing = Publishing.DISABLED,
restrictTo = RestrictTo.PROTOTYPING)
@ActionLayout(
cssClassFa = "solid file-arrow-up",
describedAs = "Uploads table column order, to be stored in memory for this object type. "
+ "It overrules the default column order definition lookup. "
+ "On application restart this information is lost.",
fieldSetId = LayoutConstants.FieldSetId.METADATA,
position = ActionLayout.Position.PANEL_DROPDOWN,
sequence = "700.2.4"
)
//framework provided domain objects and mixins should explicitly specify their introspection policy
@DomainObject(nature=Nature.MIXIN, mixinMethod = "act", introspection = Introspection.ANNOTATION_REQUIRED)
@RequiredArgsConstructor
public class Object_patchColumnOrder {

public static class ActionDomainEvent
extends org.apache.causeway.applib.CausewayModuleApplib.ActionDomainEvent<Object_patchColumnOrder> {}

@Inject MetaModelService metaModelService;
@Inject ApplicationFeatureRepository applicationFeatureRepository;

private final Object mixee;

@MemberSupport public Object act(

@Parameter
@ParameterLayout(describedAs = "The 'Feature', for which the patch is to be applied (in-memory), "
+ "that is, "
+ "either for a one-to-many relation (a PARENTED Collection), "
+ "or a domain-type (applies to all STANDALONE Collections of that element-type). "
+ "The Feature either represents a particular one-to-many relation of this domain-type or "
+ "represents the domain-type itself or one of the domain-type's super types. "
+ "The Apache Causeway Programming Model also supports {parent-type, element-type} scoped "
+ "column order definitions, which are not covered by patching yet.")
final ApplicationFeatureId featureId,

@Parameter(precedingParamsPolicy = PrecedingParamsPolicy.RESET)
@ParameterLayout(multiLine = 20, describedAs = "Automaticly filled in are all currently enabled and available "
+ "column-ids, one per line. Those available (but not enabled) are commented out. "
+ "Reorder or remove column-ids as desired.")
final String columnListing) {

var identifier = applicationFeatureRepository.asIdentifier(featureId)
.orElseThrow(); // not found -> unexpected

var listing = listingHandler().parseListing(columnListing);
var columns = Can.ofStream(listing.streamEnabled());

metaModelService.patchColumnOrder(identifier, columns);
return mixee;
}

@MemberSupport public List<ApplicationFeatureId> choicesFeatureId() {
return Stream.concat(
metaModelService.streamTypeHierarchy(mixee.getClass())
.map(ApplicationFeatureId::fromIdentifier),
metaModelService.streamCollections(mixee.getClass())
.map(ApplicationFeatureId::fromIdentifier))
.collect(Collectors.toList());
}

@MemberSupport public String defaultColumnListing(final @Nullable ApplicationFeatureId featureId) {
if(featureId==null)
return "# no feature selected";

var identifier = applicationFeatureRepository.asIdentifier(featureId)
.orElseThrow(); // not found -> unexpected

if(identifier.type().isCollection())
return listing(
metaModelService.parentedAssociationsForColumnRendering(mixee, identifier, AssociationsLookup.AVAILABLE),
metaModelService.parentedAssociationsForColumnRendering(mixee, identifier, AssociationsLookup.ENABLED))
.toString();

if(identifier.type().isClass())
return listing(
metaModelService.standaloneAssociationsForColumnRendering(identifier.logicalType(), AssociationsLookup.AVAILABLE),
metaModelService.standaloneAssociationsForColumnRendering(identifier.logicalType(), AssociationsLookup.ENABLED))
.toString();

throw _Exceptions.illegalArgument("unsupported feature type %s", identifier.type());
}

// -- HELPER

private Listing<String> listing(final Stream<Identifier> availableIds, final Stream<Identifier> enabledIds) {
// all column candidates
var available = listingHandler()
.createListing(availableIds.map(Identifier::memberLogicalName));

// all columns currently rendered
var enabled = listingHandler()
.createListing(enabledIds.map(Identifier::memberLogicalName));

return enabled.merge(MergePolicy.ADD_NEW_AS_DISABLED, available, "#AVAILABLE" /* custom merge header */);
}

private final static Listing.LineAdapter<String> listingHandler() {
return Listing.lineAdapter(String.class, UnaryOperator.identity(), UnaryOperator.identity(), UnaryOperator.identity());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@

import java.util.Optional;
import java.util.function.BiPredicate;
import java.util.stream.Stream;

import javax.inject.Named;

import org.springframework.lang.Nullable;

import org.apache.causeway.applib.Identifier;
import org.apache.causeway.applib.annotation.Action;
import org.apache.causeway.applib.annotation.DomainObject;
import org.apache.causeway.applib.annotation.DomainService;
Expand Down Expand Up @@ -175,4 +176,91 @@ enum Mode {
*/
ObjectGraph exportObjectGraph(final @NonNull BiPredicate<BeanSort, LogicalType> filter);

/**
* Stream of {@link Identifier} representing the <i>Actions</i> of given domainType, including mixed-in ones,
* but excluding <i>Actions</i>, that are only available for PROTOTYPING.
* @since 4.0
*/
Stream<Identifier> streamActions(@Nullable Class<?> domainType);

/**
* Stream of {@link Identifier} representing the <i>Properties</i> of given domainType, including mixed-in ones.
* @since 4.0
*/
Stream<Identifier> streamProperties(@Nullable Class<?> domainType);

/**
* Stream of {@link Identifier} representing the <i>Collections</i> of given domainType, including mixed-in ones.
* @since 4.0
*/
Stream<Identifier> streamCollections(@Nullable Class<?> domainType);

/**
* Stream of {@link Identifier} representing the type hierarchy of given domainType, starting at given domainType,
* going 'up' in the hierarchy, but excluding {@link Object}.
*
* <p> Included are all types in the hierarchy, that are recognized by the Metamodel, recognized Interfaces last.
*
* @apiNote Since 4.0, the Metamodel supports Interfaces acting as element-types for Collections.
* This requires explicit {@link DomainObject} annotations on those Interfaces along with the constraint, that within
* a type hierarchy, every type can have at most one super-type.
*
* @since 4.0
*/
Stream<Identifier> streamTypeHierarchy(@Nullable Class<?> domainType);

/**
* Parameter to lookup associations for column rendering.
*
* @since 4.0
*/
public enum AssociationsLookup {
/**
* The Column Order SPI and Column Order Patching have potential to hide otherwise visible columns.
* This query mode shows all columns, that are not permanently hidden while ignoring hiding from above mechanisms.
*/
AVAILABLE,
/**
* This query mode shows all currently visible columns.
*/
ENABLED;

public boolean isAvailable() { return this==AVAILABLE; }
public boolean isEnabled() { return this==ENABLED; }
}

/**
* Stream of {@link Identifier} representing the <i>Columns</i> for specified PARENTED collection.
*
* <p> Columns returned are those that are either in principle AVAILABLE or currently ENABLED, based on given {@link AssociationsLookup}.
*
* <p> The availability lookup returns {@link Identifier}(s) in no particular order,
* whereas the enablement lookup returns them in same order as rendered.
*
* <p> If parentDomainObject is null returns an empty {@link Stream}.
*
* @since 4.0
*/
Stream<Identifier> parentedAssociationsForColumnRendering(Object parentDomainObject, Identifier collectionId, AssociationsLookup lookup);

/**
* Stream of {@link Identifier} representing the <i>Columns</i> for specified STANDALONE collection.
*
* <p> Columns returned are those that are either in principle AVAILABLE or currently ENABLED, based on given {@link AssociationsLookup}.
*
* <p> The availability lookup returns {@link Identifier}(s) in no particular order,
* whereas the enablement lookup returns them in same order as rendered.
*
* @since 4.0
*/
Stream<Identifier> standaloneAssociationsForColumnRendering(LogicalType logicalType, AssociationsLookup lookup);

/**
* @param identifier either for a TYPE or a COLLECTION
* @param columnsInOrder to be used instead of the default order
*
* @since 4.0
*/
void patchColumnOrder(Identifier identifier, Can<String> columnsInOrder);

}
Loading
Loading