Skip to content

The Unified and Autonomous Development Platform

Reworked reflection bean editor

robin shine1d9c1f497244
diff --git a/commons.editable/src/main/java/com/pmease/commons/editable/BeanDescriptor.java b/commons.editable/src/main/java/com/pmease/commons/editable/BeanDescriptor.java
index 6c81802486..cc4537d08f 100644
--- a/commons.editable/src/main/java/com/pmease/commons/editable/BeanDescriptor.java
+++ b/commons.editable/src/main/java/com/pmease/commons/editable/BeanDescriptor.java
@@ -3,11 +3,13 @@ package com.pmease.commons.editable;
import java.io.Serializable;
import java.util.List;
-public interface BeanDescriptor<T> extends Serializable {
+public interface BeanDescriptor<T extends Serializable> extends Serializable {
Class<? extends T> getBeanClass();
+ T newBeanInstance();
+
List<PropertyDescriptor> getPropertyDescriptors();
- void copyProperties(Object from, Object to);
+ void copyProperties(Serializable from, Serializable to);
}
diff --git a/commons.editable/src/main/java/com/pmease/commons/editable/BeanDescriptorImpl.java b/commons.editable/src/main/java/com/pmease/commons/editable/BeanDescriptorImpl.java
index 4897faae77..58baaa3a1c 100644
--- a/commons.editable/src/main/java/com/pmease/commons/editable/BeanDescriptorImpl.java
+++ b/commons.editable/src/main/java/com/pmease/commons/editable/BeanDescriptorImpl.java
@@ -1,5 +1,6 @@
package com.pmease.commons.editable;
+import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
@@ -8,7 +9,7 @@ import com.pmease.commons.editable.annotation.Editable;
import com.pmease.commons.util.BeanUtils;
@SuppressWarnings("serial")
-public class BeanDescriptorImpl<T> implements BeanDescriptor<T> {
+public class BeanDescriptorImpl<T extends Serializable> implements BeanDescriptor<T> {
private final Class<? extends T> beanClass;
@@ -48,9 +49,18 @@ public class BeanDescriptorImpl<T> implements BeanDescriptor<T> {
}
@Override
- public void copyProperties(Object from, Object to) {
+ public void copyProperties(Serializable from, Serializable to) {
for (PropertyDescriptor propertyDescriptor: getPropertyDescriptors())
propertyDescriptor.copyProperty(from, to);
}
+ @Override
+ public T newBeanInstance() {
+ try {
+ return getBeanClass().newInstance();
+ } catch (InstantiationException | IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
}
diff --git a/commons.editable/src/main/java/com/pmease/commons/editable/PropertyDescriptor.java b/commons.editable/src/main/java/com/pmease/commons/editable/PropertyDescriptor.java
index 8de0c89702..8c93356021 100644
--- a/commons.editable/src/main/java/com/pmease/commons/editable/PropertyDescriptor.java
+++ b/commons.editable/src/main/java/com/pmease/commons/editable/PropertyDescriptor.java
@@ -5,17 +5,22 @@ import java.lang.reflect.Method;
public interface PropertyDescriptor extends Serializable {
- public Class<?> getBeanClass();
+ Class<? extends Serializable> getBeanClass();
- public String getPropertyName();
+ String getPropertyName();
- public Method getPropertyGetter();
+ Method getPropertyGetter();
- public Method getPropertySetter();
+ Method getPropertySetter();
- public Object getPropertyValue(Object bean);
+ Class<? extends Serializable> getPropertyClass();
- public void setPropertyValue(Object bean, Object propertyValue);
+ Serializable getPropertyValue(Serializable bean);
+
+ boolean isPropertyRequired();
+
+ void setPropertyValue(Serializable bean, Serializable propertyValue);
+
+ void copyProperty(Serializable fromBean, Serializable toBean);
- public void copyProperty(Object from, Object to);
}
diff --git a/commons.editable/src/main/java/com/pmease/commons/editable/PropertyDescriptorImpl.java b/commons.editable/src/main/java/com/pmease/commons/editable/PropertyDescriptorImpl.java
index 0773743a33..58a4ac3fb5 100644
--- a/commons.editable/src/main/java/com/pmease/commons/editable/PropertyDescriptorImpl.java
+++ b/commons.editable/src/main/java/com/pmease/commons/editable/PropertyDescriptorImpl.java
@@ -1,14 +1,19 @@
package com.pmease.commons.editable;
+import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import javax.validation.constraints.NotNull;
+
+import org.hibernate.validator.constraints.NotEmpty;
+
import com.pmease.commons.util.BeanUtils;
@SuppressWarnings("serial")
public class PropertyDescriptorImpl implements PropertyDescriptor {
- private final Class<?> beanClass;
+ private final Class<? extends Serializable> beanClass;
private final String propertyName;
@@ -16,19 +21,21 @@ public class PropertyDescriptorImpl implements PropertyDescriptor {
private transient Method propertySetter;
- public PropertyDescriptorImpl(Class<?> beanClass, String propertyName) {
+ public PropertyDescriptorImpl(Class<? extends Serializable> beanClass, String propertyName) {
this.beanClass = beanClass;
this.propertyName = propertyName;
}
+ @SuppressWarnings("unchecked")
public PropertyDescriptorImpl(Method propertyGetter) {
- this.beanClass = propertyGetter.getDeclaringClass();
+ this.beanClass = (Class<? extends Serializable>) propertyGetter.getDeclaringClass();
this.propertyName = BeanUtils.getPropertyName(propertyGetter);
this.propertyGetter = propertyGetter;
}
+ @SuppressWarnings("unchecked")
public PropertyDescriptorImpl(Method propertyGetter, Method propertySetter) {
- this.beanClass = propertyGetter.getDeclaringClass();
+ this.beanClass = (Class<? extends Serializable>) propertyGetter.getDeclaringClass();
this.propertyName = BeanUtils.getPropertyName(propertyGetter);
this.propertyGetter = propertyGetter;
this.propertySetter = propertySetter;
@@ -42,7 +49,7 @@ public class PropertyDescriptorImpl implements PropertyDescriptor {
}
@Override
- public Class<?> getBeanClass() {
+ public Class<? extends Serializable> getBeanClass() {
return beanClass;
}
@@ -65,21 +72,21 @@ public class PropertyDescriptorImpl implements PropertyDescriptor {
}
@Override
- public void copyProperty(Object from, Object to) {
- setPropertyValue(to, getPropertyValue(from));
+ public void copyProperty(Serializable fromBean, Serializable toBean) {
+ setPropertyValue(toBean, getPropertyValue(fromBean));
}
@Override
- public Object getPropertyValue(Object bean) {
+ public Serializable getPropertyValue(Serializable bean) {
try {
- return getPropertyGetter().invoke(bean);
+ return (Serializable) getPropertyGetter().invoke(bean);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
@Override
- public void setPropertyValue(Object bean, Object propertyValue) {
+ public void setPropertyValue(Serializable bean, Serializable propertyValue) {
try {
getPropertySetter().invoke(bean, propertyValue);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
@@ -87,4 +94,21 @@ public class PropertyDescriptorImpl implements PropertyDescriptor {
}
}
+ @SuppressWarnings("unchecked")
+ @Override
+ public Class<? extends Serializable> getPropertyClass() {
+ return (Class<? extends Serializable>) getPropertyGetter().getReturnType();
+ }
+
+ @Override
+ public boolean isPropertyRequired() {
+ if (propertyGetter.getReturnType().isPrimitive()
+ || propertyGetter.getAnnotation(NotNull.class) != null
+ || propertyGetter.getAnnotation(NotEmpty.class) != null) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
}
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/wizard/ManualConfigStep.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/wizard/ManualConfigStep.java
index 81eedcb561..3540cc0b08 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/component/wizard/ManualConfigStep.java
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/component/wizard/ManualConfigStep.java
@@ -1,5 +1,7 @@
package com.pmease.commons.wicket.component.wizard;
+import java.io.Serializable;
+
import org.apache.wicket.markup.html.form.FormComponent;
import com.pmease.commons.util.init.ManualConfig;
@@ -15,7 +17,7 @@ public class ManualConfigStep implements WizardStep {
}
@Override
- public FormComponent<Object> render(String componentId) {
+ public FormComponent<Serializable> render(String componentId) {
return BeanEditContext.edit(componentId, config.getSetting());
}
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/BeanEditContext.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/BeanEditContext.java
index 584c68a277..5dc42f0cb9 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/BeanEditContext.java
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/BeanEditContext.java
@@ -11,7 +11,7 @@ import com.pmease.commons.editable.BeanDescriptorImpl;
import com.pmease.commons.loader.AppLoader;
@SuppressWarnings("serial")
-public abstract class BeanEditContext<T> extends BeanDescriptorImpl<T> {
+public abstract class BeanEditContext<T extends Serializable> extends BeanDescriptorImpl<T> {
public BeanEditContext(Class<? extends T> beanClass) {
super(beanClass);
@@ -46,38 +46,38 @@ public abstract class BeanEditContext<T> extends BeanDescriptorImpl<T> {
};
}
- public static BeanEditor<Object> edit(String componentId, IModel<Object> beanModel, boolean selfUpdating) {
+ public static BeanEditor<Serializable> edit(String componentId, IModel<Serializable> beanModel, boolean selfUpdating) {
EditSupportRegistry registry = AppLoader.getInstance(EditSupportRegistry.class);
- BeanEditContext<Object> editContext = registry.getBeanEditContext(beanModel.getObject().getClass());
+ BeanEditContext<Serializable> editContext = registry.getBeanEditContext(beanModel.getObject().getClass());
if (selfUpdating)
beanModel = editContext.wrapAsSelfUpdating(beanModel);
return editContext.renderForEdit(componentId, beanModel);
}
- public static BeanEditor<Object> edit(String componentId, final Serializable bean) {
- IModel<Object> beanModel = new IModel<Object>() {
+ public static BeanEditor<Serializable> edit(String componentId, final Serializable bean) {
+ IModel<Serializable> beanModel = new IModel<Serializable>() {
@Override
public void detach() {
}
@Override
- public Object getObject() {
+ public Serializable getObject() {
return bean;
}
@Override
- public void setObject(Object object) {
+ public void setObject(Serializable object) {
throw new IllegalStateException();
}
};
- return edit(componentId, beanModel);
+ return edit(componentId, beanModel, true);
}
- public static Component view(String componentId, IModel<Object> beanModel) {
+ public static Component view(String componentId, IModel<Serializable> beanModel) {
EditSupportRegistry registry = AppLoader.getInstance(EditSupportRegistry.class);
- BeanEditContext<Object> editContext = registry.getBeanEditContext(beanModel.getObject().getClass());
+ BeanEditContext<Serializable> editContext = registry.getBeanEditContext(beanModel.getObject().getClass());
return editContext.renderForView(componentId, beanModel);
}
@@ -85,4 +85,12 @@ public abstract class BeanEditContext<T> extends BeanDescriptorImpl<T> {
return view(componentId, Model.of(bean));
}
+ public static BeanEditContext<Serializable> of(Class<? extends Serializable> beanClass) {
+ EditSupportRegistry registry = AppLoader.getInstance(EditSupportRegistry.class);
+ return registry.getBeanEditContext(beanClass);
+ }
+
+ public static BeanEditContext<Serializable> of(BeanDescriptor<? extends Serializable> beanDescriptor) {
+ return of(beanDescriptor.getBeanClass());
+ }
}
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/BeanEditor.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/BeanEditor.java
index 84bd537d19..727366b358 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/BeanEditor.java
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/BeanEditor.java
@@ -1,5 +1,7 @@
package com.pmease.commons.wicket.editor;
+import java.io.Serializable;
+
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
@@ -11,7 +13,7 @@ import com.pmease.commons.editable.BeanDescriptor;
import com.pmease.commons.loader.AppLoader;
@SuppressWarnings("serial")
-public abstract class BeanEditor<T> extends ValueEditor<T> {
+public abstract class BeanEditor<T extends Serializable> extends ValueEditor<T> {
private final BeanDescriptor<T> beanDescriptor;
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/DefaultEditSupportRegistry.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/DefaultEditSupportRegistry.java
index 28b93a5bc0..1fc6540c00 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/DefaultEditSupportRegistry.java
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/DefaultEditSupportRegistry.java
@@ -1,5 +1,6 @@
package com.pmease.commons.wicket.editor;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -19,22 +20,24 @@ public class DefaultEditSupportRegistry implements EditSupportRegistry {
this.editSupports = new ArrayList<EditSupport>(editSupports);
}
+ @SuppressWarnings("unchecked")
@Override
- public BeanEditContext<Object> getBeanEditContext(Class<?> beanClass) {
+ public BeanEditContext<Serializable> getBeanEditContext(Class<? extends Serializable> beanClass) {
for (EditSupport each: editSupports) {
- BeanEditContext<Object> editContext = each.getBeanEditContext(beanClass);
+ BeanEditContext<?> editContext = each.getBeanEditContext(beanClass);
if (editContext != null)
- return editContext;
+ return (BeanEditContext<Serializable>) editContext;
}
throw new GeneralException(String.format("Unable to find edit context (bean: %s)", beanClass.getName()));
}
+ @SuppressWarnings("unchecked")
@Override
- public PropertyEditContext<Object> getPropertyEditContext(Class<?> beanClass, String propertyName) {
+ public PropertyEditContext<Serializable> getPropertyEditContext(Class<? extends Serializable> beanClass, String propertyName) {
for (EditSupport each: editSupports) {
- PropertyEditContext<Object> editContext = each.getPropertyEditContext(beanClass, propertyName);
+ PropertyEditContext<?> editContext = each.getPropertyEditContext(beanClass, propertyName);
if (editContext != null)
- return editContext;
+ return (PropertyEditContext<Serializable>) editContext;
}
throw new GeneralException(String.format(
"Unable to find edit context (bean: %s, property: %s)",
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/EditSupport.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/EditSupport.java
index be76aa5d44..e7879acef4 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/EditSupport.java
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/EditSupport.java
@@ -1,8 +1,13 @@
package com.pmease.commons.wicket.editor;
+import java.io.Serializable;
+
+import com.pmease.commons.loader.ExtensionPoint;
+
+@ExtensionPoint
public interface EditSupport {
- BeanEditContext<Object> getBeanEditContext(Class<?> beanClass);
+ BeanEditContext<? extends Serializable> getBeanEditContext(Class<? extends Serializable> beanClass);
- PropertyEditContext<Object> getPropertyEditContext(Class<?> beanClass, String propertyName);
+ PropertyEditContext<? extends Serializable> getPropertyEditContext(Class<? extends Serializable> beanClass, String propertyName);
}
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/EditSupportRegistry.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/EditSupportRegistry.java
index 058a11573c..c8e93673cd 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/EditSupportRegistry.java
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/EditSupportRegistry.java
@@ -1,12 +1,14 @@
package com.pmease.commons.wicket.editor;
+import java.io.Serializable;
+
import com.google.inject.ImplementedBy;
@ImplementedBy(DefaultEditSupportRegistry.class)
public interface EditSupportRegistry {
- BeanEditContext<Object> getBeanEditContext(Class<?> beanClass);
+ BeanEditContext<Serializable> getBeanEditContext(Class<? extends Serializable> beanClass);
- PropertyEditContext<Object> getPropertyEditContext(Class<?> beanClass, String propertyName);
+ PropertyEditContext<Serializable> getPropertyEditContext(Class<? extends Serializable> beanClass, String propertyName);
}
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/PropertyEditContext.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/PropertyEditContext.java
index 883acb0dab..5312482604 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/PropertyEditContext.java
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/PropertyEditContext.java
@@ -12,9 +12,9 @@ import com.pmease.commons.editable.PropertyDescriptorImpl;
import com.pmease.commons.loader.AppLoader;
@SuppressWarnings("serial")
-public abstract class PropertyEditContext<T> extends PropertyDescriptorImpl {
+public abstract class PropertyEditContext<T extends Serializable> extends PropertyDescriptorImpl {
- public PropertyEditContext(Class<?> beanClass, String propertyName) {
+ public PropertyEditContext(Class<? extends Serializable> beanClass, String propertyName) {
super(beanClass, propertyName);
}
@@ -26,10 +26,9 @@ public abstract class PropertyEditContext<T> extends PropertyDescriptorImpl {
public abstract PropertyEditor<T> renderForEdit(String componentId, IModel<T> model);
- public static PropertyEditor<Object> edit(String componentId, final IModel<Object> beanModel, String propertyName) {
- EditSupportRegistry registry = AppLoader.getInstance(EditSupportRegistry.class);
- final PropertyEditContext<Object> editContext = registry.getPropertyEditContext(beanModel.getObject().getClass(), propertyName);
- return editContext.renderForEdit(componentId, new IModel<Object>() {
+ public static PropertyEditor<Serializable> edit(String componentId, final IModel<Serializable> beanModel, String propertyName) {
+ final PropertyEditContext<Serializable> editContext = of(beanModel.getObject().getClass(), propertyName);
+ return editContext.renderForEdit(componentId, new IModel<Serializable>() {
@Override
public void detach() {
@@ -37,12 +36,12 @@ public abstract class PropertyEditContext<T> extends PropertyDescriptorImpl {
}
@Override
- public Object getObject() {
+ public Serializable getObject() {
return editContext.getPropertyValue(beanModel.getObject());
}
@Override
- public void setObject(Object object) {
+ public void setObject(Serializable object) {
editContext.setPropertyValue(beanModel.getObject(), object);
}
@@ -70,13 +69,12 @@ public abstract class PropertyEditContext<T> extends PropertyDescriptorImpl {
return edit(componentId, beanModel, propertyName);
}
- public static Component view(String componentId, final IModel<Object> beanModel, String propertyName) {
- EditSupportRegistry registry = AppLoader.getInstance(EditSupportRegistry.class);
- final PropertyEditContext<Object> editContext = registry.getPropertyEditContext(beanModel.getObject().getClass(), propertyName);
- return editContext.renderForView(componentId, new LoadableDetachableModel<Object>() {
+ public static Component view(String componentId, final IModel<Serializable> beanModel, String propertyName) {
+ final PropertyEditContext<Serializable> editContext = of(beanModel.getObject().getClass(), propertyName);
+ return editContext.renderForView(componentId, new LoadableDetachableModel<Serializable>() {
@Override
- protected Object load() {
+ protected Serializable load() {
return editContext.getPropertyValue(beanModel.getObject());
}
@@ -87,4 +85,12 @@ public abstract class PropertyEditContext<T> extends PropertyDescriptorImpl {
return view(componentId, Model.of(bean), propertyName);
}
+ public static PropertyEditContext<Serializable> of(Class<? extends Serializable> beanClass, String propertyName) {
+ EditSupportRegistry registry = AppLoader.getInstance(EditSupportRegistry.class);
+ return registry.getPropertyEditContext(beanClass, propertyName);
+ }
+
+ public static PropertyEditContext<Serializable> of(PropertyDescriptor propertyDescriptor) {
+ return of(propertyDescriptor.getBeanClass(), propertyDescriptor.getPropertyName());
+ }
}
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/numeric/NumericEditSupport.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/numeric/NumericEditSupport.java
new file mode 100644
index 0000000000..217d98b5c0
--- /dev/null
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/numeric/NumericEditSupport.java
@@ -0,0 +1,54 @@
+package com.pmease.commons.wicket.editor.numeric;
+
+import java.io.Serializable;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.model.IModel;
+
+import com.pmease.commons.editable.PropertyDescriptor;
+import com.pmease.commons.editable.PropertyDescriptorImpl;
+import com.pmease.commons.wicket.editor.BeanEditContext;
+import com.pmease.commons.wicket.editor.EditSupport;
+import com.pmease.commons.wicket.editor.PropertyEditContext;
+import com.pmease.commons.wicket.editor.PropertyEditor;
+
+@SuppressWarnings("serial")
+public class NumericEditSupport implements EditSupport {
+
+ @Override
+ public BeanEditContext<? extends Serializable> getBeanEditContext(Class<? extends Serializable> beanClass) {
+ return null;
+ }
+
+ @Override
+ public PropertyEditContext<? extends Serializable> getPropertyEditContext(Class<? extends Serializable> beanClass, String propertyName) {
+ PropertyDescriptor propertyDescriptor = new PropertyDescriptorImpl(beanClass, propertyName);
+
+ Class<?> propertyClass = propertyDescriptor.getPropertyGetter().getReturnType();
+ if (propertyClass == int.class || propertyClass == long.class
+ || propertyClass == Integer.class || propertyClass == Long.class) {
+ return new PropertyEditContext<Number>(propertyDescriptor) {
+
+ @Override
+ public Component renderForView(String componentId, IModel<Number> model) {
+ if (model.getObject() != null) {
+ return new Label(componentId, model.getObject().toString());
+ } else {
+ return new Label(componentId, "<i>Not Defined</i>").setEscapeModelStrings(false);
+ }
+ }
+
+ @Override
+ public PropertyEditor<Number> renderForEdit(String componentId, IModel<Number> model) {
+ return new NumericPropertyEditor(componentId, this, model);
+ }
+
+ };
+ } else {
+ return null;
+ }
+
+ }
+
+}
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/numeric/NumericPropertyEditor.html b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/numeric/NumericPropertyEditor.html
new file mode 100644
index 0000000000..d5e8c8e5f7
--- /dev/null
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/numeric/NumericPropertyEditor.html
@@ -0,0 +1,3 @@
+<wicket:panel>
+ <input wicket:id="input" type="text"></input>
+</wicket:panel>
\ No newline at end of file
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/numeric/NumericPropertyEditor.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/numeric/NumericPropertyEditor.java
new file mode 100644
index 0000000000..e0dfe93b60
--- /dev/null
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/numeric/NumericPropertyEditor.java
@@ -0,0 +1,39 @@
+package com.pmease.commons.wicket.editor.numeric;
+
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.util.convert.ConversionException;
+
+import com.pmease.commons.editable.PropertyDescriptor;
+import com.pmease.commons.wicket.editor.ErrorContext;
+import com.pmease.commons.wicket.editor.PathSegment;
+import com.pmease.commons.wicket.editor.PropertyEditor;
+
+@SuppressWarnings("serial")
+public class NumericPropertyEditor extends PropertyEditor<Number> {
+
+ private TextField<Number> input;
+
+ public NumericPropertyEditor(String id, PropertyDescriptor propertyDescriptor, IModel<Number> propertyModel) {
+ super(id, propertyDescriptor, propertyModel);
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ input = new TextField<Number>("input", getModel());
+ input.setType(getPropertyDescriptor().getPropertyClass());
+ }
+
+ @Override
+ public ErrorContext getErrorContext(PathSegment pathSegment) {
+ return null;
+ }
+
+ @Override
+ protected Number convertInputToValue() throws ConversionException {
+ return input.getConvertedInput();
+ }
+
+}
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/reflection/ReflectionBeanEditor.html b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/reflection/ReflectionBeanEditor.html
new file mode 100644
index 0000000000..5aae244733
--- /dev/null
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/reflection/ReflectionBeanEditor.html
@@ -0,0 +1,40 @@
+<wicket:panel>
+ <div wicket:id="content"></div>
+
+ <wicket:fragment wicket:id="default">
+ <div class="reflection editor">
+ <div wicket:id="properties" class="form-group">
+ <wicket:enclosure child="name">
+ <label class="name control-label">
+ <span wicket:id="name"></span>
+ <span wicket:id="required" class="required"></span>
+ </label>
+ </wicket:enclosure>
+ <div class="value">
+ <div wicket:id="value"></div>
+ <div wicket:id="feedback"></div>
+ <div wicket:id="description" class="help-block"></div>
+ </div>
+ </div>
+ </div>
+ </wicket:fragment>
+
+ <wicket:fragment wicket:id="table">
+ <table class="reflection editor">
+ <tr wicket:id="properties">
+ <wicket:enclosure child="name">
+ <td class="name control-label">
+ <span wicket:id="name"></span>
+ <span wicket:id="required" class="required"></span>
+ </td>
+ </wicket:enclosure>
+ <td class="value">
+ <div wicket:id="value"></div>
+ <div wicket:id="feedback"></div>
+ <div wicket:id="description" class="help-block"></div>
+ </td>
+ </tr>
+ </table>
+ </wicket:fragment>
+
+</wicket:panel>
\ No newline at end of file
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/reflection/ReflectionBeanEditor.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/reflection/ReflectionBeanEditor.java
new file mode 100644
index 0000000000..13bc75e877
--- /dev/null
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/reflection/ReflectionBeanEditor.java
@@ -0,0 +1,136 @@
+package com.pmease.commons.wicket.editor.reflection;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.list.ListItem;
+import org.apache.wicket.markup.html.list.ListView;
+import org.apache.wicket.markup.html.panel.Fragment;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.util.convert.ConversionException;
+import org.apache.wicket.util.visit.IVisit;
+import org.apache.wicket.util.visit.IVisitor;
+
+import com.pmease.commons.editable.BeanDescriptor;
+import com.pmease.commons.editable.EditableUtils;
+import com.pmease.commons.editable.PropertyDescriptor;
+import com.pmease.commons.editable.annotation.OmitName;
+import com.pmease.commons.editable.annotation.TableLayout;
+import com.pmease.commons.wicket.editor.BeanEditor;
+import com.pmease.commons.wicket.editor.ErrorContext;
+import com.pmease.commons.wicket.editor.PathSegment;
+import com.pmease.commons.wicket.editor.PathSegment.Property;
+import com.pmease.commons.wicket.editor.PropertyEditContext;
+import com.pmease.commons.wicket.editor.PropertyEditor;
+
+import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
+
+@SuppressWarnings("serial")
+public class ReflectionBeanEditor extends BeanEditor<Serializable> {
+
+ private final List<PropertyEditContext<Serializable>> propertyContexts = new ArrayList<>();
+
+ public ReflectionBeanEditor(String id, BeanDescriptor<Serializable> beanDescriptor, IModel<Serializable> model) {
+ super(id, beanDescriptor, model);
+
+ for (PropertyDescriptor propertyDescriptor: beanDescriptor.getPropertyDescriptors()) {
+ propertyContexts.add(PropertyEditContext.of(propertyDescriptor));
+ }
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ setOutputMarkupId(true);
+
+ Fragment fragment;
+ if (getBeanDescriptor().getBeanClass().getAnnotation(TableLayout.class) == null)
+ fragment = new Fragment("content", "default", ReflectionBeanEditor.this);
+ else
+ fragment = new Fragment("content", "table", ReflectionBeanEditor.this);
+
+ add(fragment);
+
+ fragment.add(new ListView<PropertyEditContext<Serializable>>("properties", propertyContexts) {
+
+ @Override
+ protected void populateItem(ListItem<PropertyEditContext<Serializable>> item) {
+ PropertyEditContext<Serializable> propertyContext = item.getModelObject();
+
+ Label nameLabel = new Label("name", EditableUtils.getName(propertyContext.getPropertyGetter()));
+ item.add(nameLabel);
+
+ OmitName omitName = propertyContext.getPropertyGetter().getAnnotation(OmitName.class);
+ if (omitName != null && omitName.value() != OmitName.Place.VIEWER)
+ nameLabel.setVisible(false);
+
+ String required;
+ if (propertyContext.isPropertyRequired() && propertyContext.getPropertyClass() != boolean.class)
+ required = "*";
+ else
+ required = "&nbsp;";
+
+ item.add(new Label("required", required).setEscapeModelStrings(false));
+
+ Serializable propertyValue = propertyContext.getPropertyValue(ReflectionBeanEditor.this.getModelObject());
+ PropertyEditor<Serializable> propertyEditor = propertyContext.renderForEdit("value", Model.of(propertyValue));
+ item.add(propertyEditor);
+
+ String description = EditableUtils.getDescription(propertyContext.getPropertyGetter());
+ if (description != null)
+ item.add(new Label("description", description).setEscapeModelStrings(false));
+ else
+ item.add(new Label("description").setVisible(false));
+
+ item.add(new NotificationPanel("feedback", propertyEditor));
+ }
+
+ });
+ }
+
+ @Override
+ public ErrorContext getErrorContext(PathSegment pathSegment) {
+ final PathSegment.Property property = (Property) pathSegment;
+ return visitChildren(PropertyEditor.class, new IVisitor<PropertyEditor<Serializable>, PropertyEditor<Serializable>>() {
+
+ @Override
+ public void component(PropertyEditor<Serializable> object, IVisit<PropertyEditor<Serializable>> visit) {
+ if (object.getPropertyDescriptor().getPropertyName().equals(property.getname()))
+ visit.stop(object);
+ else
+ visit.dontGoDeeper();
+ }
+
+ });
+ }
+
+ @Override
+ protected Serializable convertInputToValue() throws ConversionException {
+ final Serializable bean = getBeanDescriptor().newBeanInstance();
+
+ visitChildren(PropertyEditor.class, new IVisitor<PropertyEditor<Serializable>, PropertyEditor<Serializable>>() {
+
+ @Override
+ public void component(PropertyEditor<Serializable> object, IVisit<PropertyEditor<Serializable>> visit) {
+ object.getPropertyDescriptor().setPropertyValue(bean, object.getConvertedInput());
+ visit.dontGoDeeper();
+ }
+
+ });
+
+ return bean;
+ }
+
+ @Override
+ public void renderHead(IHeaderResponse response) {
+ super.renderHead(response);
+
+ response.render(OnDomReadyHeaderItem.forScript(String.format("pmease.commons.editable.adjustReflectionEditor('%s')", getMarkupId())));
+ }
+}
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/reflection/ReflectionBeanViewer.html b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/reflection/ReflectionBeanViewer.html
new file mode 100644
index 0000000000..1a2507a7b9
--- /dev/null
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/reflection/ReflectionBeanViewer.html
@@ -0,0 +1,10 @@
+<wicket:panel>
+ <table class="reflection viewer">
+ <tr wicket:id="properties">
+ <wicket:enclosure child="name">
+ <td class="name"><span wicket:id="name"></span></td>
+ </wicket:enclosure>
+ <td class="value"><span wicket:id="value"></span></td>
+ </tr>
+ </table>
+</wicket:panel>
\ No newline at end of file
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/reflection/ReflectionBeanViewer.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/reflection/ReflectionBeanViewer.java
new file mode 100644
index 0000000000..c021c53a71
--- /dev/null
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/reflection/ReflectionBeanViewer.java
@@ -0,0 +1,60 @@
+package com.pmease.commons.wicket.editor.reflection;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.wicket.behavior.AttributeAppender;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.list.ListItem;
+import org.apache.wicket.markup.html.list.ListView;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+
+import com.pmease.commons.editable.BeanDescriptor;
+import com.pmease.commons.editable.EditableUtils;
+import com.pmease.commons.editable.PropertyDescriptor;
+import com.pmease.commons.editable.annotation.OmitName;
+import com.pmease.commons.wicket.editor.PropertyEditContext;
+
+@SuppressWarnings("serial")
+public class ReflectionBeanViewer extends Panel {
+
+ private final List<PropertyEditContext<Serializable>> propertyContexts = new ArrayList<>();
+
+ public ReflectionBeanViewer(String id, BeanDescriptor<Serializable> beanDescriptor, IModel<Serializable> model) {
+ super(id, model);
+
+ for (PropertyDescriptor propertyDescriptor: beanDescriptor.getPropertyDescriptors()) {
+ propertyContexts.add(PropertyEditContext.of(propertyDescriptor));
+ }
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ add(new ListView<PropertyEditContext<Serializable>>("properties", propertyContexts) {
+
+ @Override
+ protected void populateItem(ListItem<PropertyEditContext<Serializable>> item) {
+ PropertyEditContext<Serializable> propertyContext = item.getModelObject();
+ Method propertyGetter = propertyContext.getPropertyGetter();
+ Label nameLabel = new Label("name", EditableUtils.getName(propertyGetter));
+ item.add(nameLabel);
+ OmitName omitName = propertyGetter.getAnnotation(OmitName.class);
+
+ if (omitName != null && omitName.value() != OmitName.Place.EDITOR) {
+ nameLabel.setVisible(false);
+ item.add(AttributeAppender.append("class", "name-omitted"));
+ }
+
+ Serializable propertyValue = propertyContext.getPropertyValue((Serializable)getDefaultModelObject());
+ item.add(propertyContext.renderForView("value", Model.of(propertyValue)));
+ }
+
+ });
+ }
+}
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/reflection/ReflectionEditSupport.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/reflection/ReflectionEditSupport.java
new file mode 100644
index 0000000000..2d36b74ff6
--- /dev/null
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/reflection/ReflectionEditSupport.java
@@ -0,0 +1,71 @@
+package com.pmease.commons.wicket.editor.reflection;
+
+import java.io.Serializable;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.model.IModel;
+
+import com.pmease.commons.editable.PropertyDescriptor;
+import com.pmease.commons.editable.PropertyDescriptorImpl;
+import com.pmease.commons.editable.annotation.Editable;
+import com.pmease.commons.util.ClassUtils;
+import com.pmease.commons.wicket.editor.BeanEditContext;
+import com.pmease.commons.wicket.editor.BeanEditor;
+import com.pmease.commons.wicket.editor.EditSupport;
+import com.pmease.commons.wicket.editor.PropertyEditContext;
+import com.pmease.commons.wicket.editor.PropertyEditor;
+
+public class ReflectionEditSupport implements EditSupport {
+
+ @SuppressWarnings("serial")
+ @Override
+ public BeanEditContext<? extends Serializable> getBeanEditContext(Class<? extends Serializable> beanClass) {
+ if (beanClass.getAnnotation(Editable.class) != null && ClassUtils.isConcrete(beanClass)) {
+ return new BeanEditContext<Serializable>(beanClass) {
+
+ @Override
+ public Component renderForView(String componentId, IModel<Serializable> model) {
+ return new ReflectionBeanViewer(componentId, this, model);
+ }
+
+ @Override
+ public BeanEditor<Serializable> renderForEdit(String componentId, IModel<Serializable> model) {
+ return new ReflectionBeanEditor(componentId, this, model);
+ }
+
+ };
+ } else {
+ return null;
+ }
+ }
+
+ @SuppressWarnings("serial")
+ @Override
+ public PropertyEditContext<? extends Serializable> getPropertyEditContext(Class<? extends Serializable> beanClass, String propertyName) {
+ PropertyDescriptor propertyDescriptor = new PropertyDescriptorImpl(beanClass, propertyName);
+ Class<?> propertyClass = propertyDescriptor.getPropertyClass();
+ if (propertyClass.getAnnotation(Editable.class) != null && ClassUtils.isConcrete(propertyClass)) {
+ return new PropertyEditContext<Serializable>(propertyDescriptor) {
+
+ @Override
+ public Component renderForView(String componentId, IModel<Serializable> model) {
+ if (model.getObject() != null) {
+ return BeanEditContext.view(componentId, model.getObject());
+ } else {
+ return new Label(componentId, "<i>Not Defined</i>").setEscapeModelStrings(false);
+ }
+ }
+
+ @Override
+ public PropertyEditor<Serializable> renderForEdit(String componentId, IModel<Serializable> model) {
+ return new ReflectionPropertyEditor(componentId, this, model);
+ }
+
+ };
+ } else {
+ return null;
+ }
+ }
+
+}
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/reflection/ReflectionPropertyEditor.html b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/reflection/ReflectionPropertyEditor.html
new file mode 100644
index 0000000000..a5baed9441
--- /dev/null
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/reflection/ReflectionPropertyEditor.html
@@ -0,0 +1,6 @@
+<wicket:panel>
+ <wicket:enclosure child:id="enable">
+ <input wicket:id="enable" type="checkbox" class="enable"></input>
+ </wicket:enclosure>
+ <div wicket:id="beanEditor"></div>
+</wicket:panel>
\ No newline at end of file
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/reflection/ReflectionPropertyEditor.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/reflection/ReflectionPropertyEditor.java
new file mode 100644
index 0000000000..09bfb8c2c6
--- /dev/null
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/editor/reflection/ReflectionPropertyEditor.java
@@ -0,0 +1,121 @@
+package com.pmease.commons.wicket.editor.reflection;
+
+import java.io.Serializable;
+
+import javax.validation.constraints.NotNull;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.form.CheckBox;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.util.convert.ConversionException;
+
+import com.pmease.commons.editable.PropertyDescriptor;
+import com.pmease.commons.wicket.editor.BeanEditContext;
+import com.pmease.commons.wicket.editor.BeanEditor;
+import com.pmease.commons.wicket.editor.ErrorContext;
+import com.pmease.commons.wicket.editor.PathSegment;
+import com.pmease.commons.wicket.editor.PropertyEditor;
+
+@SuppressWarnings("serial")
+public class ReflectionPropertyEditor extends PropertyEditor<Serializable> {
+
+ private final String BEAN_EDITOR_ID = "beanEditor";
+
+ private Serializable propertyValue;
+
+ public ReflectionPropertyEditor(String id, PropertyDescriptor propertyDescriptor, IModel<Serializable> propertyModel) {
+ super(id, propertyDescriptor, propertyModel);
+
+ propertyValue = propertyModel.getObject();
+
+ if (isPropertyRequired() && propertyValue == null) {
+ try {
+ propertyValue = (Serializable) propertyDescriptor.getPropertyClass().newInstance();
+ } catch (InstantiationException | IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ private boolean isPropertyRequired() {
+ return getPropertyDescriptor().getPropertyGetter().getAnnotation(NotNull.class) != null;
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ if (isPropertyRequired()) {
+ add(new WebMarkupContainer("enable").setVisible(false));
+ } else {
+ add(new CheckBox("enable", new IModel<Boolean>() {
+
+ @Override
+ public void detach() {
+
+ }
+
+ @Override
+ public Boolean getObject() {
+ return propertyValue != null;
+ }
+
+ @Override
+ public void setObject(Boolean object) {
+ if (object) {
+ try {
+ propertyValue = (Serializable) getPropertyDescriptor().getPropertyClass().newInstance();
+ } catch (InstantiationException | IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ } else {
+ propertyValue = null;
+ }
+ }
+
+ }).add(new AjaxFormComponentUpdatingBehavior("onclick"){
+
+ @Override
+ protected void onUpdate(AjaxRequestTarget target) {
+ Component beanEditor = newBeanEditor();
+ replace(beanEditor);
+ target.add(beanEditor);
+ }
+
+ }));
+
+ }
+
+ add(newBeanEditor());
+ }
+
+ private Component newBeanEditor() {
+ Component beanEditor;
+ if (propertyValue != null) {
+ beanEditor = BeanEditContext.edit(BEAN_EDITOR_ID, propertyValue);
+ } else {
+ beanEditor = new WebMarkupContainer(BEAN_EDITOR_ID).setVisible(false);
+ }
+ beanEditor.setOutputMarkupId(true);
+ beanEditor.setOutputMarkupPlaceholderTag(true);
+ return beanEditor;
+ }
+
+ @Override
+ public ErrorContext getErrorContext(PathSegment pathSegment) {
+ return ((ErrorContext) get(BEAN_EDITOR_ID)).getErrorContext(pathSegment);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected Serializable convertInputToValue() throws ConversionException {
+ if (propertyValue != null)
+ return ((BeanEditor<Serializable>) get(BEAN_EDITOR_ID)).getConvertedInput();
+ else
+ return null;
+ }
+
+}
diff --git a/gitop.core/src/main/java/com/pmease/gitop/core/Gitop.java b/gitop.core/src/main/java/com/pmease/gitop/core/Gitop.java
index ba6dd7840b..b3fddb9124 100644
--- a/gitop.core/src/main/java/com/pmease/gitop/core/Gitop.java
+++ b/gitop.core/src/main/java/com/pmease/gitop/core/Gitop.java
@@ -56,7 +56,7 @@ public class Gitop extends AbstractPlugin {
@Inject
public Gitop(ServerConfig serverConfig, DataManager dataManager,
RepositoryManager repositoryManager, UserManager userManager,
- TaskScheduler taskScheduler, Provider<GitConfig> gitConfigProvider,
+ TaskScheduler taskScheduler, Provider<GitConfig> gitConfigProvider,
@AppName String appName) {
this.dataManager = dataManager;
this.repositoryManager = repositoryManager;
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/account/RegisterPage.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/account/RegisterPage.java
index 451243c6f4..46d59aad2e 100644
--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/account/RegisterPage.java
+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/account/RegisterPage.java
@@ -1,5 +1,7 @@
package com.pmease.gitop.web.page.account;
+import java.io.Serializable;
+
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.SubmitLink;
@@ -18,7 +20,7 @@ import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel
@SuppressWarnings("serial")
public class RegisterPage extends BasePage {
- private BeanEditor<Object> beanEditor;
+ private BeanEditor<Serializable> beanEditor;
private User user = new User();