| /*=============================================================================# |
| # Copyright (c) 2009, 2018 Stephan Wahlbrink and others. |
| # |
| # This program and the accompanying materials are made available under the |
| # terms of the Eclipse Public License 2.0 which is available at |
| # https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 |
| # which is available at https://www.apache.org/licenses/LICENSE-2.0. |
| # |
| # SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 |
| # |
| # Contributors: |
| # Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation |
| #=============================================================================*/ |
| |
| package org.eclipse.statet.rj.example.demo; |
| |
| import java.util.concurrent.CopyOnWriteArraySet; |
| |
| import org.eclipse.core.runtime.IStatus; |
| import org.eclipse.swt.events.DisposeEvent; |
| import org.eclipse.swt.events.DisposeListener; |
| |
| import org.eclipse.statet.jcommons.lang.Disposable; |
| |
| import org.eclipse.statet.ecommons.runtime.core.ECommonsRuntime; |
| |
| |
| /** Replaces missing Eclipse environment */ |
| public class EAppEnvSWT implements ECommonsRuntime.AppEnvironment, DisposeListener { |
| |
| |
| private final CopyOnWriteArraySet<Disposable> stopListeners= new CopyOnWriteArraySet<>(); |
| |
| |
| public EAppEnvSWT() { |
| ECommonsRuntime.init("org.eclipse.statet.rj.services.eruntime", this); |
| } |
| |
| |
| @Override |
| public void addStoppingListener(Disposable listener) { |
| stopListeners.add(listener); |
| } |
| |
| @Override |
| public void removeStoppingListener(Disposable listener) { |
| stopListeners.add(listener); |
| } |
| |
| @Override |
| public void log(IStatus status) { |
| System.out.println(status.toString()); |
| } |
| |
| @Override |
| public void widgetDisposed(DisposeEvent e) { |
| try { |
| for (final Disposable listener : stopListeners) { |
| listener.dispose(); |
| } |
| } |
| finally { |
| stopListeners.clear(); |
| } |
| } |
| |
| } |