Project

General

Profile

« Previous | Next » 

Revision 4f25a2e9

Added by Ayco Hollemann over 7 years ago

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/validation/MarkerManager.java
92 92
        this.problems = new ArrayList<EntityConstraintViolation>();
93 93
        for (EntityValidation result : results) {
94 94
            Set<EntityConstraintViolation> problemsPerEntity = result.getEntityConstraintViolations();
95
            //MessagingUtils.info("Number of issues/errors for entity " + result.getUserFriendlyDescription() + ": "+ problemsPerEntity.size());
96 95
            for (EntityConstraintViolation problem : problemsPerEntity) {
97 96
                problem.setEntityValidation(result);
98 97
                problems.add(problem);
99 98
            }
100

  
101 99
        }
100
        //MessagingUtils.info("Number of validation errors: " + problems.size());
102 101
    }
103 102

  
104 103
    /**
......
119 118
                marker.delete();
120 119
            }
121 120
        }
121
        //MessagingUtils.info("Obsolete markers: " + i);
122 122
        return i;
123 123
    }
124 124

  
......
136 136
        IMarker[] markers = root.findMarkers(MARKER_TYPE_ID, true, IResource.DEPTH_INFINITE);
137 137
        for (EntityConstraintViolation problem : problems) {
138 138
            if (isNewProblem(problem, markers)) {
139
                IMarker marker = root.createMarker(MARKER_TYPE_ID);
140 139
                ++i;
140
                IMarker marker = root.createMarker(MARKER_TYPE_ID);
141 141
                if (problem.getSeverity() == Severity.ERROR) {
142 142
                    marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
143 143
                } else if (problem.getSeverity() == Severity.WARNING) {
......
147 147
                }
148 148
                EntityValidation result = problem.getEntityValidation();
149 149
                marker.setAttribute(IMarker.MESSAGE, problem.getMessage());
150
                marker.setAttribute(ATTRIB_DATABASE_ID, problem.getId());
150
                marker.setAttribute(ATTRIB_DATABASE_ID, new Integer(problem.getId()));
151 151
                marker.setAttribute(ATTRIB_USER_FRIENDLY_TYPE_NAME, result.getUserFriendlyTypeName());
152 152
                marker.setAttribute(ATTRIB_USER_FRIENDLY_DESCRIPTION, result.getUserFriendlyDescription());
153 153
                marker.setAttribute(ATTRIB_USER_FRIENDLY_FIELD_NAME, problem.getUserFriendlyFieldName());
......
158 158
                marker.setAttribute(ATTRIB_ENTITY_ID, result.getValidatedEntityId());
159 159
            }
160 160
        }
161
        //MessagingUtils.info("New problems: " + i);
161 162
        return i;
162 163
    }
163 164

  
......
180 181
    }
181 182

  
182 183
    private static boolean isMarkerForProblem(IMarker marker, EntityConstraintViolation problem) throws CoreException {
183
        if (problem.getId() == (Integer) marker.getAttribute(ATTRIB_DATABASE_ID)) {
184
        if (isEqual(marker, ATTRIB_DATABASE_ID, new Integer(problem.getId()))) {
184 185
            return true;
185 186
        }
186 187
        EntityValidation result = problem.getEntityValidation();
187
        if (!((Integer) marker.getAttribute(ATTRIB_ENTITY_ID)).equals(result.getValidatedEntityId())) {
188
        if (!isEqual(marker, ATTRIB_ENTITY_ID, result.getValidatedEntityId())) {
188 189
            return false;
189 190
        }
190
        if (!marker.getAttribute(ATTRIB_INVALID_VALUE).equals(problem.getInvalidValue())) {
191
        if (!isEqual(marker, ATTRIB_INVALID_VALUE, problem.getInvalidValue())) {
191 192
            return false;
192 193
        }
193
        if (!marker.getAttribute(ATTRIB_ENTITY_CLASS).equals(result.getValidatedEntityClass())) {
194
        if (!isEqual(marker, ATTRIB_ENTITY_CLASS, result.getValidatedEntityClass())) {
194 195
            return false;
195 196
        }
196
        if (!marker.getAttribute(ATTRIB_USER_FRIENDLY_FIELD_NAME).equals(problem.getUserFriendlyFieldName())) {
197
        if (!isEqual(marker, ATTRIB_USER_FRIENDLY_FIELD_NAME, problem.getUserFriendlyFieldName())) {
197 198
            return false;
198 199
        }
199
        if (!marker.getAttribute(ATTRIB_VALIDATOR_CLASS).equals(problem.getValidator())) {
200
        if (!isEqual(marker, ATTRIB_VALIDATOR_CLASS, problem.getValidator())) {
200 201
            return false;
201 202
        }
202 203
        return true;
203 204
    }
204 205

  
206
    private static boolean isEqual(IMarker marker, String attribute, Object value) throws CoreException {
207
        Object val = marker.getAttribute(attribute);
208
        boolean equal;
209
        if (val == null) {
210
            equal = value == null;
211
        } else {
212
            equal = value != null && val.equals(value);
213
        }
214
        return equal;
215
    }
216

  
205 217
}

Also available in: Unified diff