Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 397846
Collapse All | Expand All

(-)src/org/eclipse/emf/ecp/emfstore/internal/ui/decorator/EMFStoreDirtyDecoratorCachedTree.java (-2 / +11 lines)
Lines 79-89 Link Here
79
		public void update() {
79
		public void update() {
80
			for (EMFStoreDirtyTreeNode node : values()) {
80
			for (EMFStoreDirtyTreeNode node : values()) {
81
				if (node.getChangeCount() > 0 || node.isChildChanges()) {
81
				if (node.getChangeCount() > 0 || node.isChildChanges()) {
82
					getValue().setChildChanges(true);
82
					getOwnValue().setChildChanges(true);
83
					return;
83
					return;
84
				}
84
				}
85
			}
85
			}
86
			getValue().setChildChanges(false);
86
			getOwnValue().setChildChanges(false);
87
		}
88
89
		/*
90
		 * (non-Javadoc)
91
		 * @see org.eclipse.emf.ecp.ui.common.CachedTreeNode#getDisplayValue()
92
		 */
93
		@Override
94
		public EMFStoreDirtyTreeNode getDisplayValue() {
95
			return getOwnValue();
87
		}
96
		}
88
	}
97
	}
89
98
(-)src/org/eclipse/emf/ecp/ui/common/AbstractCachedTree.java (-8 / +35 lines)
Lines 31-36 Link Here
31
 * @param <T> the actual value type that is stored by the tree
31
 * @param <T> the actual value type that is stored by the tree
32
 * 
32
 * 
33
 * @author emueller
33
 * @author emueller
34
 * @author Tobias Verhoeven
34
 */
35
 */
35
public abstract class AbstractCachedTree<T> {
36
public abstract class AbstractCachedTree<T> {
36
37
Lines 85-100 Link Here
85
		updateNode(eObject, value);
86
		updateNode(eObject, value);
86
		rootValue.putIntoCache(eObject, value);
87
		rootValue.putIntoCache(eObject, value);
87
88
88
		Set<EObject> affectedElements = new HashSet<EObject>();
89
		Set<EObject> affectedElements = removeOutdatedParentCacheIfNeeded(eObject);
89
		// propagate upwards
90
		// propagate upwards
90
		EObject parent = eObject.eContainer();
91
		EObject parent = eObject.eContainer();
91
92
92
		while (parent != null && !excludedCallback.isExcluded(parent)) {// !isExcludedType(excludedTypes,
93
		while (parent != null && !excludedCallback.isExcluded(parent)) {// !isExcludedType(excludedTypes,
93
																		// parent.getClass())
94
																		// parent.getClass())
94
			updateParentNode(parent, eObject, value);
95
			updateParentNode(parent, eObject, nodes.get(eObject).getDisplayValue());
95
			eObject = parent;
96
			eObject = parent;
96
			parent = parent.eContainer();
97
			parent = parent.eContainer();
97
			affectedElements.add(eObject);
98
			affectedElements.add(eObject);
99
		}
100
		return affectedElements;
101
	}
102
103
	// If an object has been moved the cached entries must be removed from old parents.
104
	private Set<EObject> removeOutdatedParentCacheIfNeeded(EObject eObject) {
105
106
		Set<EObject> affectedElements = new HashSet<EObject>();
107
		CachedTreeNode<T> node = nodes.get(eObject);
108
109
		if (node.getParent() != null && node.getParent() != eObject.eContainer()) {
110
			EObject oldParent = (EObject) node.getParent();
111
			while (oldParent != null && !excludedCallback.isExcluded(oldParent)) {
112
				affectedElements.add(oldParent);
113
				node = nodes.get(oldParent);
114
				node.removeFromCache(eObject);
115
				oldParent = oldParent.eContainer();
116
				eObject = oldParent;
117
			}
98
		}
118
		}
99
		return affectedElements;
119
		return affectedElements;
100
	}
120
	}
Lines 106-112 Link Here
106
	 * @return the node
126
	 * @return the node
107
	 */
127
	 */
108
	public T getRootValue() {
128
	public T getRootValue() {
109
		return rootValue.getValue();
129
		return rootValue.getDisplayValue();
110
	}
130
	}
