Skip to content

Commit

Permalink
CAUSEWAY-3859: Java record refactoring (part 49)
Browse files Browse the repository at this point in the history
  • Loading branch information
andi-huber committed Feb 26, 2025
1 parent 8cc310b commit cd7cf1a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 95 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* with the parent {@link UiAttributeWkt}, allowing also for pending values.
*/
@Log4j2
public record AttributeModelWithMultiChoice(
public record MultiChoiceModel(
/**
* chaining idiom: the {@link UiAttributeWkt} we are chained to
*/
Expand Down Expand Up @@ -69,4 +69,9 @@ public void setObject(final ArrayList<ObjectMemento> unpackedMemento) {
pendingValue().getValue().setValue(getObjectManager().demementify(packedMemento));
}

@Override
public void detach() {
attributeModel.detach();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* with the parent {@link UiAttributeWkt}.
*/
//@Log4j2
public record AttributeModelWithSingleChoice(
public record SingleChoiceModel(
/**
* chaining idiom: the {@link UiAttributeWkt} we are chained to
*/
Expand All @@ -49,4 +49,9 @@ public void setObject(final ObjectMemento memento) {
getObjectManager().demementify(memento));
}

@Override
public void detach() {
attributeModel.detach();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.causeway.viewer.wicket.model.models.interaction.prop;

import org.apache.wicket.model.ChainingModel;
import org.apache.wicket.model.IModel;

import org.apache.causeway.core.metamodel.context.HasMetaModelContext;
import org.apache.causeway.core.metamodel.interactions.managed.PropertyInteraction;
Expand All @@ -28,54 +29,62 @@
import org.apache.causeway.viewer.commons.model.attrib.UiProperty;
import org.apache.causeway.viewer.commons.model.object.HasUiParentObject;
import org.apache.causeway.viewer.commons.model.object.UiObject;
import org.apache.causeway.viewer.wicket.model.models.DelegatingModel;

/**
* <i>Property Interaction</i> model bound to its owner {@link PropertyInteractionWkt}.
*
* @see PropertyInteractionWkt
* @see ChainingModel
*/
public final class UiPropertyWkt
extends DelegatingModel<PropertyInteraction>
public record UiPropertyWkt(
PropertyInteractionWkt delegate)
implements
IModel<PropertyInteraction>,
HasMetaModelContext,
HasUiParentObject<UiObject>,
UiProperty {

private static final long serialVersionUID = 1L;

UiPropertyWkt(
final PropertyInteractionWkt model) {
super(model);
}

public final PropertyInteraction propertyInteraction() {
return getObject();
public PropertyInteraction propertyInteraction() {
return delegate.getObject();
}

public final PropertyInteractionWkt propertyInteractionModel() {
return (PropertyInteractionWkt) getChainedModel();
public PropertyInteractionWkt propertyInteractionModel() {
return delegate;
}

@Override
public final UiObject getParentUiModel() {
public UiObject getParentUiModel() {
return ()->getOwner();
}

@Override
public final ManagedObject getOwner() {
public ManagedObject getOwner() {
return propertyInteraction().getManagedProperty().get().getOwner();
}

@Override
public final OneToOneAssociation getMetaModel() {
public OneToOneAssociation getMetaModel() {
return propertyInteraction().getManagedProperty().get().getMetaModel();
}

@Override
public final PropertyNegotiationModel getPendingPropertyModel() {
public PropertyNegotiationModel getPendingPropertyModel() {
return propertyInteractionModel().propertyNegotiationModel();
}

@Override
public void detach() {
delegate.detach();
}

@Override
public void setObject(final PropertyInteraction object) {
delegate.setObject(object);
}

@Override
public PropertyInteraction getObject() {
return propertyInteraction();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import org.apache.causeway.core.metamodel.object.ManagedObject;
import org.apache.causeway.core.metamodel.objectmanager.memento.ObjectMemento;
import org.apache.causeway.core.metamodel.util.Facets;
import org.apache.causeway.viewer.wicket.model.models.AttributeModelWithMultiChoice;
import org.apache.causeway.viewer.wicket.model.models.AttributeModelWithSingleChoice;
import org.apache.causeway.viewer.wicket.model.models.MultiChoiceModel;
import org.apache.causeway.viewer.wicket.model.models.SingleChoiceModel;
import org.apache.causeway.viewer.wicket.model.models.UiAttributeWkt;
import org.apache.causeway.viewer.wicket.ui.components.attributes.AttributeModelChangeDispatcher;

Expand All @@ -43,11 +43,11 @@ static Select2 create(
var choiceProvider = new ChoiceProvider(attributeModel);
var select2 = attributeModel.isSingular()
? new SingleChoice(id,
new AttributeModelWithSingleChoice(attributeModel),
new SingleChoiceModel(attributeModel),
attributeModel,
choiceProvider)
: new MultiChoice(id,
_Casts.uncheckedCast(new AttributeModelWithMultiChoice(attributeModel)),
_Casts.uncheckedCast(new MultiChoiceModel(attributeModel)),
attributeModel,
choiceProvider);
var component = select2.component();
Expand Down

0 comments on commit cd7cf1a

Please sign in to comment.