Skip to content

Package: FileEntityPresentable

FileEntityPresentable

nameinstructionbranchcomplexitylinemethod
FileEntityPresentable(FileEntity)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
createPresentationModel(Collection)
M: 0 C: 92
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 13
100%
M: 0 C: 1
100%
lambda$createPresentationModel$0()
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$createPresentationModel$1()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$createPresentationModel$2()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * SteelBlue: DCI User Interfaces
5: * http://tidalwave.it/projects/steelblue
6: *
7: * Copyright (C) 2015 - 2024 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *************************************************************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * 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
17: * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18: *
19: * *************************************************************************************************************************************************************
20: *
21: * git clone https://bitbucket.org/tidalwave/steelblue-src
22: * git clone https://github.com/tidalwave-it/steelblue-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.role.ui.example.presentation.impl;
27:
28: import javax.annotation.Nonnull;
29: import java.time.format.DateTimeFormatter;
30: import java.time.format.FormatStyle;
31: import java.util.Collection;
32: import java.util.Locale;
33: import it.tidalwave.role.ui.Displayable;
34: import it.tidalwave.role.ui.PresentationModel;
35: import it.tidalwave.role.ui.PresentationModelAggregate;
36: import it.tidalwave.role.ui.Styleable;
37: import it.tidalwave.role.ui.example.model.FileEntity;
38: import it.tidalwave.role.ui.spi.SimpleCompositePresentable;
39: import it.tidalwave.dci.annotation.DciRole;
40: import lombok.extern.slf4j.Slf4j;
41: import static it.tidalwave.util.FunctionalCheckedExceptionWrappers.*;
42: import static it.tidalwave.util.LocalizedDateTimeFormatters.getDateTimeFormatterFor;
43: import static it.tidalwave.util.Parameters.r;
44:
45: /***************************************************************************************************************************************************************
46: *
47: * A {@link it.tidalwave.role.ui.Presentable} implementation for {@link FileEntity}, creates a {@link PresentationModel}
48: * for a tabular rendering with four columns: name, size, creationDate and latestModificationDate.
49: *
50: * @author Fabrizio Giudici
51: *
52: **************************************************************************************************************************************************************/
53: // TODO: add roles such as Removable, present only if permissions allow
54: // TODO: iconprovider
55: // START SNIPPET: all
56: @DciRole(datumType = FileEntity.class) @Slf4j
57: public class FileEntityPresentable extends SimpleCompositePresentable
58: {
59: private static final DateTimeFormatter FORMATTER = getDateTimeFormatterFor(FormatStyle.SHORT, Locale.getDefault());
60:
61: @Nonnull
62: private final FileEntity owner;
63:
64: public FileEntityPresentable (@Nonnull final FileEntity owner)
65: {
66: super(owner);
67: this.owner = owner;
68: }
69:
70: @Override @Nonnull
71: public PresentationModel createPresentationModel (@Nonnull final Collection<Object> roles)
72: {
73: final var aggregate = PresentationModelAggregate.newInstance()
74: .withPmOf("name",
75: r(owner)) // owner is a Displayable itself
76: .withPmOf("size",
77: r(Displayable.of(_s(() -> "" + owner.getSize())),
78: Styleable.of("right-aligned")))
79: .withPmOf("creationDate",
80: r(Displayable.of(_s(() -> FORMATTER.format(owner.getCreationDateTime()))),
81: Styleable.of("right-aligned")))
82: .withPmOf("latestModificationDate",
83: r(Displayable.of(_s(() -> FORMATTER.format(owner.getLastModifiedDateTime()))),
84: Styleable.of("right-aligned")));
85: return super.createPresentationModel(r(aggregate, roles));
86: }
87: }
88: // END SNIPPET: all