111
131
112
	/**
132
	/**
Lines 122-128 Link Here
122
		CachedTreeNode<T> nodeEntry = nodes.get(eObject);
142
		CachedTreeNode<T> nodeEntry = nodes.get(eObject);
123
143
124
		if (nodeEntry != null) {
144
		if (nodeEntry != null) {
125
			return nodes.get(eObject).getValue();
145
			return nodes.get(eObject).getDisplayValue();
126
		}
146
		}
127
147
128
		return getDefaultValue();
148
		return getDefaultValue();
Lines 137-143 Link Here
137
	public void remove(EObject eObject) {
157
	public void remove(EObject eObject) {
138
158
139
		CachedTreeNode<T> node = nodes.get(eObject);
159
		CachedTreeNode<T> node = nodes.get(eObject);
140
		CachedTreeNode<T> parentNode = nodes.get(node.parent);
160
		CachedTreeNode<T> parentNode = nodes.get(node.getParent());
141
161
142
		nodes.remove(eObject);
162
		nodes.remove(eObject);
143
		rootValue.removeFromCache(eObject);
163
		rootValue.removeFromCache(eObject);
Lines 167-173 Link Here
167
			node = createNodeEntry(object, t);
187
			node = createNodeEntry(object, t);
168
		}
188
		}
169
189
170
		node.setValue(t);
190
		node.setOwnValue(t);
171
	}
191
	}
172
192
173
	private CachedTreeNode<T> createNodeEntry(Object object, T t) {
193
	private CachedTreeNode<T> createNodeEntry(Object object, T t) {
Lines 176-192 Link Here
176
		return node;
196
		return node;
177
	}
197
	}
178
198
199
	/**
200
	 * Updates the passed parent nodes cached value.
201
	 * 
202
	 * @param parent the parent object to be updated
203
	 * @param object the object for which the cached value should be changed.
204
	 * @param value the the cached value for the object
205
	 */
179
	protected void updateParentNode(Object parent, Object object, T value) {
206
	protected void updateParentNode(Object parent, Object object, T value) {
180
		CachedTreeNode<T> node = nodes.get(object);
207
		CachedTreeNode<T> node = nodes.get(object);
181
		CachedTreeNode<T> parentNode = nodes.get(parent);
208
		CachedTreeNode<T> parentNode = nodes.get(parent);
182
		node.parent = parent;
209
		node.setParent(parent);
183
210
184
		if (parentNode == null) {
211
		if (parentNode == null) {
185
			parentNode = createNodeEntry(parent, value);
212
			parentNode = createNodeEntry(parent, value);
186
		}
213
		}
187
214
188
		parentNode.putIntoCache(object, value);
215
		parentNode.putIntoCache(object, value);
189
		rootValue.putIntoCache(parent, value);
216
		rootValue.putIntoCache(parent, parentNode.getDisplayValue());
190
	}
217
	}
191
218
192
	/**
219
	/**
(-)src/org/eclipse/emf/ecp/ui/common/CachedTreeNode.java (-10 / +62 lines)
Lines 1-3 Link Here
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 v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 * 
9
 * Contributors:
10
 * 
11
 *******************************************************************************/
1
package org.eclipse.emf.ecp.ui.common;
12
package org.eclipse.emf.ecp.ui.common;
2
13
3
import java.util.Collection;
14
import java.util.Collection;
Lines 10-30 Link Here
10
 * @param <T> the type of the value stored by this node
21
 * @param <T> the type of the value stored by this node
11
 * 
22
 * 
12
 * @author emueller
23
 * @author emueller
24
 * @author Tobias Verhoeven
13
 */
25
 */
