Bug 168153 [DataBinding] Simplify the management of the default Realm
In the bug where Realms where born there was talk of making the setting of the Realm a little more foolproof. Currently when setting the Realm the developer needs to remember to retrieve the current Realm and to set it back in a finally block to be a good citizen. I think Boris spoke of something like the following to remedy this... Realm.setDefault(myRealm, new Runnable() { public void run() { //do stuff with myRealm as default } }); I've been finding myself writing a method that does just this in my own code. I think this should be added to Realm to ensure that the default realm is being set and reset correctly.
bundles/org.eclipse.core.databinding.observable/src/org/eclipse/core/databinding/observable/Realm.java
/*******************************************************************************
 * Copyright (c) 2006 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 ******************************************************************************/
package org.eclipse.core.databinding.observable;
import java.util.LinkedList;
/**
 * Subclasses must override at least one of asyncExec()/syncExec(). For realms
 * based on a designated thread, it may be easier to implement asyncExec and
 * keep the default implementation of syncExec. For realms based on holding a
 * lock, it may be easier to implement syncExec and keep the default
 * implementation of asyncExec.
 * 
 * @since 1.1
 * 
 */
public abstract class Realm {