Revision 89659534
Added by Andreas Kohlbecker about 5 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/event/EditorActionContextFormatter.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.cdm.vaadin.event; |
10 | 10 |
|
11 |
import java.beans.PropertyDescriptor; |
|
12 |
import java.lang.reflect.InvocationTargetException; |
|
13 |
import java.lang.reflect.Method; |
|
11 | 14 |
import java.util.Collection; |
15 |
import java.util.HashMap; |
|
16 |
import java.util.Map; |
|
12 | 17 |
import java.util.Stack; |
13 | 18 |
|
19 |
import org.apache.commons.beanutils.BeanUtilsBean; |
|
14 | 20 |
import org.apache.commons.lang3.StringUtils; |
21 |
import org.apache.log4j.Logger; |
|
15 | 22 |
|
16 | 23 |
import com.vaadin.ui.Component; |
17 | 24 |
|
... | ... | |
29 | 36 |
*/ |
30 | 37 |
public class EditorActionContextFormatter { |
31 | 38 |
|
39 |
public static final Logger logger = Logger.getLogger(EditorActionContextFormatter.class); |
|
40 |
|
|
32 | 41 |
private static final String NEW = "New"; |
33 | 42 |
|
34 | 43 |
private static final String EDIT = "Edit"; |
... | ... | |
56 | 65 |
createOrNew = cdmEntity.isPersited() ? EDIT : NEW; |
57 | 66 |
} else { |
58 | 67 |
className = parentEntity.getClass().getSimpleName(); |
59 |
// can not decide for createOrNew in this case |
|
68 |
className = className.replace("DTO", ""); |
|
69 |
createOrNew = beanHasNonEmptyFields(parentEntity) ? EDIT : NEW; |
|
60 | 70 |
} |
61 | 71 |
} else { |
62 | 72 |
className += "[NULL_CLASS]"; |
... | ... | |
109 | 119 |
targetInfo = className; |
110 | 120 |
} |
111 | 121 |
if(targetInfo != null){ |
122 |
targetInfo = normalizeTargetInfo(targetInfo); |
|
112 | 123 |
if(!outStr.isEmpty()){ |
113 | 124 |
outStr += " "; |
114 |
targetInfo = normalizeTargetInfo(targetInfo); |
|
115 | 125 |
} |
116 | 126 |
if(format.tagName != null){ |
117 | 127 |
outStr += "<" + format.tagName + " class=\"target " + format.classAttributes + "\">" + targetInfo + "</" + format.tagName + ">"; |
... | ... | |
130 | 140 |
return outStr; |
131 | 141 |
} |
132 | 142 |
|
143 |
/** |
|
144 |
* @param parentEntity |
|
145 |
* @return |
|
146 |
*/ |
|
147 |
private boolean beanHasNonEmptyFields(Object parentEntity) { |
|
148 |
BeanUtilsBean beanUtils = BeanUtilsBean.getInstance(); |
|
149 |
Map<String, Object> description = new HashMap<>(); |
|
150 |
PropertyDescriptor[] descriptors = |
|
151 |
beanUtils.getPropertyUtils().getPropertyDescriptors(parentEntity); |
|
152 |
Class<?> clazz = parentEntity.getClass(); |
|
153 |
for (int i = 0; i < descriptors.length; i++) { |
|
154 |
|
|
155 |
String name = descriptors[i].getName(); |
|
156 |
Method getter = beanUtils.getPropertyUtils().getReadMethod(descriptors[i]); |
|
157 |
if (getter != null) { |
|
158 |
try { |
|
159 |
Object value; |
|
160 |
value = getter.invoke(parentEntity); |
|
161 |
if(value != null){ |
|
162 |
if(Collection.class.isAssignableFrom(value.getClass())){ |
|
163 |
return !((Collection)value).isEmpty(); |
|
164 |
} |
|
165 |
if(value instanceof String){ |
|
166 |
return !((String)value).isEmpty(); |
|
167 |
} |
|
168 |
return true; |
|
169 |
} |
|
170 |
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { |
|
171 |
/* IGNORE */ |
|
172 |
} |
|
173 |
} |
|
174 |
|
|
175 |
} |
|
176 |
|
|
177 |
return false; |
|
178 |
} |
|
179 |
|
|
133 | 180 |
public String format(Collection<EditorActionContext> cntxts, EditorActionContextFormat format) { |
134 | 181 |
String outStr = ""; |
135 | 182 |
for(EditorActionContext ctx : cntxts){ |
Also available in: Unified diff
fix #7962 "New" or "Edit" information and humane lables for DTO editors in context breadcrumbs