14
public abstract class CachedTreeNode<T> {
26
public abstract class CachedTreeNode<T> {
15
27
16
	private T value;
28
	private T ownValue;
29
	private T cachedChildrenValue;
17
	private Map<Object, T> cache;
30
	private Map<Object, T> cache;
18
	public Object parent;
31
	private Object parent;
19
32
20
	/**
33
	/**
21
	 * Constructor.
34
	 * Constructor.
22
	 * 
35
	 * 
23
	 * @param initialValue
36
	 * @param initialValue the initial value
24
	 *            the initial value
25
	 */
37
	 */
26
	public CachedTreeNode(T initialValue) {
38
	public CachedTreeNode(T initialValue) {
27
		this.value = initialValue;
39
		this.ownValue = initialValue;
28
		cache = new HashMap<Object, T>();
40
		cache = new HashMap<Object, T>();
29
	}
41
	}
30
42
Lines 63-70 Link Here
63
	 * 
75
	 * 
64
	 * @return the value stored within this node
76
	 * @return the value stored within this node
65
	 */
77
	 */
66
	public T getValue() {
78
	public T getOwnValue() {
67
		return value;
79
		return ownValue;
68
	}
80
	}
69
81
70
	/**
82
	/**
Lines 73-80 Link Here
73
	 * @param newValue
85
	 * @param newValue
74
	 *            the new value to be associated with this node
86
	 *            the new value to be associated with this node
75
	 */
87
	 */
76
	public void setValue(T newValue) {
88
	public void setOwnValue(T newValue) {
77
		this.value = newValue;
89
		this.ownValue = newValue;
78
	}
90
	}
79
91
80
	/**
92
	/**
Lines 85-88 Link Here
85
	public Collection<T> values() {
97
	public Collection<T> values() {
86
		return cache.values();
98
		return cache.values();
87
	}
99
	}
88
}
100
101
	/**
102
	 * Returns the most severe cached value of all children.
103
	 * 
104
	 * @return the childValue
105
	 */
106
	public T getChildValue() {
107
		return cachedChildrenValue;
108
	}
109
110
	/**
111
	 * Sets the the most severe cached value of all children.
112
	 * 
113
	 * @param childValue the childValue to set
114
	 */
115
	protected void setChildValue(T childValue) {
116
		this.cachedChildrenValue = childValue;
117
	}
118
119
	/**
120
	 * Returns the value that this node should represent.
121
	 * This value is also passed to parents in case of changes to the tree.
122
	 * 
123
	 * @return the display value
124
	 */
125
	public abstract T getDisplayValue();
126
127
	/**
128
	 * @return the parent object, this is not the parent tree node.
129
	 */
130
	public Object getParent() {
131
		return parent;
132
	}
133
134
	/**
135
	 * @param parent the parent to set, this is not the parent tree node.
136
	 */
137
	public void setParent(Object parent) {
138
		this.parent = parent;
139
	}
140
}
(-)src/org/eclipse/emf/ecp/validation/connector/Activator.java (-29 / +11 lines)
Lines 10-22 Link Here
10
 ******************************************************************************/
10
 ******************************************************************************/
11
package org.eclipse.emf.ecp.validation.connector;
11
package org.eclipse.emf.ecp.validation.connector;
12
12
13
import java.util.ArrayList;
14
import java.util.Collection;
15
import java.util.HashSet;
13
import java.util.HashSet;
16
import java.util.List;
17
import java.util.Set;
14
import java.util.Set;
18
15
19
import org.eclipse.emf.common.util.EList;
20
import org.eclipse.emf.ecore.EObject;
16
import org.eclipse.emf.ecore.EObject;
21
import org.eclipse.emf.ecp.core.ECPProject;
17
import org.eclipse.emf.ecp.core.ECPProject;
22
import org.eclipse.emf.ecp.core.util.observer.ECPObserverBus;
18
import org.eclipse.emf.ecp.core.util.observer.ECPObserverBus;
Lines 116-160 Link Here
116
112
117
		// BEGIN SUPRESS CATCH EXCEPTION
113
		// BEGIN SUPRESS CATCH EXCEPTION
118
		public void projectsChanged(ECPProject[] oldProjects, ECPProject[] newProjects) throws Exception {
114
		public void projectsChanged(ECPProject[] oldProjects, ECPProject[] newProjects) throws Exception {
119
			for (ECPProject project : newProjects) {
120
				getValidationService(project).validate(getOnlyEobjects(project.getElements()));
121
			}
122
		}
115
		}
123
116
124
		public void projectChanged(ECPProject project, boolean opened) throws Exception {
117
		public void projectChanged(ECPProject project, boolean opened) throws Exception {
125
			getValidationService(project).validate(getOnlyEobjects(project.getElements()));
126
		}
118
		}
127
119
128
		public void objectsChanged(ECPProject project, Object[] objects, boolean structural) throws Exception {
120
		public void objectsChanged(ECPProject project, Object[] objects, boolean structural) throws Exception {
129
130
		}
121
		}
131
122
132
		public Object[] objectsChanged(ECPProject project, Object[] objects) throws Exception {
123
		public Object[] objectsChanged(ECPProject project, Object[] objects) throws Exception {
133
134
			Set<EObject> allAffectedElements = new HashSet<EObject>();
124
			Set<EObject> allAffectedElements = new HashSet<EObject>();
125
			
135
			for (Object object : objects) {
126
			for (Object object : objects) {
136
127
				if (object instanceof EObject) {
137
				if (!(object instanceof EObject)) {
128
					EObject eObject = (EObject) object;
138
					continue;
129
					
130
					if (eObject.eContainer() == null) {
131
						getValidationService(project).remove(eObject);
132
					} else {
133
					  Set<EObject> affected = getValidationService(project).validate(eObject);
134
					  allAffectedElements.addAll(affected);
135
					}
139
				}
136
				}
140
141
				Set<EObject> affected = getValidationService(project).validate((EObject) object);
142
				allAffectedElements.addAll(affected);
143
144
			}
137
			}
145
			return allAffectedElements.toArray();
138
			return allAffectedElements.toArray();
146
		}
139
		}		
147
148
		private Collection<EObject> getOnlyEobjects(EList<? extends Object> elements) {
149
			List<EObject> result = new ArrayList<EObject>();
150
			for (Object o : elements) {
151
				if (EObject.class.isInstance(o)) {
152
					result.add((EObject) o);
153
				}
154
			}
155
			return result;
156
		}
157
		// END SUPRESS CATCH EXCEPTION
158
	}
140
	}
159
141
160
	/**
142
	/**
(-)src/org/eclipse/emf/ecp/validation/connector/ValidationService.java (-11 / +31 lines)
Lines 11-21 Link Here
11
package org.eclipse.emf.ecp.validation.connector;
11
package org.eclipse.emf.ecp.validation.connector;
12
12
13
import java.util.Collection;
13
import java.util.Collection;
14
import java.util.HashMap;
14
import java.util.HashSet;
15
import java.util.HashSet;
16
import java.util.Map;
15
import java.util.Set;
17
import java.util.Set;
16
18
19
import org.eclipse.emf.common.util.BasicDiagnostic;
17
import org.eclipse.emf.common.util.Diagnostic;
20
import org.eclipse.emf.common.util.Diagnostic;
18
import org.eclipse.emf.ecore.EObject;
21
import org.eclipse.emf.ecore.EObject;
22
import org.eclipse.emf.ecore.EValidator;
19
import org.eclipse.emf.ecore.util.Diagnostician;
23
import org.eclipse.emf.ecore.util.Diagnostician;
20
import org.eclipse.emf.ecp.ui.common.AbstractCachedTree;
24
import org.eclipse.emf.ecp.ui.common.AbstractCachedTree;
21
import org.eclipse.emf.ecp.ui.common.CachedTreeNode;
25
import org.eclipse.emf.ecp.ui.common.CachedTreeNode;
Lines 26-31 Link Here
26
 * Implementation of a validation service.
30
 * Implementation of a validation service.
27
 * 
31
 * 
28
 * @author emueller
32
 * @author emueller
33
 * @author Tobias Verhoeven
29
 *
34
 *
30
 */
35
 */
31
public final class ValidationService extends AbstractCachedTree<Diagnostic> implements IValidationService {
36
public final class ValidationService extends AbstractCachedTree<Diagnostic> implements IValidationService {
Lines 57-80 Link Here
57
		 * {@inheritDoc}
62
		 * {@inheritDoc}
58
		 */
63
		 */
59
		public void update() {
64
		public void update() {
60
			
61
			Collection<Diagnostic> severities = values();
65
			Collection<Diagnostic> severities = values();
62
			
66
63
			if (severities.size() > 0) {
67
			if (severities.size() > 0) {
64
				
68
				Diagnostic mostSevereDiagnostic = values().iterator().next();	
65
				Diagnostic mostSevereDiagnostic = values().iterator().next();
66
				
67
				for (Diagnostic diagnostic : severities) {
69
				for (Diagnostic diagnostic : severities) {
68
					if (diagnostic.getSeverity() > mostSevereDiagnostic.getSeverity()) {
70
					if (diagnostic.getSeverity() > mostSevereDiagnostic.getSeverity()) {
69
						mostSevereDiagnostic = diagnostic;
71
						mostSevereDiagnostic = diagnostic;
70
					}
72
					}
71
				}
73
				}
72
				
74
				setChildValue(mostSevereDiagnostic);
73
				setValue(mostSevereDiagnostic);
74
				return;
75
				return;
75
			}
76
			}
77
			setChildValue(getDefaultValue());
78
		}
76
79
77
			setValue(getDefaultValue());
80
		@Override
81
		public Diagnostic getDisplayValue() {
82
			if (getChildValue() == null ) {
83
				return getOwnValue();
84
			}
85
			return (getOwnValue().getSeverity() > getChildValue().getSeverity())?getOwnValue():getChildValue();
78
		}
86
		}
79
	}
87
	}
80
88
Lines 100-106 Link Here
100
	/**
108
	/**
101
	 * {@inheritDoc}
109
	 * {@inheritDoc}
102
	 */
110
	 */
103
	public Diagnostic getDiagnostic(Object eObject) {
111
	public Diagnostic getDiagnostic(Object eObject) {		
104
		return getCachedValue(eObject);
112
		return getCachedValue(eObject);
105
	}
113
	}
106
114
Lines 128-134 Link Here
128
	}
136
	}
129
137
130
	private Diagnostic getSeverity(EObject object) {
138
	private Diagnostic getSeverity(EObject object) {
131
		return Diagnostician.INSTANCE.validate(object);
139
		 EValidator validator = EValidator.Registry.INSTANCE.getEValidator(object.eClass().getEPackage());
132
	}
140
		 BasicDiagnostic diagnostics = Diagnostician.INSTANCE.createDefaultDiagnostic(object);
141
		 
142
		 if (validator != null) {
143
			 Map<Object, Object> context = new HashMap<Object, Object>();
144
			 context.put(EValidator.SubstitutionLabelProvider.class, Diagnostician.INSTANCE);
145
		     context.put(EValidator.class, validator);
146
			  	 
147
		   validator.validate(object, diagnostics, context);
148
		   return diagnostics;
149
		 }
150
		return diagnostics;
151
	}	
152
133
}
153
}
134
154
(-)src/org/eclipse/emf/ecp/validation/connector/ValidationServiceProvider.java (-10 / +17 lines)
Lines 16-23 Link Here
16
import java.util.List;
16
import java.util.List;
17
import java.util.Map;
17
import java.util.Map;
18
18
19
import org.eclipse.emf.common.util.EList;
19
import org.eclipse.emf.common.util.TreeIterator;
20
import org.eclipse.emf.ecore.EObject;
20
import org.eclipse.emf.ecore.EObject;
21
import org.eclipse.emf.ecore.util.EcoreUtil;
21
import org.eclipse.emf.ecp.core.ECPProject;
22
import org.eclipse.emf.ecp.core.ECPProject;
22
import org.eclipse.emf.ecp.ui.common.IExcludedObjectsCallback;
23
import org.eclipse.emf.ecp.ui.common.IExcludedObjectsCallback;
23
import org.eclipse.emf.ecp.validation.api.IValidationService;
24
import org.eclipse.emf.ecp.validation.api.IValidationService;
Lines 27-36 Link Here
27
 * Validation service provider.
28
 * Validation service provider.
28
 * 
29
 * 
29
 * @author emueller
30
 * @author emueller
31
 * @author Tobias Verhoeven
30
 */
32
 */
31
public class ValidationServiceProvider implements IValidationServiceProvider {
33
public class ValidationServiceProvider implements IValidationServiceProvider {
32
	
33
	
34
	
34
	
35
	private Map<Object, IValidationService> mapping;
35
	private Map<Object, IValidationService> mapping;
36
	
36
	
Lines 58-78 Link Here
58
			mapping.put(validationServiceObject, validationService);
58
			mapping.put(validationServiceObject, validationService);
59
			if (validationServiceObject instanceof ECPProject) {
59
			if (validationServiceObject instanceof ECPProject) {
60
				ECPProject project = (ECPProject) validationServiceObject;
60
				ECPProject project = (ECPProject) validationServiceObject;
61
				validationService.validate(getOnlyEobjects(project.getElements()));
61
				validationService.validate(getAllChildEObjects(project));
62
			}
62
			}
63
			return validationService;
63
			return validationService;
64
		}
64
		}
65
		
65
		
66
		return mapping.get(validationServiceObject);
66
		return mapping.get(validationServiceObject);
67
	}
67
	}
68
	
68
		
69
	private Collection<EObject> getOnlyEobjects(EList<? extends Object> elements) {
69
	private Collection<EObject> getAllChildEObjects(ECPProject project) {
70
		List<EObject> result = new ArrayList<EObject>();
70
		List<EObject> result = new ArrayList<EObject>();
71
		for (Object o : elements) {
71
	
72
			if (EObject.class.isInstance(o)) {
72
		for (Object object : project.getElements()) {
73
				result.add((EObject) o);
73
			if (EObject.class.isInstance(object)) {
74
				EObject eObject = (EObject) object;
75
			    result.add(eObject);	     
76
			    TreeIterator<EObject> iterator = EcoreUtil.getAllContents(eObject, false);
77
			    
78
			    while (iterator.hasNext()) {
79
			    	 result.add(iterator.next());
80
			     } 
74
			}
81
			}
75
		}
82
		}
76
		return result;
83
		return result; 
77
	}
84
	}
78
}
85
}

Return to bug 397846