Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 225430 Details for
Bug 397846
Validation Decorator not working properly
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
fixes validation decorator cache
validation.patch (text/plain), 14.78 KB, created by
Tobias Verhoeven
on 2013-01-10 07:17:59 EST
(
hide
)
Description:
fixes validation decorator cache
Filename:
MIME Type:
Creator:
Tobias Verhoeven
Created:
2013-01-10 07:17:59 EST
Size:
14.78 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.emf.ecp.emfstore.ui >diff --git src/org/eclipse/emf/ecp/emfstore/internal/ui/decorator/EMFStoreDirtyDecoratorCachedTree.java src/org/eclipse/emf/ecp/emfstore/internal/ui/decorator/EMFStoreDirtyDecoratorCachedTree.java >index 1471de8..3a3ebc1 100644 >--- src/org/eclipse/emf/ecp/emfstore/internal/ui/decorator/EMFStoreDirtyDecoratorCachedTree.java >+++ src/org/eclipse/emf/ecp/emfstore/internal/ui/decorator/EMFStoreDirtyDecoratorCachedTree.java >@@ -79,11 +79,20 @@ > public void update() { > for (EMFStoreDirtyTreeNode node : values()) { > if (node.getChangeCount() > 0 || node.isChildChanges()) { >- getValue().setChildChanges(true); >+ getOwnValue().setChildChanges(true); > return; > } > } >- getValue().setChildChanges(false); >+ getOwnValue().setChildChanges(false); >+ } >+ >+ /* >+ * (non-Javadoc) >+ * @see org.eclipse.emf.ecp.ui.common.CachedTreeNode#getDisplayValue() >+ */ >+ @Override >+ public EMFStoreDirtyTreeNode getDisplayValue() { >+ return getOwnValue(); > } > } > >#P org.eclipse.emf.ecp.ui >diff --git src/org/eclipse/emf/ecp/ui/common/AbstractCachedTree.java src/org/eclipse/emf/ecp/ui/common/AbstractCachedTree.java >index 59f5dfc..51f6b17 100644 >--- src/org/eclipse/emf/ecp/ui/common/AbstractCachedTree.java >+++ src/org/eclipse/emf/ecp/ui/common/AbstractCachedTree.java >@@ -31,6 +31,7 @@ > * @param <T> the actual value type that is stored by the tree > * > * @author emueller >+ * @author Tobias Verhoeven > */ > public abstract class AbstractCachedTree<T> { > >@@ -85,16 +86,35 @@ > updateNode(eObject, value); > rootValue.putIntoCache(eObject, value); > >- Set<EObject> affectedElements = new HashSet<EObject>(); >+ Set<EObject> affectedElements = removeOutdatedParentCacheIfNeeded(eObject); > // propagate upwards > EObject parent = eObject.eContainer(); > > while (parent != null && !excludedCallback.isExcluded(parent)) {// !isExcludedType(excludedTypes, > // parent.getClass()) >- updateParentNode(parent, eObject, value); >+ updateParentNode(parent, eObject, nodes.get(eObject).getDisplayValue()); > eObject = parent; > parent = parent.eContainer(); > affectedElements.add(eObject); >+ } >+ return affectedElements; >+ } >+ >+ // If an object has been moved the cached entries must be removed from old parents. >+ private Set<EObject> removeOutdatedParentCacheIfNeeded(EObject eObject) { >+ >+ Set<EObject> affectedElements = new HashSet<EObject>(); >+ CachedTreeNode<T> node = nodes.get(eObject); >+ >+ if (node.getParent() != null && node.getParent() != eObject.eContainer()) { >+ EObject oldParent = (EObject) node.getParent(); >+ while (oldParent != null && !excludedCallback.isExcluded(oldParent)) { >+ affectedElements.add(oldParent); >+ node = nodes.get(oldParent); >+ node.removeFromCache(eObject); >+ oldParent = oldParent.eContainer(); >+ eObject = oldParent; >+ } > } > return affectedElements; > } >@@ -106,7 +126,7 @@ > * @return the node > */ > public T getRootValue() { >- return rootValue.getValue(); >+ return rootValue.getDisplayValue(); > } > > /** >@@ -122,7 +142,7 @@ > CachedTreeNode<T> nodeEntry = nodes.get(eObject); > > if (nodeEntry != null) { >- return nodes.get(eObject).getValue(); >+ return nodes.get(eObject).getDisplayValue(); > } > > return getDefaultValue(); >@@ -137,7 +157,7 @@ > public void remove(EObject eObject) { > > CachedTreeNode<T> node = nodes.get(eObject); >- CachedTreeNode<T> parentNode = nodes.get(node.parent); >+ CachedTreeNode<T> parentNode = nodes.get(node.getParent()); > > nodes.remove(eObject); > rootValue.removeFromCache(eObject); >@@ -167,7 +187,7 @@ > node = createNodeEntry(object, t); > } > >- node.setValue(t); >+ node.setOwnValue(t); > } > > private CachedTreeNode<T> createNodeEntry(Object object, T t) { >@@ -176,17 +196,24 @@ > return node; > } > >+ /** >+ * Updates the passed parent nodes cached value. >+ * >+ * @param parent the parent object to be updated >+ * @param object the object for which the cached value should be changed. >+ * @param value the the cached value for the object >+ */ > protected void updateParentNode(Object parent, Object object, T value) { > CachedTreeNode<T> node = nodes.get(object); > CachedTreeNode<T> parentNode = nodes.get(parent); >- node.parent = parent; >+ node.setParent(parent); > > if (parentNode == null) { > parentNode = createNodeEntry(parent, value); > } > > parentNode.putIntoCache(object, value); >- rootValue.putIntoCache(parent, value); >+ rootValue.putIntoCache(parent, parentNode.getDisplayValue()); > } > > /** >diff --git src/org/eclipse/emf/ecp/ui/common/CachedTreeNode.java src/org/eclipse/emf/ecp/ui/common/CachedTreeNode.java >index 648a5ff..866c1da 100644 >--- src/org/eclipse/emf/ecp/ui/common/CachedTreeNode.java >+++ src/org/eclipse/emf/ecp/ui/common/CachedTreeNode.java >@@ -1,3 +1,14 @@ >+/******************************************************************************* >+ * Copyright (c) 2011-2012 EclipseSource Muenchen GmbH and others. >+ * >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * >+ *******************************************************************************/ > package org.eclipse.emf.ecp.ui.common; > > import java.util.Collection; >@@ -10,21 +21,22 @@ > * @param <T> the type of the value stored by this node > * > * @author emueller >+ * @author Tobias Verhoeven > */ > public abstract class CachedTreeNode<T> { > >- private T value; >+ private T ownValue; >+ private T cachedChildrenValue; > private Map<Object, T> cache; >- public Object parent; >+ private Object parent; > > /** > * Constructor. > * >- * @param initialValue >- * the initial value >+ * @param initialValue the initial value > */ > public CachedTreeNode(T initialValue) { >- this.value = initialValue; >+ this.ownValue = initialValue; > cache = new HashMap<Object, T>(); > } > >@@ -63,8 +75,8 @@ > * > * @return the value stored within this node > */ >- public T getValue() { >- return value; >+ public T getOwnValue() { >+ return ownValue; > } > > /** >@@ -73,8 +85,8 @@ > * @param newValue > * the new value to be associated with this node > */ >- public void setValue(T newValue) { >- this.value = newValue; >+ public void setOwnValue(T newValue) { >+ this.ownValue = newValue; > } > > /** >@@ -85,4 +97,44 @@ > public Collection<T> values() { > return cache.values(); > } >-} >\ No newline at end of file >+ >+ /** >+ * Returns the most severe cached value of all children. >+ * >+ * @return the childValue >+ */ >+ public T getChildValue() { >+ return cachedChildrenValue; >+ } >+ >+ /** >+ * Sets the the most severe cached value of all children. >+ * >+ * @param childValue the childValue to set >+ */ >+ protected void setChildValue(T childValue) { >+ this.cachedChildrenValue = childValue; >+ } >+ >+ /** >+ * Returns the value that this node should represent. >+ * This value is also passed to parents in case of changes to the tree. >+ * >+ * @return the display value >+ */ >+ public abstract T getDisplayValue(); >+ >+ /** >+ * @return the parent object, this is not the parent tree node. >+ */ >+ public Object getParent() { >+ return parent; >+ } >+ >+ /** >+ * @param parent the parent to set, this is not the parent tree node. >+ */ >+ public void setParent(Object parent) { >+ this.parent = parent; >+ } >+} >#P org.eclipse.emf.ecp.validation.connector >diff --git src/org/eclipse/emf/ecp/validation/connector/Activator.java src/org/eclipse/emf/ecp/validation/connector/Activator.java >index 299c5f8..d36d866 100644 >--- src/org/eclipse/emf/ecp/validation/connector/Activator.java >+++ src/org/eclipse/emf/ecp/validation/connector/Activator.java >@@ -10,13 +10,9 @@ > ******************************************************************************/ > package org.eclipse.emf.ecp.validation.connector; > >-import java.util.ArrayList; >-import java.util.Collection; > import java.util.HashSet; >-import java.util.List; > import java.util.Set; > >-import org.eclipse.emf.common.util.EList; > import org.eclipse.emf.ecore.EObject; > import org.eclipse.emf.ecp.core.ECPProject; > import org.eclipse.emf.ecp.core.util.observer.ECPObserverBus; >@@ -116,45 +112,31 @@ > > // BEGIN SUPRESS CATCH EXCEPTION > public void projectsChanged(ECPProject[] oldProjects, ECPProject[] newProjects) throws Exception { >- for (ECPProject project : newProjects) { >- getValidationService(project).validate(getOnlyEobjects(project.getElements())); >- } > } > > public void projectChanged(ECPProject project, boolean opened) throws Exception { >- getValidationService(project).validate(getOnlyEobjects(project.getElements())); > } > > public void objectsChanged(ECPProject project, Object[] objects, boolean structural) throws Exception { >- > } > > public Object[] objectsChanged(ECPProject project, Object[] objects) throws Exception { >- > Set<EObject> allAffectedElements = new HashSet<EObject>(); >+ > for (Object object : objects) { >- >- if (!(object instanceof EObject)) { >- continue; >+ if (object instanceof EObject) { >+ EObject eObject = (EObject) object; >+ >+ if (eObject.eContainer() == null) { >+ getValidationService(project).remove(eObject); >+ } else { >+ Set<EObject> affected = getValidationService(project).validate(eObject); >+ allAffectedElements.addAll(affected); >+ } > } >- >- Set<EObject> affected = getValidationService(project).validate((EObject) object); >- allAffectedElements.addAll(affected); >- > } > return allAffectedElements.toArray(); >- } >- >- private Collection<EObject> getOnlyEobjects(EList<? extends Object> elements) { >- List<EObject> result = new ArrayList<EObject>(); >- for (Object o : elements) { >- if (EObject.class.isInstance(o)) { >- result.add((EObject) o); >- } >- } >- return result; >- } >- // END SUPRESS CATCH EXCEPTION >+ } > } > > /** >diff --git src/org/eclipse/emf/ecp/validation/connector/ValidationService.java src/org/eclipse/emf/ecp/validation/connector/ValidationService.java >index b818cc7..2d0ed87 100644 >--- src/org/eclipse/emf/ecp/validation/connector/ValidationService.java >+++ src/org/eclipse/emf/ecp/validation/connector/ValidationService.java >@@ -11,11 +11,15 @@ > package org.eclipse.emf.ecp.validation.connector; > > import java.util.Collection; >+import java.util.HashMap; > import java.util.HashSet; >+import java.util.Map; > import java.util.Set; > >+import org.eclipse.emf.common.util.BasicDiagnostic; > import org.eclipse.emf.common.util.Diagnostic; > import org.eclipse.emf.ecore.EObject; >+import org.eclipse.emf.ecore.EValidator; > import org.eclipse.emf.ecore.util.Diagnostician; > import org.eclipse.emf.ecp.ui.common.AbstractCachedTree; > import org.eclipse.emf.ecp.ui.common.CachedTreeNode; >@@ -26,6 +30,7 @@ > * Implementation of a validation service. > * > * @author emueller >+ * @author Tobias Verhoeven > * > */ > public final class ValidationService extends AbstractCachedTree<Diagnostic> implements IValidationService { >@@ -57,24 +62,27 @@ > * {@inheritDoc} > */ > public void update() { >- > Collection<Diagnostic> severities = values(); >- >+ > if (severities.size() > 0) { >- >- Diagnostic mostSevereDiagnostic = values().iterator().next(); >- >+ Diagnostic mostSevereDiagnostic = values().iterator().next(); > for (Diagnostic diagnostic : severities) { > if (diagnostic.getSeverity() > mostSevereDiagnostic.getSeverity()) { > mostSevereDiagnostic = diagnostic; > } > } >- >- setValue(mostSevereDiagnostic); >+ setChildValue(mostSevereDiagnostic); > return; > } >+ setChildValue(getDefaultValue()); >+ } > >- setValue(getDefaultValue()); >+ @Override >+ public Diagnostic getDisplayValue() { >+ if (getChildValue() == null ) { >+ return getOwnValue(); >+ } >+ return (getOwnValue().getSeverity() > getChildValue().getSeverity())?getOwnValue():getChildValue(); > } > } > >@@ -100,7 +108,7 @@ > /** > * {@inheritDoc} > */ >- public Diagnostic getDiagnostic(Object eObject) { >+ public Diagnostic getDiagnostic(Object eObject) { > return getCachedValue(eObject); > } > >@@ -128,7 +136,19 @@ > } > > private Diagnostic getSeverity(EObject object) { >- return Diagnostician.INSTANCE.validate(object); >- } >+ EValidator validator = EValidator.Registry.INSTANCE.getEValidator(object.eClass().getEPackage()); >+ BasicDiagnostic diagnostics = Diagnostician.INSTANCE.createDefaultDiagnostic(object); >+ >+ if (validator != null) { >+ Map<Object, Object> context = new HashMap<Object, Object>(); >+ context.put(EValidator.SubstitutionLabelProvider.class, Diagnostician.INSTANCE); >+ context.put(EValidator.class, validator); >+ >+ validator.validate(object, diagnostics, context); >+ return diagnostics; >+ } >+ return diagnostics; >+ } >+ > } > >diff --git src/org/eclipse/emf/ecp/validation/connector/ValidationServiceProvider.java src/org/eclipse/emf/ecp/validation/connector/ValidationServiceProvider.java >index b42bfee..f4e2825 100644 >--- src/org/eclipse/emf/ecp/validation/connector/ValidationServiceProvider.java >+++ src/org/eclipse/emf/ecp/validation/connector/ValidationServiceProvider.java >@@ -16,8 +16,9 @@ > import java.util.List; > import java.util.Map; > >-import org.eclipse.emf.common.util.EList; >+import org.eclipse.emf.common.util.TreeIterator; > import org.eclipse.emf.ecore.EObject; >+import org.eclipse.emf.ecore.util.EcoreUtil; > import org.eclipse.emf.ecp.core.ECPProject; > import org.eclipse.emf.ecp.ui.common.IExcludedObjectsCallback; > import org.eclipse.emf.ecp.validation.api.IValidationService; >@@ -27,10 +28,9 @@ > * Validation service provider. > * > * @author emueller >+ * @author Tobias Verhoeven > */ > public class ValidationServiceProvider implements IValidationServiceProvider { >- >- > > private Map<Object, IValidationService> mapping; > >@@ -58,21 +58,28 @@ > mapping.put(validationServiceObject, validationService); > if (validationServiceObject instanceof ECPProject) { > ECPProject project = (ECPProject) validationServiceObject; >- validationService.validate(getOnlyEobjects(project.getElements())); >+ validationService.validate(getAllChildEObjects(project)); > } > return validationService; > } > > return mapping.get(validationServiceObject); > } >- >- private Collection<EObject> getOnlyEobjects(EList<? extends Object> elements) { >+ >+ private Collection<EObject> getAllChildEObjects(ECPProject project) { > List<EObject> result = new ArrayList<EObject>(); >- for (Object o : elements) { >- if (EObject.class.isInstance(o)) { >- result.add((EObject) o); >+ >+ for (Object object : project.getElements()) { >+ if (EObject.class.isInstance(object)) { >+ EObject eObject = (EObject) object; >+ result.add(eObject); >+ TreeIterator<EObject> iterator = EcoreUtil.getAllContents(eObject, false); >+ >+ while (iterator.hasNext()) { >+ result.add(iterator.next()); >+ } > } > } >- return result; >+ return result; > } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
eneufeld
:
iplog+
Actions:
View
|
Diff
Attachments on
bug 397846
: 225430