Removed depcrecated package com.arsdigita.ui.admin.configuration from ccm-core

pull/28/head
Jens Pelzetter 2022-03-19 17:38:45 +01:00
parent 50be17c101
commit 473240777a
14 changed files with 0 additions and 3768 deletions

View File

@ -1,311 +0,0 @@
/*
* Copyright (C) 2016 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.ui.admin.configuration;
import com.arsdigita.bebop.BoxPanel;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.SaveCancelSection;
import com.arsdigita.bebop.event.FormInitListener;
import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.event.FormValidationListener;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.util.UncheckedWrapperException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.util.Strings;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.configuration.ConfigurationManager;
import java.lang.reflect.Field;
import static com.arsdigita.ui.admin.AdminUiConstants.*;
/**
* An abstract base class for a form for editing settings with a single value.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
* @param <T>
*/
public abstract class AbstractSettingFormSingleValue<T> extends Form {
private static final Logger LOGGER = LogManager.getLogger(
AbstractSettingFormSingleValue.class);
private static final String VALUE_FIELD = "valueField";
private final SaveCancelSection saveCancelSection;
/**
* Constructor, initialises the form and the supporting widgets.
*
* @param configurationTab The configuration tab in which the form is shown.
* @param selectedConf Parameter containing the selected configuration
* class.
* @param selectedSetting Parameter containing the selected setting.
*/
public AbstractSettingFormSingleValue(
final ConfigurationTab configurationTab,
final ParameterSingleSelectionModel<String> selectedConf,
final ParameterSingleSelectionModel<String> selectedSetting) {
super("settingFormSingleValue", new BoxPanel(BoxPanel.VERTICAL));
add(new SettingFormHeader(configurationTab,
selectedConf,
selectedSetting));
add(new SettingFormCurrentValuePanel(selectedConf, selectedSetting));
final TextField valueField = new TextField(VALUE_FIELD);
valueField.setLabel(new GlobalizedMessage(
"ui.admin.configuration.setting.edit.new_value", ADMIN_BUNDLE));
add(valueField);
saveCancelSection = new SaveCancelSection();
add(saveCancelSection);
addInitListener(new InitListener(selectedConf,
selectedSetting,
valueField));
addValidationListener(new ValidationListener());
addProcessListener(new ProcessListener(configurationTab,
selectedConf,
selectedSetting));
}
/**
* Converts a string to the value type of the setting. Must be overwritten
* by the none abstract sub classes.
*
* @param valueData The data to convert.
*
* @return The converted data.
*/
abstract T convertValue(final String valueData);
/**
* {@link FormInitListener} for the form. Loads the current value of the
* setting from the database and puts it into the input field.
*/
private class InitListener implements FormInitListener {
private final ParameterSingleSelectionModel<String> selectedConf;
private final ParameterSingleSelectionModel<String> selectedSetting;
private final TextField valueField;
public InitListener(
final ParameterSingleSelectionModel<String> selectedConf,
final ParameterSingleSelectionModel<String> selectedSetting,
final TextField valueField) {
this.selectedConf = selectedConf;
this.selectedSetting = selectedSetting;
this.valueField = valueField;
}
@Override
public void init(final FormSectionEvent event)
throws FormProcessException {
final PageState state = event.getPageState();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final Class<?> confClass;
try {
confClass = Class
.forName(selectedConf.getSelectedKey(state));
} catch (ClassNotFoundException ex) {
throw new UncheckedWrapperException(ex);
}
final ConfigurationManager confManager = cdiUtil.findBean(
ConfigurationManager.class);
final Object config = confManager.findConfiguration(confClass);
final Object value;
try {
final Field field = confClass.getDeclaredField(selectedSetting
.getSelectedKey(state));
field.setAccessible(true);
value = field.get(config);
} catch (NoSuchFieldException |
SecurityException |
IllegalAccessException |
ClassCastException ex) {
LOGGER.warn("Failed to read setting {} from configuration {}",
selectedSetting.getSelectedKey(state),
selectedConf.getSelectedKey(state));
LOGGER.warn(ex);
return;
}
if (value == null) {
valueField.setValue(state, "");
} else {
valueField.setValue(state, value.toString());
}
}
}
/**
* {@link FormValidationListener} which checks if the value provided by the
* user can be converted into the type of the setting.
*
*/
private class ValidationListener implements FormValidationListener {
@Override
public void validate(final FormSectionEvent event)
throws FormProcessException {
final FormData data = event.getFormData();
final PageState state = event.getPageState();
if (saveCancelSection.getSaveButton().isSelected(state)) {
final String valueData = data.getString(VALUE_FIELD);
if (Strings.isBlank(valueData)) {
data.addError(VALUE_FIELD,
new GlobalizedMessage(
"ui.admin.configuration.setting.error.blank",
ADMIN_BUNDLE));
}
try {
final T value = convertValue(valueData);
LOGGER.debug("New value {} is a valid BigDecimal.", value);
} catch (NumberFormatException ex) {
data.addError(
VALUE_FIELD,
new GlobalizedMessage(
"ui.admin.configuration.setting.error.incorrect_format",
ADMIN_BUNDLE));
}
}
}
}
/**
* {@link FormProcessListener} to store the new value of the setting
* in the database.
*/
private class ProcessListener implements FormProcessListener {
private final ConfigurationTab configurationTab;
private final ParameterSingleSelectionModel<String> selectedConf;
private final ParameterSingleSelectionModel<String> selectedSetting;
public ProcessListener(
final ConfigurationTab configurationTab,
final ParameterSingleSelectionModel<String> selectedConf,
final ParameterSingleSelectionModel<String> selectedSetting) {
this.configurationTab = configurationTab;
this.selectedConf = selectedConf;
this.selectedSetting = selectedSetting;
}
@Override
public void process(final FormSectionEvent event)
throws FormProcessException {
final PageState state = event.getPageState();
if (saveCancelSection.getSaveButton().isSelected(state)) {
final FormData data = event.getFormData();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final Class<?> confClass;
try {
confClass = Class
.forName(selectedConf.getSelectedKey(state));
} catch (ClassNotFoundException ex) {
throw new UncheckedWrapperException(ex);
}
final ConfigurationManager confManager = cdiUtil.findBean(
ConfigurationManager.class);
final String settingName = selectedSetting.getSelectedKey(state);
final Object config = confManager.findConfiguration(confClass);
final Field field;
try {
field = confClass.getDeclaredField(settingName);
field.setAccessible(true);
} catch (NoSuchFieldException | SecurityException ex) {
LOGGER.error("Failed to retrieve field \"{}\" "
+ "from configuration class \"{}\".",
settingName,
confClass.getName());
LOGGER.error(ex);
throw new FormProcessException(
String.format(
"Failed to retrieve field \"%s\" "
+ "from configuration class \"%s\".",
settingName,
confClass.getName()),
new GlobalizedMessage(
"ui.admin.configuration.setting.failed_to_set_value",
ADMIN_BUNDLE),
ex);
}
final String valueData = data.getString(VALUE_FIELD);
final T value = convertValue(valueData);
try {
field.set(config, value);
confManager.saveConfiguration(config);
configurationTab.hideSettingForms(state);
} catch (IllegalArgumentException | IllegalAccessException ex) {
LOGGER.error("Failed to change value of field \"{}\" "
+ "of configuration class \"{}\".",
settingName,
confClass.getName());
LOGGER.error(ex);
throw new FormProcessException(
String.format(
"Failed to change value of field \"%s\" "
+ "of configuration class \"%s\".",
settingName,
confClass.getName()),
new GlobalizedMessage(
"ui.admin.configuration.setting.failed_to_set_value",
ADMIN_BUNDLE),
ex);
}
}
configurationTab.hideSettingForms(state);
}
}
}

View File

