Skip to content

Package: SWTValidationHelper

SWTValidationHelper

nameinstructionbranchcomplexitylinemethod
SWTValidationHelper()
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
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: 35 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%
getDefaultValidationStyle()
M: 62 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%
getErrorColorHEX(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%
getErrorForegroundColorHEX(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%
getErrorImageURL(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%
getErrorOverlayURL(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%
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: 19 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%
getOkColorHEX(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%
getOkForegroundColorHEX(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%
getOkImageURL(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%
getOkOverlayURL(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%
getValidationBackgroundColor(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%
getValidationBackgroundColor(int, VElement, ViewModelContext)
M: 78 C: 0
0%
M: 10 C: 0
0%
M: 8 C: 0
0%
M: 20 C: 0
0%
M: 1 C: 0
0%
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: 78 C: 0
0%
M: 10 C: 0
0%
M: 8 C: 0
0%
M: 20 C: 0
0%
M: 1 C: 0
0%
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: 68 C: 0
0%
M: 8 C: 0
0%
M: 7 C: 0
0%
M: 20 C: 0
0%
M: 1 C: 0
0%
getValidationOverlayDescriptor(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%
getValidationOverlayDescriptor(int, VElement, ViewModelContext)
M: 68 C: 0
0%
M: 8 C: 0
0%
M: 7 C: 0
0%
M: 20 C: 0
0%
M: 1 C: 0
0%
getValidationStyleProperty(VElement, ViewModelContext)
M: 41 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 13 C: 0
0%
M: 1 C: 0
0%
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: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

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