Refactored ac classes.
This commit is contained in:
parent
207f7065fc
commit
ec43ca1c51
src/main/java/se/su/dsv/scipro/reusable
@ -1,5 +1,6 @@
|
||||
package se.su.dsv.scipro.reusable;
|
||||
|
||||
import org.apache.wicket.ajax.AjaxRequestTarget;
|
||||
import se.su.dsv.scipro.data.dataobjects.Role;
|
||||
import se.su.dsv.wicket.components.AutoCompleteObjectField;
|
||||
|
||||
@ -16,6 +17,33 @@ public abstract class AbstractRoleAutoCompleteComponent<T extends Role> extends
|
||||
super(id, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Long getId(T s) {
|
||||
// return s.getId();
|
||||
if (s != null) {
|
||||
return s.getId();
|
||||
}
|
||||
else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Long convertId(String id) {
|
||||
// return Long.valueOf(id);
|
||||
if (id != null && !id.isEmpty()) {
|
||||
return Long.valueOf(id);
|
||||
}
|
||||
else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getName(T item) {
|
||||
return item.getNameAsString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Renderer<T> getListItemRenderer() {
|
||||
return new Renderer<T>() {
|
||||
@ -30,4 +58,23 @@ public abstract class AbstractRoleAutoCompleteComponent<T extends Role> extends
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewSelection(AjaxRequestTarget pTarget, T newSelection) {
|
||||
if (newSelection != null) {
|
||||
if (pTarget != null) {
|
||||
action(pTarget, 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, T newSelection);
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package se.su.dsv.scipro.reusable;
|
||||
|
||||
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;
|
||||
@ -37,31 +36,12 @@ public abstract class AuthorAutoComplete extends AbstractRoleAutoCompleteCompone
|
||||
super(id, Student.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Long getId(Student s) {
|
||||
// return s.getId();
|
||||
if (s != null) {
|
||||
return s.getId();
|
||||
} else {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Long convertId(String id) {
|
||||
// return Long.valueOf(id);
|
||||
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 {
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -71,21 +51,4 @@ public abstract class AuthorAutoComplete extends AbstractRoleAutoCompleteCompone
|
||||
return authorDao.getAutoCompleteAuthors(input, 6).iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewSelection(AjaxRequestTarget pTarget, Student newSelection) {
|
||||
super.onNewSelection(pTarget, newSelection);
|
||||
if (newSelection != null) {
|
||||
if (pTarget != null) {
|
||||
action(pTarget, 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);
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package se.su.dsv.scipro.reusable;
|
||||
|
||||
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;
|
||||
@ -37,29 +36,12 @@ public abstract class EmployeeAutoComplete extends AbstractRoleAutoCompleteCompo
|
||||
super(id, Employee.class);
|
||||
}
|
||||
|
||||
@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 Employee loadObject(Long id) {
|
||||
if (id != null && id != 0L) {
|
||||
return supervisorDao.load(id);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -69,21 +51,5 @@ public abstract class EmployeeAutoComplete extends AbstractRoleAutoCompleteCompo
|
||||
return supervisorDao.getAutoCompleteCapableSupervisors(input, 6).iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewSelection(AjaxRequestTarget pTarget, Employee newSelection) {
|
||||
super.onNewSelection(pTarget, newSelection);
|
||||
if (newSelection != null) {
|
||||
if (pTarget != null) {
|
||||
action(pTarget, 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, Employee newSelection);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user