]> git.argeo.org Git - lgpl/argeo-commons.git/blob - server/runtime/org.argeo.server.core/src/main/java/org/argeo/server/dao/LightDaoPropertyEditor.java
Update versions used
[lgpl/argeo-commons.git] / server / runtime / org.argeo.server.core / src / main / java / org / argeo / server / dao / LightDaoPropertyEditor.java
1 package org.argeo.server.dao;
2
3 import java.beans.PropertyEditorSupport;
4
5 import org.argeo.ArgeoException;
6
7 public class LightDaoPropertyEditor extends PropertyEditorSupport implements
8 LightDaoAware {
9 private LightDaoSupport lightDaoSupport;
10
11 private Class<?> targetClass;
12 /** Can be null */
13 private String businessIdField;
14
15 @Override
16 public String getAsText() {
17 return getValue().toString();
18 }
19
20 @Override
21 public void setAsText(String text) throws IllegalArgumentException {
22 if (targetClass == null)
23 throw new ArgeoException("Target class cannot be null");
24
25 if (businessIdField != null)
26 setValue(lightDaoSupport.getByField(targetClass, businessIdField,
27 text));
28 else
29 setValue(lightDaoSupport.getByKey(targetClass, text));
30 }
31
32 public void setLightDaoSupport(LightDaoSupport lightDaoSupport) {
33 this.lightDaoSupport = lightDaoSupport;
34 }
35
36 public void setTargetClass(Class<?> targetClass) {
37 this.targetClass = targetClass;
38 }
39
40 public void setBusinessIdField(String businessIdField) {
41 this.businessIdField = businessIdField;
42 }
43
44 }