| /*=============================================================================# |
| # Copyright (c) 2009, 2022 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.internal.rj.example.rcpdemo; |
| |
| import org.eclipse.equinox.app.IApplication; |
| import org.eclipse.equinox.app.IApplicationContext; |
| import org.eclipse.swt.widgets.Display; |
| import org.eclipse.ui.IWorkbench; |
| import org.eclipse.ui.PlatformUI; |
| |
| |
| /** |
| * This class controls all aspects of the application's execution |
| */ |
| public class Application implements IApplication { |
| |
| |
| public Application() { |
| } |
| |
| |
| @Override |
| public Object start(final IApplicationContext context) { |
| final Display display= PlatformUI.createDisplay(); |
| try { |
| final int returnCode= PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor()); |
| if (returnCode == PlatformUI.RETURN_RESTART) { |
| return IApplication.EXIT_RESTART; |
| } |
| return IApplication.EXIT_OK; |
| } |
| finally { |
| display.dispose(); |
| } |
| } |
| |
| @Override |
| public void stop() { |
| if (!PlatformUI.isWorkbenchRunning()) { |
| return; |
| } |
| final IWorkbench workbench= PlatformUI.getWorkbench(); |
| final Display display= workbench.getDisplay(); |
| display.syncExec(new Runnable() { |
| @Override |
| public void run() { |
| if (!display.isDisposed()) { |
| workbench.close(); |
| } |
| } |
| }); |
| } |
| |
| } |