CCM NG: Current status of UI for the configuration system
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4055 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
f188ce7f57
commit
e55e65bcf9
|
|
@ -351,6 +351,44 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>de.jpdigital</groupId>
|
||||
<artifactId>hibernate5-ddl-maven-plugin</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<configuration>
|
||||
<outputDirectory>target/generated-resources/hibernate5/sql/ddl/auto</outputDirectory>
|
||||
<dialects>
|
||||
<param>h2</param>
|
||||
<!--<param>mysql5_innodb</param>-->
|
||||
<param>oracle10g</param>
|
||||
<param>postgresql9</param>
|
||||
</dialects>
|
||||
<packages>
|
||||
<param>org.libreccm.categorization</param>
|
||||
<param>org.libreccm.core</param>
|
||||
<param>org.libreccm.formbuilder</param>
|
||||
<param>org.libreccm.jpa</param>
|
||||
<param>org.libreccm.l10n</param>
|
||||
<param>org.libreccm.messaging</param>
|
||||
<param>org.libreccm.notification</param>
|
||||
<param>org.libreccm.portal</param>
|
||||
<param>org.libreccm.runtime</param>
|
||||
<param>org.libreccm.search.lucene</param>
|
||||
<param>org.libreccm.web</param>
|
||||
<param>org.libreccm.workflow</param>
|
||||
</packages>
|
||||
<persistenceXml>${basedir}/src/main/resources/META-INF/persistence-ddl.xml</persistenceXml>
|
||||
<useEnvers>true</useEnvers>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>gen-ddl</goal>
|
||||
</goals>
|
||||
<phase>process-classes</phase>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!--<plugin>
|
||||
<groupId>org.jboss.tattletale</groupId>
|
||||
<artifactId>tattletale-maven</artifactId>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
* 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);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,241 @@
|
|||
/*
|
||||
* 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 java.math.BigDecimal;
|
||||
|
||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @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";
|
||||
|
||||
public AbstractSettingFormSingleValue(
|
||||
final ConfigurationTab configurationTab,
|
||||
final ParameterSingleSelectionModel<String> selectedConf,
|
||||
final ParameterSingleSelectionModel<String> selectedSetting) {
|
||||
|
||||
super("settingFormSingleValue", new BoxPanel(BoxPanel.VERTICAL));
|
||||
|
||||
add(new SettingFormHeader(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);
|
||||
|
||||
final SaveCancelSection saveCancelSection = new SaveCancelSection();
|
||||
add(saveCancelSection);
|
||||
|
||||
addInitListener(new InitListener(selectedConf,
|
||||
selectedSetting,
|
||||
valueField));
|
||||
|
||||
addValidationListener(new ValidationListener());
|
||||
|
||||
addProcessListener(new ProcessListener(selectedConf, selectedSetting));
|
||||
|
||||
}
|
||||
|
||||
abstract T convertValue(final String valueData);
|
||||
|
||||
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 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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ValidationListener implements FormValidationListener {
|
||||
|
||||
@Override
|
||||
public void validate(final FormSectionEvent event) throws
|
||||
FormProcessException {
|
||||
final FormData data = event.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 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.not_a_bigdecimal",
|
||||
ADMIN_BUNDLE));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class ProcessListener implements FormProcessListener {
|
||||
|
||||
private final ParameterSingleSelectionModel<String> selectedConf;
|
||||
private final ParameterSingleSelectionModel<String> selectedSetting;
|
||||
|
||||
public ProcessListener(
|
||||
final ParameterSingleSelectionModel<String> selectedConf,
|
||||
final ParameterSingleSelectionModel<String> selectedSetting) {
|
||||
this.selectedConf = selectedConf;
|
||||
this.selectedSetting = selectedSetting;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
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.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 T value = convertValue(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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -21,6 +21,7 @@ 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;
|
||||
|
|
@ -30,6 +31,7 @@ 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;
|
||||
|
|
@ -160,7 +162,8 @@ public class SettingFormBigDecimal extends Form {
|
|||
try {
|
||||
value = (BigDecimal) confClass.getField(selectedSetting
|
||||
.getSelectedKey(state)).get(config);
|
||||
} catch (NoSuchFieldException | SecurityException | IllegalAccessException | ClassCastException ex) {
|
||||
} catch (NoSuchFieldException | SecurityException |
|
||||
IllegalAccessException | ClassCastException ex) {
|
||||
LOGGER.warn("Failed to read setting {} from configuration {}",
|
||||
selectedSetting.getSelectedKey(state),
|
||||
selectedConf.getSelectedKey(state));
|
||||
|
|
@ -203,7 +206,8 @@ public class SettingFormBigDecimal extends Form {
|
|||
try {
|
||||
value = (BigDecimal) confClass.getField(selectedSetting
|
||||
.getSelectedKey(state)).get(config);
|
||||
} catch (NoSuchFieldException | SecurityException | IllegalAccessException | ClassCastException ex) {
|
||||
} catch (NoSuchFieldException | SecurityException |
|
||||
IllegalAccessException | ClassCastException ex) {
|
||||
LOGGER.warn("Failed to read setting {} from configuration {}",
|
||||
selectedSetting.getSelectedKey(state),
|
||||
selectedConf.getSelectedKey(state));
|
||||
|
|
@ -211,11 +215,10 @@ public class SettingFormBigDecimal extends Form {
|
|||
return;
|
||||
}
|
||||
|
||||
valueField.setValue(state, value);
|
||||
valueField.setValue(state, value.toString());
|
||||
});
|
||||
|
||||
addValidationListener(e -> {
|
||||
final PageState state = e.getPageState();
|
||||
final FormData data = e.getFormData();
|
||||
|
||||
final String valueData = data.getString(VALUE_FIELD);
|
||||
|
|
@ -239,10 +242,58 @@ public class SettingFormBigDecimal extends Form {
|
|||
});
|
||||
|
||||
addProcessListener(e -> {
|
||||
throw new UnsupportedOperationException();
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,12 +20,20 @@ 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.SaveCancelSection;
|
||||
import com.arsdigita.bebop.Text;
|
||||
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 java.util.Objects;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
|
@ -44,6 +52,9 @@ import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|||
*/
|
||||
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);
|
||||
|
||||
|
|
@ -121,6 +132,155 @@ public class SettingFormBoolean extends Form {
|
|||
|
||||
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(
|
||||
VALUE_FIELD_GROUP);
|
||||
valueFieldGroup.addOption(
|
||||
new Option(VALUE_FIELD,
|
||||
new Label(new GlobalizedMessage(
|
||||
"ui.admin.configuration.setting.edit.new_value",
|
||||
ADMIN_BUNDLE))));
|
||||
|
||||
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 {
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
||||
if (value) {
|
||||
valueFieldGroup.setValue(state, VALUE_FIELD);
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
} 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,91 @@
|
|||
/*
|
||||
* 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 static com.arsdigita.ui.admin.AdminUiConstants.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @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 {
|
||||
value = confClass.getField(selectedSetting
|
||||
.getSelectedKey(state)).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));
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,160 @@
|
|||
/*
|
||||
* 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.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.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class SettingFormHeader extends BoxPanel {
|
||||
|
||||
public SettingFormHeader(
|
||||
final ParameterSingleSelectionModel<String> selectedConf,
|
||||
final ParameterSingleSelectionModel<String> selectedSetting) {
|
||||
|
||||
super(BoxPanel.VERTICAL);
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,296 @@
|
|||
/*
|
||||
* 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.GridPanel;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
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>
|
||||
*/
|
||||
public class SettingFormLong extends Form {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(
|
||||
SettingFormLong.class);
|
||||
|
||||
private static final String VALUE_FIELD = "valueField";
|
||||
|
||||
public SettingFormLong(
|
||||
final ConfigurationTab configurationTab,
|
||||
final ParameterSingleSelectionModel<String> selectedConf,
|
||||
final ParameterSingleSelectionModel<String> selectedSetting) {
|
||||
|
||||
super("settingBoolean", 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);
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue