CCM NG: Current status of admin UI for configuration
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4056 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
e55e65bcf9
commit
3c28579a3c
|
|
@ -1,133 +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.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 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.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public abstract class AbstractSettingForm extends Form {
|
|
||||||
|
|
||||||
public AbstractSettingForm(
|
|
||||||
final String name,
|
|
||||||
final ConfigurationTab configurationTab,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedConf,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedSetting) {
|
|
||||||
|
|
||||||
super(name, new BoxPanel(BoxPanel.VERTICAL));
|
|
||||||
|
|
||||||
final Label heading = new Label(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final Label target = (Label) e.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}));
|
|
||||||
});
|
|
||||||
|
|
||||||
heading.setClassAttr("heading");
|
|
||||||
|
|
||||||
add(heading);
|
|
||||||
|
|
||||||
final Text desc = new Text(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final Text target = (Text) e.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()));
|
|
||||||
});
|
|
||||||
|
|
||||||
add(desc);
|
|
||||||
|
|
||||||
addCurrentValuePanel(selectedConf, selectedSetting);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void addCurrentValuePanel(
|
|
||||||
final ParameterSingleSelectionModel<String> selectedConf,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedSetting);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -51,7 +51,8 @@ import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractSettingFormSingleValue<T> extends Form {
|
public abstract class AbstractSettingFormSingleValue<T> extends Form {
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(AbstractSettingFormSingleValue.class);
|
private static final Logger LOGGER = LogManager.getLogger(
|
||||||
|
AbstractSettingFormSingleValue.class);
|
||||||
|
|
||||||
private static final String VALUE_FIELD = "valueField";
|
private static final String VALUE_FIELD = "valueField";
|
||||||
|
|
||||||
|
|
@ -80,7 +81,9 @@ public abstract class AbstractSettingFormSingleValue<T> extends Form {
|
||||||
|
|
||||||
addValidationListener(new ValidationListener());
|
addValidationListener(new ValidationListener());
|
||||||
|
|
||||||
addProcessListener(new ProcessListener(selectedConf, selectedSetting));
|
addProcessListener(new ProcessListener(configurationTab,
|
||||||
|
selectedConf,
|
||||||
|
selectedSetting));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -121,9 +124,9 @@ public abstract class AbstractSettingFormSingleValue<T> extends Form {
|
||||||
|
|
||||||
final Object config = confManager.findConfiguration(confClass);
|
final Object config = confManager.findConfiguration(confClass);
|
||||||
|
|
||||||
final BigDecimal value;
|
final Object value;
|
||||||
try {
|
try {
|
||||||
value = (BigDecimal) confClass.getField(selectedSetting
|
value = confClass.getField(selectedSetting
|
||||||
.getSelectedKey(state)).get(config);
|
.getSelectedKey(state)).get(config);
|
||||||
} catch (NoSuchFieldException | SecurityException |
|
} catch (NoSuchFieldException | SecurityException |
|
||||||
IllegalAccessException | ClassCastException ex) {
|
IllegalAccessException | ClassCastException ex) {
|
||||||
|
|
@ -168,12 +171,15 @@ public abstract class AbstractSettingFormSingleValue<T> extends Form {
|
||||||
|
|
||||||
private class ProcessListener implements FormProcessListener {
|
private class ProcessListener implements FormProcessListener {
|
||||||
|
|
||||||
|
private final ConfigurationTab configurationTab;
|
||||||
private final ParameterSingleSelectionModel<String> selectedConf;
|
private final ParameterSingleSelectionModel<String> selectedConf;
|
||||||
private final ParameterSingleSelectionModel<String> selectedSetting;
|
private final ParameterSingleSelectionModel<String> selectedSetting;
|
||||||
|
|
||||||
public ProcessListener(
|
public ProcessListener(
|
||||||
|
final ConfigurationTab configurationTab,
|
||||||
final ParameterSingleSelectionModel<String> selectedConf,
|
final ParameterSingleSelectionModel<String> selectedConf,
|
||||||
final ParameterSingleSelectionModel<String> selectedSetting) {
|
final ParameterSingleSelectionModel<String> selectedSetting) {
|
||||||
|
this.configurationTab = configurationTab;
|
||||||
this.selectedConf = selectedConf;
|
this.selectedConf = selectedConf;
|
||||||
this.selectedSetting = selectedSetting;
|
this.selectedSetting = selectedSetting;
|
||||||
}
|
}
|
||||||
|
|
@ -222,6 +228,7 @@ public abstract class AbstractSettingFormSingleValue<T> extends Form {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
field.set(config, value);
|
field.set(config, value);
|
||||||
|
configurationTab.hideSettingForms(state);
|
||||||
} catch (IllegalArgumentException | IllegalAccessException ex) {
|
} catch (IllegalArgumentException | IllegalAccessException ex) {
|
||||||
throw new FormProcessException(
|
throw new FormProcessException(
|
||||||
String.format(
|
String.format(
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,396 @@
|
||||||
|
/*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.ActionLink;
|
||||||
|
import com.arsdigita.bebop.BoxPanel;
|
||||||
|
import com.arsdigita.bebop.Component;
|
||||||
|
import com.arsdigita.bebop.ControlLink;
|
||||||
|
import com.arsdigita.bebop.Form;
|
||||||
|
import com.arsdigita.bebop.Label;
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
|
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
||||||
|
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.Select;
|
||||||
|
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 com.sun.javafx.scene.control.skin.VirtualFlow;
|
||||||
|
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 sun.util.resources.cldr.gv.LocaleNames_gv;
|
||||||
|
|
||||||
|
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.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @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 static final String LOCALE_SELECT = "localeSelect";
|
||||||
|
private static final String VALUE = "value";
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
final ActionLink backLink = new ActionLink(new GlobalizedMessage(
|
||||||
|
"ui.admin.configuration.setting.localized_string.back",
|
||||||
|
ADMIN_BUNDLE));
|
||||||
|
backLink.addActionListener(e -> {
|
||||||
|
configurationTab.hideSettingForms(e.getPageState());
|
||||||
|
});
|
||||||
|
add(backLink);
|
||||||
|
|
||||||
|
add(new SettingFormHeader(selectedConf, selectedSetting));
|
||||||
|
|
||||||
|
add(new ValuesTable());
|
||||||
|
|
||||||
|
final Form form = new Form("settingLocalizedStringForm");
|
||||||
|
|
||||||
|
final SingleSelect 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 {
|
||||||
|
value = (LocalizedString) confClass.getField(
|
||||||
|
selectedSetting.getSelectedKey(state)).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);
|
||||||
|
}
|
||||||
|
form.add(localeSelect);
|
||||||
|
|
||||||
|
final TextField localizedValue = new TextField(VALUE);
|
||||||
|
localizedValue.setLabel(new GlobalizedMessage(
|
||||||
|
"ui.admin.configuration.setting.localized_string.value.label",
|
||||||
|
ADMIN_BUNDLE));
|
||||||
|
form.add(localizedValue);
|
||||||
|
|
||||||
|
form.addInitListener(e -> {
|
||||||
|
//ToDo
|
||||||
|
});
|
||||||
|
|
||||||
|
form.addProcessListener(e -> {
|
||||||
|
//ToDo
|
||||||
|
});
|
||||||
|
|
||||||
|
//Form
|
||||||
|
//process: if value is selected update selected value
|
||||||
|
// if no value is selected add new setting
|
||||||
|
add(form);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ValuesTable extends Table {
|
||||||
|
|
||||||
|
public ValuesTable() {
|
||||||
|
|
||||||
|
super();
|
||||||
|
|
||||||
|
setIdAttr("localizedStringSettingValues");
|
||||||
|
|
||||||
|
setEmptyView(new Label(new GlobalizedMessage(
|
||||||
|
"ui.admin.categories.setting.localized_string.no_values",
|
||||||
|
ADMIN_BUNDLE)));
|
||||||
|
|
||||||
|
final TableColumnModel columnModel = getColumnModel();
|
||||||
|
columnModel.add(new TableColumn(
|
||||||
|
COL_LOCALE,
|
||||||
|
new Label(new GlobalizedMessage(
|
||||||
|
"ui.admin.categories.setting.localized_string.col_lang",
|
||||||
|
ADMIN_BUNDLE))));
|
||||||
|
columnModel.add(new TableColumn(
|
||||||
|
COL_VALUE,
|
||||||
|
new Label(new GlobalizedMessage(
|
||||||
|
"ui.admin.categories.setting.localized_string.col_value",
|
||||||
|
ADMIN_BUNDLE))));
|
||||||
|
columnModel.add(new TableColumn(
|
||||||
|
COL_EDIT,
|
||||||
|
new Label(new GlobalizedMessage(
|
||||||
|
"ui.admin.categories.setting.localized_string.col_del",
|
||||||
|
ADMIN_BUNDLE))));
|
||||||
|
columnModel.add(new TableColumn(
|
||||||
|
COL_DEL,
|
||||||
|
new Label(new GlobalizedMessage(
|
||||||
|
"ui.admin.categories.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((String) 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.categories.setting.localized_string.del_confirm",
|
||||||
|
ADMIN_BUNDLE));
|
||||||
|
return link;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
addTableActionListener(new TableActionListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cellSelected(final TableActionEvent event) {
|
||||||
|
final PageState state = event.getPageState();
|
||||||
|
|
||||||
|
selectedValue.setSelectedKey(state, event.getRowKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 {
|
||||||
|
value = (LocalizedString) confClass.getField(selectedSetting
|
||||||
|
.getSelectedKey(state)).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.categories.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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -18,282 +18,27 @@
|
||||||
*/
|
*/
|
||||||
package com.arsdigita.ui.admin.configuration;
|
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.GridPanel;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
|
||||||
import com.arsdigita.bebop.Text;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
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.apache.logging.log4j.util.Strings;
|
|
||||||
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 java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
public class SettingFormBigDecimal extends Form {
|
public class SettingFormBigDecimal
|
||||||
|
extends AbstractSettingFormSingleValue<BigDecimal> {
|
||||||
private static final Logger LOGGER = LogManager.getLogger(
|
|
||||||
SettingFormBigDecimal.class);
|
|
||||||
|
|
||||||
private static final String VALUE_FIELD = "valueField";
|
|
||||||
|
|
||||||
public SettingFormBigDecimal(
|
public SettingFormBigDecimal(
|
||||||
final ConfigurationTab configurationTab,
|
final ConfigurationTab configurationTab,
|
||||||
final ParameterSingleSelectionModel<String> selectedConf,
|
final ParameterSingleSelectionModel<String> selectedConf,
|
||||||
final ParameterSingleSelectionModel<String> selectedSetting) {
|
final ParameterSingleSelectionModel<String> selectedSetting) {
|
||||||
|
super(configurationTab, selectedConf, selectedSetting);
|
||||||
|
}
|
||||||
|
|
||||||
super("settingFormBigDecimal", new BoxPanel(BoxPanel.VERTICAL));
|
@Override
|
||||||
|
BigDecimal convertValue(final String valueData) {
|
||||||
final Label heading = new Label(e -> {
|
return new BigDecimal(valueData);
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final Label target = (Label) e.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}));
|
|
||||||
});
|
|
||||||
|
|
||||||
heading.setClassAttr("heading");
|
|
||||||
|
|
||||||
add(heading);
|
|
||||||
|
|
||||||
final Text desc = new Text(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final Text target = (Text) e.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()));
|
|
||||||
});
|
|
||||||
|
|
||||||
add(desc);
|
|
||||||
|
|
||||||
final GridPanel gridPanel = new GridPanel(2);
|
|
||||||
|
|
||||||
gridPanel.add(new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.configuration.setting.edit.current_value",
|
|
||||||
ADMIN_BUNDLE)));
|
|
||||||
|
|
||||||
gridPanel.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 BigDecimal value;
|
|
||||||
try {
|
|
||||||
value = (BigDecimal) confClass.getField(selectedSetting
|
|
||||||
.getSelectedKey(state)).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);
|
|
||||||
target.setText("Failed to read setting value.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
target.setText(Objects.toString(value));
|
|
||||||
}));
|
|
||||||
|
|
||||||
add(gridPanel);
|
|
||||||
|
|
||||||
final TextField valueField = new TextField(VALUE_FIELD);
|
|
||||||
valueField.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.configuration.setting.edit.new_value", ADMIN_BUNDLE));
|
|
||||||
add(valueField);
|
|
||||||
|
|
||||||
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 BigDecimal value;
|
|
||||||
try {
|
|
||||||
value = (BigDecimal) confClass.getField(selectedSetting
|
|
||||||
.getSelectedKey(state)).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;
|
|
||||||
}
|
|
||||||
|
|
||||||
valueField.setValue(state, value.toString());
|
|
||||||
});
|
|
||||||
|
|
||||||
addValidationListener(e -> {
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
|
|
||||||
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 BigDecimal value = new BigDecimal(valueData);
|
|
||||||
LOGGER.debug("New value {} is a valid BigDecimal.", value);
|
|
||||||
} catch (NumberFormatException ex) {
|
|
||||||
data.addError(VALUE_FIELD,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.configuration.setting.error.not_a_bigdecimal",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addProcessListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
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.getField(settingName);
|
|
||||||
} 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
final String valueData = data.getString(VALUE_FIELD);
|
|
||||||
final BigDecimal value = new BigDecimal(valueData);
|
|
||||||
|
|
||||||
try {
|
|
||||||
field.set(config, value);
|
|
||||||
} catch (IllegalArgumentException | IllegalAccessException 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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,27 +22,21 @@ import com.arsdigita.bebop.BoxPanel;
|
||||||
import com.arsdigita.bebop.Form;
|
import com.arsdigita.bebop.Form;
|
||||||
import com.arsdigita.bebop.FormData;
|
import com.arsdigita.bebop.FormData;
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
import com.arsdigita.bebop.FormProcessException;
|
||||||
import com.arsdigita.bebop.GridPanel;
|
|
||||||
import com.arsdigita.bebop.Label;
|
import com.arsdigita.bebop.Label;
|
||||||
import com.arsdigita.bebop.PageState;
|
import com.arsdigita.bebop.PageState;
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
import com.arsdigita.bebop.SaveCancelSection;
|
||||||
import com.arsdigita.bebop.Text;
|
|
||||||
import com.arsdigita.bebop.form.CheckboxGroup;
|
import com.arsdigita.bebop.form.CheckboxGroup;
|
||||||
import com.arsdigita.bebop.form.Option;
|
import com.arsdigita.bebop.form.Option;
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
import com.arsdigita.util.UncheckedWrapperException;
|
import com.arsdigita.util.UncheckedWrapperException;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
import org.libreccm.configuration.ConfigurationInfo;
|
|
||||||
import org.libreccm.configuration.ConfigurationManager;
|
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.*;
|
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
||||||
|
|
||||||
|
|
@ -56,133 +50,26 @@ public class SettingFormBoolean extends Form {
|
||||||
private static final String VALUE_FIELD = "valueField";
|
private static final String VALUE_FIELD = "valueField";
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(
|
private static final Logger LOGGER = LogManager.getLogger(
|
||||||
SettingFormBoolean.class);
|
SettingFormBoolean.class);
|
||||||
|
|
||||||
public SettingFormBoolean(
|
public SettingFormBoolean(
|
||||||
final ConfigurationTab configurationTab,
|
final ConfigurationTab configurationTab,
|
||||||
final ParameterSingleSelectionModel<String> selectedConf,
|
final ParameterSingleSelectionModel<String> selectedConf,
|
||||||
final ParameterSingleSelectionModel<String> selectedSetting) {
|
final ParameterSingleSelectionModel<String> selectedSetting) {
|
||||||
|
|
||||||
super("settingFormBoolean", new BoxPanel(BoxPanel.VERTICAL));
|
super("settingFormBoolean", new BoxPanel(BoxPanel.VERTICAL));
|
||||||
|
|
||||||
final Label heading = new Label(e -> {
|
add(new SettingFormHeader(selectedConf, selectedSetting));
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final Label target = (Label) e.getTarget();
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
add(new SettingFormCurrentValuePanel(selectedConf, selectedSetting));
|
||||||
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}));
|
|
||||||
});
|
|
||||||
|
|
||||||
heading.setClassAttr("heading");
|
|
||||||
|
|
||||||
add(heading);
|
|
||||||
|
|
||||||
final Text desc = new Text(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final Text target = (Text) e.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()));
|
|
||||||
});
|
|
||||||
|
|
||||||
add(desc);
|
|
||||||
|
|
||||||
final GridPanel gridPanel = new GridPanel(2);
|
|
||||||
|
|
||||||
gridPanel.add(new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.configuration.setting.edit.current_value",
|
|
||||||
ADMIN_BUNDLE)));
|
|
||||||
|
|
||||||
gridPanel.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 Boolean value;
|
|
||||||
try {
|
|
||||||
value = (Boolean) confClass.getField(selectedSetting
|
|
||||||
.getSelectedKey(state)).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);
|
|
||||||
target.setText("Failed to read setting value.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
target.setText(Objects.toString(value));
|
|
||||||
}));
|
|
||||||
|
|
||||||
add(gridPanel);
|
|
||||||
|
|
||||||
final CheckboxGroup valueFieldGroup = new CheckboxGroup(
|
final CheckboxGroup valueFieldGroup = new CheckboxGroup(
|
||||||
VALUE_FIELD_GROUP);
|
VALUE_FIELD_GROUP);
|
||||||
valueFieldGroup.addOption(
|
valueFieldGroup.addOption(
|
||||||
new Option(VALUE_FIELD,
|
new Option(VALUE_FIELD,
|
||||||
new Label(new GlobalizedMessage(
|
new Label(new GlobalizedMessage(
|
||||||
"ui.admin.configuration.setting.edit.new_value",
|
"ui.admin.configuration.setting.edit.new_value",
|
||||||
ADMIN_BUNDLE))));
|
ADMIN_BUNDLE))));
|
||||||
|
|
||||||
final SaveCancelSection saveCancelSection = new SaveCancelSection();
|
final SaveCancelSection saveCancelSection = new SaveCancelSection();
|
||||||
add(saveCancelSection);
|
add(saveCancelSection);
|
||||||
|
|
@ -194,20 +81,20 @@ public class SettingFormBoolean extends Form {
|
||||||
final Class<?> confClass;
|
final Class<?> confClass;
|
||||||
try {
|
try {
|
||||||
confClass = Class
|
confClass = Class
|
||||||
.forName(selectedConf.getSelectedKey(state));
|
.forName(selectedConf.getSelectedKey(state));
|
||||||
} catch (ClassNotFoundException ex) {
|
} catch (ClassNotFoundException ex) {
|
||||||
throw new UncheckedWrapperException(ex);
|
throw new UncheckedWrapperException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
final ConfigurationManager confManager = cdiUtil.findBean(
|
final ConfigurationManager confManager = cdiUtil.findBean(
|
||||||
ConfigurationManager.class);
|
ConfigurationManager.class);
|
||||||
|
|
||||||
final Object config = confManager.findConfiguration(confClass);
|
final Object config = confManager.findConfiguration(confClass);
|
||||||
|
|
||||||
final Boolean value;
|
final Boolean value;
|
||||||
try {
|
try {
|
||||||
value = (Boolean) confClass.getField(selectedSetting
|
value = (Boolean) confClass.getField(selectedSetting
|
||||||
.getSelectedKey(state)).get(config);
|
.getSelectedKey(state)).get(config);
|
||||||
} catch (NoSuchFieldException | SecurityException |
|
} catch (NoSuchFieldException | SecurityException |
|
||||||
IllegalAccessException | ClassCastException ex) {
|
IllegalAccessException | ClassCastException ex) {
|
||||||
LOGGER.warn("Failed to read setting {} from configuration {}",
|
LOGGER.warn("Failed to read setting {} from configuration {}",
|
||||||
|
|
@ -230,13 +117,13 @@ public class SettingFormBoolean extends Form {
|
||||||
final Class<?> confClass;
|
final Class<?> confClass;
|
||||||
try {
|
try {
|
||||||
confClass = Class
|
confClass = Class
|
||||||
.forName(selectedConf.getSelectedKey(state));
|
.forName(selectedConf.getSelectedKey(state));
|
||||||
} catch (ClassNotFoundException ex) {
|
} catch (ClassNotFoundException ex) {
|
||||||
throw new UncheckedWrapperException(ex);
|
throw new UncheckedWrapperException(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
final ConfigurationManager confManager = cdiUtil.findBean(
|
final ConfigurationManager confManager = cdiUtil.findBean(
|
||||||
ConfigurationManager.class);
|
ConfigurationManager.class);
|
||||||
final String settingName = selectedSetting.getSelectedKey(state);
|
final String settingName = selectedSetting.getSelectedKey(state);
|
||||||
|
|
||||||
final Object config = confManager.findConfiguration(confClass);
|
final Object config = confManager.findConfiguration(confClass);
|
||||||
|
|
@ -246,38 +133,39 @@ public class SettingFormBoolean extends Form {
|
||||||
field = confClass.getField(settingName);
|
field = confClass.getField(settingName);
|
||||||
} catch (NoSuchFieldException | SecurityException ex) {
|
} catch (NoSuchFieldException | SecurityException ex) {
|
||||||
throw new FormProcessException(
|
throw new FormProcessException(
|
||||||
String.format(
|
String.format(
|
||||||
"Failed to retrieve field \"%s\" "
|
"Failed to retrieve field \"%s\" "
|
||||||
+ "from configuration class \"%s\".",
|
+ "from configuration class \"%s\".",
|
||||||
settingName,
|
settingName,
|
||||||
confClass.getName()),
|
confClass.getName()),
|
||||||
new GlobalizedMessage(
|
new GlobalizedMessage(
|
||||||
"ui.admin.configuration.setting.failed_to_set_value",
|
"ui.admin.configuration.setting.failed_to_set_value",
|
||||||
ADMIN_BUNDLE),
|
ADMIN_BUNDLE),
|
||||||
ex);
|
ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final String[] valueData = (String[]) data.
|
final String[] valueData = (String[]) data.
|
||||||
get(VALUE_FIELD_GROUP);
|
get(VALUE_FIELD_GROUP);
|
||||||
if (valueData != null && valueData.length > 0) {
|
if (valueData != null && valueData.length > 0) {
|
||||||
if (VALUE_FIELD.equals(valueData[0])) {
|
if (VALUE_FIELD.equals(valueData[0])) {
|
||||||
field.set(config, Boolean.TRUE);
|
field.set(config, Boolean.TRUE);
|
||||||
} else {
|
} else {
|
||||||
field.set(config, Boolean.FALSE);
|
field.set(config, Boolean.FALSE);
|
||||||
}
|
}
|
||||||
|
configurationTab.hideSettingForms(state);
|
||||||
}
|
}
|
||||||
} catch (IllegalArgumentException | IllegalAccessException ex) {
|
} catch (IllegalArgumentException | IllegalAccessException ex) {
|
||||||
throw new FormProcessException(
|
throw new FormProcessException(
|
||||||
String.format(
|
String.format(
|
||||||
"Failed to change value of field \"%s\" "
|
"Failed to change value of field \"%s\" "
|
||||||
+ "of configuration class \"%s\".",
|
+ "of configuration class \"%s\".",
|
||||||
settingName,
|
settingName,
|
||||||
confClass.getName()),
|
confClass.getName()),
|
||||||
new GlobalizedMessage(
|
new GlobalizedMessage(
|
||||||
"ui.admin.configuration.setting.failed_to_set_value",
|
"ui.admin.configuration.setting.failed_to_set_value",
|
||||||
ADMIN_BUNDLE),
|
ADMIN_BUNDLE),
|
||||||
ex);
|
ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -18,279 +18,25 @@
|
||||||
*/
|
*/
|
||||||
package com.arsdigita.ui.admin.configuration;
|
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.GridPanel;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
|
||||||
import com.arsdigita.bebop.Text;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.util.UncheckedWrapperException;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.Objects;
|
|
||||||
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.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.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
public class SettingFormLong extends Form {
|
public class SettingFormLong extends AbstractSettingFormSingleValue<Long> {
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(
|
|
||||||
SettingFormLong.class);
|
|
||||||
|
|
||||||
private static final String VALUE_FIELD = "valueField";
|
|
||||||
|
|
||||||
public SettingFormLong(
|
public SettingFormLong(
|
||||||
final ConfigurationTab configurationTab,
|
final ConfigurationTab configurationTab,
|
||||||
final ParameterSingleSelectionModel<String> selectedConf,
|
final ParameterSingleSelectionModel<String> selectedConf,
|
||||||
final ParameterSingleSelectionModel<String> selectedSetting) {
|
final ParameterSingleSelectionModel<String> selectedSetting) {
|
||||||
|
|
||||||
|
super(configurationTab, selectedConf, selectedSetting);
|
||||||
|
}
|
||||||
|
|
||||||
super("settingBoolean", new BoxPanel(BoxPanel.VERTICAL));
|
@Override
|
||||||
|
Long convertValue(final String valueData) {
|
||||||
final Label heading = new Label(e -> {
|
return Long.parseLong(valueData);
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final Label target = (Label) e.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}));
|
|
||||||
});
|
|
||||||
|
|
||||||
heading.setClassAttr("heading");
|
|
||||||
|
|
||||||
add(heading);
|
|
||||||
|
|
||||||
final Text desc = new Text(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final Text target = (Text) e.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()));
|
|
||||||
});
|
|
||||||
|
|
||||||
add(desc);
|
|
||||||
|
|
||||||
final GridPanel gridPanel = new GridPanel(2);
|
|
||||||
|
|
||||||
gridPanel.add(new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.configuration.setting.edit.current_value",
|
|
||||||
ADMIN_BUNDLE)));
|
|
||||||
|
|
||||||
gridPanel.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 Long value;
|
|
||||||
try {
|
|
||||||
value = (Long) confClass.getField(selectedSetting
|
|
||||||
.getSelectedKey(state)).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);
|
|
||||||
target.setText("Failed to read setting value.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
target.setText(Objects.toString(value));
|
|
||||||
}));
|
|
||||||
|
|
||||||
add(gridPanel);
|
|
||||||
|
|
||||||
final TextField valueField = new TextField(VALUE_FIELD);
|
|
||||||
valueField.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.configuration.setting.edit.new_value", ADMIN_BUNDLE));
|
|
||||||
add(valueField);
|
|
||||||
|
|
||||||
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 Long value;
|
|
||||||
try {
|
|
||||||
value = (Long) confClass.getField(selectedSetting
|
|
||||||
.getSelectedKey(state)).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;
|
|
||||||
}
|
|
||||||
|
|
||||||
valueField.setValue(state, value.toString());
|
|
||||||
});
|
|
||||||
|
|
||||||
addValidationListener(e -> {
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
|
|
||||||
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 Long value = new Long(valueData);
|
|
||||||
LOGGER.debug("New value {} is a valid Long.", value);
|
|
||||||
} catch (NumberFormatException ex) {
|
|
||||||
data.addError(VALUE_FIELD,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.configuration.setting.error.not_a_long",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addProcessListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
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.getField(settingName);
|
|
||||||
} 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
final String valueData = data.getString(VALUE_FIELD);
|
|
||||||
final Long value = new Long(valueData);
|
|
||||||
|
|
||||||
try {
|
|
||||||
field.set(config, value);
|
|
||||||
} catch (IllegalArgumentException | IllegalAccessException 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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -425,3 +425,9 @@ ui.admin.configuration.setting.edit.heading=Edit setting {0}/{1}
|
||||||
ui.admin.configuration.setting.edit.current_value=Current value
|
ui.admin.configuration.setting.edit.current_value=Current value
|
||||||
ui.admin.configuration.setting.edit.new_value=New value
|
ui.admin.configuration.setting.edit.new_value=New value
|
||||||
ui.admin.configuration.setting.error.blank=New value can't be blank.
|
ui.admin.configuration.setting.error.blank=New value can't be blank.
|
||||||
|
ui.admin.categories.setting.localized_string.no_values=No values for this setting.
|
||||||
|
ui.admin.categories.setting.localized_string.del_confirm=Are you sure to delete this value?
|
||||||
|
ui.admin.configuration.setting.localized_string.value.edit=Edit
|
||||||
|
ui.admin.categories.setting.localized_string.title.del=Delete
|
||||||
|
ui.admin.configuration.setting.localized_string.back=Back
|
||||||
|
ui.admin.configuration.setting.localized_string.locale.label=Locale
|
||||||
|
|
|
||||||
|
|
@ -428,3 +428,9 @@ ui.admin.configuration.setting.edit.heading=Parameter {0}/{1} bearbeiten
|
||||||
ui.admin.configuration.setting.edit.current_value=Aktueller Wert
|
ui.admin.configuration.setting.edit.current_value=Aktueller Wert
|
||||||
ui.admin.configuration.setting.edit.new_value=Neuer Wert
|
ui.admin.configuration.setting.edit.new_value=Neuer Wert
|
||||||
ui.admin.configuration.setting.error.blank=Der neue Wert darf nicht leer sein.
|
ui.admin.configuration.setting.error.blank=Der neue Wert darf nicht leer sein.
|
||||||
|
ui.admin.categories.setting.localized_string.no_values=Keine Werte f\u00fcr diesen Parameter.
|
||||||
|
ui.admin.categories.setting.localized_string.del_confirm=Sind Sie sicher, dass Sie diesen Wert entfernen wollen?
|
||||||
|
ui.admin.configuration.setting.localized_string.value.edit=Bearbeiten
|
||||||
|
ui.admin.categories.setting.localized_string.title.del=L\u00f6schen
|
||||||
|
ui.admin.configuration.setting.localized_string.back=Zur\u00fcck
|
||||||
|
ui.admin.configuration.setting.localized_string.locale.label=Sprache
|
||||||
|
|
|
||||||
|
|
@ -401,3 +401,9 @@ ui.admin.configuration.setting.edit.heading=Edit setting {0}/{1}
|
||||||
ui.admin.configuration.setting.edit.current_value=Current value
|
ui.admin.configuration.setting.edit.current_value=Current value
|
||||||
ui.admin.configuration.setting.edit.new_value=New value
|
ui.admin.configuration.setting.edit.new_value=New value
|
||||||
ui.admin.configuration.setting.error.blank=New value can't be blank.
|
ui.admin.configuration.setting.error.blank=New value can't be blank.
|
||||||
|
ui.admin.categories.setting.localized_string.no_values=No values for this setting.
|
||||||
|
ui.admin.categories.setting.localized_string.del_confirm=Are you sure to delete this value?
|
||||||
|
ui.admin.configuration.setting.localized_string.value.edit=Edit
|
||||||
|
ui.admin.categories.setting.localized_string.title.del=Delete
|
||||||
|
ui.admin.configuration.setting.localized_string.back=Back
|
||||||
|
ui.admin.configuration.setting.localized_string.locale.label=Locale
|
||||||
|
|
|
||||||
|
|
@ -392,3 +392,9 @@ ui.admin.configuration.setting.edit.heading=Edit setting {0}/{1}
|
||||||
ui.admin.configuration.setting.edit.current_value=Current value
|
ui.admin.configuration.setting.edit.current_value=Current value
|
||||||
ui.admin.configuration.setting.edit.new_value=New value
|
ui.admin.configuration.setting.edit.new_value=New value
|
||||||
ui.admin.configuration.setting.error.blank=New value can't be blank.
|
ui.admin.configuration.setting.error.blank=New value can't be blank.
|
||||||
|
ui.admin.categories.setting.localized_string.no_values=No values for this setting.
|
||||||
|
ui.admin.categories.setting.localized_string.del_confirm=Are you sure to delete this value?
|
||||||
|
ui.admin.configuration.setting.localized_string.value.edit=Edit
|
||||||
|
ui.admin.categories.setting.localized_string.title.del=Delete
|
||||||
|
ui.admin.configuration.setting.localized_string.back=Back
|
||||||
|
ui.admin.configuration.setting.localized_string.locale.label=Locale
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue