Skip to content

Commit

Permalink
CAUSEWAY-3859: Java record refactoring (part 50)
Browse files Browse the repository at this point in the history
  • Loading branch information
andi-huber committed Feb 26, 2025
1 parent cd7cf1a commit ac86f6c
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.causeway.viewer.commons.applib.services.menu.model;

import java.io.Serializable;
import java.util.Locale;

import org.jspecify.annotations.Nullable;
Expand All @@ -28,7 +29,7 @@

public record NavbarSection(
DomainServiceLayout.MenuBar menuBarSelect,
Can<MenuDropdown> topLevelEntries) {
Can<MenuDropdown> topLevelEntries) implements Serializable {

public String cssClass() {
return menuBarSelect.name().toLowerCase(Locale.ENGLISH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
*/
package org.apache.causeway.viewer.wicket.model.models;

import org.apache.wicket.model.IModel;

import org.apache.causeway.core.config.CausewayConfiguration;

/**
* Model providing welcome text.
*/
public final class AboutModel
extends ModelAbstract<CausewayConfiguration.Viewer.Common.Application> {

private static final long serialVersionUID = 1L;
public record AboutModel(CausewayConfiguration.Viewer.Common.Application applicationSettings)
implements IModel<CausewayConfiguration.Viewer.Common.Application> {

@Override
protected CausewayConfiguration.Viewer.Common.Application load() {
return getApplicationSettings();
public CausewayConfiguration.Viewer.Common.Application getObject() {
return applicationSettings();
}

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

import org.apache.wicket.model.IModel;

import org.apache.causeway.viewer.commons.applib.services.menu.model.NavbarSection;
/**
* Backing model for actions of application services menu bar (typically, as
* displayed along the top or side of the page).
*/
public class ServiceActionsModel extends ModelAbstract<NavbarSection> {

private static final long serialVersionUID = 1L;

private final NavbarSection navBarSection;

/**
* @param navBarSection - may be null in special case of rendering the tertiary menu on the error page.
*/
public ServiceActionsModel(
final NavbarSection navBarSection) {

this.navBarSection = navBarSection;
}
public record ServiceActionsModel(
/** may be null in special case of rendering the tertiary menu on the error page */
NavbarSection navBarSection) implements IModel<NavbarSection> {

@Override
protected NavbarSection load() {
public NavbarSection getObject() {
return navBarSection;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,16 @@
/**
* Represents a standalone value (used for standalone value page).
*/
public class ValueModel
public final class ValueModel
extends ModelAbstract<ManagedObject> {

private static final long serialVersionUID = 1L;

// -- FACTORIES

public static ValueModel of(
final @NonNull ObjectMember objectMember,
final @NonNull ManagedObject valueAdapter) {
return new ValueModel(objectMember, valueAdapter);
}

// --

private final ObjectMemento adapterMemento;

private ValueModel(
public ValueModel(
final @NonNull ObjectMember objectMember,
final @NonNull ManagedObject valueAdapter) {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,23 @@
*/
package org.apache.causeway.viewer.wicket.model.models;

import org.apache.wicket.model.IModel;

import org.apache.causeway.core.config.CausewayConfiguration;

/**
* Model providing welcome text.
*/
public class WelcomeModel
extends ModelAbstract<CausewayConfiguration.Viewer.Wicket.Welcome> {
public record WelcomeModel(String welcomeText)
implements IModel<String> {

private static final long serialVersionUID = 1L;
public WelcomeModel(final CausewayConfiguration config) {
this(config.getViewer().getWicket().getWelcome().getText());
}

@Override
protected CausewayConfiguration.Viewer.Wicket.Welcome load() {
return getWicketViewerSettings().getWelcome();
public String getObject() {
return welcomeText;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public ApplicationAdvice appliesTo(final IModel<?> model) {

@Override
public Component createComponent(final String id, final IModel<?> model) {
return new AboutPanel(id, new AboutModel());
return new AboutPanel(id, new AboutModel(getMetaModelContext().getApplicationSettings()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private Component createCellElementComponent(
final String componentId, final DataColumn dataColumn, final ManagedObject cellElement) {

if(ManagedObjects.isValue(cellElement)) {
var valueModel = ValueModel.of(dataColumn.associationMetaModel(), cellElement);
var valueModel = new ValueModel(dataColumn.associationMetaModel(), cellElement);
var componentFactory = findComponentFactory(UiComponentType.VALUE, valueModel);
return componentFactory.createComponent(componentId, valueModel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected Component createCellComponent(

if(ManagedObjects.isValue(rowElement)) {
var objectMember = dataRow.parentTable().getMetaModel();
var valueModel = ValueModel.of(objectMember, rowElement);
var valueModel = new ValueModel(objectMember, rowElement);
var componentFactory = findComponentFactory(UiComponentType.VALUE, valueModel);
return componentFactory.createComponent(componentId, valueModel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
*/
package org.apache.causeway.viewer.wicket.ui.components.welcome;

import org.apache.wicket.model.LambdaModel;

import org.apache.causeway.core.config.CausewayConfiguration;
import org.apache.causeway.viewer.wicket.model.models.WelcomeModel;
import org.apache.causeway.viewer.wicket.ui.pages.home.HomePage;
import org.apache.causeway.viewer.wicket.ui.panels.PanelAbstract;
Expand All @@ -31,15 +28,15 @@
* {@link HomePage}).
*/
class WelcomePanel
extends PanelAbstract<CausewayConfiguration.Viewer.Wicket.Welcome, WelcomeModel> {
extends PanelAbstract<String, WelcomeModel> {

private static final long serialVersionUID = 1L;

private static final String ID_MESSAGE = "message";

public WelcomePanel(final String id, final WelcomeModel welcomeModel) {
super(id, welcomeModel);
Wkt.labelAdd(this, ID_MESSAGE, LambdaModel.of(()->welcomeModel.getObject().getText()))
Wkt.labelAdd(this, ID_MESSAGE, welcomeModel)
// safe to not escape, welcome message is read from file (part of deployed WAR)
.setEscapeModelStrings(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public ApplicationAdvice appliesTo(final IModel<?> model) {

@Override
public Component createComponent(final String id, final IModel<?> model) {
return new WelcomePanel(id, new WelcomeModel());
return new WelcomePanel(id, new WelcomeModel(getMetaModelContext().getConfiguration()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private Mediator actionResultResponse(
return Mediator.toPage(pageRedirectRequest);
}
case VALUE: {
var valueModel = ValueModel.of(actionModel.getAction(), resultAdapter);
var valueModel = new ValueModel(actionModel.getAction(), resultAdapter);
valueModel.setActionHint(actionModel);
var valuePage = new ValuePage(valueModel);
var pageRedirectRequest = PageRedirectRequest.forPage(ValuePage.class, valuePage);
Expand Down

0 comments on commit ac86f6c

Please sign in to comment.