@ -1,576 +0,0 @@
/*
* Copyright (C) 2016 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.ui.admin.configuration;
import com.arsdigita.bebop.ActionLink;
import com.arsdigita.bebop.BoxPanel;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.SegmentedPanel;
import com.arsdigita.bebop.form.Submit;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.toolbox.ui.LayoutPanel;
import com.arsdigita.util.UncheckedWrapperException;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.configuration.ConfigurationInfo;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.l10n.GlobalizationHelper;
import static com.arsdigita.ui.admin.AdminUiConstants.*;
/**
* Tab for the admin application containing the UI to manage the settings in the
* various configuration classes.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class ConfigurationTab extends LayoutPanel {
private static final String CONF_CLASSES_FILTER = "confClassesFilter";
/**
* Parameter for the selected configuration.
*/
private final StringParameter selectedConfParam;
private final ParameterSingleSelectionModel<String> selectedConf;
/**
* Parameter for the selected setting.
*/
private final StringParameter selectedSettingParam;
private final ParameterSingleSelectionModel<String> selectedSetting;
/**
* Parameter for the selected value of multi-value settings.
*/
private final StringParameter selectedValueParam;
private final ParameterSingleSelectionModel<String> selectedValue;
/**
* Heading of the table of configurations.
*/
private final Label confClassesFilterHeading;
/**
* Form for filtering the table of configurations.
*/
private final Form confClassesFilterForm;
/**
* The table which lists all available configurations.
*/
private final ConfigurationsTable configurationsTable;
/**
* Link to go back to the listing of configurations.
*/
private final ActionLink configurationBackLink;
/**
* Heading for the list of settings of a configuration.
*/
private final Label configurationHeading;
/**
* The table which lists a settings of configuration.
*/
private final ConfigurationTable configurationTable;
/**
* The form for editing a setting of the type {@code boolean}.
*/
private final SettingFormBoolean settingFormBoolean;
/**
* The form for editing a setting of the type {@code long}.
*/
private final SettingFormLong settingFormLong;
/**
* The form for editing a setting of the type {@code double}.
*/
private final SettingFormDouble settingFormDouble;
/**
* The form for editing a setting of the type {@code BigDecimal}.
*/
private final SettingFormBigDecimal settingFormBigDecimal;
/**
* The form for editing a setting of the type {@code String}.
*/
private final SettingFormString settingFormString;
/**
* The form for editing a setting of the type {@code LocalizedString}.
*/
private final SettingEditorLocalizedString settingEditorLocalizedString;
/**
* The form for editing a setting of the type {@code List<String>}.
*/
private final SettingEditorStringList settingEditorStringList;
/**
* The form for editing a setting of the type {@code Set<String>}.
*/
private final SettingEditorEnum settingEditorEnum;
/**
* Initialises the parameters, widgets and forms.
*/
public ConfigurationTab() {
super();
setClassAttr("sidebarNavPanel");
selectedConfParam = new StringParameter("selectedConfiguration");
selectedConf = new ParameterSingleSelectionModel<>(selectedConfParam);
selectedSettingParam = new StringParameter("selectedSetting");
selectedSetting = new ParameterSingleSelectionModel<>(
selectedSettingParam);
selectedValueParam = new StringParameter("selectedValue");
selectedValue = new ParameterSingleSelectionModel<>(selectedValueParam);
final SegmentedPanel left = new SegmentedPanel();
confClassesFilterHeading = new Label(new GlobalizedMessage(
"ui.admin.configuration.classes.filter.heading", ADMIN_BUNDLE));
confClassesFilterForm = new Form("confClassesForm");
final TextField confClassesFilter = new TextField(CONF_CLASSES_FILTER);
confClassesFilterForm.add(confClassesFilter);
confClassesFilterForm.add(new Submit(new GlobalizedMessage(
"ui.admin.configuration.classes.filter.submit", ADMIN_BUNDLE)));
final ActionLink clearLink = new ActionLink(new GlobalizedMessage(
"ui.admin.configuration.classes.filter.clear", ADMIN_BUNDLE));
clearLink.addActionListener(e -> {
final PageState state = e.getPageState();
confClassesFilter.setValue(state, null);
});
confClassesFilterForm.add(clearLink);
left.addSegment(confClassesFilterHeading, confClassesFilterForm);
setLeft(left);
final BoxPanel body = new BoxPanel(BoxPanel.VERTICAL);
configurationsTable = new ConfigurationsTable(
this, selectedConf, confClassesFilter);
body.add(configurationsTable);
configurationBackLink = new ActionLink(new GlobalizedMessage(
"ui.admin.configuration.back_to_configurations",
ADMIN_BUNDLE));
configurationBackLink.addActionListener(e -> {
final PageState state = e.getPageState();
hideConfiguration(state);
});
body.add(configurationBackLink);
configurationHeading = new Label(e -> {
//This print listener includes the (localised title) of the selected
//configuration in the heading
final PageState state = e.getPageState();
final Class<?> confClass;
try {
confClass = Class.forName(selectedConf.getSelectedKey(state));
} catch (ClassNotFoundException ex) {
throw new UncheckedWrapperException(
String.format("Configuration class \"%s\" not found.",
selectedConf.getSelectedKey(state)),
ex);
}
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ConfigurationManager confManager = cdiUtil.findBean(
ConfigurationManager.class);
final ConfigurationInfo confInfo = confManager.getConfigurationInfo(
confClass);
final GlobalizationHelper globalizationHelper = cdiUtil.findBean(
GlobalizationHelper.class);
final Label target = (Label) e.getTarget();
final String confTitle = confInfo.getTitle(globalizationHelper
.getNegotiatedLocale());
target.setLabel(new GlobalizedMessage(
"ui.admin.configuration.editing_configuration",
ADMIN_BUNDLE,
new String[]{confTitle}));
});
configurationHeading.setClassAttr("heading");
body.add(configurationHeading);
configurationTable = new ConfigurationTable(this,
selectedConf,
selectedSetting);
body.add(configurationTable);
settingFormBoolean = new SettingFormBoolean(this,
selectedConf,
selectedSetting);
body.add(settingFormBoolean);
settingFormLong = new SettingFormLong(this,
selectedConf,
selectedSetting);
body.add(settingFormLong);
settingFormDouble = new SettingFormDouble(this,
selectedConf,
selectedSetting);
body.add(settingFormDouble);
settingFormBigDecimal = new SettingFormBigDecimal(this,
selectedConf,
selectedSetting);
body.add(settingFormBigDecimal);
settingFormString = new SettingFormString(this,
selectedConf,
selectedSetting);
body.add(settingFormString);
settingEditorLocalizedString = new SettingEditorLocalizedString(
this, selectedConf, selectedSetting, selectedValue);
body.add(settingEditorLocalizedString);
settingEditorStringList = new SettingEditorStringList(
this, selectedConf, selectedSetting, selectedValue);
body.add(settingEditorStringList);
settingEditorEnum = new SettingEditorEnum(
this, selectedConf, selectedSetting, selectedValue);
body.add(settingEditorEnum);
setBody(body);
}
/**
* Registers all forms and widgets in the page for visibility management and
* registers all parameters. The method is called by Bebop when the tab is
* rendered.
*
* @param page The page which this tab is part of.
*/
@Override
public void register(final Page page) {
super.register(page);
page.addGlobalStateParam(selectedConfParam);
page.addGlobalStateParam(selectedSettingParam);
page.addGlobalStateParam(selectedValueParam);
page.setVisibleDefault(confClassesFilterHeading, true);
page.setVisibleDefault(confClassesFilterForm, true);
page.setVisibleDefault(configurationsTable, true);
page.setVisibleDefault(configurationBackLink, false);
page.setVisibleDefault(configurationHeading, false);
page.setVisibleDefault(configurationTable, false);
page.setVisibleDefault(settingFormBoolean, false);
page.setVisibleDefault(settingFormLong, false);
page.setVisibleDefault(settingFormDouble, false);
page.setVisibleDefault(settingFormBigDecimal, false);
page.setVisibleDefault(settingFormString, false);
page.setVisibleDefault(settingEditorLocalizedString, false);
page.setVisibleDefault(settingEditorStringList, false);
page.setVisibleDefault(settingEditorEnum, false);
}
/**
* Shows the {@link #configurationsTable} and hides all other widgets and
* forms.
*
* @param state The current {@link PageState}.
*/
protected void showConfigurationsTable(final PageState state) {
confClassesFilterHeading.setVisible(state, true);
confClassesFilterForm.setVisible(state, true);
configurationsTable.setVisible(state, true);
configurationTable.setVisible(state, false);
settingFormBoolean.setVisible(state, false);
settingFormLong.setVisible(state, false);
settingFormDouble.setVisible(state, false);
settingFormBigDecimal.setVisible(state, false);
settingFormString.setVisible(state, false);
settingEditorLocalizedString.setVisible(state, false);
settingEditorStringList.setVisible(state, false);
settingEditorEnum.setVisible(state, false);
}
/**
* Hides the {@link #configurationsTable} and its supporting widgets.
*
* @param state The current {@link PageState}.
*/
protected void hideConfigurationsTable(final PageState state) {
confClassesFilterHeading.setVisible(state, false);
confClassesFilterForm.setVisible(state, false);
configurationsTable.setVisible(state, false);
}
/**
* Shows the {@link #configurationTable} which lists all settings of a
* configuration.
*
* @param state The current {@link PageState}.
*/
protected void showConfiguration(final PageState state) {
hideConfigurationsTable(state);
hideSettingForms(state);
configurationBackLink.setVisible(state, true);
configurationHeading.setVisible(state, true);
configurationTable.setVisible(state, true);
}
/**
* Hides the configuration table and resets the {@link #selectedConf}
* parameter.
*
* @param state The current {@link PageState}.
*/
protected void hideConfiguration(final PageState state) {
configurationBackLink.setVisible(state, false);
configurationHeading.setVisible(state, false);
configurationTable.setVisible(state, false);
selectedConf.clearSelection(state);
showConfigurationsTable(state);
}
/**
* Shows the {@link #settingFormBigDecimal}.
*
* @param state The current {@link PageState}.
*/
protected void showBigDecimalSettingForm(final PageState state) {
confClassesFilterHeading.setVisible(state, false);
confClassesFilterForm.setVisible(state, false);
configurationsTable.setVisible(state, false);
configurationBackLink.setVisible(state, false);
configurationHeading.setVisible(state, false);
configurationTable.setVisible(state, false);
settingFormBoolean.setVisible(state, false);
settingFormLong.setVisible(state, false);
settingFormDouble.setVisible(state, false);
settingFormBigDecimal.setVisible(state, true);
settingFormString.setVisible(state, false);
settingEditorLocalizedString.setVisible(state, false);
settingEditorStringList.setVisible(state, false);
settingEditorEnum.setVisible(state, false);
}
/**
* Shows the {@link #settingFormBoolean}.
*
* @param state The current {@link PageState}.
*/
protected void showBooleanSettingForm(final PageState state) {
confClassesFilterHeading.setVisible(state, false);
confClassesFilterForm.setVisible(state, false);
configurationsTable.setVisible(state, false);
configurationBackLink.setVisible(state, false);
configurationHeading.setVisible(state, false);
configurationTable.setVisible(state, false);
settingFormBoolean.setVisible(state, true);
settingFormLong.setVisible(state, false);
settingFormDouble.setVisible(state, false);
settingFormBigDecimal.setVisible(state, false);
settingFormString.setVisible(state, false);
settingEditorLocalizedString.setVisible(state, false);
settingEditorStringList.setVisible(state, false);
settingEditorEnum.setVisible(state, false);
}
/**
* Shows the {@link #settingFormDouble}.
*
* @param state The current {@link PageState}.
*/
protected void showDoubleSettingForm(final PageState state) {
confClassesFilterHeading.setVisible(state, false);
confClassesFilterForm.setVisible(state, false);
configurationsTable.setVisible(state, false);
configurationBackLink.setVisible(state, false);
configurationHeading.setVisible(state, false);
configurationTable.setVisible(state, false);
settingFormBoolean.setVisible(state, false);
settingFormLong.setVisible(state, false);
settingFormDouble.setVisible(state, true);
settingFormBigDecimal.setVisible(state, false);
settingFormString.setVisible(state, false);
settingEditorLocalizedString.setVisible(state, false);
settingEditorStringList.setVisible(state, false);
settingEditorEnum.setVisible(state, false);
}
/**
* Shows the {@link #settingEditorEnum}.
*
* @param state The current {@link PageState}.
*/
protected void showEnumSettingForm(final PageState state) {
confClassesFilterHeading.setVisible(state, false);
confClassesFilterForm.setVisible(state, false);
configurationsTable.setVisible(state, false);
configurationBackLink.setVisible(state, false);
configurationHeading.setVisible(state, false);
configurationTable.setVisible(state, false);
settingFormBoolean.setVisible(state, false);
settingFormLong.setVisible(state, false);
settingFormDouble.setVisible(state, false);
settingFormBigDecimal.setVisible(state, false);
settingFormString.setVisible(state, false);
settingEditorLocalizedString.setVisible(state, false);
settingEditorStringList.setVisible(state, false);
settingEditorEnum.setVisible(state, true);
}
/**
* Show the {@link #settingEditorLocalizedString}.
*
* @param state The current {@link PageState}.
*/
protected void showLocalizedStringSettingForm(final PageState state) {
confClassesFilterHeading.setVisible(state, false);
confClassesFilterForm.setVisible(state, false);
configurationsTable.setVisible(state, false);
configurationBackLink.setVisible(state, false);
configurationHeading.setVisible(state, false);
configurationTable.setVisible(state, false);
settingFormBoolean.setVisible(state, false);
settingFormLong.setVisible(state, false);
settingFormDouble.setVisible(state, false);
settingFormBigDecimal.setVisible(state, false);
settingFormString.setVisible(state, false);
settingEditorLocalizedString.setVisible(state, true);
settingEditorStringList.setVisible(state, false);
settingEditorEnum.setVisible(state, false);
}
/**
* Shows the {@link #settingFormLong}.
*
* @param state The current {@link PageState}.
*/
protected void showLongSettingForm(final PageState state) {
confClassesFilterHeading.setVisible(state, false);
confClassesFilterForm.setVisible(state, false);
configurationsTable.setVisible(state, false);
configurationBackLink.setVisible(state, false);
configurationHeading.setVisible(state, false);
configurationTable.setVisible(state, false);
settingFormBoolean.setVisible(state, false);
settingFormLong.setVisible(state, true);
settingFormDouble.setVisible(state, false);
settingFormBigDecimal.setVisible(state, false);
settingFormString.setVisible(state, false);
settingEditorLocalizedString.setVisible(state, false);
settingEditorStringList.setVisible(state, false);
settingEditorEnum.setVisible(state, false);
}
/**
* Shows the {@link #settingEditorStringList}.
*
* @param state The current {@link PageState}.
*/
protected void showStringListSettingForm(final PageState state) {
confClassesFilterHeading.setVisible(state, false);
confClassesFilterForm.setVisible(state, false);
configurationsTable.setVisible(state, false);
configurationBackLink.setVisible(state, false);
configurationHeading.setVisible(state, false);
configurationTable.setVisible(state, false);
settingFormBoolean.setVisible(state, false);
settingFormLong.setVisible(state, false);
settingFormDouble.setVisible(state, false);
settingFormBigDecimal.setVisible(state, false);
settingFormString.setVisible(state, false);
settingEditorLocalizedString.setVisible(state, false);
settingEditorStringList.setVisible(state, true);
settingEditorEnum.setVisible(state, false);
}
/**
* Shows the {@link #settingFormString}.
*
* @param state The current {@link PageState}.
*/
protected void showStringSettingForm(final PageState state) {
confClassesFilterHeading.setVisible(state, false);
confClassesFilterForm.setVisible(state, false);
configurationsTable.setVisible(state, false);
configurationBackLink.setVisible(state, false);
configurationHeading.setVisible(state, false);
configurationTable.setVisible(state, false);
settingFormBoolean.setVisible(state, false);
settingFormLong.setVisible(state, false);
settingFormDouble.setVisible(state, false);
settingFormBigDecimal.setVisible(state, false);
settingFormString.setVisible(state, true);
settingEditorLocalizedString.setVisible(state, false);
settingEditorStringList.setVisible(state, false);
settingEditorEnum.setVisible(state, false);
}
/**
* Hides all settings forms/editors and resets the {@link #selectedSetting}
* and {@link #selectedValue} parameters.
*
* @param state The current {@link PageState}.
*/
protected void hideSettingForms(final PageState state) {
confClassesFilterHeading.setVisible(state, false);
confClassesFilterForm.setVisible(state, false);
configurationsTable.setVisible(state, false);
configurationBackLink.setVisible(state, true);
configurationHeading.setVisible(state, true);
configurationTable.setVisible(state, true);
settingFormBoolean.setVisible(state, false);
settingFormLong.setVisible(state, false);
settingFormDouble.setVisible(state, false);
settingFormBigDecimal.setVisible(state, false);
settingFormString.setVisible(state, false);
settingEditorLocalizedString.setVisible(state, false);
settingEditorStringList.setVisible(state, false);
settingEditorEnum.setVisible(state, false);
selectedSetting.clearSelection(state);
selectedValue.clearSelection(state);
}
}

