package de.espirit.firstspirit.access.editor; import de.espirit.firstspirit.access.Language; import de.espirit.firstspirit.access.editor.value.DatasetContainer; import de.espirit.firstspirit.access.editor.value.InvalidValueException; import de.espirit.firstspirit.access.store.contentstore.Content2; import de.espirit.firstspirit.access.store.contentstore.Dataset; import java.util.List; /** * Example how to get the value of a DatasetEditorValue and how to store a value into a DatasetEditorValue. * * @since 4.2.34 */ public class DatasetEditorValueExample { /** * Stores the value into the DatasetEditorValue for the given language. * * @since 4.2.34 */ public void setValueForLanguage(final DatasetEditorValue editor, final Content2 content, final Language language) throws InvalidValueException { // 1. check if language is provided if editor is language dependent ("useLanguages='yes'" in gom syntax) if (editor.isLanguageDependent() && (language == null)) { throw new NullPointerException("Language is missing!"); } // 2. retrieve datasets from content element final List<Dataset> datasets = content.getDatasets(); // 3. retrieve the Dataset for the Entity from the content element final Dataset dataset = datasets.get(0); // 4. create a storable container object final DatasetContainer value = editor.createDatasetContainer(dataset.getEntity(), dataset.getTableTemplate(), language); // 5. store value into the editor value editor.set(language, value); } /** * Stores the value into the DatasetEditorValue for the given language. * * @since 4.2.34 */ public DatasetContainer getValueForLanguage(final DatasetEditorValue editor, final Language language) { // 1. get the stored instance in the editor value final DatasetContainer value = editor.get(language); // 2. and return the value for further processing return value; } }