Refactored RoleAutocompletecomponents
This commit is contained in:
parent
272ab407d1
commit
ae9ea54a52
src/main/java/se/su/dsv/scipro/reusable
@ -0,0 +1,34 @@
|
||||
package se.su.dsv.scipro.reusable;
|
||||
|
||||
import se.su.dsv.scipro.data.dataobjects.Role;
|
||||
import se.su.dsv.wicket.components.AutoCompleteObjectField;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: herder
|
||||
* Date: 2012-03-30
|
||||
* Time: 10:05
|
||||
*/
|
||||
public abstract class AbstractRoleAutoCompleteComponent<T extends Role> extends AutoCompleteObjectField<T, Long> {
|
||||
|
||||
|
||||
public AbstractRoleAutoCompleteComponent(String id, Class<T> type) {
|
||||
super(id, type);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Renderer<T> getListItemRenderer() {
|
||||
return new Renderer<T>() {
|
||||
@Override
|
||||
protected String getHeader(T item) {
|
||||
return item.getNameAsString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSubheader(T item) {
|
||||
return item.getEmailAsString();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -4,93 +4,88 @@ import org.apache.wicket.ajax.AjaxRequestTarget;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import se.su.dsv.scipro.data.dataobjects.Student;
|
||||
import se.su.dsv.scipro.match.dao.interfaces.AuthorDao;
|
||||
import se.su.dsv.wicket.components.AutoCompleteObjectField;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* author:fred-fri
|
||||
*
|
||||
* <p/>
|
||||
* An auto-completing textfield for employees/supervisors in SciPro. Use as follows:
|
||||
*
|
||||
* <p/>
|
||||
* add(new EmployeeAutoComplete("eac") {
|
||||
*
|
||||
* private static final long serialVersionUID = 1L;
|
||||
*
|
||||
* protected void action(AjaxRequestTarget pTarget, Employee newSelection) {
|
||||
* System.out.println(newSelection.getNameAsString());
|
||||
* }
|
||||
*
|
||||
* <p/>
|
||||
* private static final long serialVersionUID = 1L;
|
||||
* <p/>
|
||||
* protected void action(AjaxRequestTarget pTarget, Employee newSelection) {
|
||||
* System.out.println(newSelection.getNameAsString());
|
||||
* }
|
||||
* <p/>
|
||||
* });
|
||||
*
|
||||
* <p/>
|
||||
* <input wicket:id="eac"/>
|
||||
*
|
||||
* <p/>
|
||||
* TODO: Currently displays "Kalle Svensson", we need "Kalle Svensson <kalle@dsv.su.se>"
|
||||
*/
|
||||
public abstract class AuthorAutoComplete extends AutoCompleteObjectField<Student, Long> {
|
||||
public abstract class AuthorAutoComplete extends AbstractRoleAutoCompleteComponent<Student> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@SpringBean
|
||||
private AuthorDao authorDao;
|
||||
@SpringBean
|
||||
private AuthorDao authorDao;
|
||||
|
||||
public AuthorAutoComplete(String id) {
|
||||
super(id, Student.class);
|
||||
}
|
||||
public AuthorAutoComplete(String id) {
|
||||
super(id, Student.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Long getId(Student s) {
|
||||
@Override
|
||||
protected Long getId(Student s) {
|
||||
// return s.getId();
|
||||
if(s != null) {
|
||||
return s.getId();
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
if (s != null) {
|
||||
return s.getId();
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Long convertId(String id) {
|
||||
@Override
|
||||
protected Long convertId(String id) {
|
||||
// return Long.valueOf(id);
|
||||
if(id != null && !id.isEmpty()) {
|
||||
return Long.valueOf(id);
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
if (id != null && !id.isEmpty()) {
|
||||
return Long.valueOf(id);
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Student loadObject(Long id) {
|
||||
if (id != null && id != 0L) {
|
||||
return authorDao.load(id);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected Student loadObject(Long id) {
|
||||
if (id != null && id != 0L) {
|
||||
return authorDao.load(id);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Iterator<Student> getChoices(String input) {
|
||||
return authorDao.getAutoCompleteAuthors(input, 6).iterator();
|
||||
}
|
||||
@Override
|
||||
protected Iterator<Student> getChoices(String input) {
|
||||
return authorDao.getAutoCompleteAuthors(input, 6).iterator();
|
||||
}
|
||||
|
||||
protected void beforeOnNewSelectionChecker(AjaxRequestTarget pTarget, Student newSelection) {
|
||||
super.onNewSelection(pTarget, newSelection);
|
||||
if (newSelection != null) {
|
||||
if (pTarget != null) {
|
||||
action(pTarget, newSelection);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected void beforeOnNewSelectionChecker(AjaxRequestTarget pTarget, Student newSelection) {
|
||||
super.onNewSelection(pTarget, newSelection);
|
||||
if (newSelection != null) {
|
||||
if (pTarget != null) {
|
||||
action(pTarget, newSelection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getName(Student item) {
|
||||
return item.getNameAsString() + " <" + item.getUser().getEmailAddress() + ">";
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this method for actions to be performed when an object is selected.
|
||||
*
|
||||
* @param pTarget ajax
|
||||
* @param newSelection employee
|
||||
*/
|
||||
protected abstract void action(AjaxRequestTarget pTarget, Student newSelection);
|
||||
/**
|
||||
* Override this method for actions to be performed when an object is selected.
|
||||
*
|
||||
* @param pTarget ajax
|
||||
* @param newSelection employee
|
||||
*/
|
||||
protected abstract void action(AjaxRequestTarget pTarget, Student newSelection);
|
||||
}
|
||||
|
@ -4,91 +4,105 @@ import org.apache.wicket.ajax.AjaxRequestTarget;
|
||||
import org.apache.wicket.spring.injection.annot.SpringBean;
|
||||
import se.su.dsv.scipro.data.dataobjects.Employee;
|
||||
import se.su.dsv.scipro.match.dao.interfaces.SupervisorDao;
|
||||
import se.su.dsv.wicket.components.AutoCompleteObjectField;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* author:fred-fri
|
||||
*
|
||||
* <p/>
|
||||
* An auto-completing textfield for employees/supervisors in SciPro. Use as follows:
|
||||
*
|
||||
* <p/>
|
||||
* add(new EmployeeAutoComplete("eac") {
|
||||
*
|
||||
* private static final long serialVersionUID = 1L;
|
||||
*
|
||||
* protected void action(AjaxRequestTarget pTarget, Employee newSelection) {
|
||||
* System.out.println(newSelection.getNameAsString());
|
||||
* }
|
||||
*
|
||||
* <p/>
|
||||
* private static final long serialVersionUID = 1L;
|
||||
* <p/>
|
||||
* protected void action(AjaxRequestTarget pTarget, Employee newSelection) {
|
||||
* System.out.println(newSelection.getNameAsString());
|
||||
* }
|
||||
* <p/>
|
||||
* });
|
||||
*
|
||||
* <p/>
|
||||
* <input wicket:id="eac"/>
|
||||
*
|
||||
* <p/>
|
||||
* TODO: Currently displays "Kalle Svensson", we need "Kalle Svensson <kalle@dsv.su.se>"
|
||||
*/
|
||||
public abstract class EmployeeAutoComplete extends AutoCompleteObjectField<Employee, Long> {
|
||||
public abstract class EmployeeAutoComplete extends AbstractRoleAutoCompleteComponent<Employee> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@SpringBean
|
||||
private SupervisorDao supervisorDao;
|
||||
@SpringBean
|
||||
private SupervisorDao supervisorDao;
|
||||
|
||||
public EmployeeAutoComplete(String id) {
|
||||
super(id, Employee.class);
|
||||
}
|
||||
public EmployeeAutoComplete(String id) {
|
||||
super(id, Employee.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Long getId(Employee e) {
|
||||
if(e != null) {
|
||||
return e.getId();
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected Long getId(Employee e) {
|
||||
if (e != null) {
|
||||
return e.getId();
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Long convertId(String id) {
|
||||
if(id != null && !id.isEmpty()) {
|
||||
return Long.valueOf(id);
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected Long convertId(String id) {
|
||||
if (id != null && !id.isEmpty()) {
|
||||
return Long.valueOf(id);
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Employee loadObject(Long id) {
|
||||
if (id != null && id != 0L) {
|
||||
return supervisorDao.load(id);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected Employee loadObject(Long id) {
|
||||
if (id != null && id != 0L) {
|
||||
return supervisorDao.load(id);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Iterator<Employee> getChoices(String input) {
|
||||
return supervisorDao.getAutoCompleteCapableSupervisors(input, 6).iterator();
|
||||
}
|
||||
@Override
|
||||
protected Iterator<Employee> getChoices(String input) {
|
||||
return supervisorDao.getAutoCompleteCapableSupervisors(input, 6).iterator();
|
||||
}
|
||||
|
||||
protected void beforeOnNewSelectionChecker(AjaxRequestTarget pTarget, Employee newSelection) {
|
||||
super.onNewSelection(pTarget, newSelection);
|
||||
if (newSelection != null) {
|
||||
if (pTarget != null) {
|
||||
action(pTarget, newSelection);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected void beforeOnNewSelectionChecker(AjaxRequestTarget pTarget, Employee newSelection) {
|
||||
super.onNewSelection(pTarget, newSelection);
|
||||
if (newSelection != null) {
|
||||
if (pTarget != null) {
|
||||
action(pTarget, newSelection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getName(Employee item) {
|
||||
return item.getNameAsString() + " <" + item.getUser().getEmailAddress() + ">";
|
||||
}
|
||||
@Override
|
||||
protected Renderer<Employee> getListItemRenderer() {
|
||||
return new Renderer<Employee>() {
|
||||
@Override
|
||||
protected String getHeader(Employee employee) {
|
||||
return employee.getNameAsString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this method for actions to be performed when an object is selected.
|
||||
*
|
||||
* @param pTarget ajax
|
||||
* @param newSelection employee
|
||||
*/
|
||||
protected abstract void action(AjaxRequestTarget pTarget, Employee newSelection);
|
||||
@Override
|
||||
protected String getSubheader(Employee item) {
|
||||
return item.getEmailAsString();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getName(Employee item) {
|
||||
return item.getNameAsString() + " <" + item.getUser().getEmailAddress() + ">";
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this method for actions to be performed when an object is selected.
|
||||
*
|
||||
* @param pTarget ajax
|
||||
* @param newSelection employee
|
||||
*/
|
||||
protected abstract void action(AjaxRequestTarget pTarget, Employee newSelection);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user