View File

@ -1,352 +0,0 @@
/*
* Copyright (C) 2016 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.ui.admin.configuration;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.ControlLink;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.Table;
import com.arsdigita.bebop.event.TableActionEvent;
import com.arsdigita.bebop.event.TableActionListener;
import com.arsdigita.bebop.table.TableCellRenderer;
import com.arsdigita.bebop.table.TableColumn;
import com.arsdigita.bebop.table.TableColumnModel;
import com.arsdigita.bebop.table.TableModel;
import com.arsdigita.bebop.table.TableModelBuilder;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.util.LockableImpl;
import com.arsdigita.util.UncheckedWrapperException;
import java.lang.reflect.Field;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.configuration.SettingInfo;
import org.libreccm.configuration.SettingManager;
import org.libreccm.l10n.GlobalizationHelper;
import org.libreccm.l10n.LocalizedString;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import static com.arsdigita.ui.admin.AdminUiConstants.*;
/**
* This table lists all settings of a configuration class. The table shows the
* current value and the description of each setting. If there is localised
* label for the setting this label is used, otherwise the name of the setting
* is used.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class ConfigurationTable extends Table {
private static final Logger LOGGER = LogManager.getLogger(
ConfigurationTable.class);
private static final int COL_SETTING_LABEL = 0;
private static final int COL_SETTING_VALUE = 1;
private static final int COL_SETTING_DESC = 2;
private static final int COL_EDIT_SETTING = 3;
private ParameterSingleSelectionModel<String> selectedConf;
private ParameterSingleSelectionModel<String> selectedSetting;
public ConfigurationTable(
final ConfigurationTab configurationTab,
final ParameterSingleSelectionModel<String> selectedConf,
final ParameterSingleSelectionModel<String> selectedSetting) {
super();
setIdAttr("configurationTable");
this.selectedConf = selectedConf;
this.selectedSetting = selectedSetting;
setEmptyView(new Label(new GlobalizedMessage(
"ui.admin.configuration.settings.none", ADMIN_BUNDLE)));
final TableColumnModel columnModel = getColumnModel();
columnModel.add(new TableColumn(
COL_SETTING_LABEL,
new Label(new GlobalizedMessage(
"ui.admin.configuration.settings.table.col_setting_label.header",
ADMIN_BUNDLE))));
columnModel.add(new TableColumn(
COL_SETTING_VALUE,
new Label(new GlobalizedMessage(
"ui.admin.configuration.settings.table.col_setting_value.header",
ADMIN_BUNDLE))));
columnModel.add(new TableColumn(
COL_SETTING_DESC,
new Label(new GlobalizedMessage(
"ui.admin.configuration.settings.table.col_setting_desc.header",
ADMIN_BUNDLE))));
columnModel.add(new TableColumn(
COL_EDIT_SETTING,
new Label(new GlobalizedMessage(
"ui.admin.configuration.settings.table.col_edit_setting.header",
ADMIN_BUNDLE))));
columnModel.get(COL_EDIT_SETTING).setCellRenderer(
new TableCellRenderer() {
@Override
public Component getComponent(final Table table,
final PageState state,
final Object value,
final boolean isSelected,
final Object key,
final int row,
final int column) {
return new ControlLink((Component) value);
}
});
addTableActionListener(new TableActionListener() {
@Override
public void cellSelected(final TableActionEvent event) {
final PageState state = event.getPageState();
if (event.getColumn() == COL_EDIT_SETTING) {
final String settingName = (String) event.getRowKey();
selectedSetting.setSelectedKey(state, settingName);
switch (getTypeOfSelectedSetting(state)) {
case "boolean":
LOGGER.debug("Setting is of type boolean");
configurationTab.showBooleanSettingForm(state);
break;
case "long":
LOGGER.debug("Setting is of type long");
configurationTab.showLongSettingForm(state);
break;
case "double":
LOGGER.debug("Setting is of type double");
configurationTab.showDoubleSettingForm(state);
break;
case "java.math.BigDecimal":
LOGGER.debug("Setting is of type BigDecimal");
configurationTab.showBigDecimalSettingForm(state);
break;
case "org.libreccm.l10n.LocalizedString":
LOGGER.debug("Setting is of type LocalizedString");
configurationTab.showLocalizedStringSettingForm(
state);
break;
case "java.lang.String":
LOGGER.debug("Setting is of type String");
configurationTab.showStringSettingForm(state);
break;
case "java.util.Set":
LOGGER.debug("Setting is of type Enum");
configurationTab.showEnumSettingForm(state);
break;
case "java.util.List":
LOGGER.debug("Setting is of type List");
configurationTab.showStringListSettingForm(state);
break;
default:
throw new IllegalArgumentException(String.format(
"Unknown setting type \"%s\".",
getTypeOfSelectedSetting(state)));
}
}
}
@Override
public void headSelected(final TableActionEvent event) {
//Nothing
}
});
setModelBuilder(new ConfigurationTableModelBuilder());
}
private String getTypeOfSelectedSetting(final PageState state) {
final Class<?> confClass;
try {
confClass = Class.forName(selectedConf.getSelectedKey(state));
} catch (ClassNotFoundException ex) {
LOGGER.error("Configuration class '{}' not found.",
selectedConf.getSelectedKey(state));
throw new UncheckedWrapperException(String.format(
"Configuration class '%s not found'",
selectedConf.getSelectedKey(state)), ex);
}
final SettingManager settingManager = CdiUtil.createCdiUtil().findBean(
SettingManager.class);
final SettingInfo info = settingManager.getSettingInfo(confClass,
selectedSetting.
getSelectedKey(
state));
return info.getValueType();
}
private class ConfigurationTableModelBuilder
extends LockableImpl implements TableModelBuilder {
@Override
public TableModel makeModel(final Table table, final PageState state) {
final ConfigurationManager confManager = CdiUtil.createCdiUtil()
.findBean(ConfigurationManager.class);
final Class<?> confClass;
try {
confClass = Class.forName(selectedConf.getSelectedKey(state));
} catch (ClassNotFoundException ex) {
LOGGER.error("Configuration class '{}' not found.",
selectedConf.getSelectedKey(state));
throw new UncheckedWrapperException(String.format(
"Configuration class '%s not found'",
selectedConf.getSelectedKey(state)), ex);
}
final Object configuration = confManager
.findConfiguration(confClass);
return new ConfigurationTableModel(configuration, state);
}
}
private class ConfigurationTableModel implements TableModel {
private final Object configuration;
private final ConfigurationManager confManager;
private final SettingManager settingManager;
private final GlobalizationHelper globalizationHelper;
private final List<String> settings;
private int index = -1;
public ConfigurationTableModel(final Object configuration,
final PageState state) {
this.configuration = configuration;
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
confManager = cdiUtil.findBean(ConfigurationManager.class);
settingManager = cdiUtil.findBean(SettingManager.class);
globalizationHelper = cdiUtil.findBean(GlobalizationHelper.class);
settings = settingManager.getAllSettings(configuration.getClass());
}
@Override
public int getColumnCount() {
return 4;
}
@Override
public boolean nextRow() {
index++;
return index < settings.size();
}
@Override
public Object getElementAt(final int columnIndex) {
final String setting = settings.get(index);
final SettingInfo settingInfo = settingManager.getSettingInfo(
configuration.getClass(), setting);
switch (columnIndex) {
case COL_SETTING_LABEL:
return settingInfo.getLabel(globalizationHelper
.getNegotiatedLocale());
case COL_SETTING_VALUE: {
try {
final Field field = configuration.getClass().
getDeclaredField(setting);
field.setAccessible(true);
return buildValueColumn(settingInfo,
field.get(configuration));
} catch (NoSuchFieldException |
SecurityException |
IllegalAccessException ex) {
LOGGER.error("Failed to read value from configuration.",
ex);
return new Label(new GlobalizedMessage(
"ui.admin.configuration.settings.read_error",
ADMIN_BUNDLE));
}
}
case COL_SETTING_DESC:
return settingInfo.getDescription(globalizationHelper
.getNegotiatedLocale());
case COL_EDIT_SETTING:
return new Label(new GlobalizedMessage(
"ui.admin.configuration.settings.edit", ADMIN_BUNDLE));
default:
throw new IllegalArgumentException("Illegal column index");
}
}
private String buildValueColumn(final SettingInfo settingInfo,
final Object settingValue) {
switch (settingInfo.getValueType()) {
case "java.util.List": {
@SuppressWarnings("unchecked")
final List<String> value = (List<String>) settingValue;
return String.join(", ", value);
}
case "java.util.Set": {
@SuppressWarnings("unchecked")
final Set<String> value = (Set<String>) settingValue;
return String.join(", ", value);
}
case "org.libreccm.l10n.LocalizedString": {
final LocalizedString value = (LocalizedString) settingValue;
final List<String> entries = new ArrayList<>();
value.getValues().entrySet().forEach(e -> {
entries.add(String.format("%s: %s",
e.getKey(),
e.getValue()));
});
return String.join("; ", entries);
}
default: {
return Objects.toString(settingValue);
}
}
}
@Override
public Object getKeyAt(final int columnIndex
) {
return settings.get(index);
}
}
}

View File

@ -1,228 +0,0 @@
/*
* Copyright (C) 2016 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.ui.admin.configuration;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.ControlLink;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.Table;
import com.arsdigita.bebop.event.TableActionEvent;
import com.arsdigita.bebop.event.TableActionListener;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.table.TableCellRenderer;
import com.arsdigita.bebop.table.TableColumn;
import com.arsdigita.bebop.table.TableColumnModel;
import com.arsdigita.bebop.table.TableModel;
import com.arsdigita.bebop.table.TableModelBuilder;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.util.LockableImpl;
import org.apache.logging.log4j.util.Strings;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.configuration.ConfigurationInfo;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.l10n.GlobalizationHelper;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.SortedSet;
import java.util.stream.Collectors;
import static com.arsdigita.ui.admin.AdminUiConstants.*;
/**
* This table lists all available configuration classes together with their
* descriptions (if any). If there is localised title for the configuration this
* title is used, otherwise the fully qualified name of the configuration is
* used.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class ConfigurationsTable extends Table {
private static final int COL_TITLE = 0;
private static final int COL_DESC = 1;
public ConfigurationsTable(
final ConfigurationTab configurationTab,
final ParameterSingleSelectionModel<String> selectedConf,
final TextField confClassesFilter) {
super();
setIdAttr("configurationsTable");
setEmptyView(new Label(new GlobalizedMessage(
"ui.admin.configuration.configurations.none", ADMIN_BUNDLE)));
final TableColumnModel columnModel = getColumnModel();
columnModel.add(new TableColumn(
COL_TITLE,
new Label(new GlobalizedMessage(
"ui.admin.configuration.configurations.table.name",
ADMIN_BUNDLE))));
columnModel.add(new TableColumn(
COL_DESC,
new Label(new GlobalizedMessage(
"ui.admin.configuration.configurations.table.desc",
ADMIN_BUNDLE))));
columnModel.get(COL_TITLE).setCellRenderer(new TableCellRenderer() {
@Override
public Component getComponent(final Table table,
final PageState state,
final Object value,
final boolean isSelected,
final Object key,
final int row,
final int column) {
return new ControlLink((String) value);
}
});
addTableActionListener(new TableActionListener() {
@Override
public void cellSelected(final TableActionEvent event) {
final PageState state = event.getPageState();
if (event.getColumn() == COL_TITLE) {
final String confClassName = (String) event.getRowKey();
selectedConf.setSelectedKey(state, confClassName);
configurationTab.showConfiguration(state);
}
}
@Override
public void headSelected(final TableActionEvent event) {
//Nothing
}
});
setModelBuilder(new ConfigurationsTableModelBuilder(confClassesFilter));
}
private class ConfigurationsTableModelBuilder
extends LockableImpl implements TableModelBuilder {
private final TextField confClassesFilter;
public ConfigurationsTableModelBuilder(
final TextField confClassesField) {
this.confClassesFilter = confClassesField;
}
@Override
public TableModel makeModel(final Table table,
final PageState state) {
table.getRowSelectionModel().clearSelection(state);
return new ConfigurationsTableModel(confClassesFilter, state);
}
}
private class ConfigurationsTableModel implements TableModel {
private final List<Class<?>> configurations;
private int index = -1;
private final ConfigurationManager confManager;
private final Locale negoiatedLocale;
public ConfigurationsTableModel(final TextField confClassesFilter,
final PageState state) {
final String filterTerm = (String) confClassesFilter
.getValue(state);
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
confManager = cdiUtil.findBean(ConfigurationManager.class);
final GlobalizationHelper globalizationHelper = cdiUtil.findBean(
GlobalizationHelper.class);
negoiatedLocale = globalizationHelper.getNegotiatedLocale();
final SortedSet<Class<?>> confs = confManager
.findAllConfigurations();
configurations = confs.stream()
.filter(c -> {
final ConfigurationInfo info = confManager
.getConfigurationInfo(c);
// return c.getName().startsWith(filterTerm);
if (filterTerm == null || filterTerm.isEmpty()) {
return true;
} else {
return info.getTitle(negoiatedLocale).startsWith(
filterTerm);
}
})
.collect(Collectors.toCollection(ArrayList::new));
configurations.sort((c1, c2) -> {
// return c1.getName().compareTo(c2.getName());
final ConfigurationInfo info1 = confManager
.getConfigurationInfo(c1);
final ConfigurationInfo info2 = confManager
.getConfigurationInfo(c2);
return info1.getTitle(negoiatedLocale)
.compareTo(info2.getTitle(negoiatedLocale));
});
}
@Override
public int getColumnCount() {
return 2;
}
@Override
public boolean nextRow() {
index++;
return index < configurations.size();
}
@Override
public Object getElementAt(final int columnIndex) {
final ConfigurationInfo info = confManager.getConfigurationInfo(
configurations.get(index));
switch (columnIndex) {
case COL_TITLE:
if (Strings.isBlank(info.getTitle(negoiatedLocale))) {
return configurations.get(index).getSimpleName();
} else {
return info.getTitle(negoiatedLocale);
}
case COL_DESC:
return info.getDescription(negoiatedLocale);
default:
throw new IllegalArgumentException("Illegal column index");
}
}
@Override
public Object getKeyAt(final int columnIndex) {
return configurations.get(index).getName();
}
}
}

View File

@ -1,433 +0,0 @@
/*
* Copyright (C) 2016 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.ui.admin.configuration;
import com.arsdigita.bebop.BoxPanel;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.ControlLink;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.SaveCancelSection;
import com.arsdigita.bebop.Table;
import com.arsdigita.bebop.Text;
import com.arsdigita.bebop.event.TableActionEvent;
import com.arsdigita.bebop.event.TableActionListener;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.table.TableCellRenderer;
import com.arsdigita.bebop.table.TableColumn;
import com.arsdigita.bebop.table.TableColumnModel;
import com.arsdigita.bebop.table.TableModel;
import com.arsdigita.bebop.table.TableModelBuilder;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.util.LockableImpl;
import com.arsdigita.util.UncheckedWrapperException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.configuration.EnumSetting;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static com.arsdigita.ui.admin.AdminUiConstants.*;
/**
* Editor for {@link EnumSetting}s. The editor consists of the usual header (see
* {@link SettingFormHeader}) which is used by all setting forms/editors, a
* table which displays all current values together with links for editing and
* deleting the values and a form for adding and editing values.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class SettingEditorEnum extends BoxPanel {
private static final Logger LOGGER = LogManager.getLogger(
SettingEditorEnum.class);
private static final int COL_VALUE = 0;
private static final int COL_EDIT = 1;
private static final int COL_DEL = 2;
private final ConfigurationTab configurationTab;
private final ParameterSingleSelectionModel<String> selectedConf;
private final ParameterSingleSelectionModel<String> selectedSetting;
private final ParameterSingleSelectionModel<String> selectedValue;
public SettingEditorEnum(
final ConfigurationTab configurationTab,
final ParameterSingleSelectionModel<String> selectedConf,
final ParameterSingleSelectionModel<String> selectedSetting,
final ParameterSingleSelectionModel<String> selectedValue) {
super(BoxPanel.VERTICAL);
this.configurationTab = configurationTab;
this.selectedConf = selectedConf;
this.selectedSetting = selectedSetting;
this.selectedValue = selectedValue;
add(new SettingFormHeader(configurationTab,
selectedConf,
selectedSetting));
add(new ValuesTable());
add(new ValueForm());
}
private class ValuesTable extends Table {
public ValuesTable() {
super();
setIdAttr("enumValues");
setEmptyView(new Label(new GlobalizedMessage(
"ui.admin.configuration.setting.enum.no_values", ADMIN_BUNDLE)));
final TableColumnModel columnModel = getColumnModel();
columnModel.add(new TableColumn(
COL_VALUE,
new Label(new GlobalizedMessage(
"ui.admin.configuration.setting.enum.col_value",
ADMIN_BUNDLE))));
columnModel.add(new TableColumn(
COL_EDIT,
new Label(new GlobalizedMessage(
"ui.admin.configuration.setting.enum.col_edit",
ADMIN_BUNDLE))));
columnModel.add(new TableColumn(
COL_DEL,
new Label(new GlobalizedMessage(
"ui.admin.configuration.setting.enum.col_del",
ADMIN_BUNDLE))));
columnModel.get(COL_EDIT).setCellRenderer(new TableCellRenderer() {
@Override
public Component getComponent(final Table table,
final PageState state,
final Object value,
final boolean isSelected,
final Object key,
final int row,
final int column) {
return new ControlLink((Component) value);
}
});
columnModel.get(COL_DEL).setCellRenderer(new TableCellRenderer() {
@Override
public Component getComponent(final Table table,
final PageState state,
final Object value,
final boolean isSelected,
final Object key,
final int row,
final int column) {
if (value == null) {
return new Text("");
} else {
final ControlLink link = new ControlLink(
(Component) value);
link.setConfirmation(new GlobalizedMessage(
"ui.admin.configuration.setting.enum.del_confirm",
ADMIN_BUNDLE));
return link;
}
}
});
addTableActionListener(new TableActionListener() {
@Override
@SuppressWarnings("unchecked")
public void cellSelected(final TableActionEvent event) {
final PageState state = event.getPageState();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final Class<?> confClass;
try {
confClass = Class
.forName(selectedConf.getSelectedKey(state));
} catch (ClassNotFoundException ex) {
throw new UncheckedWrapperException(ex);
}
final ConfigurationManager confManager = cdiUtil
.findBean(
ConfigurationManager.class);
final Object config = confManager.findConfiguration(
confClass);
final Set<String> values;
try {
final Field field = confClass.getDeclaredField(
selectedSetting.getSelectedKey(state));
field.setAccessible(true);
values = (Set<String>) field.get(config);
} catch (NoSuchFieldException |
SecurityException |
IllegalAccessException |
ClassCastException ex) {
LOGGER.warn(
"Failed to read setting {} from configuration {}",
selectedSetting.getSelectedKey(state),
selectedConf.getSelectedKey(state));
LOGGER.warn(ex);
throw new UncheckedWrapperException(ex);
}
switch (event.getColumn()) {
case COL_EDIT: {
selectedValue.setSelectedKey(state, event
.getRowKey());
break;
}
case COL_DEL: {
values.remove(event.getRowKey());
confManager.saveConfiguration(config);
break;
}
}
}
@Override
public void headSelected(final TableActionEvent event) {
//Notthing
}
});
setModelBuilder(new ValuesTableModelBuilder());
}
}
private class ValuesTableModelBuilder
extends LockableImpl
implements TableModelBuilder {
@Override
public TableModel makeModel(final Table table,
final PageState state) {
table.getRowSelectionModel().clearSelection(state);
return new ValuesTableModel(state);
}
}
private class ValuesTableModel implements TableModel {
private final List<String> values;
private int index = -1;
public ValuesTableModel(final PageState state) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final Class<?> confClass;
try {
confClass = Class
.forName(selectedConf.getSelectedKey(state));
} catch (ClassNotFoundException ex) {
throw new UncheckedWrapperException(ex);
}
final ConfigurationManager confManager = cdiUtil.findBean(
ConfigurationManager.class);
final Object config = confManager.findConfiguration(confClass);
try {
@SuppressWarnings("unchecked")
final Field field = confClass.getDeclaredField(selectedSetting
.getSelectedKey(state));
field.setAccessible(true);
final Set<String> valuesSet = (Set<String>) field.get(config);
values = new ArrayList<>(valuesSet);
} catch (NoSuchFieldException |
SecurityException |
IllegalAccessException |
ClassCastException ex) {
LOGGER.warn("Failed to read setting {} from configuration {}",
selectedSetting.getSelectedKey(state),
selectedConf.getSelectedKey(state));
LOGGER.warn(ex);
throw new UncheckedWrapperException(ex);
}
}
@Override
public int getColumnCount() {
return 3;
}
@Override
public boolean nextRow() {
index++;
return index < values.size();
}
@Override
public Object getElementAt(final int columnIndex) {
switch (columnIndex) {
case COL_VALUE:
return values.get(index);
case COL_EDIT:
return new Label(new GlobalizedMessage(
"ui.admin.configuration.setting.enum.value.edit",
ADMIN_BUNDLE));
case COL_DEL:
return new Label(new GlobalizedMessage(
"ui.admin.configuration.setting.enum.value.del",
ADMIN_BUNDLE));
default:
throw new IllegalArgumentException(
"Not a valid column index");
}
}
@Override
public Object getKeyAt(final int columnIndex) {
return values.get(index);
}
}
private class ValueForm extends Form {
private final String VALUE = "value";
@SuppressWarnings("unchecked")
public ValueForm() {
super("settingEnumValueForm");
final TextField valueField = new TextField(VALUE);
valueField.setLabel(new GlobalizedMessage(
"ui.admin.configuration.setting.enum.value.label",
ADMIN_BUNDLE));
add(valueField);
final SaveCancelSection saveCancelSection = new SaveCancelSection();
add(saveCancelSection);
addInitListener(e -> {
final PageState state = e.getPageState();
if (selectedValue.getSelectedKey(state) != null) {
valueField.setValue(state, selectedValue.getSelectedKey(
state));
}
});
addProcessListener(e -> {
final PageState state = e.getPageState();
if (saveCancelSection.getSaveButton().isSelected(state)) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final Class<?> confClass;
try {
confClass = Class
.forName(selectedConf.getSelectedKey(state));
} catch (ClassNotFoundException ex) {
throw new UncheckedWrapperException(ex);
}
final ConfigurationManager confManager = cdiUtil.findBean(
ConfigurationManager.class);
final Object config = confManager.findConfiguration(
confClass);
final Set<String> enumSetting;
try {
final Field field = confClass.getDeclaredField(
selectedSetting.getSelectedKey(state));
field.setAccessible(true);
final Object value = field.get(config);
if (value == null) {
enumSetting = new HashSet<>();
confClass.getDeclaredField(selectedSetting
.getSelectedKey(state)).set(config,
enumSetting);
} else {
enumSetting = (Set<String>) value;
}
} catch (NoSuchFieldException |
SecurityException |
IllegalAccessException |
ClassCastException ex) {
LOGGER.warn(
"Failed to read setting {} from configuration {}",
selectedSetting.getSelectedKey(state),
selectedConf.getSelectedKey(state));
LOGGER.warn(ex);
throw new UncheckedWrapperException(ex);
}
final FormData data = e.getFormData();
final String valueData = data.getString(VALUE);
if (selectedValue.getSelectedKey(state) == null) {
enumSetting.add(valueData);
} else {
final String selected = selectedValue.getSelectedKey(
state);
enumSetting.remove(selected);
enumSetting.add(valueData);
}
confManager.saveConfiguration(config);
}
selectedValue.clearSelection(state);
valueField.setValue(state, null);
});
}
}
}

View File

@ -1,632 +0,0 @@
/*p
* Copyright (C) 2016 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.ui.admin.configuration;
import com.arsdigita.bebop.BoxPanel;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.ControlLink;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.SaveCancelSection;
import com.arsdigita.bebop.Table;
import com.arsdigita.bebop.Text;
import com.arsdigita.bebop.event.TableActionEvent;
import com.arsdigita.bebop.event.TableActionListener;
import com.arsdigita.bebop.form.Option;
import com.arsdigita.bebop.form.SingleSelect;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.table.TableCellRenderer;
import com.arsdigita.bebop.table.TableColumn;
import com.arsdigita.bebop.table.TableColumnModel;
import com.arsdigita.bebop.table.TableModel;
import com.arsdigita.bebop.table.TableModelBuilder;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.kernel.KernelConfig;
import com.arsdigita.util.LockableImpl;
import com.arsdigita.util.UncheckedWrapperException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.l10n.LocalizedString;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.TooManyListenersException;
import static com.arsdigita.ui.admin.AdminUiConstants.*;
/**
* Editor for {@link LocalizedStringSetting}s. The editor consists of the usual
* header (see {@link SettingFormHeader}) which is used by all setting
* forms/editors, a table which displays all current values together with links
* for editing and deleting the values and a form for adding and editing values.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class SettingEditorLocalizedString extends BoxPanel {
private final static Logger LOGGER = LogManager.getLogger(
SettingEditorLocalizedString.class);
private static final int COL_LOCALE = 0;
private static final int COL_VALUE = 1;
private static final int COL_EDIT = 2;
private static final int COL_DEL = 3;
private final ConfigurationTab configurationTab;
private final ParameterSingleSelectionModel<String> selectedConf;
private final ParameterSingleSelectionModel<String> selectedSetting;
private final ParameterSingleSelectionModel<String> selectedValue;
public SettingEditorLocalizedString(
final ConfigurationTab configurationTab,
final ParameterSingleSelectionModel<String> selectedConf,
final ParameterSingleSelectionModel<String> selectedSetting,
final ParameterSingleSelectionModel<String> selectedValue) {
super(BoxPanel.VERTICAL);
this.configurationTab = configurationTab;
this.selectedConf = selectedConf;
this.selectedSetting = selectedSetting;
this.selectedValue = selectedValue;
add(new SettingFormHeader(configurationTab,
selectedConf,
selectedSetting));
add(new ValuesTable());
add(new ValueForm());
}
private class ValuesTable extends Table {
public ValuesTable() {
super();
setIdAttr("localizedStringSettingValues");
setEmptyView(new Label(new GlobalizedMessage(
"ui.admin.configuration.setting.localized_string.no_values",
ADMIN_BUNDLE)));
final TableColumnModel columnModel = getColumnModel();
columnModel.add(new TableColumn(
COL_LOCALE,
new Label(new GlobalizedMessage(
"ui.admin.configuration.setting.localized_string.col_lang",
ADMIN_BUNDLE))));
columnModel.add(new TableColumn(
COL_VALUE,
new Label(new GlobalizedMessage(
"ui.admin.configuration.setting.localized_string.col_value",
ADMIN_BUNDLE))));
columnModel.add(new TableColumn(
COL_EDIT,
new Label(new GlobalizedMessage(
"ui.admin.configuration.setting.localized_string.col_edit",
ADMIN_BUNDLE))));
columnModel.add(new TableColumn(
COL_DEL,
new Label(new GlobalizedMessage(
"ui.admin.configuration.setting.localized_string.col_del",
ADMIN_BUNDLE))));
columnModel.get(COL_EDIT).setCellRenderer(new TableCellRenderer() {
@Override
public Component getComponent(final Table table,
final PageState state,
final Object value,
final boolean isSelected,
final Object key,
final int row,
final int column) {
return new ControlLink((Component) value);
}
});
columnModel.get(COL_DEL).setCellRenderer(new TableCellRenderer() {
@Override
public Component getComponent(final Table table,
final PageState state,
final Object value,
final boolean isSelected,
final Object key,
final int row,
final int column) {
if (value == null) {
return new Text("");
} else {
final ControlLink link = new ControlLink(
(Component) value);
link.setConfirmation(new GlobalizedMessage(
"ui.admin.configuration.setting.localized_string.del_confirm",
ADMIN_BUNDLE));
return link;
}
}
});
addTableActionListener(new TableActionListener() {
@Override
public void cellSelected(final TableActionEvent event) {
final PageState state = event.getPageState();
switch (event.getColumn()) {
case COL_EDIT:
selectedValue.setSelectedKey(state,
event.getRowKey());
break;
case COL_DEL:
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final Class<?> confClass;
try {
confClass = Class
.forName(selectedConf.getSelectedKey(state));
} catch (ClassNotFoundException ex) {
throw new UncheckedWrapperException(ex);
}
final ConfigurationManager confManager = cdiUtil
.findBean(
ConfigurationManager.class);
final Object config = confManager.findConfiguration(
confClass);
final LocalizedString localizedStr;
try {
final Field field = confClass.getDeclaredField(
selectedSetting.getSelectedKey(state));
field.setAccessible(true);
final Object value = field.get(config);
if (value == null) {
localizedStr = new LocalizedString();
field.set(config, localizedStr);
} else {
localizedStr = (LocalizedString) value;
}
} catch (NoSuchFieldException |
SecurityException |
IllegalAccessException |
ClassCastException ex) {
LOGGER.warn(
"Failed to read setting {} from configuration {}",
selectedSetting.getSelectedKey(state),
selectedConf.getSelectedKey(state));
LOGGER.warn(ex);
throw new UncheckedWrapperException(ex);
}
final Locale locale = new Locale((String) event
.getRowKey());
localizedStr.removeValue(locale);
confManager.saveConfiguration(config);
break;
}
}
@Override
public void headSelected(final TableActionEvent event) {
//Nothing
}
});
setModelBuilder(new ValuesTableModelBuilder());
}
}
private class ValuesTableModelBuilder
extends LockableImpl
implements TableModelBuilder {
@Override
public TableModel makeModel(final Table table,
final PageState state) {
table.getRowSelectionModel().clearSelection(state);
return new ValuesTableModel(state);
}
}
private class ValuesTableModel implements TableModel {
private final LocalizedString value;
private final List<Locale> locales;
private int index = -1;
public ValuesTableModel(final PageState state) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final Class<?> confClass;
try {
confClass = Class
.forName(selectedConf.getSelectedKey(state));
} catch (ClassNotFoundException ex) {
throw new UncheckedWrapperException(ex);
}
final ConfigurationManager confManager = cdiUtil.findBean(
ConfigurationManager.class);
final Object config = confManager.findConfiguration(confClass);
try {
final Field field = confClass.getDeclaredField(selectedSetting
.getSelectedKey(state));
field.setAccessible(true);
value = (LocalizedString) field.get(config);
locales = new ArrayList<>();
locales.addAll(value.getAvailableLocales());
locales.sort((s1, s2) -> {
return s1.toString().compareTo(s2.toString());
});
} catch (NoSuchFieldException |
SecurityException |
IllegalAccessException |
ClassCastException ex) {
LOGGER.warn("Failed to read setting {} from configuration {}",
selectedSetting.getSelectedKey(state),
selectedConf.getSelectedKey(state));
LOGGER.warn(ex);
throw new UncheckedWrapperException(ex);
}
}
@Override
public int getColumnCount() {
return 4;
}
@Override
public boolean nextRow() {
index++;
return index < locales.size();
}
@Override
public Object getElementAt(final int columnIndex) {
final Locale locale = locales.get(index);
switch (columnIndex) {
case COL_LOCALE:
return locale.toString();
case COL_VALUE:
return value.getValue(locale);
case COL_EDIT:
return new Label(new GlobalizedMessage(
"ui.admin.configuration.setting.localized_string.value.edit",
ADMIN_BUNDLE));
case COL_DEL:
return new Label(new GlobalizedMessage(
"ui.admin.configuration.setting.localized_string.title.del",
ADMIN_BUNDLE
));
default:
throw new IllegalArgumentException(
"Not a valid column index");
}
}
@Override
public Object getKeyAt(final int columnIndex) {
return locales.get(index);
}
}
private class ValueForm extends Form {
private static final String LOCALE_SELECT = "localeSelect";
private static final String VALUE = "value";
private final SingleSelect localeSelect;
public ValueForm() {
super("settingLocalizedStringValueForm");
localeSelect = new SingleSelect(LOCALE_SELECT);
localeSelect.setLabel(new GlobalizedMessage(
"ui.admin.configuration.setting.localized_string.locale.label",
ADMIN_BUNDLE));
try {
localeSelect.addPrintListener(e -> {
final PageState state = e.getPageState();
if (selectedValue.getSelectedKey(state) == null) {
final ConfigurationManager confManager = CdiUtil
.createCdiUtil()
.findBean(ConfigurationManager.class);
final Class<?> confClass;
try {
confClass = Class
.forName(selectedConf.getSelectedKey(state));
} catch (ClassNotFoundException ex) {
throw new UncheckedWrapperException(ex);
}
final Object config = confManager.findConfiguration(
confClass);
final LocalizedString value;
try {
final Field field = confClass.getDeclaredField(
selectedSetting.getSelectedKey(state));
field.setAccessible(true);
value = (LocalizedString) field.get(config);
} catch (NoSuchFieldException |
SecurityException |
IllegalAccessException |
ClassCastException ex) {
LOGGER.warn(
"Failed to read setting {} from configuration {}",
selectedSetting.getSelectedKey(state),
selectedConf.getSelectedKey(state));
LOGGER.warn(ex);
throw new UncheckedWrapperException(
String.format(
"Failed to read setting %s from configuration %s",
selectedSetting.getSelectedKey(state),
selectedConf.getSelectedKey(state)),
ex);
}
final Set<String> supportedLanguages = KernelConfig
.getConfig().getSupportedLanguages();
final Set<String> assignedLanguages = new HashSet<>();
value.getAvailableLocales().forEach(l -> {
assignedLanguages.add(l.toString());
});
final SingleSelect target = (SingleSelect) e.getTarget();
target.clearOptions();
supportedLanguages.forEach(l -> {
if (!assignedLanguages.contains(l)) {
target.addOption(new Option(l, new Text(l)));
}
});
} else {
final SingleSelect target = (SingleSelect) e.getTarget();
target.clearOptions();
final String language = selectedValue.getSelectedKey(
state);
target.addOption(
new Option(language, new Text(language)));
}
});
} catch (TooManyListenersException ex) {
//We are in big trouble...
throw new UncheckedWrapperException(ex);
}
add(localeSelect);
final TextField localizedValue = new TextField(VALUE);
localizedValue.setLabel(new GlobalizedMessage(
"ui.admin.configuration.setting.localized_string.value.label",
ADMIN_BUNDLE));
add(localizedValue);
final SaveCancelSection saveCancelSection = new SaveCancelSection();
add(saveCancelSection);
addInitListener(e -> {
final PageState state = e.getPageState();
if (selectedValue.getSelectedKey(state) != null) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final Class<?> confClass;
try {
confClass = Class
.forName(selectedConf.getSelectedKey(state));
} catch (ClassNotFoundException ex) {
throw new UncheckedWrapperException(ex);
}
final ConfigurationManager confManager = cdiUtil.findBean(
ConfigurationManager.class);
final Object config = confManager.findConfiguration(
confClass);
try {
final Field field = confClass.getDeclaredField(
selectedSetting.getSelectedKey(state));
field.setAccessible(true);
final LocalizedString localizedStr
= (LocalizedString) field.get(
config);
final String value = localizedStr.getValue(new Locale(
selectedValue.getSelectedKey(state)));
localizedValue.setValue(state, value);
} catch (NoSuchFieldException | SecurityException |
IllegalAccessException | ClassCastException ex) {
LOGGER.warn(
"Failed to read setting {} from configuration {}",
selectedSetting.getSelectedKey(state),
selectedConf.getSelectedKey(state));
LOGGER.warn(ex);
throw new UncheckedWrapperException(ex);
}
}
});
addProcessListener(e -> {
final PageState state = e.getPageState();
if (saveCancelSection.getSaveButton().isSelected(state)) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final Class<?> confClass;
try {
confClass = Class
.forName(selectedConf.getSelectedKey(state));
} catch (ClassNotFoundException ex) {
throw new UncheckedWrapperException(ex);
}
final ConfigurationManager confManager = cdiUtil.findBean(
ConfigurationManager.class);
final Object config = confManager.findConfiguration(
confClass);
final LocalizedString localizedStr;
try {
final Field field = confClass.getDeclaredField(
selectedSetting.getSelectedKey(state));
field.setAccessible(true);
final Object value = field.get(config);
if (value == null) {
localizedStr = new LocalizedString();
field.set(config, localizedStr);
} else {
localizedStr = (LocalizedString) value;
}
} catch (NoSuchFieldException |
SecurityException |
IllegalAccessException |
ClassCastException ex) {
LOGGER.warn(
"Failed to read setting {} from configuration {}",
selectedSetting.getSelectedKey(state),
selectedConf.getSelectedKey(state));
LOGGER.warn(ex);
throw new UncheckedWrapperException(ex);
}
final FormData data = e.getFormData();
final Locale locale = new Locale(data.getString(
LOCALE_SELECT));
final String valueData = data.getString(VALUE);
localizedStr.putValue(locale, valueData);
confManager.saveConfiguration(config);
}
selectedValue.clearSelection(state);
localeSelect.setValue(state, null);
localizedValue.setValue(state, null);
});
}
@Override
public boolean isVisible(final PageState state) {
if (super.isVisible(state)) {
if (selectedValue.getSelectedKey(state) == null) {
final ConfigurationManager confManager = CdiUtil
.createCdiUtil()
.findBean(ConfigurationManager.class);
final Class<?> confClass;
try {
confClass = Class
.forName(selectedConf.getSelectedKey(state));
} catch (ClassNotFoundException ex) {
throw new UncheckedWrapperException(ex);
}
final Object config = confManager.findConfiguration(
confClass);
final LocalizedString value;
try {
final Field field = confClass.getDeclaredField(
selectedSetting.getSelectedKey(state));
field.setAccessible(true);
value = (LocalizedString) field.get(config);
} catch (NoSuchFieldException |
SecurityException |
IllegalAccessException |
ClassCastException ex) {
LOGGER.warn(
"Failed to read setting {} from configuration {}",
selectedSetting.getSelectedKey(state),
selectedConf.getSelectedKey(state));
LOGGER.warn(ex);
throw new UncheckedWrapperException(
String.format(
"Failed to read setting %s from configuration %s",
selectedSetting.getSelectedKey(state),
selectedConf.getSelectedKey(state)),
ex);
}
final Set<String> supportedLanguages = KernelConfig
.getConfig().getSupportedLanguages();
final Set<String> assignedLanguages = new HashSet<>();
value.getAvailableLocales().forEach(l -> {
assignedLanguages.add(l.toString());
});
return !assignedLanguages.equals(supportedLanguages);
} else {
return true;
}
} else {
return false;
}
}
}
}

View File

@ -1,591 +0,0 @@
/*
* Copyright (C) 2016 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.ui.admin.configuration;
import com.arsdigita.bebop.BoxPanel;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.ControlLink;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.SaveCancelSection;
import com.arsdigita.bebop.Table;
import com.arsdigita.bebop.Text;
import com.arsdigita.bebop.event.TableActionEvent;
import com.arsdigita.bebop.event.TableActionListener;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.table.TableCellRenderer;
import com.arsdigita.bebop.table.TableColumn;
import com.arsdigita.bebop.table.TableColumnModel;
import com.arsdigita.bebop.table.TableModel;
import com.arsdigita.bebop.table.TableModelBuilder;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.util.LockableImpl;
import com.arsdigita.util.UncheckedWrapperException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.configuration.EnumSetting;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import static com.arsdigita.ui.admin.AdminUiConstants.*;
/**
* Editor for {@link EnumSetting}s. The editor consists of the usual header (see
* {@link SettingFormHeader}) which is used by all setting forms/editors, a
* table which displays all current values together with links for moving,
* editing and deleting the values and a form for adding and editing values.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class SettingEditorStringList extends BoxPanel {
private static final Logger LOGGER = LogManager.getLogger(
SettingEditorStringList.class);
private static final int COL_VALUE = 0;
private static final int COL_UP = 1;
private static final int COL_DOWN = 2;
private static final int COL_EDIT = 3;
private static final int COL_DEL = 4;
private final ConfigurationTab configurationTab;
private final ParameterSingleSelectionModel<String> selectedConf;
private final ParameterSingleSelectionModel<String> selectedSetting;
private final ParameterSingleSelectionModel<String> selectedValue;
public SettingEditorStringList(
final ConfigurationTab configurationTab,
final ParameterSingleSelectionModel<String> selectedConf,
final ParameterSingleSelectionModel<String> selectedSetting,
final ParameterSingleSelectionModel<String> selectedValue) {
super(BoxPanel.VERTICAL);
this.configurationTab = configurationTab;
this.selectedConf = selectedConf;
this.selectedSetting = selectedSetting;
this.selectedValue = selectedValue;
add(new SettingFormHeader(configurationTab,
selectedConf,
selectedSetting));
add(new ValuesTable());
add(new ValueForm());
}
private class ValuesTable extends Table {
public ValuesTable() {
super();
setIdAttr("stringListValues");
setEmptyView(new Label(new GlobalizedMessage(
"ui.admin.configuration.setting.stringlist.no_values",
ADMIN_BUNDLE)));
final TableColumnModel columnModel = getColumnModel();
columnModel.add(new TableColumn(
COL_VALUE,
new Label(new GlobalizedMessage(
"ui.admin.configuration.setting.stringlist.col_value",
ADMIN_BUNDLE))));
columnModel.add(new TableColumn(
COL_UP,
new Label(new GlobalizedMessage(
"ui.admin.configuration.setting.stringlist.col_up",
ADMIN_BUNDLE))));
columnModel.add(new TableColumn(
COL_DOWN,
new Label(new GlobalizedMessage(
"ui.admin.configuration.setting.stringlist.col_down",
ADMIN_BUNDLE))));
columnModel.add(new TableColumn(
COL_EDIT,
new Label(new GlobalizedMessage(
"ui.admin.configuration.setting.stringlist.col_edit",
ADMIN_BUNDLE))));
columnModel.add(new TableColumn(
COL_DEL,
new Label(new GlobalizedMessage(
"ui.admin.configuration.setting.stringlist.col_delete",
ADMIN_BUNDLE))));
columnModel.get(COL_UP).setCellRenderer(new TableCellRenderer() {
@Override
public Component getComponent(final Table table,
final PageState state,
final Object value,
final boolean isSelected,
final Object key,
final int row,
final int column) {
if (row > 0) {
return new ControlLink((Component) value);
} else {
return new Text("");
}
}
});
columnModel.get(COL_DOWN).setCellRenderer(new TableCellRenderer() {
@Override
@SuppressWarnings("unchecked")
public Component getComponent(final Table table,
final PageState state,
final Object value,
final boolean isSelected,
final Object key,
final int row,
final int column) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final Class<?> confClass;
try {
confClass = Class
.forName(selectedConf.getSelectedKey(state));
} catch (ClassNotFoundException ex) {
throw new UncheckedWrapperException(ex);
}
final ConfigurationManager confManager = cdiUtil
.findBean(
ConfigurationManager.class);
final Object config = confManager.findConfiguration(
confClass);
final List<String> values;
try {
final Field field = confClass.getDeclaredField(
selectedSetting.getSelectedKey(state));
field.setAccessible(true);
values = (List<String>) field.get(config);
} catch (NoSuchFieldException |
SecurityException |
IllegalAccessException |
ClassCastException ex) {
LOGGER.warn(
"Failed to read setting {} from configuration {}",
selectedSetting.getSelectedKey(state),
selectedConf.getSelectedKey(state));
LOGGER.warn(ex);
throw new UncheckedWrapperException(ex);
}
if (row < values.size()) {
return new ControlLink((Component) value);
} else {
return new Text("");
}
}
});
columnModel.get(COL_EDIT).setCellRenderer(new TableCellRenderer() {
@Override
public Component getComponent(final Table table,
final PageState state,
final Object value,
final boolean isSelected,
final Object key,
final int row,
final int column) {
return new ControlLink((Component) value);
}
});
columnModel.get(COL_DEL).setCellRenderer(new TableCellRenderer() {
@Override
public Component getComponent(final Table table,
final PageState state,
final Object value,
final boolean isSelected,
final Object key,
final int row,
final int column) {
if (value == null) {
return new Text("");
} else {
final ControlLink link = new ControlLink(
(Component) value);
link.setConfirmation(new GlobalizedMessage(
"ui.admin.configuration.setting.stringlist.del_confirm",
ADMIN_BUNDLE));
return link;
}
}
});
addTableActionListener(new TableActionListener() {
@Override
@SuppressWarnings("unchecked")
public void cellSelected(final TableActionEvent event) {
final PageState state = event.getPageState();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final Class<?> confClass;
try {
confClass = Class
.forName(selectedConf.getSelectedKey(state));
} catch (ClassNotFoundException ex) {
throw new UncheckedWrapperException(ex);
}
final ConfigurationManager confManager = cdiUtil
.findBean(
ConfigurationManager.class);
final Object config = confManager.findConfiguration(
confClass);
final List<String> values;
try {
final Field field = confClass.getDeclaredField(
selectedSetting.getSelectedKey(state));
field.setAccessible(true);
values = (List<String>) field.get(config);
} catch (NoSuchFieldException | SecurityException |
IllegalAccessException | ClassCastException ex) {
LOGGER.warn(
"Failed to read setting {} from configuration {}",
selectedSetting.getSelectedKey(state),
selectedConf.getSelectedKey(state));
LOGGER.warn(ex);
throw new UncheckedWrapperException(ex);
}
switch (event.getColumn()) {
case COL_UP: {
final int currentIndex = Integer.parseInt(
(String) event.getRowKey());
final int previousIndex = currentIndex - 1;
final String currentValue = values.get(currentIndex);
final String previousValue = values.get(
previousIndex);
values.set(previousIndex, currentValue);
values.set(currentIndex, previousValue);
confManager.saveConfiguration(config);
break;
}
case COL_DOWN: {
final int currentIndex = Integer.parseInt(
(String) event.getRowKey());
final int nextIndex = currentIndex + 1;
final String currentValue = values.get(currentIndex);
final String nextValue = values.get(nextIndex);
values.set(nextIndex, currentValue);
values.set(currentIndex, nextValue);
confManager.saveConfiguration(config);
break;
}
case COL_EDIT: {
selectedValue.setSelectedKey(state,
event.getRowKey());
break;
}
case COL_DEL: {
values.remove(Integer.parseInt((String) event
.getRowKey()));
confManager.saveConfiguration(config);
break;
}
}
}
@Override
public void headSelected(final TableActionEvent event) {
//Notthing
}
});
setModelBuilder(new ValuesTableModelBuilder());
}
}
private class ValuesTableModelBuilder
extends LockableImpl
implements TableModelBuilder {
@Override
public TableModel makeModel(final Table table,
final PageState state) {
table.getRowSelectionModel().clearSelection(state);
return new ValuesTableModel(state);
}
}
private class ValuesTableModel implements TableModel {
private final List<String> values;
private int index = -1;
@SuppressWarnings("unchecked")
public ValuesTableModel(final PageState state) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final Class<?> confClass;
try {
confClass = Class
.forName(selectedConf.getSelectedKey(state));
} catch (ClassNotFoundException ex) {
throw new UncheckedWrapperException(ex);
}
final ConfigurationManager confManager = cdiUtil.findBean(
ConfigurationManager.class);
final Object config = confManager.findConfiguration(confClass);
try {
final Field field = confClass.getDeclaredField(selectedSetting
.getSelectedKey(state));
field.setAccessible(true);
values = (List<String>) field.get(config);
} catch (NoSuchFieldException |
SecurityException |
IllegalAccessException |
ClassCastException ex) {
LOGGER.warn("Failed to read setting {} from configuration {}",
selectedSetting.getSelectedKey(state),
selectedConf.getSelectedKey(state));
LOGGER.warn(ex);
throw new UncheckedWrapperException(ex);
}
}
@Override
public int getColumnCount() {
return 5;
}
@Override
public boolean nextRow() {
index++;
return index < values.size();
}
@Override
public Object getElementAt(final int columnIndex) {
switch (columnIndex) {
case COL_VALUE:
return values.get(index);
case COL_UP:
return new Label(new GlobalizedMessage(
"ui.admin.configuration.setting.stringlist.value.up",
ADMIN_BUNDLE));
case COL_DOWN:
return new Label(new GlobalizedMessage(
"ui.admin.configuration.setting.stringlist.value.down",
ADMIN_BUNDLE));
case COL_EDIT:
return new Label(new GlobalizedMessage(
"ui.admin.configuration.setting.stringlist.value.edit",
ADMIN_BUNDLE));
case COL_DEL:
return new Label(new GlobalizedMessage(
"ui.admin.configuration.setting.stringlist.value.del",
ADMIN_BUNDLE));
default:
throw new IllegalArgumentException(
"Not a valid column index");
}
}
@Override
public Object getKeyAt(final int columnIndex) {
return index;
}
}
private class ValueForm extends Form {
private final String VALUE = "value";
@SuppressWarnings("unchecked")
public ValueForm() {
super("settingStringListValueForm");
final TextField valueField = new TextField(VALUE);
valueField.setLabel(new GlobalizedMessage(
"ui.admin.configuration.setting.stringlist.value.label",
ADMIN_BUNDLE));
add(valueField);
final SaveCancelSection saveCancelSection = new SaveCancelSection();
add(saveCancelSection);
addInitListener(e -> {
final PageState state = e.getPageState();
if (selectedValue.getSelectedKey(state) != null) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final Class<?> confClass;
try {
confClass = Class
.forName(selectedConf.getSelectedKey(state));
} catch (ClassNotFoundException ex) {
throw new UncheckedWrapperException(ex);
}
final ConfigurationManager confManager = cdiUtil.findBean(
ConfigurationManager.class);
final Object config = confManager.findConfiguration(
confClass);
try {
@SuppressWarnings("unchecked")
final Field field = confClass.getDeclaredField(
selectedSetting.getSelectedKey(state));
field.setAccessible(true);
final List<String> stringList = (List<String>) field
.get(config);
final String str = stringList.get(Integer.parseInt(
selectedValue.getSelectedKey(state)));
valueField.setValue(state, str);
} catch (NoSuchFieldException | SecurityException |
IllegalAccessException | ClassCastException ex) {
LOGGER.warn(
"Failed to read setting {} from configuration {}",
selectedSetting.getSelectedKey(state),
selectedConf.getSelectedKey(state));
LOGGER.warn(ex);
throw new UncheckedWrapperException(ex);
}
}
});
addProcessListener(e -> {
final PageState state = e.getPageState();
if (saveCancelSection.getSaveButton().isSelected(state)) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final Class<?> confClass;
try {
confClass = Class
.forName(selectedConf.getSelectedKey(state));
} catch (ClassNotFoundException ex) {
throw new UncheckedWrapperException(ex);
}
final ConfigurationManager confManager = cdiUtil.findBean(
ConfigurationManager.class);
final Object config = confManager.findConfiguration(
confClass);
final List<String> stringList;
try {
final Field field = confClass.getDeclaredField(
selectedSetting.getSelectedKey(state));
field.setAccessible(true);
final Object value = field.get(config);
if (value == null) {
stringList = new ArrayList<>();
field.set(config, stringList);
} else {
stringList = (List<String>) value;
}
} catch (NoSuchFieldException |
SecurityException |
IllegalAccessException |
ClassCastException ex) {
LOGGER.warn(
"Failed to read setting {} from configuration {}",
selectedSetting.getSelectedKey(state),
selectedConf.getSelectedKey(state));
LOGGER.warn(ex);
throw new UncheckedWrapperException(ex);
}
final FormData data = e.getFormData();
final String valueData = data.getString(VALUE);
if (selectedValue.getSelectedKey(state) == null) {
stringList.add(valueData);
} else {
final int selected = Integer.parseInt(selectedValue
.getSelectedKey(state));
stringList.set(selected, valueData);
}
confManager.saveConfiguration(config);
}
selectedValue.clearSelection(state);
valueField.setValue(state, null);
});
}
}
}

View File

@ -1,48 +0,0 @@
/*
* Copyright (C) 2016 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.ui.admin.configuration;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import org.libreccm.configuration.BigDecimalSetting;
import java.math.BigDecimal;
/**
* A subclass of {@link AbstractSettingFormSingleValue} for editing the value
* of a {@link BigDecimalSetting}.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class SettingFormBigDecimal
extends AbstractSettingFormSingleValue<BigDecimal> {
public SettingFormBigDecimal(
final ConfigurationTab configurationTab,
final ParameterSingleSelectionModel<String> selectedConf,
final ParameterSingleSelectionModel<String> selectedSetting) {
super(configurationTab, selectedConf, selectedSetting);
}
@Override
BigDecimal convertValue(final String valueData) {
return new BigDecimal(valueData);
}
}

View File

@ -1,193 +0,0 @@
/*
* Copyright (C) 2016 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.ui.admin.configuration;
import com.arsdigita.bebop.BoxPanel;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.SaveCancelSection;
import com.arsdigita.bebop.form.CheckboxGroup;
import com.arsdigita.bebop.form.Option;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.util.UncheckedWrapperException;
import java.lang.reflect.Field;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.configuration.ConfigurationManager;
import static com.arsdigita.ui.admin.AdminUiConstants.*;
/**
* A subclass of {@link AbstractSettingFormSingleValue} for editing the value
* of a {@code boolean}.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class SettingFormBoolean extends Form {
private static final String VALUE_FIELD_GROUP = "valueFieldGroup";
private static final String VALUE_FIELD = "valueField";
private static final Logger LOGGER = LogManager.getLogger(
SettingFormBoolean.class);
public SettingFormBoolean(
final ConfigurationTab configurationTab,
final ParameterSingleSelectionModel<String> selectedConf,
final ParameterSingleSelectionModel<String> selectedSetting) {
super("settingFormBoolean", new BoxPanel(BoxPanel.VERTICAL));
add(new SettingFormHeader(configurationTab,
selectedConf,
selectedSetting));
add(new SettingFormCurrentValuePanel(selectedConf, selectedSetting));
final CheckboxGroup valueFieldGroup = new CheckboxGroup(
VALUE_FIELD_GROUP);
valueFieldGroup.addOption(
new Option(VALUE_FIELD,
new Label(new GlobalizedMessage(
"ui.admin.configuration.setting.edit.new_value",
ADMIN_BUNDLE))));
add(valueFieldGroup);
final SaveCancelSection saveCancelSection = new SaveCancelSection();
add(saveCancelSection);
addInitListener(e -> {
final PageState state = e.getPageState();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final Class<?> confClass;
try {
confClass = Class
.forName(selectedConf.getSelectedKey(state));
} catch (ClassNotFoundException ex) {
throw new UncheckedWrapperException(ex);
}
final ConfigurationManager confManager = cdiUtil.findBean(
ConfigurationManager.class);
final Object config = confManager.findConfiguration(confClass);
final Boolean value;
try {
final Field field = confClass.getDeclaredField(selectedSetting
.getSelectedKey(state));
field.setAccessible(true);
value = (Boolean) field.get(config);
} catch (NoSuchFieldException |
SecurityException |
IllegalAccessException |
ClassCastException ex) {
LOGGER.warn("Failed to read setting {} from configuration {}",
selectedSetting.getSelectedKey(state),
selectedConf.getSelectedKey(state));
LOGGER.warn(ex);
return;
}
if (value) {
valueFieldGroup.setValue(state, VALUE_FIELD);
}
});
addProcessListener(e -> {
final PageState state = e.getPageState();
if (saveCancelSection.getSaveButton().isSelected(state)) {
final FormData data = e.getFormData();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final Class<?> confClass;
try {
confClass = Class
.forName(selectedConf.getSelectedKey(state));
} catch (ClassNotFoundException ex) {
throw new UncheckedWrapperException(ex);
}
final ConfigurationManager confManager = cdiUtil.findBean(
ConfigurationManager.class);
final String settingName = selectedSetting.getSelectedKey(state);
final Object config = confManager.findConfiguration(confClass);
final Field field;
try {
field = confClass.getDeclaredField(settingName);
field.setAccessible(true);
} catch (NoSuchFieldException |
SecurityException ex) {
throw new FormProcessException(
String.format(
"Failed to retrieve field \"%s\" "
+ "from configuration class \"%s\".",
settingName,
confClass.getName()),
new GlobalizedMessage(
"ui.admin.configuration.setting.failed_to_set_value",
ADMIN_BUNDLE),
ex);
}
try {
final String[] valueData = (String[]) data.
get(VALUE_FIELD_GROUP);
if (valueData != null && valueData.length > 0) {
if (VALUE_FIELD.equals(valueData[0])) {
field.set(config, Boolean.TRUE);
} else {
field.set(config, Boolean.FALSE);
}
} else {
field.set(config, Boolean.FALSE);
}
confManager.saveConfiguration(config);
configurationTab.hideSettingForms(state);
} catch (IllegalArgumentException | IllegalAccessException ex) {
LOGGER.error(ex);
throw new FormProcessException(
String.format(
"Failed to change value of field \"%s\" "
+ "of configuration class \"%s\".",
settingName,
confClass.getName()),
new GlobalizedMessage(
"ui.admin.configuration.setting.failed_to_set_value",
ADMIN_BUNDLE),
ex);
}
}
configurationTab.hideSettingForms(state);
});
}
}

View File

@ -1,99 +0,0 @@
/*
* Copyright (C) 2016 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.ui.admin.configuration;
import com.arsdigita.bebop.GridPanel;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.Text;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.util.UncheckedWrapperException;
import java.util.Objects;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.configuration.ConfigurationManager;
import java.lang.reflect.Field;
import static com.arsdigita.ui.admin.AdminUiConstants.*;
/**
* A panel which show the current value of a (single value) setting.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class SettingFormCurrentValuePanel extends GridPanel {
private final static Logger LOGGER = LogManager.getLogger(
SettingFormCurrentValuePanel.class);
public SettingFormCurrentValuePanel(
final ParameterSingleSelectionModel<String> selectedConf,
final ParameterSingleSelectionModel<String> selectedSetting) {
super(2);
add(new Label(new GlobalizedMessage(
"ui.admin.configuration.setting.edit.current_value",
ADMIN_BUNDLE)));
add(new Text(e -> {
final PageState state = e.getPageState();
final Text target = (Text) e.getTarget();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final Class<?> confClass;
try {
confClass = Class
.forName(selectedConf.getSelectedKey(state));
} catch (ClassNotFoundException ex) {
throw new UncheckedWrapperException(ex);
}
final ConfigurationManager confManager = cdiUtil.findBean(
ConfigurationManager.class);
final Object config = confManager.findConfiguration(confClass);
final Object value;
try {
final Field field = confClass.getDeclaredField(selectedSetting
.getSelectedKey(state));
field.setAccessible(true);
value = field.get(config);
} catch (NoSuchFieldException |
SecurityException |
IllegalAccessException ex) {
LOGGER.warn("Failed to read setting {} from configuration {}",
selectedSetting.getSelectedKey(state),
selectedConf.getSelectedKey(state));
LOGGER.warn(ex);
target.setText("Failed to read setting value.");
return;
}
target.setText(Objects.toString(value));
}));
}
}

View File

@ -1,44 +0,0 @@
/*
* Copyright (C) 2016 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.ui.admin.configuration;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
/**
* A subclass of {@link AbstractSettingFormSingleValue} for editing the value
* of a {@link DoubleSetting}.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class SettingFormDouble extends AbstractSettingFormSingleValue<Double> {
public SettingFormDouble(
final ConfigurationTab configurationTab,
final ParameterSingleSelectionModel<String> selectedConf,
final ParameterSingleSelectionModel<String> selectedSetting) {
super(configurationTab, selectedConf, selectedSetting);
}
@Override
Double convertValue(final String valueData) {
return Double.parseDouble(valueData);
}
}

View File

@ -1,173 +0,0 @@
/*
* Copyright (C) 2016 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.ui.admin.configuration;
import com.arsdigita.bebop.ActionLink;
import com.arsdigita.bebop.BoxPanel;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.Text;
import com.arsdigita.bebop.event.PrintEvent;
import com.arsdigita.bebop.event.PrintListener;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.util.UncheckedWrapperException;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.configuration.ConfigurationInfo;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.configuration.SettingInfo;
import org.libreccm.configuration.SettingManager;
import org.libreccm.l10n.GlobalizationHelper;
import static com.arsdigita.ui.admin.AdminUiConstants.*;
/**
* Header used by all setting forms/editors. The header contains a link to go
* back to the list of settings and heading for contains the title of the
* configuration class and the label of the setting which is edited.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class SettingFormHeader extends BoxPanel {
public SettingFormHeader(
final ConfigurationTab configurationTab,
final ParameterSingleSelectionModel<String> selectedConf,
final ParameterSingleSelectionModel<String> selectedSetting) {
super(BoxPanel.VERTICAL);
final ActionLink backLink = new ActionLink(new GlobalizedMessage(
"ui.admin.configuration.setting.edit.back", ADMIN_BUNDLE));
backLink.addActionListener(e -> {
final PageState state = e.getPageState();
configurationTab.hideSettingForms(state);
});
add(backLink);
final Label heading = new Label(new HeadingPrintListener(
selectedConf, selectedSetting));
heading.setClassAttr("heading");
add(heading);
final Text desc = new Text(new DescPrintListener(selectedConf,
selectedSetting));
add(desc);
}
private class HeadingPrintListener implements PrintListener {
private final ParameterSingleSelectionModel<String> selectedConf;
private final ParameterSingleSelectionModel<String> selectedSetting;
public HeadingPrintListener(
final ParameterSingleSelectionModel<String> selectedConf,
final ParameterSingleSelectionModel<String> selectedSetting) {
this.selectedConf = selectedConf;
this.selectedSetting = selectedSetting;
}
@Override
public void prepare(final PrintEvent event) {
final PageState state = event.getPageState();
final Label target = (Label) event.getTarget();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ConfigurationManager confManager = cdiUtil.findBean(
ConfigurationManager.class);
final SettingManager settingManager = cdiUtil.findBean(
SettingManager.class);
final GlobalizationHelper globalizationHelper = cdiUtil
.findBean(GlobalizationHelper.class);
final Class<?> confClass;
try {
confClass = Class
.forName(selectedConf.getSelectedKey(state));
} catch (ClassNotFoundException ex) {
throw new UncheckedWrapperException(ex);
}
final ConfigurationInfo confInfo = confManager
.getConfigurationInfo(confClass);
final SettingInfo settingInfo = settingManager.getSettingInfo(
confClass, selectedSetting.getSelectedKey(state));
final String confTitle = confInfo.getTitle(globalizationHelper
.getNegotiatedLocale());
final String settingLabel = settingInfo.getLabel(
globalizationHelper.getNegotiatedLocale());
target.setLabel(new GlobalizedMessage(
"ui.admin.configuration.setting.edit.heading",
ADMIN_BUNDLE,
new String[]{confTitle, settingLabel}));
}
}
private class DescPrintListener implements PrintListener {
private final ParameterSingleSelectionModel<String> selectedConf;
private final ParameterSingleSelectionModel<String> selectedSetting;
public DescPrintListener(
final ParameterSingleSelectionModel<String> selectedConf,
final ParameterSingleSelectionModel<String> selectedSetting) {
this.selectedConf = selectedConf;
this.selectedSetting = selectedSetting;
}
@Override
public void prepare(final PrintEvent event) {
final PageState state = event.getPageState();
final Text target = (Text) event.getTarget();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final SettingManager settingManager = cdiUtil.findBean(
SettingManager.class);
final GlobalizationHelper globalizationHelper = cdiUtil
.findBean(GlobalizationHelper.class);
final Class<?> confClass;
try {
confClass = Class
.forName(selectedConf.getSelectedKey(state));
} catch (ClassNotFoundException ex) {
throw new UncheckedWrapperException(ex);
}
final SettingInfo settingInfo = settingManager.getSettingInfo(
confClass, selectedSetting.getSelectedKey(state));
target.setText(settingInfo.getDescription(globalizationHelper
.getNegotiatedLocale()));
}
}
}

View File

@ -1,44 +0,0 @@
/*
* Copyright (C) 2016 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.ui.admin.configuration;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
/**
* A subclass of {@link AbstractSettingFormSingleValue} for editing the value
* of a {@link LongSetting}.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class SettingFormLong extends AbstractSettingFormSingleValue<Long> {
public SettingFormLong(
final ConfigurationTab configurationTab,
final ParameterSingleSelectionModel<String> selectedConf,
final ParameterSingleSelectionModel<String> selectedSetting) {
super(configurationTab, selectedConf, selectedSetting);
}
@Override
Long convertValue(final String valueData) {
return Long.parseLong(valueData);
}
}

View File

@ -1,44 +0,0 @@
/*
* Copyright (C) 2016 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.ui.admin.configuration;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
/**
* A subclass of {@link AbstractSettingFormSingleValue} for editing the value
* of a {@link StringSetting}.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class SettingFormString extends AbstractSettingFormSingleValue<String> {
public SettingFormString(
final ConfigurationTab configurationTab,
final ParameterSingleSelectionModel<String> selectedConf,
final ParameterSingleSelectionModel<String> selectedSetting) {
super(configurationTab, selectedConf, selectedSetting);
}
@Override
String convertValue(final String valueData) {
return valueData;
}
}