Skip to content

Package: ECPValidationServiceLabelDecorator

ECPValidationServiceLabelDecorator

nameinstructionbranchcomplexitylinemethod
ECPValidationServiceLabelDecorator(TreeViewer, Notifier, DiagnosticCache)
M: 0 C: 25
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
addListener(ILabelProviderListener)
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%
decorateImage(Image, Object)
M: 4 C: 56
93%
M: 2 C: 6
75%
M: 2 C: 3
60%
M: 2 C: 13
87%
M: 0 C: 1
100%
decorateText(String, Object)
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
dispose()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
isLabelProperty(Object, String)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
refreshViewer(EObject)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
removeListener(ILabelProviderListener)
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%
updateViewer(EObject)
M: 0 C: 6
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-2018 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: * Christian W. Damus - bug 533522
14: ******************************************************************************/
15: package org.eclipse.emfforms.internal.swt.treemasterdetail.decorator.validation.ecp;
16:
17: import java.util.Collection;
18:
19: import org.eclipse.emf.common.notify.Notifier;
20: import org.eclipse.emf.ecore.EObject;
21: import org.eclipse.emf.ecore.resource.Resource;
22: import org.eclipse.emfforms.spi.swt.core.ui.SWTValidationHelper;
23: import org.eclipse.emfforms.spi.swt.treemasterdetail.diagnostic.DiagnosticCache;
24: import org.eclipse.emfforms.spi.swt.treemasterdetail.diagnostic.DiagnosticCache.ValidationListener;
25: import org.eclipse.jface.resource.DeviceResourceManager;
26: import org.eclipse.jface.resource.ImageDescriptor;
27: import org.eclipse.jface.resource.ResourceManager;
28: import org.eclipse.jface.viewers.DecorationOverlayIcon;
29: import org.eclipse.jface.viewers.ILabelDecorator;
30: import org.eclipse.jface.viewers.ILabelProviderListener;
31: import org.eclipse.jface.viewers.TreeViewer;
32: import org.eclipse.swt.graphics.Image;
33: import org.eclipse.swt.graphics.Point;
34: import org.eclipse.swt.graphics.Rectangle;
35:
36: /**
37: * Decorator showing diagnostics.
38: *
39: * @author Johannes Faltermeier
40: *
41: */
42: public class ECPValidationServiceLabelDecorator implements ILabelDecorator {
43:
44:         private final DiagnosticCache cache;
45:         private final TreeViewer viewer;
46:
47:         private final ResourceManager images;
48:
49:         /**
50:          * Default constructor.
51:          *
52:          * @param viewer the {@link TreeViewer}
53:          * @param input the input notifier
54:          * @param cache the {@link DiagnosticCache}
55:          */
56:         public ECPValidationServiceLabelDecorator(TreeViewer viewer, Notifier input, DiagnosticCache cache) {
57:                 this.viewer = viewer;
58:                 this.cache = cache;
59:                 images = new DeviceResourceManager(viewer.getControl().getDisplay());
60:
61:                 cache.registerValidationListener(new ValidationListener() {
62:
63:                         @Override
64:                         public void revalidationOccurred(Collection<EObject> object, boolean potentialStructuralChange) {
65:                                 if (potentialStructuralChange) {
66:                                         for (final EObject o : object) {
67:                                                 refreshViewer(o);
68:                                         }
69:                                 } else {
70:                                         for (final EObject o : object) {
71:                                                 updateViewer(o);
72:                                         }
73:                                 }
74:                         }
75:                 });
76:                 viewer.refresh();
77:         }
78:
79:         @Override
80:         public Image decorateImage(Image image, Object element) {
81:•                if (image == null) {
82:                         return image;
83:                 }
84:•                if (!EObject.class.isInstance(element) && !Resource.class.isInstance(element)) {
85:                         return image;
86:                 }
87:
88:                 final org.eclipse.emf.common.util.Diagnostic diagnostic = cache.getCachedValue(element);
89:                 final int severity = diagnostic.getSeverity();
90:                 final ImageDescriptor validationOverlayDescriptor = SWTValidationHelper.INSTANCE
91:                         .getValidationOverlayDescriptor(severity);
92:•                if (validationOverlayDescriptor == null) {
93:                         return image;
94:                 }
95:                 final Rectangle bounds = image.getBounds();
96:                 final Point size = new Point(bounds.width, bounds.height);
97:                 final DecorationOverlayIcon icon = new DecorationOverlayIcon(image,
98:                         new ImageDescriptor[] { validationOverlayDescriptor }, size);
99:                 return (Image) images.get(icon);
100:         }
101:
102:         /**
103:          * Called in order to update the cache. This also triggers a viewer refresh.
104:          *
105:          * @param element The element which changed
106:          */
107:         protected void refreshViewer(EObject element) {
108:                 viewer.refresh(element, true);
109:         }
110:
111:         /**
112:          * Called in order to update the cache. This also triggers a viewer update.
113:          *
114:          * @param element The element which changed
115:          */
116:         protected void updateViewer(EObject element) {
117:                 viewer.update(element, null);
118:         }
119:
120:         @Override
121:         public String decorateText(String text, Object element) {
122:                 /* no op */
123:                 return text;
124:         }
125:
126:         @Override
127:         public void addListener(ILabelProviderListener listener) {
128:                 /* no op */
129:         }
130:
131:         @Override
132:         public boolean isLabelProperty(Object element, String property) {
133:                 /* no op */
134:                 return false;
135:         }
136:
137:         @Override
138:         public void removeListener(ILabelProviderListener listener) {
139:                 /* no op */
140:         }
141:
142:         @Override
143:         public void dispose() {
144:                 cache.dispose();
145:                 images.dispose();
146:         }
147:
148: }