/*******************************************************************************
* Copyright (c) 2012 Michael Vorburger (http://www.vorburger.ch).
* 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
*******************************************************************************/
/**
* Copyright 2012 Michael Vorburger (http://www.vorburger.ch)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.vorburger.databinding.tests.utils;
import org.eclipse.core.databinding.observable.Realm;
/**
* DataBinding Realm for Unit Tests.
*
* "Simple realm implementation that will set itself as default when constructed. Invoke
* {@link #dispose()} to remove the realm from being the default. Does not support asyncExec(...)."
*
* @see http://wiki.eclipse.org/JFace_Data_Binding/Realm
*/
public class DatabindingTestRealm extends Realm {
private Realm previousRealm;
public DatabindingTestRealm() {
previousRealm = super.setDefault(this);
}
/**
* @return always returns true
*/
public boolean isCurrent() {
return true;
}
protected void syncExec(Runnable runnable) {
runnable.run();
}
/**
* @throws UnsupportedOperationException
*/
public void asyncExec(Runnable runnable) {
throw new UnsupportedOperationException("asyncExec is unsupported");
}
/**
* Removes the realm from being the current and sets the previous realm to the default.
*/
public void dispose() {
if (getDefault() == this) {
setDefault(previousRealm);
}
}
}