Revision c78fd1ac
Added by Andreas Kohlbecker over 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.util.Collection; |
|
11 | 12 |
import java.util.Stack; |
12 | 13 |
|
13 | 14 |
import org.apache.commons.lang3.StringUtils; |
14 | 15 |
|
15 |
import com.vaadin.ui.Component; |
|
16 |
|
|
17 | 16 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
18 | 17 |
import eu.etaxonomy.cdm.ref.TypedEntityReference; |
19 | 18 |
import eu.etaxonomy.cdm.vaadin.event.EditorActionContextFormat.TargetInfoType; |
... | ... | |
36 | 35 |
|
37 | 36 |
String className = null; |
38 | 37 |
String targetInfo = null; |
38 |
String targetEntityStr = null; |
|
39 | 39 |
String createOrNew = null; |
40 | 40 |
|
41 | 41 |
Object parentEntity = cntxt.getParentEntity(); |
... | ... | |
60 | 60 |
className += "[NULL_CLASS]"; |
61 | 61 |
} |
62 | 62 |
|
63 |
if (format.doTargetInfo && cntxt.getParentView() != null && AbstractPopupEditor.class.isAssignableFrom(cntxt.getParentView().getClass())) {
|
|
63 |
if ((format.doTargetInfo || format.doTargetEntity) && cntxt.getParentView() != null && AbstractPopupEditor.class.isAssignableFrom(cntxt.getParentView().getClass())) {
|
|
64 | 64 |
// the top element is the cntxt istself!! we need to dig one step deeper to get the previous popup editor |
65 | 65 |
// TODO chaining the EditorActionContext would ease find the contexts of parent editors |
66 | 66 |
Stack<EditorActionContext> ctxtStack = ((AbstractPopupEditor)cntxt.getParentView()).getEditorActionContext(); |
... | ... | |
72 | 72 |
if (propertyIdPath != null) { |
73 | 73 |
targetInfo = propertyIdPath.toString(); |
74 | 74 |
} |
75 |
} else { |
|
76 |
// TargetInfoType.FIELD_CAPTION |
|
77 |
if(parentCtx.getTargetField() != null){ |
|
78 |
Component captionComponent = parentCtx.getTargetField(); |
|
79 |
while(captionComponent != null){ |
|
80 |
targetInfo = captionComponent.getCaption(); |
|
81 |
if(targetInfo != null){ |
|
82 |
break; |
|
83 |
} |
|
84 |
captionComponent = captionComponent.getParent(); |
|
85 |
} |
|
86 |
} |
|
87 | 75 |
} |
88 | 76 |
} |
89 | 77 |
} |
78 |
if(format.doTargetEntity){ |
|
79 |
targetEntityStr = formatTargetEntityString(cntxt.parentEntity, format); |
|
80 |
} |
|
90 | 81 |
|
91 | 82 |
// create output |
92 |
String markup = "";
|
|
83 |
String outStr = "";
|
|
93 | 84 |
|
94 | 85 |
if (format.doCreateOrNew && createOrNew != null) { |
95 |
markup += "<" + format.tagName + " class=\"operation " + format.classAttributes + "\">" + createOrNew + "</" + format.tagName + ">"; |
|
86 |
if(format.tagName != null){ |
|
87 |
outStr += "<" + format.tagName + " class=\"operation " + format.classAttributes + "\">" + createOrNew + "</" + format.tagName + ">"; |
|
88 |
} else { |
|
89 |
outStr += createOrNew; |
|
90 |
} |
|
96 | 91 |
} |
97 | 92 |
|
98 | 93 |
if (format.doTargetInfo) { |
... | ... | |
100 | 95 |
targetInfo = className; |
101 | 96 |
} |
102 | 97 |
if(targetInfo != null){ |
103 |
if(!markup.isEmpty()){
|
|
104 |
markup += " ";
|
|
98 |
if(!outStr.isEmpty()){
|
|
99 |
outStr += " ";
|
|
105 | 100 |
targetInfo = normalizeTargetInfo(targetInfo); |
106 | 101 |
} |
107 |
markup += "<" + format.tagName + " class=\"target " + format.classAttributes + "\">" + targetInfo + "</" + format.tagName + ">"; |
|
102 |
if(format.tagName != null){ |
|
103 |
outStr += "<" + format.tagName + " class=\"target " + format.classAttributes + "\">" + targetInfo + "</" + format.tagName + ">"; |
|
104 |
} else { |
|
105 |
outStr += targetInfo; |
|
106 |
} |
|
107 |
} |
|
108 |
} |
|
109 |
if(format.doTargetEntity && targetEntityStr != null){ |
|
110 |
if(format.tagName != null){ |
|
111 |
outStr += "<" + format.tagName + " class=\"target-entity" + format.classAttributes + "\">" + targetEntityStr + "</" + format.tagName + ">"; |
|
112 |
} else { |
|
113 |
outStr += " (" + targetEntityStr + ")"; |
|
114 |
} |
|
115 |
} |
|
116 |
return outStr; |
|
117 |
} |
|
118 |
|
|
119 |
public String format(Collection<EditorActionContext> cntxts, EditorActionContextFormat format) { |
|
120 |
String outStr = ""; |
|
121 |
for(EditorActionContext ctx : cntxts){ |
|
122 |
if(!outStr.isEmpty()){ |
|
123 |
outStr += " > "; // FIXME allow configuring the separator |
|
108 | 124 |
} |
125 |
outStr += format(ctx, format) ; |
|
126 |
} |
|
127 |
return outStr; |
|
128 |
} |
|
129 |
|
|
130 |
/** |
|
131 |
* @param value |
|
132 |
* @param format |
|
133 |
* @return |
|
134 |
*/ |
|
135 |
private String formatTargetEntityString(Object value, EditorActionContextFormat format) { |
|
136 |
|
|
137 |
if(value == null){ |
|
138 |
return "NULL"; |
|
139 |
} |
|
140 |
String outStr; |
|
141 |
if(value instanceof CdmBase){ |
|
142 |
outStr = ((CdmBase)value).instanceToString(); |
|
143 |
} else if(value instanceof CdmEntityAdapterDTO) { |
|
144 |
outStr = value.getClass().getSimpleName() + ": "; |
|
145 |
outStr += ((CdmEntityAdapterDTO)value).cdmEntity().toString(); |
|
146 |
} else { |
|
147 |
outStr = value.getClass().getSimpleName() + ": " + value.toString(); |
|
109 | 148 |
} |
110 |
return markup;
|
|
149 |
return outStr;
|
|
111 | 150 |
} |
112 | 151 |
|
113 | 152 |
/** |
Also available in: Unified diff
improving error messaging: PopupEditorException with editor context information