Skip to content
Snippets Groups Projects
Commit dc10af6b authored by Simon Barner's avatar Simon Barner
Browse files

Move DreamsPlatformUtils.{disableNotificationsOf(), enableNotificationsOf(),...

Move DreamsPlatformUtils.{disableNotificationsOf(), enableNotificationsOf(), setNotificationsOf()} to EcoreUtils
parent 612d22d9
No related branches found
No related tags found
No related merge requests found
......@@ -18,11 +18,13 @@ $Id: codetemplates.xml 1 2011-01-01 00:00:01Z hoelzl $
package org.fortiss.tooling.kernel.utils;
import static org.eclipse.emf.common.notify.Notification.EVENT_TYPE_COUNT;
import static org.eclipse.emf.ecore.util.EcoreUtil.getAllContents;
import static org.eclipse.emf.ecore.util.EcoreUtil.getRootContainer;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
......@@ -53,7 +55,7 @@ import org.eclipse.emf.ecore.util.EcoreUtil.UsageCrossReferencer;
* @author ratiu
* @author $Author: hoelzl $
* @version $Rev: 18709 $
* @ConQAT.Rating YELLOW Hash: 1389480141899137DCF3BC8ED77C4616
* @ConQAT.Rating YELLOW Hash: D4F6E8CB31511C0DB589D3C69E6D24E9
*/
public class EcoreUtils {
......@@ -441,4 +443,53 @@ public class EcoreUtils {
return usages;
}
/**
* <p>
* Disables the notifications emitted by the given {@link EObject} and its children.
* </p>
* <p>
* <b>CAVEAT:</b> This method should be only used to avoid a notification flood when editing
* models massively. The Undo/Redo-logging is disabled thereby. You must ensure to re-enable the
* notifications, after the modifications are done.
* </p>
*
* @param element
* The element for whom and its children the notifications shall be disabled.
*
* @return {@code true}, if the notifications can be disabled for the given {@link EObject}
*/
public static boolean disableNotificationsOf(EObject element) {
return setNotificationsOf(element, false);
}
/**
* Enables the notifications for the given {@link EObject} and its children.
*
* @param element
* The element for whom and its children the notifications shall be enabled.
*
* @return {@code true}, if the notifications can be disabled for the given {@link EObject}
*/
public static boolean enableNotificationsOf(EObject element) {
return setNotificationsOf(element, true);
}
/**
* Sets the notification state for the given {@link EObject} and its children.
*
* @param element
* The element for whom and its children the notification state should be .
*
* @return {@code true}, if the notifications can be disabled for the given {@link EObject}
*/
private static boolean setNotificationsOf(EObject element, boolean value) {
element.eSetDeliver(value);
Iterator<EObject> childIterator = getAllContents(element, true);
while(childIterator.hasNext()) {
EObject currentChild = childIterator.next();
currentChild.eSetDeliver(value);
}
return true;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment