Skip to content

Commit

Permalink
CAUSEWAY-3859: Java record refactoring (part 47)
Browse files Browse the repository at this point in the history
  • Loading branch information
andi-huber committed Feb 26, 2025
1 parent c6bcceb commit 5cfc8c8
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,10 @@ private Optional<Bookmark> createBookmark() {
@Override
public final void refreshViewmodel(final @Nullable Supplier<Bookmark> bookmarkSupplier) {
var shouldRefresh = getTransactionService().currentTransactionId()
.map(this::shouldRefresh)
.orElse(true); // if there is no current transaction, refresh regardless; unexpected state, might fail later
.map(this::shouldRefresh)
.orElse(true); // if there is no current transaction, refresh regardless; unexpected state, might fail later

if(!shouldRefresh) {
return;
}
if(!shouldRefresh) return;

if(isBookmarkMemoized()) {
reloadViewmodelFromMemoizedBookmark();
Expand Down
1 change: 0 additions & 1 deletion viewers/wicket/model/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
exports org.apache.causeway.viewer.wicket.model.hints;
exports org.apache.causeway.viewer.wicket.model.itemreuse;
exports org.apache.causeway.viewer.wicket.model.models;
exports org.apache.causeway.viewer.wicket.model.models.binding;
exports org.apache.causeway.viewer.wicket.model;
exports org.apache.causeway.viewer.wicket.model.links;
exports org.apache.causeway.viewer.wicket.model.models.interaction.act;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,19 @@
*/
package org.apache.causeway.viewer.wicket.model.models;

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

import org.apache.causeway.core.metamodel.object.ManagedObject;

import org.jspecify.annotations.NonNull;
public record BooleanAttributeModel(
boolean isPrimitive,
UiAttributeWkt attributeModel) implements IModel<Boolean> {

public class BooleanModel
extends ChainingModel<Boolean> {

private static final long serialVersionUID = 1L;

public static BooleanModel forAttributeModel(final @NonNull UiAttributeWkt attributeModel) {
return new BooleanModel(attributeModel);
}

final boolean isPrimitive;

protected BooleanModel(final UiAttributeWkt attributeModel) {
super(attributeModel);

var spec = attributeModel().getElementType();
this.isPrimitive = spec.getFullIdentifier().equals("boolean");
public BooleanAttributeModel(final UiAttributeWkt attributeModel) {
this(
attributeModel.getElementType().getFullIdentifier().equals("boolean"),
attributeModel);
}

@Override
Expand Down Expand Up @@ -82,7 +71,7 @@ public IModel<String> asStringModel(
private static final long serialVersionUID = 1L;

@Override public String getObject() {
final Boolean bool = BooleanModel.this.getObject();
final Boolean bool = BooleanAttributeModel.this.getObject();
return bool == null
? notSetLiteral // '(not set)'
: bool
Expand All @@ -92,10 +81,4 @@ public IModel<String> asStringModel(
};
}

// -- HELPER

protected UiAttributeWkt attributeModel() {
return (UiAttributeWkt) super.getTarget();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*/
package org.apache.causeway.viewer.wicket.model.models;

import org.apache.wicket.model.ChainingModel;

import org.apache.causeway.commons.internal.exceptions._Exceptions;
import org.apache.causeway.core.metamodel.commons.ViewOrEditMode;
import org.apache.causeway.core.metamodel.object.ManagedObject;
Expand All @@ -29,27 +27,17 @@
/**
* Wraps a {@link UiAttributeWkt} to act as an {@link ObjectAdapterModel}.
*/
public final class ChainingObjectModel
extends ChainingModel<ManagedObject>
public record ChainingObjectModel(
/**
* chaining idiom: the {@link UiAttributeWkt} we are chained to
*/
UiAttributeWkt attributeModel)
implements ObjectAdapterModel {

private static final long serialVersionUID = 1L;

public static ChainingObjectModel chain(final UiAttributeWkt attributeModel) {
return new ChainingObjectModel(attributeModel);
}

private ChainingObjectModel(final UiAttributeWkt attributeModel) {
super(attributeModel);
}

/**
* chaining idiom: the {@link UiAttributeWkt} we are chained to
*/
public UiAttributeWkt attributeModel() {
return (UiAttributeWkt) super.getTarget();
}

/**
* chaining idiom: the 'local' model derived from the chain
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* 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.viewer.wicket.model.models;

import org.apache.wicket.model.IModel;

//TODO[causeway-viewer-wicket-model-CAUSEWAY-3859] intermediate refactoring helper, perhaps remove later
public class DelegatingModel<T> implements IModel<T> {
private static final long serialVersionUID = 1L;

private IModel<T> delegate;

public DelegatingModel(final IModel<T> modelObject) {
this.delegate = modelObject;
}

@Override
public final void detach() {
if(delegate!=null) delegate.detach();
}

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

@Override
public final T getObject() {
return delegate!=null
? delegate.getObject()
: null;
}

public final IModel<?> getChainedModel() {
return delegate;
}

@Override
public String toString() {
return new StringBuilder("Model:classname=[")
.append(getClass().getName()).append(']')
.append(":nestedModel=[").append(delegate).append(']')
.toString();
}

public final Object getInnermostModelOrObject() {
Object object = delegate;
while (object instanceof IModel) {
Object tmp = ((IModel<?>)object).getObject();
if (tmp == object) break;
object = tmp;
}
return object;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import java.util.Optional;
import java.util.OptionalInt;

import org.apache.wicket.model.ChainingModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.util.convert.IConverter;
import org.jspecify.annotations.NonNull;

import org.apache.causeway.applib.annotation.PromptStyle;
import org.apache.causeway.commons.collections.Can;
Expand All @@ -42,7 +42,6 @@
import org.apache.causeway.viewer.wicket.model.value.ConverterBasedOnValueSemantics;

import lombok.Getter;
import org.jspecify.annotations.NonNull;
import lombok.Setter;

/**
Expand All @@ -64,8 +63,7 @@
*/
//@Log4j2
public abstract class UiAttributeWkt
extends ChainingModel<ManagedObject>
implements HasRenderingHints, UiAttribute, FormExecutorContext {
implements IModel<ManagedObject>, HasRenderingHints, UiAttribute, FormExecutorContext {

private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -98,7 +96,6 @@ protected UiAttributeWkt(
final @NonNull UiObjectWkt parentEntityModel,
final @NonNull ViewOrEditMode viewOrEdit,
final @NonNull RenderingHint renderingHint) {
super(parentEntityModel); // the so called target model, we are chaining us to
this.parentEntityModel = parentEntityModel;
this.renderingHint = renderingHint;
this.viewOrEditMode = viewOrEdit;
Expand Down

This file was deleted.

Loading

0 comments on commit 5cfc8c8

Please sign in to comment.