diff --git a/src/main/java/com/avispa/ecm/model/configuration/propertypage/content/PropertyPageContent.java b/src/main/java/com/avispa/ecm/model/configuration/propertypage/content/PropertyPageContent.java index 8071221..df49ba9 100644 --- a/src/main/java/com/avispa/ecm/model/configuration/propertypage/content/PropertyPageContent.java +++ b/src/main/java/com/avispa/ecm/model/configuration/propertypage/content/PropertyPageContent.java @@ -19,6 +19,7 @@ package com.avispa.ecm.model.configuration.propertypage.content; import com.avispa.ecm.model.configuration.propertypage.content.control.Control; +import com.avispa.ecm.model.configuration.propertypage.content.control.Hidden; import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Getter; import lombok.Setter; @@ -37,4 +38,23 @@ public class PropertyPageContent { private PropertyPageContext context; private String size = "normal"; private List controls; + + /** + * Adds hidden control on the root level of control hierarchy (can't be nested in lists, tables or even columns). + * It can be called only after successful mapping of property page configuration. + * + * @param property property name + * @param value value + */ + public void addHiddenControl(String property, Object value) { + if (controls == null) { + throw new IllegalStateException("Map property page configuration to this object first"); + } + + Hidden hidden = new Hidden(); + hidden.setProperty(property); + hidden.setValue(value); + + controls.add(hidden); + } } diff --git a/src/main/java/com/avispa/ecm/model/configuration/propertypage/content/control/Table.java b/src/main/java/com/avispa/ecm/model/configuration/propertypage/content/control/Table.java index f144752..ab3942d 100644 --- a/src/main/java/com/avispa/ecm/model/configuration/propertypage/content/control/Table.java +++ b/src/main/java/com/avispa/ecm/model/configuration/propertypage/content/control/Table.java @@ -31,6 +31,7 @@ public class Table extends PropertyControl { private List controls; + private boolean fixed; private int size; public Table() { diff --git a/src/main/resources/json-schemas/control/table.json b/src/main/resources/json-schemas/control/table.json index 1c2798a..02d1f78 100644 --- a/src/main/resources/json-schemas/control/table.json +++ b/src/main/resources/json-schemas/control/table.json @@ -15,6 +15,9 @@ "readonly": { "type": "boolean" }, + "fixed": { + "type": "boolean" + }, "property": { "type": "string", "pattern": "^[a-zA-Z](?:[a-zA-Z\\d.]*[a-zA-Z\\d])?+$" diff --git a/src/test/java/com/avispa/ecm/model/configuration/propertypage/content/PropertyPageContentTest.java b/src/test/java/com/avispa/ecm/model/configuration/propertypage/content/PropertyPageContentTest.java new file mode 100644 index 0000000..3054f5a --- /dev/null +++ b/src/test/java/com/avispa/ecm/model/configuration/propertypage/content/PropertyPageContentTest.java @@ -0,0 +1,49 @@ +/* + * Avispa ECM - a small framework for implementing basic ECM solution + * Copyright (C) 2024 Rafał Hiszpański + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package com.avispa.ecm.model.configuration.propertypage.content; + +import com.avispa.ecm.model.configuration.propertypage.content.control.Hidden; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertThrows; + +/** + * @author Rafał Hiszpański + */ +class PropertyPageContentTest { + @Test + void givenEmptyPropertyPageContent_whenAddHidden_thenThrowException() { + var content = new PropertyPageContent(); + assertThrows(IllegalStateException.class, () -> content.addHiddenControl("test", "test")); + } + + @Test + void givenCorrectPropertyPageContent_whenAddHidden_thenNewControlAppears() { + var content = new PropertyPageContent(); + content.setControls(new ArrayList<>()); + content.addHiddenControl("test", "test"); + + assertFalse(content.getControls().isEmpty()); + assertInstanceOf(Hidden.class, content.getControls().get(0)); + } +} \ No newline at end of file