Revision ca22953d
Added by Andreas Müller over 9 years ago
.gitattributes | ||
---|---|---|
481 | 481 |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/MoveSynonymToAnotherAcceptedTaxonOperation.java -text |
482 | 482 |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/RemoveHomotypicalGroupBasionymOperation.java -text |
483 | 483 |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/operation/SwapSynonymAndAcceptedOperation.java -text |
484 |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/validation/MarkerManager.java -text |
|
485 |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/validation/ValidationContextListener.java -text |
|
486 |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/validation/ValidationDaemon.java -text |
|
484 | 487 |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/ChecklistContentProvider.java -text |
485 | 488 |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/ChecklistEditor.java -text |
486 | 489 |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/ChecklistEditorComparator.java -text |
... | ... | |
599 | 602 |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/operation/CreateTaxonUseOperation.java -text |
600 | 603 |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/operation/CreateUseRecordOperation.java -text |
601 | 604 |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/operation/CreateUseSummaryOperation.java -text |
605 |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/validation/EntityClassMarkerField.java -text |
|
606 |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/validation/EntityIdMarkerField.java -text |
|
607 |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/validation/InvalidValueMarkerField.java -text |
|
608 |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/validation/UserFriendlyDescriptionMarkerField.java -text |
|
609 |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/validation/UserFriendlyFieldNameMarkerField.java -text |
|
610 |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/validation/UserFriendlyTypeNameMarkerField.java -text |
|
611 |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/validation/ValidationProblemsView.java -text |
|
612 |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/validation/ValidatorClassMarkerField.java -text |
|
613 |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/validation/ValidatorMessageMarkerField.java -text |
|
602 | 614 |
eu.etaxonomy.taxeditor.editor/src/main/resources/TaonDescriptionEditor.screen -text |
603 | 615 |
eu.etaxonomy.taxeditor.editor/src/main/resources/log4j.properties -text |
604 | 616 |
eu.etaxonomy.taxeditor.editor/src/test/java/eu/etaxonomy/taxeditor/editor/Application.java -text |
eu.etaxonomy.taxeditor.editor/plugin.xml | ||
---|---|---|
145 | 145 |
name="%view.name.5"> |
146 | 146 |
</view> |
147 | 147 |
</extension> |
148 |
<extension |
|
148 |
|
|
149 |
<!-- VALIDATION RELATED STUFF --> |
|
150 |
<extension point="org.eclipse.ui.menus"> |
|
151 |
<menuContribution locationURI="menu:eu.etaxonomy.taxeditor.menu.showView?after=org.eclipse.ui.views.showView.problems"> |
|
152 |
<command |
|
153 |
commandId="org.eclipse.ui.views.showView" |
|
154 |
label="Validation Problems" |
|
155 |
style="push"> |
|
156 |
<parameter |
|
157 |
name="org.eclipse.ui.views.showView.viewId" |
|
158 |
value="eu.etaxonomy.taxeditor.editor.view.validation.problems"> |
|
159 |
</parameter> |
|
160 |
</command> |
|
161 |
</menuContribution> |
|
162 |
</extension> |
|
163 |
<extension point="org.eclipse.ui.views"> |
|
164 |
<view |
|
165 |
allowMultiple="false" |
|
166 |
category="eu.etaxonomy.taxeditor.editor.category" |
|
167 |
class="eu.etaxonomy.taxeditor.editor.view.validation.ValidationProblemsView" |
|
168 |
icon="icons/edit_16x16.gif" |
|
169 |
id="eu.etaxonomy.taxeditor.editor.view.validation.problems" |
|
170 |
name="Validation problems"> |
|
171 |
</view> |
|
172 |
</extension> |
|
173 |
<extension point="org.eclipse.core.resources.markers" name="Validation Error" id="eu.etaxonomy.taxeditor.markers.validationerror"> |
|
174 |
<super type="org.eclipse.core.resources.problemmarker"/> |
|
175 |
<attribute name="databaseId"/> |
|
176 |
<attribute name="userFriendlyTypeName"/> |
|
177 |
<attribute name="userFriendlyDescription"/> |
|
178 |
<attribute name="userFriendlyFieldName"/> |
|
179 |
<attribute name="validatorMessage"/> |
|
180 |
<attribute name="invalidValue"/> |
|
181 |
<attribute name="validatorClass"/> |
|
182 |
<attribute name="entityClass"/> |
|
183 |
<attribute name="entityId"/> |
|
184 |
<persistent value="false"/> |
|
185 |
</extension> |
|
186 |
|
|
187 |
<extension point="org.eclipse.ui.ide.markerSupport"> |
|
188 |
<markerContentGenerator |
|
189 |
id="eu.etaxonomy.taxeditor.editor.validation.ValidationProblemsMarkerGenerator" |
|
190 |
name="Validation Problems Marker Generator"> |
|
191 |
<markerTypeReference id="eu.etaxonomy.taxeditor.markers.validationerror" /> |
|
192 |
|
|
193 |
<markerFieldReference id="eu.etaxonomy.taxeditor.markers.validation.userFriendlyTypeName" visible="true" /> |
|
194 |
<markerFieldReference id="eu.etaxonomy.taxeditor.markers.validation.userFriendlyDescription" visible="true" /> |
|
195 |
<markerFieldReference id="eu.etaxonomy.taxeditor.markers.validation.userFriendlyFieldName" visible="true" /> |
|
196 |
<markerFieldReference id="eu.etaxonomy.taxeditor.markers.validation.validatorMessage" visible="true" /> |
|
197 |
<markerFieldReference id="eu.etaxonomy.taxeditor.markers.validation.invalidValue" visible="true" /> |
|
198 |
<markerFieldReference id="eu.etaxonomy.taxeditor.markers.validation.validatorClass" visible="false" /> |
|
199 |
<markerFieldReference id="eu.etaxonomy.taxeditor.markers.validation.entityClass" visible="false" /> |
|
200 |
<markerFieldReference id="eu.etaxonomy.taxeditor.markers.validation.entityId" visible="false" /> |
|
201 |
</markerContentGenerator> |
|
202 |
|
|
203 |
<markerField |
|
204 |
class="eu.etaxonomy.taxeditor.editor.view.validation.UserFriendlyTypeNameMarkerField" |
|
205 |
id="eu.etaxonomy.taxeditor.markers.validation.userFriendlyTypeName" |
|
206 |
name="Object Type"> |
|
207 |
</markerField> |
|
208 |
<markerField |
|
209 |
class="eu.etaxonomy.taxeditor.editor.view.validation.UserFriendlyDescriptionMarkerField" |
|
210 |
id="eu.etaxonomy.taxeditor.markers.validation.userFriendlyDescription" |
|
211 |
name="Object"> |
|
212 |
</markerField> |
|
213 |
<markerField |
|
214 |
class="eu.etaxonomy.taxeditor.editor.view.validation.UserFriendlyFieldNameMarkerField" |
|
215 |
id="eu.etaxonomy.taxeditor.markers.validation.userFriendlyFieldName" |
|
216 |
name="Attribute"> |
|
217 |
</markerField> |
|
218 |
<markerField |
|
219 |
class="eu.etaxonomy.taxeditor.editor.view.validation.InvalidValueMarkerField" |
|
220 |
id="eu.etaxonomy.taxeditor.markers.validation.invalidValue" |
|
221 |
name="Problematic Value"> |
|
222 |
</markerField> |
|
223 |
<markerField |
|
224 |
class="eu.etaxonomy.taxeditor.editor.view.validation.ValidatorMessageMarkerField" |
|
225 |
id="eu.etaxonomy.taxeditor.markers.validation.validatorMessage" |
|
226 |
name="Problem description"> |
|
227 |
</markerField> |
|
228 |
<markerField |
|
229 |
class="eu.etaxonomy.taxeditor.editor.view.validation.ValidatorClassMarkerField" |
|
230 |
id="eu.etaxonomy.taxeditor.markers.validation.validatorClass" |
|
231 |
name="Validator"> |
|
232 |
</markerField> |
|
233 |
<markerField |
|
234 |
class="eu.etaxonomy.taxeditor.editor.view.validation.EntityClassMarkerField" |
|
235 |
id="eu.etaxonomy.taxeditor.markers.validation.entityClass" |
|
236 |
name="Entity Class"> |
|
237 |
</markerField> |
|
238 |
<markerField |
|
239 |
class="eu.etaxonomy.taxeditor.editor.view.validation.EntityIdMarkerField" |
|
240 |
id="eu.etaxonomy.taxeditor.markers.validation.entityId" |
|
241 |
name="Entity Id"> |
|
242 |
</markerField> |
|
243 |
</extension> |
|
244 |
|
|
245 |
<extension |
|
149 | 246 |
point="org.eclipse.ui.elementFactories"> |
150 | 247 |
<factory |
151 | 248 |
class="eu.etaxonomy.taxeditor.editor.TaxonEditorInputFactory" |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/internal/TaxeditorEditorPlugin.java | ||
---|---|---|
6 | 6 |
|
7 | 7 |
import eu.etaxonomy.taxeditor.editor.EditorStateManager; |
8 | 8 |
import eu.etaxonomy.taxeditor.editor.UseObjectManager; |
9 |
import eu.etaxonomy.taxeditor.editor.validation.ValidationContextListener; |
|
9 | 10 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
10 | 11 |
|
11 | 12 |
/** |
... | ... | |
43 | 44 |
EditorStateManager stateManager = new EditorStateManager(); |
44 | 45 |
CdmStore.getContextManager().addContextListener(stateManager); |
45 | 46 |
|
47 |
ValidationContextListener vcl = new ValidationContextListener(); |
|
48 |
CdmStore.getContextManager().addContextListener(vcl); |
|
49 |
|
|
46 | 50 |
plugin = this; |
47 | 51 |
logger.trace("Plugin started: " + this.getBundle().getSymbolicName()); |
48 | 52 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/validation/MarkerManager.java | ||
---|---|---|
1 |
package eu.etaxonomy.taxeditor.editor.validation; |
|
2 |
|
|
3 |
import java.util.HashMap; |
|
4 |
import java.util.List; |
|
5 |
import java.util.Set; |
|
6 |
|
|
7 |
import javax.xml.validation.Validator; |
|
8 |
|
|
9 |
import org.eclipse.core.resources.IMarker; |
|
10 |
import org.eclipse.core.resources.IResource; |
|
11 |
import org.eclipse.core.resources.IWorkspaceRoot; |
|
12 |
import org.eclipse.core.resources.ResourcesPlugin; |
|
13 |
import org.eclipse.core.runtime.CoreException; |
|
14 |
|
|
15 |
import eu.etaxonomy.cdm.model.validation.EntityConstraintViolation; |
|
16 |
import eu.etaxonomy.cdm.model.validation.EntityValidationResult; |
|
17 |
import eu.etaxonomy.cdm.model.validation.Severity; |
|
18 |
|
|
19 |
/** |
|
20 |
* A class responsible for refreshing problem markers coming from the CVI |
|
21 |
* (Cdmlib Validation Infrastructure). |
|
22 |
* |
|
23 |
* @author ayco_holleman |
|
24 |
* |
|
25 |
*/ |
|
26 |
/* |
|
27 |
* See following for problems with icons in Problems view |
|
28 |
* http://stackoverflow.com |
|
29 |
* /questions/13497258/markers-view-shows-my-marker-with- |
|
30 |
* a-red-square-insted-of-error-warning-icon |
|
31 |
* http://stackoverflow.com/questions/2888207 |
|
32 |
* /eclipse-plugin-custom-icon-for-a-marker |
|
33 |
* http://www.eclipse.org/articles/Article-Mark%20My%20Words/mark-my-words.html |
|
34 |
* http |
|
35 |
* ://cubussapiens.hu/2010/11/markers-and-annotations-in-eclipse-for-error-feedback |
|
36 |
* / |
|
37 |
* |
|
38 |
* See here for difficulty of attaching markers to non-resources (files, |
|
39 |
* folders): |
|
40 |
* http://stackoverflow.com/questions/12493179/eclipse-virtual-resources |
|
41 |
*/ |
|
42 |
public class MarkerManager { |
|
43 |
|
|
44 |
public static final String MARKER_TYPE_ID = "eu.etaxonomy.taxeditor.markers.validationerror"; |
|
45 |
|
|
46 |
/** |
|
47 |
* The primary key (id) of the EntityValidationResult record |
|
48 |
*/ |
|
49 |
public static final String ATTRIB_DATABASE_ID = "databaseId"; |
|
50 |
|
|
51 |
// The values of the following constants must correspond to the attributes |
|
52 |
// defined for the org.eclipse.core.resources.markers extension point in |
|
53 |
// plugin.xml |
|
54 |
|
|
55 |
/** |
|
56 |
* A user-friendly description of the type of the entity |
|
57 |
*/ |
|
58 |
public static final String ATTRIB_USER_FRIENDLY_TYPE_NAME = "userFriendlyTypeName"; |
|
59 |
/** |
|
60 |
* A user-friendly description of the entity |
|
61 |
*/ |
|
62 |
public static final String ATTRIB_USER_FRIENDLY_DESCRIPTION = "userFriendlyDescription"; |
|
63 |
/** |
|
64 |
* The field whose value violated a constraint |
|
65 |
*/ |
|
66 |
public static final String ATTRIB_USER_FRIENDLY_FIELD_NAME = "userFriendlyFieldName"; |
|
67 |
/** |
|
68 |
* The value violating a constraint |
|
69 |
*/ |
|
70 |
public static final String ATTRIB_INVALID_VALUE = "invalidValue"; |
|
71 |
/** |
|
72 |
* The message from the {@link Validator} about what was wrong. |
|
73 |
*/ |
|
74 |
public static final String ATTRIB_VALIDATOR_MESSAGE = "validatorMessage"; |
|
75 |
/** |
|
76 |
* The class of the {@link Validator} coding for the constraint |
|
77 |
*/ |
|
78 |
public static final String ATTRIB_VALIDATOR_CLASS = "validatorClass"; |
|
79 |
/** |
|
80 |
* The class of the validated entity |
|
81 |
*/ |
|
82 |
public static final String ATTRIB_ENTITY_CLASS = "entityClass"; |
|
83 |
/** |
|
84 |
* The id of the validated entity |
|
85 |
*/ |
|
86 |
public static final String ATTRIB_ENTITY_ID = "entityId"; |
|
87 |
|
|
88 |
private final IWorkspaceRoot root; |
|
89 |
private final IMarker[] markers; |
|
90 |
private final List<EntityValidationResult> results; |
|
91 |
private final HashMap<Integer, EntityValidationResult> resultMap; |
|
92 |
private final HashMap<Integer, IMarker> markerMap; |
|
93 |
|
|
94 |
|
|
95 |
MarkerManager(List<EntityValidationResult> results) throws CoreException |
|
96 |
{ |
|
97 |
this.root = ResourcesPlugin.getWorkspace().getRoot(); |
|
98 |
this.markers = root.findMarkers(MARKER_TYPE_ID, true, IResource.DEPTH_INFINITE); |
|
99 |
this.markerMap = new HashMap<Integer, IMarker>(); |
|
100 |
for (IMarker marker : markers) { |
|
101 |
markerMap.put(getDatabaseId(marker), marker); |
|
102 |
} |
|
103 |
this.results = results; |
|
104 |
this.resultMap = new HashMap<Integer, EntityValidationResult>(); |
|
105 |
for (EntityValidationResult result : results) { |
|
106 |
resultMap.put(result.getId(), result); |
|
107 |
} |
|
108 |
} |
|
109 |
|
|
110 |
|
|
111 |
/** |
|
112 |
* Delete all markers that refer to errors that do not exist any longer |
|
113 |
* (i.e. the corresponding database record has been deleted). |
|
114 |
* |
|
115 |
* @return The number of deleted markers |
|
116 |
* |
|
117 |
* @throws CoreException |
|
118 |
*/ |
|
119 |
int deleteObsoleteMarkers() throws CoreException |
|
120 |
{ |
|
121 |
int i = 0; |
|
122 |
IMarker[] markers = root.findMarkers(MARKER_TYPE_ID, true, IResource.DEPTH_INFINITE); |
|
123 |
for (IMarker marker : markers) { |
|
124 |
if (isObsoleteMarker(marker)) { |
|
125 |
++i; |
|
126 |
marker.delete(); |
|
127 |
} |
|
128 |
} |
|
129 |
return i; |
|
130 |
} |
|
131 |
|
|
132 |
|
|
133 |
/** |
|
134 |
* Create markers for new errors (i.e. no marker has been created for them |
|
135 |
* yet). |
|
136 |
* |
|
137 |
* @return The number of new markers |
|
138 |
* |
|
139 |
* @throws CoreException |
|
140 |
*/ |
|
141 |
int createMarkers() throws CoreException |
|
142 |
{ |
|
143 |
int i = 0; |
|
144 |
IMarker[] markers = root.findMarkers(MARKER_TYPE_ID, true, IResource.DEPTH_INFINITE); |
|
145 |
for (EntityValidationResult result : results) { |
|
146 |
if (!isNewResult(result)) { |
|
147 |
continue; |
|
148 |
} |
|
149 |
Set<EntityConstraintViolation> problems = result.getEntityConstraintViolations(); |
|
150 |
for (EntityConstraintViolation problem : problems) { |
|
151 |
if (markerExistsForProblem(problem, markers)) { |
|
152 |
continue; |
|
153 |
} |
|
154 |
IMarker marker = root.createMarker(MARKER_TYPE_ID); |
|
155 |
++i; |
|
156 |
if (problem.getSeverity() == Severity.ERROR) { |
|
157 |
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR); |
|
158 |
} |
|
159 |
else if (problem.getSeverity() == Severity.WARNING) { |
|
160 |
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING); |
|
161 |
} |
|
162 |
else { |
|
163 |
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO); |
|
164 |
} |
|
165 |
marker.setAttribute(IMarker.MESSAGE, problem.getMessage()); |
|
166 |
marker.setAttribute(ATTRIB_DATABASE_ID, result.getId()); |
|
167 |
marker.setAttribute(ATTRIB_USER_FRIENDLY_TYPE_NAME, result.getUserFriendlyTypeName()); |
|
168 |
marker.setAttribute(ATTRIB_USER_FRIENDLY_DESCRIPTION, result.getUserFriendlyDescription()); |
|
169 |
marker.setAttribute(ATTRIB_USER_FRIENDLY_FIELD_NAME, problem.getUserFriendlyFieldName()); |
|
170 |
marker.setAttribute(ATTRIB_VALIDATOR_MESSAGE, problem.getMessage()); |
|
171 |
marker.setAttribute(ATTRIB_INVALID_VALUE, problem.getInvalidValue()); |
|
172 |
marker.setAttribute(ATTRIB_VALIDATOR_CLASS, problem.getValidator()); |
|
173 |
marker.setAttribute(ATTRIB_ENTITY_CLASS, result.getValidatedEntityClass()); |
|
174 |
marker.setAttribute(ATTRIB_ENTITY_ID, result.getValidatedEntityId()); |
|
175 |
} |
|
176 |
} |
|
177 |
return i; |
|
178 |
} |
|
179 |
|
|
180 |
|
|
181 |
/** |
|
182 |
* Is there a problem marker that captures the specified |
|
183 |
* {@link EntityConstraintViolation}? See |
|
184 |
* {@link #markerCapturesProblem(IMarker, EntityConstraintViolation)}. |
|
185 |
* |
|
186 |
* @param problem |
|
187 |
* @param markers |
|
188 |
* @return |
|
189 |
* @throws CoreException |
|
190 |
*/ |
|
191 |
private boolean markerExistsForProblem(EntityConstraintViolation problem, IMarker[] markers) throws CoreException |
|
192 |
{ |
|
193 |
for (IMarker marker : markers) { |
|
194 |
if (markerCapturesProblem(marker, problem)) { |
|
195 |
return true; |
|
196 |
} |
|
197 |
} |
|
198 |
return false; |
|
199 |
} |
|
200 |
|
|
201 |
|
|
202 |
/** |
|
203 |
* <p> |
|
204 |
* This method determines whether the problem exposed by the specified |
|
205 |
* marker is <b>de facto</b> equivalent to the specified |
|
206 |
* {@code EntityConstraintViolation}. When the CVI validates an entity, it |
|
207 |
* first deletes previous validation results for that entity and only then |
|
208 |
* saves the new validation result. Thus you cannot rely on the database id |
|
209 |
* of the {@code EntityConstraintViolation} to determine equivalence. Maybe |
|
210 |
* later we can make the CVI more sophisticated in this respect. Or maybe |
|
211 |
* see if solving it through the equals() method of |
|
212 |
* {@code EntityValidationResult} and/or {@code EntityConstraintViolation} |
|
213 |
* is possible. But for now this is the easiest solution. |
|
214 |
* </p> |
|
215 |
* <p> |
|
216 |
* The reason we check for equivalence, is that we don't want to |
|
217 |
* unnecessarily update the Problems view. If a marker is there, we don't |
|
218 |
* want to replace it with an equivalent marker, because that might lead to |
|
219 |
* strange click behaviour for end users (e.g. selected problems will |
|
220 |
* disappear and re-appear unselected). |
|
221 |
* </p> |
|
222 |
* |
|
223 |
* @param marker |
|
224 |
* @param problem |
|
225 |
* @return |
|
226 |
* @throws CoreException |
|
227 |
*/ |
|
228 |
private static boolean markerCapturesProblem(IMarker marker, EntityConstraintViolation problem) throws CoreException |
|
229 |
{ |
|
230 |
EntityValidationResult result = problem.getEntityValidationResult(); |
|
231 |
if (!marker.getAttribute(ATTRIB_ENTITY_CLASS).equals(result.getValidatedEntityClass())) { |
|
232 |
return false; |
|
233 |
} |
|
234 |
if (!marker.getAttribute(ATTRIB_ENTITY_ID).equals(result.getValidatedEntityId())) { |
|
235 |
return false; |
|
236 |
} |
|
237 |
if (!marker.getAttribute(ATTRIB_USER_FRIENDLY_FIELD_NAME).equals(problem.getPropertyPath())) { |
|
238 |
return false; |
|
239 |
} |
|
240 |
if (!marker.getAttribute(ATTRIB_INVALID_VALUE).equals(problem.getInvalidValue())) { |
|
241 |
return false; |
|
242 |
} |
|
243 |
if (!marker.getAttribute(ATTRIB_VALIDATOR_CLASS).equals(problem.getValidator())) { |
|
244 |
return false; |
|
245 |
} |
|
246 |
return true; |
|
247 |
} |
|
248 |
|
|
249 |
|
|
250 |
/** |
|
251 |
* Is this a marker without a corresponding database record ( |
|
252 |
* {@link EntityValidationResult})? |
|
253 |
* |
|
254 |
* @param marker |
|
255 |
* @return |
|
256 |
* @throws CoreException |
|
257 |
*/ |
|
258 |
private boolean isObsoleteMarker(IMarker marker) throws CoreException |
|
259 |
{ |
|
260 |
return resultMap.get(getDatabaseId(marker)) == null; |
|
261 |
} |
|
262 |
|
|
263 |
|
|
264 |
/** |
|
265 |
* Is this an {@link EntityValidationResult} for which no marker has been |
|
266 |
* created yet? |
|
267 |
* |
|
268 |
* @param result |
|
269 |
* @return |
|
270 |
*/ |
|
271 |
private boolean isNewResult(EntityValidationResult result) |
|
272 |
{ |
|
273 |
return markerMap.get(result.getId()) == null; |
|
274 |
} |
|
275 |
|
|
276 |
|
|
277 |
/** |
|
278 |
* Get the id of the {@link EntityValidationResult} that was stored as one |
|
279 |
* of the marker's attributes. |
|
280 |
* |
|
281 |
* @param marker |
|
282 |
* @return |
|
283 |
* @throws CoreException |
|
284 |
*/ |
|
285 |
private static Integer getDatabaseId(IMarker marker) throws CoreException |
|
286 |
{ |
|
287 |
return (Integer) marker.getAttribute(ATTRIB_DATABASE_ID); |
|
288 |
} |
|
289 |
|
|
290 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/validation/ValidationContextListener.java | ||
---|---|---|
1 |
package eu.etaxonomy.taxeditor.editor.validation; |
|
2 |
|
|
3 |
import org.apache.log4j.Logger; |
|
4 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
5 |
import org.eclipse.ui.IMemento; |
|
6 |
|
|
7 |
import eu.etaxonomy.taxeditor.editor.internal.TaxeditorEditorPlugin; |
|
8 |
import eu.etaxonomy.taxeditor.model.IContextListener; |
|
9 |
|
|
10 |
/** |
|
11 |
* An {@code IContextListener} responsible for starting the |
|
12 |
* {@link ValidationDaemon}. |
|
13 |
* |
|
14 |
* @see TaxeditorEditorPlugin#start(org.osgi.framework.BundleContext) |
|
15 |
* |
|
16 |
* @author ayco_holleman |
|
17 |
* |
|
18 |
*/ |
|
19 |
public class ValidationContextListener implements IContextListener { |
|
20 |
|
|
21 |
@SuppressWarnings("unused") |
|
22 |
private static final Logger logger = Logger.getLogger(ValidationContextListener.class); |
|
23 |
|
|
24 |
private ValidationDaemon daemon; |
|
25 |
|
|
26 |
|
|
27 |
public ValidationContextListener(){ |
|
28 |
} |
|
29 |
|
|
30 |
|
|
31 |
@Override |
|
32 |
public void contextAboutToStop(IMemento memento, IProgressMonitor monitor){ |
|
33 |
if (daemon != null) { |
|
34 |
daemon.cancel(); |
|
35 |
daemon.setCancelRequested(); |
|
36 |
} |
|
37 |
} |
|
38 |
|
|
39 |
|
|
40 |
@Override |
|
41 |
public void contextStop(IMemento memento, IProgressMonitor monitor){ |
|
42 |
if (daemon != null) { |
|
43 |
daemon.cancel(); |
|
44 |
daemon.setCancelRequested(); |
|
45 |
} |
|
46 |
} |
|
47 |
|
|
48 |
|
|
49 |
@Override |
|
50 |
public void contextStart(IMemento memento, IProgressMonitor monitor){ |
|
51 |
if (daemon == null) { |
|
52 |
daemon = new ValidationDaemon(); |
|
53 |
} |
|
54 |
daemon.schedule(); |
|
55 |
} |
|
56 |
|
|
57 |
|
|
58 |
@Override |
|
59 |
public void contextRefresh(IProgressMonitor monitor){ |
|
60 |
if (daemon != null) { |
|
61 |
daemon.cancel(); |
|
62 |
daemon.setCancelRequested(); |
|
63 |
} |
|
64 |
} |
|
65 |
|
|
66 |
|
|
67 |
@Override |
|
68 |
public void workbenchShutdown(IMemento memento, IProgressMonitor monitor){ |
|
69 |
if (daemon != null) { |
|
70 |
daemon.cancel(); |
|
71 |
daemon.setCancelRequested(); |
|
72 |
daemon = null; |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/validation/ValidationDaemon.java | ||
---|---|---|
1 |
package eu.etaxonomy.taxeditor.editor.validation; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
|
|
5 |
import org.apache.log4j.Logger; |
|
6 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
7 |
import org.eclipse.core.runtime.IStatus; |
|
8 |
import org.eclipse.core.runtime.Status; |
|
9 |
import org.eclipse.core.runtime.jobs.Job; |
|
10 |
|
|
11 |
import eu.etaxonomy.cdm.api.service.IEntityConstraintViolationService; |
|
12 |
import eu.etaxonomy.cdm.api.service.IEntityValidationResultService; |
|
13 |
import eu.etaxonomy.cdm.model.validation.EntityValidationResult; |
|
14 |
import eu.etaxonomy.taxeditor.model.MessagingUtils; |
|
15 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
|
16 |
|
|
17 |
/** |
|
18 |
* A job that repeatedly checks the error tables and refreshes the problem |
|
19 |
* markers created from them. |
|
20 |
* |
|
21 |
* @author ayco_holleman |
|
22 |
* |
|
23 |
*/ |
|
24 |
public class ValidationDaemon extends Job { |
|
25 |
|
|
26 |
@SuppressWarnings("unused") |
|
27 |
private static final Logger logger = Logger.getLogger(ValidationDaemon.class); |
|
28 |
|
|
29 |
private final IEntityValidationResultService validationResultService; |
|
30 |
|
|
31 |
@SuppressWarnings("unused") |
|
32 |
/* Not currently needed but present for future use if/when required */ |
|
33 |
private final IEntityConstraintViolationService constraintViolationService; |
|
34 |
|
|
35 |
private boolean cancelRequested = false; |
|
36 |
|
|
37 |
public ValidationDaemon(){ |
|
38 |
super("Initializing validation module"); |
|
39 |
// StoreUtil.info("Initializing validation module"); |
|
40 |
MessagingUtils.info("Initializing validation module"); |
|
41 |
constraintViolationService = CdmStore.getService(IEntityConstraintViolationService.class); |
|
42 |
validationResultService = CdmStore.getService(IEntityValidationResultService.class); |
|
43 |
} |
|
44 |
|
|
45 |
|
|
46 |
@Override |
|
47 |
protected void canceling(){ |
|
48 |
cancelRequested = true; |
|
49 |
} |
|
50 |
|
|
51 |
|
|
52 |
/** |
|
53 |
* This method is called by {@link ValidationContextListener} rather than |
|
54 |
* {@link Job#cancel()}, because that method does not have the desired |
|
55 |
* effect. |
|
56 |
*/ |
|
57 |
public void setCancelRequested(){ |
|
58 |
cancelRequested = true; |
|
59 |
} |
|
60 |
|
|
61 |
|
|
62 |
@Override |
|
63 |
protected IStatus run(IProgressMonitor monitor){ |
|
64 |
MarkerManager markerManager; |
|
65 |
List<EntityValidationResult> results; |
|
66 |
try { |
|
67 |
while (!cancelRequested) { |
|
68 |
results = validationResultService.getValidationResults(); |
|
69 |
markerManager = new MarkerManager(results); |
|
70 |
markerManager.deleteObsoleteMarkers(); |
|
71 |
markerManager.createMarkers(); |
|
72 |
// Might want to make this configurable: |
|
73 |
Thread.sleep(5000); |
|
74 |
} |
|
75 |
// StoreUtil.info("Validation module stopped"); |
|
76 |
MessagingUtils.info("Validation module stopped"); |
|
77 |
return Status.OK_STATUS; |
|
78 |
} |
|
79 |
catch (Throwable t) { |
|
80 |
// StoreUtil.info("Validation module terminated unexpectedly: " + t.getMessage()); |
|
81 |
MessagingUtils.info("Validation module terminated unexpectedly: " + t.getMessage()); |
|
82 |
return Status.CANCEL_STATUS; |
|
83 |
} |
|
84 |
} |
|
85 |
|
|
86 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/validation/EntityClassMarkerField.java | ||
---|---|---|
1 |
package eu.etaxonomy.taxeditor.editor.view.validation; |
|
2 |
|
|
3 |
import org.eclipse.core.runtime.CoreException; |
|
4 |
import org.eclipse.ui.views.markers.MarkerField; |
|
5 |
import org.eclipse.ui.views.markers.MarkerItem; |
|
6 |
|
|
7 |
import eu.etaxonomy.taxeditor.editor.validation.MarkerManager; |
|
8 |
|
|
9 |
public class EntityClassMarkerField extends MarkerField { |
|
10 |
|
|
11 |
@Override |
|
12 |
public String getValue(MarkerItem item) |
|
13 |
{ |
|
14 |
try { |
|
15 |
Object value = item.getMarker().getAttribute(MarkerManager.ATTRIB_ENTITY_CLASS); |
|
16 |
return value == null ? "" : value.toString(); |
|
17 |
} |
|
18 |
catch (CoreException e) { |
|
19 |
throw new RuntimeException("Error while retrieving value for " + MarkerManager.ATTRIB_ENTITY_CLASS); |
|
20 |
} |
|
21 |
} |
|
22 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/validation/EntityIdMarkerField.java | ||
---|---|---|
1 |
package eu.etaxonomy.taxeditor.editor.view.validation; |
|
2 |
|
|
3 |
import org.eclipse.core.runtime.CoreException; |
|
4 |
import org.eclipse.ui.views.markers.MarkerField; |
|
5 |
import org.eclipse.ui.views.markers.MarkerItem; |
|
6 |
|
|
7 |
import eu.etaxonomy.taxeditor.editor.validation.MarkerManager; |
|
8 |
|
|
9 |
public class EntityIdMarkerField extends MarkerField { |
|
10 |
|
|
11 |
@Override |
|
12 |
public String getValue(MarkerItem item) |
|
13 |
{ |
|
14 |
try { |
|
15 |
Object value = item.getMarker().getAttribute(MarkerManager.ATTRIB_ENTITY_ID); |
|
16 |
return value == null ? "" : value.toString(); |
|
17 |
} |
|
18 |
catch (CoreException e) { |
|
19 |
throw new RuntimeException("Error while retrieving value for " + MarkerManager.ATTRIB_ENTITY_ID); |
|
20 |
} |
|
21 |
} |
|
22 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/validation/InvalidValueMarkerField.java | ||
---|---|---|
1 |
package eu.etaxonomy.taxeditor.editor.view.validation; |
|
2 |
|
|
3 |
import org.eclipse.core.runtime.CoreException; |
|
4 |
import org.eclipse.ui.views.markers.MarkerField; |
|
5 |
import org.eclipse.ui.views.markers.MarkerItem; |
|
6 |
|
|
7 |
import eu.etaxonomy.taxeditor.editor.validation.MarkerManager; |
|
8 |
|
|
9 |
public class InvalidValueMarkerField extends MarkerField { |
|
10 |
|
|
11 |
@Override |
|
12 |
public String getValue(MarkerItem item) |
|
13 |
{ |
|
14 |
try { |
|
15 |
Object value = item.getMarker().getAttribute(MarkerManager.ATTRIB_INVALID_VALUE); |
|
16 |
return value == null ? "" : value.toString(); |
|
17 |
} |
|
18 |
catch (CoreException e) { |
|
19 |
throw new RuntimeException("Error while retrieving value for " + MarkerManager.ATTRIB_INVALID_VALUE); |
|
20 |
} |
|
21 |
} |
|
22 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/validation/UserFriendlyDescriptionMarkerField.java | ||
---|---|---|
1 |
package eu.etaxonomy.taxeditor.editor.view.validation; |
|
2 |
|
|
3 |
import org.eclipse.core.runtime.CoreException; |
|
4 |
import org.eclipse.ui.views.markers.MarkerField; |
|
5 |
import org.eclipse.ui.views.markers.MarkerItem; |
|
6 |
|
|
7 |
import eu.etaxonomy.taxeditor.editor.validation.MarkerManager; |
|
8 |
|
|
9 |
public class UserFriendlyDescriptionMarkerField extends MarkerField { |
|
10 |
|
|
11 |
@Override |
|
12 |
public String getValue(MarkerItem item) |
|
13 |
{ |
|
14 |
try { |
|
15 |
Object value = item.getMarker().getAttribute(MarkerManager.ATTRIB_USER_FRIENDLY_DESCRIPTION); |
|
16 |
return value == null ? "" : value.toString(); |
|
17 |
} |
|
18 |
catch (CoreException e) { |
|
19 |
throw new RuntimeException("Error while retrieving value for " + MarkerManager.ATTRIB_USER_FRIENDLY_DESCRIPTION); |
|
20 |
} |
|
21 |
} |
|
22 |
|
|
23 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/validation/UserFriendlyFieldNameMarkerField.java | ||
---|---|---|
1 |
package eu.etaxonomy.taxeditor.editor.view.validation; |
|
2 |
|
|
3 |
import org.eclipse.core.runtime.CoreException; |
|
4 |
import org.eclipse.ui.views.markers.MarkerField; |
|
5 |
import org.eclipse.ui.views.markers.MarkerItem; |
|
6 |
|
|
7 |
import eu.etaxonomy.taxeditor.editor.validation.MarkerManager; |
|
8 |
|
|
9 |
public class UserFriendlyFieldNameMarkerField extends MarkerField { |
|
10 |
|
|
11 |
@Override |
|
12 |
public String getValue(MarkerItem item) |
|
13 |
{ |
|
14 |
try { |
|
15 |
Object value = item.getMarker().getAttribute(MarkerManager.ATTRIB_USER_FRIENDLY_FIELD_NAME); |
|
16 |
return value == null ? "" : value.toString(); |
|
17 |
} |
|
18 |
catch (CoreException e) { |
|
19 |
throw new RuntimeException("Error while retrieving value for " + MarkerManager.ATTRIB_USER_FRIENDLY_FIELD_NAME); |
|
20 |
} |
|
21 |
} |
|
22 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/validation/UserFriendlyTypeNameMarkerField.java | ||
---|---|---|
1 |
package eu.etaxonomy.taxeditor.editor.view.validation; |
|
2 |
|
|
3 |
import org.eclipse.core.runtime.CoreException; |
|
4 |
import org.eclipse.ui.views.markers.MarkerField; |
|
5 |
import org.eclipse.ui.views.markers.MarkerItem; |
|
6 |
|
|
7 |
import eu.etaxonomy.taxeditor.editor.validation.MarkerManager; |
|
8 |
|
|
9 |
public class UserFriendlyTypeNameMarkerField extends MarkerField { |
|
10 |
|
|
11 |
@Override |
|
12 |
public String getValue(MarkerItem item) |
|
13 |
{ |
|
14 |
try { |
|
15 |
Object value = item.getMarker().getAttribute(MarkerManager.ATTRIB_USER_FRIENDLY_TYPE_NAME); |
|
16 |
return value == null ? "" : value.toString(); |
|
17 |
} |
|
18 |
catch (CoreException e) { |
|
19 |
throw new RuntimeException("Error while retrieving value for " + MarkerManager.ATTRIB_USER_FRIENDLY_TYPE_NAME); |
|
20 |
} |
|
21 |
} |
|
22 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/validation/ValidationProblemsView.java | ||
---|---|---|
1 |
package eu.etaxonomy.taxeditor.editor.view.validation; |
|
2 |
|
|
3 |
import org.eclipse.ui.views.markers.MarkerSupportView; |
|
4 |
|
|
5 |
public class ValidationProblemsView extends MarkerSupportView { |
|
6 |
|
|
7 |
public ValidationProblemsView() |
|
8 |
{ |
|
9 |
super("eu.etaxonomy.taxeditor.editor.validation.ValidationProblemsMarkerGenerator"); |
|
10 |
} |
|
11 |
|
|
12 |
|
|
13 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/validation/ValidatorClassMarkerField.java | ||
---|---|---|
1 |
package eu.etaxonomy.taxeditor.editor.view.validation; |
|
2 |
|
|
3 |
import org.eclipse.core.runtime.CoreException; |
|
4 |
import org.eclipse.ui.views.markers.MarkerField; |
|
5 |
import org.eclipse.ui.views.markers.MarkerItem; |
|
6 |
|
|
7 |
import eu.etaxonomy.taxeditor.editor.validation.MarkerManager; |
|
8 |
|
|
9 |
public class ValidatorClassMarkerField extends MarkerField { |
|
10 |
|
|
11 |
@Override |
|
12 |
public String getValue(MarkerItem item) |
|
13 |
{ |
|
14 |
try { |
|
15 |
Object value = item.getMarker().getAttribute(MarkerManager.ATTRIB_VALIDATOR_CLASS); |
|
16 |
return value == null ? "" : value.toString(); |
|
17 |
} |
|
18 |
catch (CoreException e) { |
|
19 |
throw new RuntimeException("Error while retrieving value for " + MarkerManager.ATTRIB_VALIDATOR_CLASS); |
|
20 |
} |
|
21 |
} |
|
22 |
|
|
23 |
} |
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/validation/ValidatorMessageMarkerField.java | ||
---|---|---|
1 |
package eu.etaxonomy.taxeditor.editor.view.validation; |
|
2 |
|
|
3 |
import org.eclipse.core.runtime.CoreException; |
|
4 |
import org.eclipse.ui.views.markers.MarkerField; |
|
5 |
import org.eclipse.ui.views.markers.MarkerItem; |
|
6 |
|
|
7 |
import eu.etaxonomy.taxeditor.editor.validation.MarkerManager; |
|
8 |
|
|
9 |
public class ValidatorMessageMarkerField extends MarkerField { |
|
10 |
|
|
11 |
@Override |
|
12 |
public String getValue(MarkerItem item) |
|
13 |
{ |
|
14 |
try { |
|
15 |
Object value = item.getMarker().getAttribute(MarkerManager.ATTRIB_VALIDATOR_MESSAGE); |
|
16 |
return value == null ? "" : value.toString(); |
|
17 |
} |
|
18 |
catch (CoreException e) { |
|
19 |
throw new RuntimeException("Error while retrieving value for " + MarkerManager.ATTRIB_VALIDATOR_MESSAGE); |
|
20 |
} |
|
21 |
} |
|
22 |
|
|
23 |
} |
Also available in: Unified diff
merge validation editor branch to trunk