Skip to content

Package: ECPContentProvider

ECPContentProvider

nameinstructionbranchcomplexitylinemethod
ECPContentProvider()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
dispose()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
fillChildren(Object, InternalChildrenList)
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
getModelContext(Object)
M: 14 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
notifyChanged(Notification)
M: 34 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /********************************************************************************
2: * Copyright (c) 2011 Eike Stepper (Berlin, Germany) 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: * Eike Stepper - initial API and implementation
13: ********************************************************************************/
14: package org.eclipse.emf.ecp.internal.ui.model;
15:
16: import org.eclipse.emf.common.notify.Notification;
17: import org.eclipse.emf.ecp.core.util.ECPContainer;
18: import org.eclipse.emf.ecp.core.util.ECPModelContextProvider;
19: import org.eclipse.emf.ecp.spi.core.InternalProvider;
20: import org.eclipse.emf.ecp.spi.core.util.InternalChildrenList;
21: import org.eclipse.emf.edit.provider.INotifyChangedListener;
22: import org.eclipse.emf.edit.provider.IViewerNotification;
23: import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider.ViewerRefresh;
24: import org.eclipse.jface.viewers.TreeViewer;
25:
26: /**
27: * @author Eike Stepper
28: * @param <INPUT> The type of input (root of the tree)
29: */
30: public abstract class ECPContentProvider<INPUT> extends TreeContentProvider<INPUT> implements ECPModelContextProvider,
31:         INotifyChangedListener {
32:         private ViewerRefresh viewerRefresh;
33:
34:         /**
35:          * Default constructor.
36:          */
37:         public ECPContentProvider() {
38:                 InternalProvider.EMF_ADAPTER_FACTORY.addListener(this);
39:         }
40:
41:         @Override
42:         public void dispose() {
43:                 InternalProvider.EMF_ADAPTER_FACTORY.removeListener(this);
44:                 super.dispose();
45:         }
46:
47:         @Override
48:         protected void fillChildren(Object parent, InternalChildrenList childrenList) {
49:                 final ECPContainer context = getModelContext(parent);
50:•                if (context != null) {
51:                         final InternalProvider provider = (InternalProvider) context.getProvider();
52:                         provider.fillChildren(context, parent, childrenList);
53:                 }
54:         }
55:
56:         /** {@inheritDoc} */
57:         @Override
58:         public ECPContainer getModelContext(Object element) {
59:•                while (element != null) {
60:•                        if (element instanceof ECPContainer) {
61:                                 break;
62:                         }
63:
64:                         element = getParent(element);
65:                 }
66:
67:                 return (ECPContainer) element;
68:         }
69:
70:         /** {@inheritDoc} */
71:         @Override
72:         public void notifyChanged(Notification notification) {
73:                 final TreeViewer viewer = getViewer();
74:•                if (viewer != null && viewer.getControl() != null && !viewer.getControl().isDisposed()) {
75:•                        if (viewerRefresh == null) {
76:                                 viewerRefresh = new ViewerRefresh(viewer);
77:                         }
78:
79:•                        if (viewerRefresh.addNotification((IViewerNotification) notification)) {
80:                                 viewer.getControl().getDisplay().asyncExec(viewerRefresh);
81:                         }
82:                 }
83:         }
84: }