Skip to content

Package: ValidationContentProvider

ValidationContentProvider

nameinstructionbranchcomplexitylinemethod
ValidationContentProvider()
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
dispose()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
getChildren(Object)
M: 0 C: 36
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
getElements(Object)
M: 19 C: 7
27%
M: 5 C: 1
17%
M: 3 C: 1
25%
M: 5 C: 2
29%
M: 0 C: 1
100%
getParent(Object)
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%
hasChildren(Object)
M: 0 C: 11
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
inputChanged(Viewer, Object, Object)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2014 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: ******************************************************************************/
14: package org.eclipse.emf.ecp.internal.ui.validation;
15:
16: import java.util.LinkedHashMap;
17: import java.util.List;
18: import java.util.Map;
19:
20: import org.eclipse.emf.common.util.Diagnostic;
21: import org.eclipse.jface.viewers.ITreeContentProvider;
22: import org.eclipse.jface.viewers.Viewer;
23:
24: /**
25: * {@link ITreeContentProvider} for displaying {@link org.eclipse.emf.common.util.Diagnostic Diagnostics}.
26: *
27: * @author jfaltermeier
28: *
29: */
30: public class ValidationContentProvider implements ITreeContentProvider {
31:
32:         private final Map<Object, Object> diagnosticToParentMap;
33:
34:         /**
35:          * Default constructor.
36:          */
37:         public ValidationContentProvider() {
38:                 diagnosticToParentMap = new LinkedHashMap<Object, Object>();
39:         }
40:
41:         /**
42:          * {@inheritDoc}
43:          *
44:          * @see org.eclipse.jface.viewers.IContentProvider#dispose()
45:          */
46:         @Override
47:         public void dispose() {
48:                 diagnosticToParentMap.clear();
49:         }
50:
51:         /**
52:          * {@inheritDoc}
53:          *
54:          * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object,
55:          * java.lang.Object)
56:          */
57:         @Override
58:         public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
59:                 diagnosticToParentMap.clear();
60:         }
61:
62:         /**
63:          * {@inheritDoc}
64:          *
65:          * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
66:          */
67:         @Override
68:         public Object[] getElements(Object inputElement) {
69:•                if (inputElement instanceof Diagnostic) {
70:                         return getChildren(inputElement);
71:                 }
72:•                if (inputElement instanceof Diagnostic[]) {
73:                         return (Diagnostic[]) inputElement;
74:                 }
75:•                if (inputElement instanceof List<?>) {
76:                         return ((List<?>) inputElement).toArray(new Diagnostic[((List<?>) inputElement).size()]);
77:                 }
78:                 return null;
79:         }
80:
81:         /**
82:          * {@inheritDoc}
83:          *
84:          * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
85:          */
86:         @Override
87:         public Object[] getChildren(Object parentElement) {
88:                 final Diagnostic diagnostic = (Diagnostic) parentElement;
89:                 final Diagnostic[] childDiagnostics = diagnostic.getChildren().toArray(
90:                         new Diagnostic[diagnostic.getChildren().size()]);
91:•                for (final Diagnostic child : childDiagnostics) {
92:                         diagnosticToParentMap.put(child, diagnostic);
93:                 }
94:                 return childDiagnostics;
95:         }
96:
97:         /**
98:          * {@inheritDoc}
99:          *
100:          * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
101:          */
102:         @Override
103:         public Object getParent(Object element) {
104:                 return diagnosticToParentMap.get(element);
105:         }
106:
107:         /**
108:          * {@inheritDoc}
109:          *
110:          * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
111:          */
112:         @Override
113:         public boolean hasChildren(Object element) {
114:                 final Diagnostic diagnostic = (Diagnostic) element;
115:•                return diagnostic.getChildren().size() > 0 ? true : false;
116:         }
117:
118: }