mirror of
https://github.com/theonedev/onedev.git
synced 2025-12-08 18:26:30 +00:00
Make required indicator appearing at right of property name.
This commit is contained in:
parent
a4c7cc6cd5
commit
b2a394715f
@ -10,6 +10,10 @@ import java.util.Collections;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
|
|
||||||
import com.pmease.commons.editable.annotation.Editable;
|
import com.pmease.commons.editable.annotation.Editable;
|
||||||
import com.pmease.commons.loader.AppLoader;
|
import com.pmease.commons.loader.AppLoader;
|
||||||
import com.pmease.commons.util.GeneralException;
|
import com.pmease.commons.util.GeneralException;
|
||||||
@ -125,4 +129,14 @@ public class EditableUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isPropertyRequired(Method propertyGetter) {
|
||||||
|
if (propertyGetter.getReturnType().isPrimitive() && propertyGetter.getReturnType() != boolean.class
|
||||||
|
|| propertyGetter.getAnnotation(NotNull.class) != null
|
||||||
|
|| propertyGetter.getAnnotation(NotEmpty.class) != null) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,9 +6,6 @@ import java.lang.reflect.Method;
|
|||||||
|
|
||||||
import javax.validation.ConstraintViolation;
|
import javax.validation.ConstraintViolation;
|
||||||
import javax.validation.Validator;
|
import javax.validation.Validator;
|
||||||
import javax.validation.constraints.NotNull;
|
|
||||||
|
|
||||||
import org.hibernate.validator.constraints.NotEmpty;
|
|
||||||
|
|
||||||
import com.pmease.commons.loader.AppLoader;
|
import com.pmease.commons.loader.AppLoader;
|
||||||
import com.pmease.commons.util.BeanUtils;
|
import com.pmease.commons.util.BeanUtils;
|
||||||
@ -81,13 +78,7 @@ public abstract class PropertyEditContext extends AbstractEditContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPropertyRequired() {
|
public boolean isPropertyRequired() {
|
||||||
if (getPropertyGetter().getReturnType().isPrimitive()
|
return EditableUtils.isPropertyRequired(getPropertyGetter());
|
||||||
|| getPropertyGetter().getAnnotation(NotNull.class) != null
|
|
||||||
|| getPropertyGetter().getAnnotation(NotEmpty.class) != null) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -109,6 +109,7 @@ table td, table th {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.required {
|
.required {
|
||||||
|
font-size: 18px;
|
||||||
color: #B94A48;
|
color: #B94A48;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<th wicket:id="headers">
|
<th wicket:id="headers">
|
||||||
<span wicket:id="header"></span>
|
<span wicket:id="header"></span>
|
||||||
|
<span wicket:id="required" class="required"></span>
|
||||||
</th>
|
</th>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|||||||
@ -110,6 +110,14 @@ public class TableListPropertyEditor extends Panel {
|
|||||||
@Override
|
@Override
|
||||||
protected void populateItem(ListItem<Method> item) {
|
protected void populateItem(ListItem<Method> item) {
|
||||||
item.add(new Label("header", EditableUtils.getName(item.getModelObject())));
|
item.add(new Label("header", EditableUtils.getName(item.getModelObject())));
|
||||||
|
|
||||||
|
String required;
|
||||||
|
if (EditableUtils.isPropertyRequired(item.getModelObject()))
|
||||||
|
required = "*";
|
||||||
|
else
|
||||||
|
required = " ";
|
||||||
|
|
||||||
|
item.add(new Label("required", required).setEscapeModelStrings(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -3,7 +3,9 @@ package com.pmease.commons.wicket.editable.nuemric;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.wicket.markup.ComponentTag;
|
||||||
import org.apache.wicket.markup.html.basic.Label;
|
import org.apache.wicket.markup.html.basic.Label;
|
||||||
|
import org.apache.wicket.markup.html.form.TextField;
|
||||||
import org.apache.wicket.model.IModel;
|
import org.apache.wicket.model.IModel;
|
||||||
import org.apache.wicket.model.Model;
|
import org.apache.wicket.model.Model;
|
||||||
|
|
||||||
@ -30,7 +32,18 @@ public class NumericPropertyEditContext extends PropertyEditContext {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object renderForEdit(Object renderParam) {
|
public Object renderForEdit(Object renderParam) {
|
||||||
return new NumericPropertyEditor((String) renderParam, this);
|
return new TextField<String>((String) renderParam, getInputModel()) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onComponentTag(ComponentTag tag) {
|
||||||
|
tag.setName("input");
|
||||||
|
tag.put("type", "text");
|
||||||
|
tag.put("class", "form-control");
|
||||||
|
|
||||||
|
super.onComponentTag(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -1,16 +0,0 @@
|
|||||||
<wicket:panel>
|
|
||||||
<div wicket:id="content"></div>
|
|
||||||
|
|
||||||
<wicket:fragment wicket:id="required">
|
|
||||||
<div class="input-group">
|
|
||||||
<input wicket:id="input" type="text" class="form-control">
|
|
||||||
<span class="input-group-addon required" title="This field is required">
|
|
||||||
<span class="glyphicon glyphicon-asterisk"></span>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</wicket:fragment>
|
|
||||||
|
|
||||||
<wicket:fragment wicket:id="notRequired">
|
|
||||||
<input wicket:id="input" type="text" class="form-control">
|
|
||||||
</wicket:fragment>
|
|
||||||
</wicket:panel>
|
|
||||||
@ -1,31 +0,0 @@
|
|||||||
package com.pmease.commons.wicket.editable.nuemric;
|
|
||||||
|
|
||||||
import org.apache.wicket.markup.html.form.TextField;
|
|
||||||
import org.apache.wicket.markup.html.panel.Fragment;
|
|
||||||
import org.apache.wicket.markup.html.panel.Panel;
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
|
||||||
public class NumericPropertyEditor extends Panel {
|
|
||||||
|
|
||||||
private final NumericPropertyEditContext editContext;
|
|
||||||
|
|
||||||
public NumericPropertyEditor(String id, NumericPropertyEditContext editContext) {
|
|
||||||
super(id);
|
|
||||||
this.editContext = editContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onInitialize() {
|
|
||||||
super.onInitialize();
|
|
||||||
|
|
||||||
Fragment fragment;
|
|
||||||
if (editContext.isPropertyRequired()) {
|
|
||||||
fragment = new Fragment("content", "required", this);
|
|
||||||
} else {
|
|
||||||
fragment = new Fragment("content", "notRequired", this);
|
|
||||||
}
|
|
||||||
fragment.add(new TextField<String>("input", editContext.getInputModel()));
|
|
||||||
add(fragment);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -12,6 +12,7 @@
|
|||||||
<tr wicket:id="properties">
|
<tr wicket:id="properties">
|
||||||
<td class="name control-label">
|
<td class="name control-label">
|
||||||
<span wicket:id="name"></span>
|
<span wicket:id="name"></span>
|
||||||
|
<span wicket:id="required" class="required"></span>
|
||||||
</td>
|
</td>
|
||||||
<td class="value">
|
<td class="value">
|
||||||
<div wicket:id="value"></div>
|
<div wicket:id="value"></div>
|
||||||
|
|||||||
@ -65,6 +65,15 @@ public class ReflectionBeanEditor extends Panel {
|
|||||||
protected void populateItem(ListItem<PropertyEditContext> item) {
|
protected void populateItem(ListItem<PropertyEditContext> item) {
|
||||||
final PropertyEditContext propertyContext = item.getModelObject();
|
final PropertyEditContext propertyContext = item.getModelObject();
|
||||||
item.add(new Label("name", EditableUtils.getName(propertyContext.getPropertyGetter())));
|
item.add(new Label("name", EditableUtils.getName(propertyContext.getPropertyGetter())));
|
||||||
|
|
||||||
|
String required;
|
||||||
|
if (propertyContext.isPropertyRequired())
|
||||||
|
required = "*";
|
||||||
|
else
|
||||||
|
required = " ";
|
||||||
|
|
||||||
|
item.add(new Label("required", required).setEscapeModelStrings(false));
|
||||||
|
|
||||||
item.add((Component)propertyContext.renderForEdit("value"));
|
item.add((Component)propertyContext.renderForEdit("value"));
|
||||||
|
|
||||||
String description = EditableUtils.getDescription(propertyContext.getPropertyGetter());
|
String description = EditableUtils.getDescription(propertyContext.getPropertyGetter());
|
||||||
|
|||||||
@ -3,7 +3,10 @@ package com.pmease.commons.wicket.editable.string;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.wicket.markup.ComponentTag;
|
||||||
import org.apache.wicket.markup.html.basic.Label;
|
import org.apache.wicket.markup.html.basic.Label;
|
||||||
|
import org.apache.wicket.markup.html.form.TextField;
|
||||||
|
import org.apache.wicket.model.IModel;
|
||||||
|
|
||||||
import com.pmease.commons.editable.EditContext;
|
import com.pmease.commons.editable.EditContext;
|
||||||
import com.pmease.commons.editable.PropertyEditContext;
|
import com.pmease.commons.editable.PropertyEditContext;
|
||||||
@ -17,7 +20,34 @@ public class StringPropertyEditContext extends PropertyEditContext {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object renderForEdit(Object renderParam) {
|
public Object renderForEdit(Object renderParam) {
|
||||||
return new StringPropertyEditor((String) renderParam, this);
|
return new TextField<String>((String) renderParam, new IModel<String>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void detach() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getObject() {
|
||||||
|
return (String) getPropertyValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setObject(String object) {
|
||||||
|
setPropertyValue(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
}) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onComponentTag(ComponentTag tag) {
|
||||||
|
tag.setName("input");
|
||||||
|
tag.put("type", "text");
|
||||||
|
tag.put("class", "form-control");
|
||||||
|
|
||||||
|
super.onComponentTag(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -1,16 +0,0 @@
|
|||||||
<wicket:panel>
|
|
||||||
<div wicket:id="content"></div>
|
|
||||||
|
|
||||||
<wicket:fragment wicket:id="required">
|
|
||||||
<div class="input-group">
|
|
||||||
<input wicket:id="input" type="text" class="form-control">
|
|
||||||
<span class="input-group-addon required" title="This field is required">
|
|
||||||
<span class="glyphicon glyphicon-asterisk"></span>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</wicket:fragment>
|
|
||||||
|
|
||||||
<wicket:fragment wicket:id="notRequired">
|
|
||||||
<input wicket:id="input" type="text" class="form-control">
|
|
||||||
</wicket:fragment>
|
|
||||||
</wicket:panel>
|
|
||||||
@ -1,50 +0,0 @@
|
|||||||
package com.pmease.commons.wicket.editable.string;
|
|
||||||
|
|
||||||
import org.apache.wicket.markup.html.form.TextField;
|
|
||||||
import org.apache.wicket.markup.html.panel.Fragment;
|
|
||||||
import org.apache.wicket.markup.html.panel.Panel;
|
|
||||||
import org.apache.wicket.model.IModel;
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
|
||||||
public class StringPropertyEditor extends Panel {
|
|
||||||
|
|
||||||
private final StringPropertyEditContext editContext;
|
|
||||||
|
|
||||||
public StringPropertyEditor(String id, StringPropertyEditContext editContext) {
|
|
||||||
super(id);
|
|
||||||
this.editContext = editContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onInitialize() {
|
|
||||||
super.onInitialize();
|
|
||||||
|
|
||||||
Fragment fragment;
|
|
||||||
if (editContext.isPropertyRequired()) {
|
|
||||||
fragment = new Fragment("content", "required", this);
|
|
||||||
} else {
|
|
||||||
fragment = new Fragment("content", "notRequired", this);
|
|
||||||
}
|
|
||||||
|
|
||||||
fragment.add(new TextField<String>("input", new IModel<String>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void detach() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getObject() {
|
|
||||||
return (String) editContext.getPropertyValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setObject(String object) {
|
|
||||||
editContext.setPropertyValue(object);
|
|
||||||
}
|
|
||||||
|
|
||||||
}));
|
|
||||||
|
|
||||||
add(fragment);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user