1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.simulation.project;
14 import java.util.concurrent.atomic.AtomicBoolean;
15 import java.util.concurrent.atomic.AtomicInteger;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.IStatus;
19 import org.simantics.simulation.Activator;
20 import org.simantics.simulation.experiment.IExperiment;
23 * @author Tuukka Lehtonen
25 public class CountingExperimentActivationListener implements IExperimentActivationListener {
27 IExperimentActivationListener proxy;
28 AtomicInteger activationCounter;
29 IProgressMonitor monitor;
30 AtomicBoolean excepted = new AtomicBoolean(false);
32 public CountingExperimentActivationListener(IExperimentActivationListener proxy, int expectedActivations) {
33 this(proxy, expectedActivations, null);
36 public CountingExperimentActivationListener(IExperimentActivationListener proxy, int expectedActivations, IProgressMonitor monitor) {
38 this.activationCounter = new AtomicInteger(expectedActivations);
39 this.monitor = monitor;
43 public void onMessage(IStatus message) {
44 proxy.onMessage(message);
48 public void onExperimentActivated(IExperiment experiment) {
49 if (activationCounter.decrementAndGet() == 0) {
51 proxy.onExperimentActivated(experiment);
56 public void onFailure(Throwable e) {
57 if (excepted.compareAndSet(false, true))
60 Activator.logError(e.getMessage(), e);
64 public IProgressMonitor getProgressMonitor() {
65 return monitor != null ? monitor : proxy.getProgressMonitor();