Skip to content

Package: EditorContext$IECPProjectsChangedUIObserverImplementation

EditorContext$IECPProjectsChangedUIObserverImplementation

nameinstructionbranchcomplexitylinemethod
EditorContext.IECPProjectsChangedUIObserverImplementation(EditorContext)
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%
contentTouched(ECPProject, Collection, boolean)
M: 34 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
projectChanged(ECPProject, boolean)
M: 21 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
projectsChanged(Collection, Collection)
M: 25 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2012 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: *
14: *******************************************************************************/
15: package org.eclipse.emf.ecp.explorereditorbridge.internal;
16:
17: import java.util.ArrayList;
18: import java.util.Collection;
19: import java.util.List;
20:
21: import org.eclipse.emf.ecore.EObject;
22: import org.eclipse.emf.ecp.core.ECPProject;
23: import org.eclipse.emf.ecp.core.util.ECPUtil;
24: import org.eclipse.emf.ecp.core.util.observer.ECPProjectContentTouchedObserver;
25: import org.eclipse.emf.ecp.core.util.observer.ECPProjectOpenClosedObserver;
26: import org.eclipse.emf.ecp.core.util.observer.ECPProjectsChangedObserver;
27: import org.eclipse.emf.ecp.edit.spi.ECPContextDisposedListener;
28: import org.eclipse.emf.ecp.editor.e3.ECPEditorContext;
29: import org.eclipse.emf.ecp.spi.core.InternalProject;
30:
31: /**
32: * An EditorContext depending on an {@link ECPProject}.
33: *
34: * @author Eugen Neufeld
35: *
36: */
37: public class EditorContext implements ECPEditorContext {
38:
39:         /**
40:          * @author Jonas
41:          *
42:          */
43:         private final class IECPProjectsChangedUIObserverImplementation implements ECPProjectsChangedObserver,
44:                 ECPProjectOpenClosedObserver, ECPProjectContentTouchedObserver {
45:                 /** {@inheritDoc} */
46:                 @Override
47:                 public void projectsChanged(Collection<ECPProject> oldProjects, Collection<ECPProject> newProjects) {
48:                         // TODO Auto-generated method stub
49:•                        if (!newProjects.contains(ecpProject)) {
50:•                                for (final ECPContextDisposedListener contextListener : contextListeners) {
51:                                         contextListener.contextDisposed();
52:                                 }
53:                                 dispose();
54:                         }
55:                 }
56:
57:                 /** {@inheritDoc} */
58:                 @Override
59:                 public void projectChanged(ECPProject project, boolean opened) {
60:•                        if (!opened) {
61:•                                for (final ECPContextDisposedListener contextListener : contextListeners) {
62:                                         contextListener.contextDisposed();
63:                                 }
64:                                 dispose();
65:                         }
66:                 }
67:
68:                 /** {@inheritDoc} */
69:                 @Override
70:                 public void contentTouched(ECPProject project, Collection<Object> objects, boolean structural) {
71:                         // if we have a structural change (otherwise nothing should be closed), and the change is in our project
72:                         // and our model element is no longer contained
73:                         // then we notify about deletion and dispose ourself
74:•                        if (structural && ecpProject.equals(project) && !((InternalProject) project).contains(getDomainObject())) {
75:•                                for (final ECPContextDisposedListener contextListener : contextListeners) {
76:                                         contextListener.contextDisposed();
77:                                 }
78:                                 dispose();
79:                         }
80:                 }
81:         }
82:
83:         private final List<ECPContextDisposedListener> contextListeners = new ArrayList<ECPContextDisposedListener>();
84:
85:         private final ECPProjectsChangedObserver projectObserver;
86:
87:         private final ECPProject ecpProject;
88:
89:         private final EObject modelElement;
90:
91:         /**
92:          * Default constructor.
93:          *
94:          * @param modelElement the model element to be displayed in the editor
95:          * @param ecpProject the {@link ECPProject} containing the model element
96:          */
97:         public EditorContext(EObject modelElement, ECPProject ecpProject) {
98:                 this.modelElement = modelElement;
99:                 this.ecpProject = ecpProject;
100:                 projectObserver = new IECPProjectsChangedUIObserverImplementation();
101:                 ECPUtil.getECPObserverBus().register(projectObserver);
102:         }
103:
104:         /** {@inheritDoc} */
105:         @Override
106:         public void addECPContextDisposeListener(ECPContextDisposedListener modelElementContextListener) {
107:                 contextListeners.add(modelElementContextListener);
108:         }
109:
110:         /**
111:          * Dispose the context.
112:          */
113:         @Override
114:         public void dispose() {
115:                 ECPUtil.getECPObserverBus().unregister(projectObserver);
116:                 contextListeners.clear();
117:         }
118:
119:         /**
120:          * {@inheritDoc}
121:          *
122:          * @see org.eclipse.emf.ecp.editor.e3.ECPEditorContext#getDomainObject()
123:          */
124:         @Override
125:         public EObject getDomainObject() {
126:                 return modelElement;
127:         }
128:
129: }