Skip to content

Package: ValidationProvider

ValidationProvider

nameinstructionbranchcomplexitylinemethod
setContext(ViewModelContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
unsetContext(ViewModelContext)
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
validate(ViewModelContext, EObject)
M: 0 C: 4
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-2019 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: * Eugen Neufeld - initial API and implementation
13: * Christian W. Damus - bug 552715
14: ******************************************************************************/
15: package org.eclipse.emf.ecp.view.spi.validation;
16:
17: import java.util.List;
18:
19: import org.eclipse.emf.common.util.Diagnostic;
20: import org.eclipse.emf.ecore.EObject;
21: import org.eclipse.emf.ecp.view.spi.context.ViewModelContext;
22: import org.eclipse.emfforms.common.spi.validation.Validator;
23:
24: /**
25: * <p>
26: * The ValidationService calls the providers after the validation with EMF.
27: * By providing an own provider, one can extend the EMF validation by providing additional validation rules.
28: * </p>
29: * <p>
30: * As of the 1.23 release, for validation that requires the current view model context, consider using a subclass of the
31: * nested {@link ContextSensitive} class.
32: * </p>
33: *
34: * @author Eugen Neufeld
35: * @since 1.5
36: *
37: */
38: public interface ValidationProvider extends Validator {
39:
40:         /**
41:          * Initialize me in the view model {@code context} of the {@link ValidationService} to which I have been added.
42:          * Note that I could be added to validation services in more than one context.
43:          *
44:          * @param context the context of the {@link ValidationService} to which I have been added
45:          *
46:          * @since 1.23
47:          */
48:         default void setContext(ViewModelContext context) {
49:                 // Nothing to do
50:         }
51:
52:         /**
53:          * Notify me that I have been removed from the {@link ValidationService} in the given {@code context}.
54:          * Note that I may still be used in validation services in other contexts.
55:          *
56:          * @param context the context of the {@link ValidationService} from which I have been removed
57:          *
58:          * @since 1.23
59:          */
60:         default void unsetContext(ViewModelContext context) {
61:                 // Nothing to do
62:         }
63:
64:         /**
65:          * Validate an {@code object} in a view model {@code context}.
66:          *
67:          * @param context the view model context in which validation is occurring
68:          * @param object the object to validate
69:          * @return the results of validation of the {@code object}, or {@code null} if none
70:          *
71:          * @since 1.23
72:          */
73:         default Iterable<? extends Diagnostic> validate(ViewModelContext context, EObject object) {
74:                 return validate(object);
75:         }
76:
77:         //
78:         // Nested types
79:         //
80:
81:         /**
82:          * A context-sensitive {@link ValidationProvider} that implements the
83:          * {@link ValidationProvider#validate(ViewModelContext, EObject)}
84:          * method to the exclusion of {@link Validator#validate(EObject)}.
85:          *
86:          * @since 1.23
87:          */
88:         abstract class ContextSensitive implements ValidationProvider {
89:
90:                 /**
91:                  * Initializes me.
92:                  */
93:                 public ContextSensitive() {
94:                         super();
95:                 }
96:
97:                 /**
98:                  * Un-implements the inherited method.
99:                  *
100:                  * @throws UnsupportedOperationException always
101:                  */
102:                 @Override
103:                 public final List<Diagnostic> validate(EObject eObject) {
104:                         throw new UnsupportedOperationException("validate(EObject)"); //$NON-NLS-1$
105:                 }
106:
107:                 @Override
108:                 public abstract Iterable<? extends Diagnostic> validate(ViewModelContext context, EObject object);
109:
110:         }
111:
112: }