Skip to content

Package: SWTValidationHelper

SWTValidationHelper

nameinstructionbranchcomplexitylinemethod
SWTValidationHelper()
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getCancelColorHEX(VTValidationStyleProperty, VElement, ViewModelContext)
M: 19 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
getCancelForegroundColorHEX(VTValidationStyleProperty, VElement, ViewModelContext)
M: 19 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
getCancelImageURL(VTValidationStyleProperty, VElement, ViewModelContext)
M: 19 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
getCancelOverlayURL(VTValidationStyleProperty, VElement, ViewModelContext)
M: 19 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
getColor(String)
M: 0 C: 35
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
getDefaultValidationStyle()
M: 0 C: 62
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 16
100%
M: 0 C: 1
100%
getErrorColorHEX(VTValidationStyleProperty, VElement, ViewModelContext)
M: 3 C: 16
84%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 1 C: 7
88%
M: 0 C: 1
100%
getErrorForegroundColorHEX(VTValidationStyleProperty, VElement, ViewModelContext)
M: 3 C: 16
84%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 1 C: 7
88%
M: 0 C: 1
100%
getErrorImageURL(VTValidationStyleProperty, VElement, ViewModelContext)
M: 3 C: 16
84%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 1 C: 7
88%
M: 0 C: 1
100%
getErrorOverlayURL(VTValidationStyleProperty, VElement, ViewModelContext)
M: 3 C: 16
84%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 1 C: 7
88%
M: 0 C: 1
100%
getInfoColorHEX(VTValidationStyleProperty, VElement, ViewModelContext)
M: 19 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
getInfoForegroundColorHEX(VTValidationStyleProperty, VElement, ViewModelContext)
M: 19 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
getInfoImageURL(VTValidationStyleProperty, VElement, ViewModelContext)
M: 19 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
getInfoOverlayURL(VTValidationStyleProperty, VElement, ViewModelContext)
M: 3 C: 16
84%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 1 C: 7
88%
M: 0 C: 1
100%
getOkColorHEX(VTValidationStyleProperty, VElement, ViewModelContext)
M: 3 C: 16
84%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 1 C: 7
88%
M: 0 C: 1
100%
getOkForegroundColorHEX(VTValidationStyleProperty, VElement, ViewModelContext)
M: 3 C: 16
84%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 1 C: 7
88%
M: 0 C: 1
100%
getOkImageURL(VTValidationStyleProperty, VElement, ViewModelContext)
M: 3 C: 16
84%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 1 C: 7
88%
M: 0 C: 1
100%
getOkOverlayURL(VTValidationStyleProperty, VElement, ViewModelContext)
M: 3 C: 16
84%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 1 C: 7
88%
M: 0 C: 1
100%
getValidationBackgroundColor(int)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getValidationBackgroundColor(int, VElement, ViewModelContext)
M: 36 C: 42
54%
M: 5 C: 5
50%
M: 5 C: 3
38%
M: 9 C: 11
55%
M: 0 C: 1
100%
getValidationColorHEX(int, VElement, ViewModelContext)
M: 57 C: 0
0%
M: 6 C: 0
0%
M: 6 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%
getValidationForegroundColor(int)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getValidationForegroundColor(int, VElement, ViewModelContext)
M: 53 C: 25
32%
M: 7 C: 3
30%
M: 6 C: 2
25%
M: 11 C: 9
45%
M: 0 C: 1
100%
getValidationIcon(int)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getValidationIcon(int, VElement, ViewModelContext)
M: 37 C: 31
46%
M: 4 C: 4
50%
M: 4 C: 3
43%
M: 10 C: 10
50%
M: 0 C: 1
100%
getValidationOverlayDescriptor(int)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getValidationOverlayDescriptor(int, VElement, ViewModelContext)
M: 30 C: 38
56%
M: 3 C: 5
63%
M: 3 C: 4
57%
M: 8 C: 12
60%
M: 0 C: 1
100%
getValidationStyleProperty(VElement, ViewModelContext)
M: 16 C: 25
61%
M: 5 C: 5
50%
M: 4 C: 2
33%
M: 5 C: 8
62%
M: 0 C: 1
100%
getWarningColorHEX(VTValidationStyleProperty, VElement, ViewModelContext)
M: 19 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
getWarningForegroundColorHEX(VTValidationStyleProperty, VElement, ViewModelContext)
M: 19 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
getWarningImageURL(VTValidationStyleProperty, VElement, ViewModelContext)
M: 19 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
getWarningOverlayURL(VTValidationStyleProperty, VElement, ViewModelContext)
M: 19 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2016 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Johannes Faltermeier - initial API and implementation
13: * Eugen Neufeld - VTViewTemplate implementation
14: ******************************************************************************/
15: package org.eclipse.emfforms.spi.swt.core.ui;
16:
17: import java.net.MalformedURLException;
18: import java.net.URL;
19: import java.util.LinkedHashMap;
20: import java.util.Map;
21: import java.util.Set;
22:
23: import org.eclipse.emf.common.util.Diagnostic;
24: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
25: import org.eclipse.emf.ecp.view.spi.model.VElement;
26: import org.eclipse.emf.ecp.view.template.model.VTStyleProperty;
27: import org.eclipse.emf.ecp.view.template.model.VTViewTemplateProvider;
28: import org.eclipse.emf.ecp.view.template.style.validation.model.VTValidationFactory;
29: import org.eclipse.emf.ecp.view.template.style.validation.model.VTValidationStyleProperty;
30: import org.eclipse.emfforms.internal.swt.core.Activator;
31: import org.eclipse.jface.resource.ImageDescriptor;
32: import org.eclipse.swt.graphics.Color;
33: import org.eclipse.swt.graphics.Image;
34: import org.eclipse.swt.widgets.Display;
35:
36: /**
37: * Helper class for accessing icons and colours for validations.
38: *
39: * @author jfaltermeier
40: * @since 1.23
41: *
42: */
43: public class SWTValidationHelper {
44:
45:         /**
46:          * The instance of the SWTValidationHelper.
47:          */
48:         public static final SWTValidationHelper INSTANCE = new SWTValidationHelper();
49:         private final Map<String, Color> colorMap = new LinkedHashMap<String, Color>();
50:         private VTValidationStyleProperty defaultValidationStyle;
51:
52:         /**
53:          * Returns the background color for a control with the given validation severity, VElement
54:          * and view model context, if applicable.
55:          *
56:          * @param severity severity the severity of the {@link Diagnostic}
57:          * @param vElement The {@link VElement} that is being rendered
58:          * @param viewModelContext The corresponding {@link ViewModelContext}
59:          * @return the color to be used as a background color
60:          */
61:         public Color getValidationBackgroundColor(int severity, VElement vElement, ViewModelContext viewModelContext) {
62:                 final VTValidationStyleProperty defaultStyle = getDefaultValidationStyle();
63:                 String colorHex = null;
64:
65:•                switch (severity) {
66:                 case Diagnostic.OK:
67:                         colorHex = getOkColorHEX(defaultStyle, vElement, viewModelContext);
68:                         break;
69:                 case Diagnostic.INFO:
70:                         colorHex = getInfoColorHEX(defaultStyle, vElement, viewModelContext);
71:                         break;
72:                 case Diagnostic.WARNING:
73:                         colorHex = getWarningColorHEX(defaultStyle, vElement, viewModelContext);
74:                         break;
75:                 case Diagnostic.ERROR:
76:                         colorHex = getErrorColorHEX(defaultStyle, vElement, viewModelContext);
77:                         break;
78:                 case Diagnostic.CANCEL:
79:                         colorHex = getCancelColorHEX(defaultStyle, vElement, viewModelContext);
80:                         break;
81:                 default:
82:                         throw new IllegalArgumentException(
83:                                 "The specified severity value " + severity + " is invalid. See Diagnostic class."); //$NON-NLS-1$ //$NON-NLS-2$
84:                 }
85:•                if (colorHex == null) {
86:                         return null;
87:                 }
88:•                if (!colorMap.containsKey(colorHex)) {
89:                         colorMap.put(colorHex, getColor(colorHex));
90:                 }
91:                 return colorMap.get(colorHex);
92:         }
93:
94:         /**
95:          * Returns the foreground color for a control with the given validation severity, VElement
96:          * and view model context, if applicable.
97:          *
98:          * @param severity severity the severity of the {@link Diagnostic}
99:          * @param vElement The {@link VElement} that is being rendered
100:          * @param viewModelContext The corresponding {@link ViewModelContext}
101:          * @return the color to be used as a foreground color
102:          * @since 1.10
103:          */
104:         public Color getValidationForegroundColor(int severity, VElement vElement, ViewModelContext viewModelContext) {
105:                 final VTValidationStyleProperty defaultStyle = getDefaultValidationStyle();
106:                 String colorHex = null;
107:
108:•                switch (severity) {
109:                 case Diagnostic.OK:
110:                         colorHex = getOkForegroundColorHEX(defaultStyle, vElement, viewModelContext);
111:                         break;
112:                 case Diagnostic.INFO:
113:                         colorHex = getInfoForegroundColorHEX(defaultStyle, vElement, viewModelContext);
114:                         break;
115:                 case Diagnostic.WARNING:
116:                         colorHex = getWarningForegroundColorHEX(defaultStyle, vElement, viewModelContext);
117:                         break;
118:                 case Diagnostic.ERROR:
119:                         colorHex = getErrorForegroundColorHEX(defaultStyle, vElement, viewModelContext);
120:                         break;
121:                 case Diagnostic.CANCEL:
122:                         colorHex = getCancelForegroundColorHEX(defaultStyle, vElement, viewModelContext);
123:                         break;
124:                 default:
125:                         throw new IllegalArgumentException(
126:                                 "The specified severity value " + severity + " is invalid. See Diagnostic class."); //$NON-NLS-1$ //$NON-NLS-2$
127:                 }
128:•                if (colorHex == null) {
129:                         return null;
130:                 }
131:•                if (!colorMap.containsKey(colorHex)) {
132:                         colorMap.put(colorHex, getColor(colorHex));
133:                 }
134:                 return colorMap.get(colorHex);
135:         }
136:
137:         /**
138:          * Returns the background color for a control with the given validation severity.
139:          *
140:          * @param severity severity the severity of the {@link Diagnostic}
141:          * @return the color to be used as a background color
142:          */
143:         public Color getValidationBackgroundColor(int severity) {
144:                 return getValidationBackgroundColor(severity, null, null);
145:         }
146:
147:         /**
148:          * Returns the foreground color for a control with the given validation severity.
149:          *
150:          * @param severity severity the severity of the {@link Diagnostic}
151:          * @return the color to be used as a foreground color
152:          * @since 1.10
153:          */
154:         public Color getValidationForegroundColor(int severity) {
155:                 return getValidationForegroundColor(severity, null, null);
156:         }
157:
158:         /**
159:          * Returns the hex color for a control with the given validation severity, VElement
160:          * and view model context, if applicable.
161:          *
162:          * @param severity severity the severity of the {@link Diagnostic}
163:          * @param vElement The {@link VElement} that is being rendered
164:          * @param viewModelContext The corresponding {@link ViewModelContext}
165:          * @return the hex value to be used
166:          * @since 1.9
167:          */
168:         public String getValidationColorHEX(int severity, VElement vElement, ViewModelContext viewModelContext) {
169:                 final VTValidationStyleProperty defaultStyle = getDefaultValidationStyle();
170:                 String colorHex = null;
171:
172:•                switch (severity) {
173:                 case Diagnostic.OK:
174:                         colorHex = getOkColorHEX(defaultStyle, vElement, viewModelContext);
175:                         break;
176:                 case Diagnostic.INFO:
177:                         colorHex = getInfoColorHEX(defaultStyle, vElement, viewModelContext);
178:                         break;
179:                 case Diagnostic.WARNING:
180:                         colorHex = getWarningColorHEX(defaultStyle, vElement, viewModelContext);
181:                         break;
182:                 case Diagnostic.ERROR:
183:                         colorHex = getErrorColorHEX(defaultStyle, vElement, viewModelContext);
184:                         break;
185:                 case Diagnostic.CANCEL:
186:                         colorHex = getCancelColorHEX(defaultStyle, vElement, viewModelContext);
187:                         break;
188:                 default:
189:                         throw new IllegalArgumentException(
190:                                 "The specified severity value " + severity + " is invalid. See Diagnostic class."); //$NON-NLS-1$ //$NON-NLS-2$
191:                 }
192:                 return colorHex;
193:         }
194:
195:         /**
196:          * Returns the validation icon matching the given severity, VElement
197:          * and view model context, if applicable.
198:          *
199:          * @param severity the severity of the {@link Diagnostic}
200:          * @param vElement The {@link VElement} that is being rendered
201:          * @param viewModelContext The corresponding {@link ViewModelContext}
202:          * @return the icon to be displayed, or <code>null</code> when no icon is to be displayed
203:          */
204:         public Image getValidationIcon(int severity, VElement vElement, ViewModelContext viewModelContext) {
205:                 final VTValidationStyleProperty defaultStyle = getDefaultValidationStyle();
206:                 String imageUrl = null;
207:
208:•                switch (severity) {
209:                 case Diagnostic.OK:
210:                         imageUrl = getOkImageURL(defaultStyle, vElement, viewModelContext);
211:                         break;
212:                 case Diagnostic.INFO:
213:                         imageUrl = getInfoImageURL(defaultStyle, vElement, viewModelContext);
214:                         break;
215:                 case Diagnostic.WARNING:
216:                         imageUrl = getWarningImageURL(defaultStyle, vElement, viewModelContext);
217:                         break;
218:                 case Diagnostic.ERROR:
219:                         imageUrl = getErrorImageURL(defaultStyle, vElement, viewModelContext);
220:                         break;
221:                 case Diagnostic.CANCEL:
222:                         imageUrl = getCancelImageURL(defaultStyle, vElement, viewModelContext);
223:                         break;
224:                 default:
225:                         throw new IllegalArgumentException(
226:                                 "The specified severity value " + severity + " is invalid. See Diagnostic class."); //$NON-NLS-1$ //$NON-NLS-2$
227:                 }
228:•                if (imageUrl == null) {
229:                         return null;
230:                 }
231:                 try {
232:                         return Activator.getImage(new URL(imageUrl));
233:                 } catch (final MalformedURLException ex) {
234:                         return null;
235:                 }
236:         }
237:
238:         /**
239:          * Returns the validation icon matching the given severity.
240:          *
241:          * @param severity the severity of the {@link Diagnostic}
242:          * @return the icon to be displayed, or <code>null</code> when no icon is to be displayed
243:          */
244:         public Image getValidationIcon(int severity) {
245:                 return getValidationIcon(severity, null, null);
246:         }
247:
248:         /**
249:          * Returns the validation overlay icon matching the given severity, VElement
250:          * and view model context, if applicable.
251:          *
252:          * @param severity the severity of the {@link Diagnostic}
253:          * @param vElement The {@link VElement} that is being rendered
254:          * @param viewModelContext The corresponding {@link ViewModelContext}
255:          * @return the icon to be displayed, or <code>null</code> when no icon is to be displayed
256:          */
257:         public ImageDescriptor getValidationOverlayDescriptor(int severity, VElement vElement,
258:                 ViewModelContext viewModelContext) {
259:                 final VTValidationStyleProperty defaultStyle = getDefaultValidationStyle();
260:                 String imageUrl = null;
261:
262:•                switch (severity) {
263:                 case Diagnostic.OK:
264:                         imageUrl = getOkOverlayURL(defaultStyle, vElement, viewModelContext);
265:                         break;
266:                 case Diagnostic.INFO:
267:                         imageUrl = getInfoOverlayURL(defaultStyle, vElement, viewModelContext);
268:                         break;
269:                 case Diagnostic.WARNING:
270:                         imageUrl = getWarningOverlayURL(defaultStyle, vElement, viewModelContext);
271:                         break;
272:                 case Diagnostic.ERROR:
273:                         imageUrl = getErrorOverlayURL(defaultStyle, vElement, viewModelContext);
274:                         break;
275:                 case Diagnostic.CANCEL:
276:                         imageUrl = getCancelOverlayURL(defaultStyle, vElement, viewModelContext);
277:                         break;
278:                 default:
279:                         throw new IllegalArgumentException(
280:                                 "The specified severity value " + severity + " is invalid. See Diagnostic class."); //$NON-NLS-1$ //$NON-NLS-2$
281:                 }
282:•                if (imageUrl == null) {
283:                         return null;
284:                 }
285:                 try {
286:                         return ImageDescriptor.createFromURL(new URL(imageUrl));
287:                 } catch (final MalformedURLException ex) {
288:                         return null;
289:                 }
290:         }
291:
292:         /**
293:          * Returns an image descriptor which can be used as an overlay for validation icons.
294:          *
295:          * @param severity the severity of the validation
296:          * @return the descriptor
297:          */
298:         public ImageDescriptor getValidationOverlayDescriptor(int severity) {
299:                 return getValidationOverlayDescriptor(severity, null, null);
300:         }
301:
302:         private String getOkColorHEX(VTValidationStyleProperty defaultStyle, VElement vElement,
303:                 ViewModelContext viewModelContext) {
304:                 String colorHex = null;
305:                 final VTValidationStyleProperty validationStyleProperty = getValidationStyleProperty(vElement,
306:                         viewModelContext);
307:•                if (defaultStyle != null) {
308:                         colorHex = defaultStyle.getOkColorHEX();
309:                 }
310:•                if (validationStyleProperty != null) {
311:                         colorHex = validationStyleProperty.getOkColorHEX();
312:                 }
313:                 return colorHex;
314:         }
315:
316:         private String getOkForegroundColorHEX(VTValidationStyleProperty defaultStyle, VElement vElement,
317:                 ViewModelContext viewModelContext) {
318:                 String colorHex = null;
319:                 final VTValidationStyleProperty validationStyleProperty = getValidationStyleProperty(vElement,
320:                         viewModelContext);
321:•                if (defaultStyle != null) {
322:                         colorHex = defaultStyle.getOkForegroundColorHEX();
323:                 }
324:•                if (validationStyleProperty != null) {
325:                         colorHex = validationStyleProperty.getOkForegroundColorHEX();
326:                 }
327:                 return colorHex;
328:         }
329:
330:         private String getInfoColorHEX(VTValidationStyleProperty defaultStyle, VElement vElement,
331:                 ViewModelContext viewModelContext) {
332:                 String colorHex = null;
333:                 final VTValidationStyleProperty validationStyleProperty = getValidationStyleProperty(vElement,
334:                         viewModelContext);
335:•                if (defaultStyle != null) {
336:                         colorHex = defaultStyle.getInfoColorHEX();
337:                 }
338:•                if (validationStyleProperty != null) {
339:                         colorHex = validationStyleProperty.getInfoColorHEX();
340:                 }
341:                 return colorHex;
342:         }
343:
344:         private String getInfoForegroundColorHEX(VTValidationStyleProperty defaultStyle, VElement vElement,
345:                 ViewModelContext viewModelContext) {
346:                 String colorHex = null;
347:                 final VTValidationStyleProperty validationStyleProperty = getValidationStyleProperty(vElement,
348:                         viewModelContext);
349:•                if (defaultStyle != null) {
350:                         colorHex = defaultStyle.getInfoForegroundColorHEX();
351:                 }
352:•                if (validationStyleProperty != null) {
353:                         colorHex = validationStyleProperty.getInfoForegroundColorHEX();
354:                 }
355:                 return colorHex;
356:         }
357:
358:         private String getWarningColorHEX(VTValidationStyleProperty defaultStyle, VElement vElement,
359:                 ViewModelContext viewModelContext) {
360:                 String colorHex = null;
361:                 final VTValidationStyleProperty validationStyleProperty = getValidationStyleProperty(vElement,
362:                         viewModelContext);
363:•                if (defaultStyle != null) {
364:                         colorHex = defaultStyle.getWarningColorHEX();
365:                 }
366:•                if (validationStyleProperty != null) {
367:                         colorHex = validationStyleProperty.getWarningColorHEX();
368:                 }
369:                 return colorHex;
370:         }
371:
372:         private String getWarningForegroundColorHEX(VTValidationStyleProperty defaultStyle, VElement vElement,
373:                 ViewModelContext viewModelContext) {
374:                 String colorHex = null;
375:                 final VTValidationStyleProperty validationStyleProperty = getValidationStyleProperty(vElement,
376:                         viewModelContext);
377:•                if (defaultStyle != null) {
378:                         colorHex = defaultStyle.getWarningForegroundColorHEX();
379:                 }
380:•                if (validationStyleProperty != null) {
381:                         colorHex = validationStyleProperty.getWarningForegroundColorHEX();
382:                 }
383:                 return colorHex;
384:         }
385:
386:         private String getErrorColorHEX(VTValidationStyleProperty defaultStyle, VElement vElement,
387:                 ViewModelContext viewModelContext) {
388:                 String colorHex = null;
389:                 final VTValidationStyleProperty validationStyleProperty = getValidationStyleProperty(vElement,
390:                         viewModelContext);
391:•                if (defaultStyle != null) {
392:                         colorHex = defaultStyle.getErrorColorHEX();
393:                 }
394:•                if (validationStyleProperty != null) {
395:                         colorHex = validationStyleProperty.getErrorColorHEX();
396:                 }
397:                 return colorHex;
398:         }
399:
400:         private String getErrorForegroundColorHEX(VTValidationStyleProperty defaultStyle, VElement vElement,
401:                 ViewModelContext viewModelContext) {
402:                 String colorHex = null;
403:                 final VTValidationStyleProperty validationStyleProperty = getValidationStyleProperty(vElement,
404:                         viewModelContext);
405:•                if (defaultStyle != null) {
406:                         colorHex = defaultStyle.getErrorForegroundColorHEX();
407:                 }
408:•                if (validationStyleProperty != null) {
409:                         colorHex = validationStyleProperty.getErrorForegroundColorHEX();
410:                 }
411:                 return colorHex;
412:         }
413:
414:         private String getCancelColorHEX(VTValidationStyleProperty defaultStyle, VElement vElement,
415:                 ViewModelContext viewModelContext) {
416:                 String colorHex = null;
417:                 final VTValidationStyleProperty validationStyleProperty = getValidationStyleProperty(vElement,
418:                         viewModelContext);
419:•                if (defaultStyle != null) {
420:                         colorHex = defaultStyle.getCancelColorHEX();
421:                 }
422:•                if (validationStyleProperty != null) {
423:                         colorHex = validationStyleProperty.getCancelColorHEX();
424:                 }
425:                 return colorHex;
426:         }
427:
428:         private String getCancelForegroundColorHEX(VTValidationStyleProperty defaultStyle, VElement vElement,
429:                 ViewModelContext viewModelContext) {
430:                 String colorHex = null;
431:                 final VTValidationStyleProperty validationStyleProperty = getValidationStyleProperty(vElement,
432:                         viewModelContext);
433:•                if (defaultStyle != null) {
434:                         colorHex = defaultStyle.getCancelForegroundColorHEX();
435:                 }
436:•                if (validationStyleProperty != null) {
437:                         colorHex = validationStyleProperty.getCancelForegroundColorHEX();
438:                 }
439:                 return colorHex;
440:         }
441:
442:         private String getOkImageURL(VTValidationStyleProperty defaultStyle, VElement vElement,
443:                 ViewModelContext viewModelContext) {
444:                 String imageURL = null;
445:                 final VTValidationStyleProperty validationStyleProperty = getValidationStyleProperty(vElement,
446:                         viewModelContext);
447:•                if (defaultStyle != null) {
448:                         imageURL = defaultStyle.getOkImageURL();
449:                 }
450:•                if (validationStyleProperty != null) {
451:                         imageURL = validationStyleProperty.getOkImageURL();
452:                 }
453:                 return imageURL;
454:         }
455:
456:         private String getInfoImageURL(VTValidationStyleProperty defaultStyle, VElement vElement,
457:                 ViewModelContext viewModelContext) {
458:                 String imageURL = null;
459:                 final VTValidationStyleProperty validationStyleProperty = getValidationStyleProperty(vElement,
460:                         viewModelContext);
461:•                if (defaultStyle != null) {
462:                         imageURL = defaultStyle.getInfoImageURL();
463:                 }
464:•                if (validationStyleProperty != null) {
465:                         imageURL = validationStyleProperty.getInfoImageURL();
466:                 }
467:                 return imageURL;
468:         }
469:
470:         private String getWarningImageURL(VTValidationStyleProperty defaultStyle, VElement vElement,
471:                 ViewModelContext viewModelContext) {
472:                 String imageURL = null;
473:                 final VTValidationStyleProperty validationStyleProperty = getValidationStyleProperty(vElement,
474:                         viewModelContext);
475:•                if (defaultStyle != null) {
476:                         imageURL = defaultStyle.getWarningImageURL();
477:                 }
478:•                if (validationStyleProperty != null) {
479:                         imageURL = validationStyleProperty.getWarningImageURL();
480:                 }
481:                 return imageURL;
482:         }
483:
484:         private String getErrorImageURL(VTValidationStyleProperty defaultStyle, VElement vElement,
485:                 ViewModelContext viewModelContext) {
486:                 String imageURL = null;
487:                 final VTValidationStyleProperty validationStyleProperty = getValidationStyleProperty(vElement,
488:                         viewModelContext);
489:•                if (defaultStyle != null) {
490:                         imageURL = defaultStyle.getErrorImageURL();
491:                 }
492:•                if (validationStyleProperty != null) {
493:                         imageURL = validationStyleProperty.getErrorImageURL();
494:                 }
495:                 return imageURL;
496:         }
497:
498:         private String getCancelImageURL(VTValidationStyleProperty defaultStyle, VElement vElement,
499:                 ViewModelContext viewModelContext) {
500:                 String imageURL = null;
501:                 final VTValidationStyleProperty validationStyleProperty = getValidationStyleProperty(vElement,
502:                         viewModelContext);
503:•                if (defaultStyle != null) {
504:                         imageURL = defaultStyle.getCancelImageURL();
505:                 }
506:•                if (validationStyleProperty != null) {
507:                         imageURL = validationStyleProperty.getCancelImageURL();
508:                 }
509:                 return imageURL;
510:         }
511:
512:         private String getOkOverlayURL(VTValidationStyleProperty defaultStyle, VElement vElement,
513:                 ViewModelContext viewModelContext) {
514:                 String overlayURL = null;
515:                 final VTValidationStyleProperty validationStyleProperty = getValidationStyleProperty(vElement,
516:                         viewModelContext);
517:•                if (defaultStyle != null) {
518:                         overlayURL = defaultStyle.getOkOverlayURL();
519:                 }
520:•                if (validationStyleProperty != null) {
521:                         overlayURL = validationStyleProperty.getOkOverlayURL();
522:                 }
523:                 return overlayURL;
524:         }
525:
526:         private String getInfoOverlayURL(VTValidationStyleProperty defaultStyle, VElement vElement,
527:                 ViewModelContext viewModelContext) {
528:                 String overlayURL = null;
529:                 final VTValidationStyleProperty validationStyleProperty = getValidationStyleProperty(vElement,
530:                         viewModelContext);
531:•                if (defaultStyle != null) {
532:                         overlayURL = defaultStyle.getInfoOverlayURL();
533:                 }
534:•                if (validationStyleProperty != null) {
535:                         overlayURL = validationStyleProperty.getInfoOverlayURL();
536:                 }
537:                 return overlayURL;
538:         }
539:
540:         private String getWarningOverlayURL(VTValidationStyleProperty defaultStyle, VElement vElement,
541:                 ViewModelContext viewModelContext) {
542:                 String overlayURL = null;
543:                 final VTValidationStyleProperty validationStyleProperty = getValidationStyleProperty(vElement,
544:                         viewModelContext);
545:•                if (defaultStyle != null) {
546:                         overlayURL = defaultStyle.getWarningOverlayURL();
547:                 }
548:•                if (validationStyleProperty != null) {
549:                         overlayURL = validationStyleProperty.getWarningOverlayURL();
550:                 }
551:                 return overlayURL;
552:         }
553:
554:         private String getErrorOverlayURL(VTValidationStyleProperty defaultStyle, VElement vElement,
555:                 ViewModelContext viewModelContext) {
556:                 String overlayURL = null;
557:                 final VTValidationStyleProperty validationStyleProperty = getValidationStyleProperty(vElement,
558:                         viewModelContext);
559:•                if (defaultStyle != null) {
560:                         overlayURL = defaultStyle.getErrorOverlayURL();
561:                 }
562:•                if (validationStyleProperty != null) {
563:                         overlayURL = validationStyleProperty.getErrorOverlayURL();
564:                 }
565:                 return overlayURL;
566:         }
567:
568:         private String getCancelOverlayURL(VTValidationStyleProperty defaultStyle, VElement vElement,
569:                 ViewModelContext viewModelContext) {
570:                 String overlayURL = null;
571:                 final VTValidationStyleProperty validationStyleProperty = getValidationStyleProperty(vElement,
572:                         viewModelContext);
573:•                if (defaultStyle != null) {
574:                         overlayURL = defaultStyle.getCancelOverlayURL();
575:                 }
576:•                if (validationStyleProperty != null) {
577:                         overlayURL = validationStyleProperty.getCancelOverlayURL();
578:                 }
579:                 return overlayURL;
580:         }
581:
582:         private VTValidationStyleProperty getValidationStyleProperty(VElement vElement, ViewModelContext viewModelContext) {
583:                 VTValidationStyleProperty validationStyleProperty = null;
584:•                if (vElement != null && viewModelContext != null) {
585:                         final VTViewTemplateProvider vtViewTemplateProvider = Activator.getDefault().getVTViewTemplateProvider();
586:•                        if (vtViewTemplateProvider == null) {
587:                                 return validationStyleProperty;
588:                         }
589:                         final Set<VTStyleProperty> styleProperties = vtViewTemplateProvider.getStyleProperties(vElement,
590:                                 viewModelContext);
591:•                        for (final VTStyleProperty styleProperty : styleProperties) {
592:•                                if (VTValidationStyleProperty.class.isInstance(styleProperty)) {
593:                                         validationStyleProperty = VTValidationStyleProperty.class
594:                                                 .cast(styleProperty);
595:                                         break;
596:                                 }
597:                         }
598:                 }
599:                 return validationStyleProperty;
600:         }
601:
602:         /**
603:          * @return The default validation style to apply if none is specified for a {@link VElement}.
604:          */
605:         private VTValidationStyleProperty getDefaultValidationStyle() {
606:•                if (defaultValidationStyle == null) {
607:                         defaultValidationStyle = VTValidationFactory.eINSTANCE.createValidationStyleProperty();
608:                         defaultValidationStyle.setOkColorHEX("ffffff"); //$NON-NLS-1$
609:                         defaultValidationStyle.setErrorColorHEX("ff0000"); //$NON-NLS-1$
610:                         defaultValidationStyle.setWarningColorHEX("FFD800");//$NON-NLS-1$
611:                         defaultValidationStyle.setErrorImageURL(Activator.getDefault().getBundle()
612:                                 .getResource("icons/validation_error.png").toExternalForm()); //$NON-NLS-1$
613:                         defaultValidationStyle.setErrorOverlayURL(Activator.getDefault().getBundle()
614:                                 .getResource("icons/error_decorate.png").toExternalForm()); //$NON-NLS-1$
615:                         defaultValidationStyle.setWarningImageURL(Activator.getDefault().getBundle()
616:                                 .getResource("icons/validation_warning.png").toExternalForm()); //$NON-NLS-1$
617:                         defaultValidationStyle.setWarningOverlayURL(Activator.getDefault().getBundle()
618:                                 .getResource("icons/warning_decorate.png").toExternalForm()); //$NON-NLS-1$
619:                         defaultValidationStyle.setInfoOverlayURL(Activator.getDefault().getBundle()
620:                                 .getResource("icons/info_decorate.gif").toExternalForm()); //$NON-NLS-1$
621:                 }
622:                 return defaultValidationStyle;
623:         }
624:
625:         /**
626:          * @param colorHex
627:          * @return
628:          */
629:         private Color getColor(String colorHex) {
630:                 final String redString = colorHex.substring(0, 2);
631:                 final String greenString = colorHex.substring(2, 4);
632:                 final String blueString = colorHex.substring(4, 6);
633:                 final int red = Integer.parseInt(redString, 16);
634:                 final int green = Integer.parseInt(greenString, 16);
635:                 final int blue = Integer.parseInt(blueString, 16);
636:                 return new Color(Display.getDefault(), red, green, blue);
637:         }
638:
639: }