Commit | Line | Data |
---|---|---|
9c0ffa34 BH |
1 | /********************************************************************** |
2 | * Copyright (c) 2013 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Bernd Hufmann - Initial API and implementation | |
11 | **********************************************************************/ | |
12 | package org.eclipse.linuxtools.internal.tracing.rcp.ui; | |
13 | ||
14 | import org.eclipse.equinox.app.IApplication; | |
15 | import org.eclipse.equinox.app.IApplicationContext; | |
16 | import org.eclipse.swt.widgets.Display; | |
17 | import org.eclipse.ui.IWorkbench; | |
18 | import org.eclipse.ui.PlatformUI; | |
19 | ||
20 | /** | |
21 | * This class controls all aspects of the application's execution | |
22 | * @author Bernd Hufmann | |
23 | */ | |
24 | public class Application implements IApplication { | |
25 | ||
26 | @Override | |
27 | public Object start(IApplicationContext context) throws Exception { | |
28 | Display display = PlatformUI.createDisplay(); | |
29 | try { | |
30 | int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor()); | |
31 | if (returnCode == PlatformUI.RETURN_RESTART) { | |
32 | return IApplication.EXIT_RESTART; | |
33 | } | |
34 | return IApplication.EXIT_OK; | |
35 | } finally { | |
36 | display.dispose(); | |
37 | } | |
38 | } | |
39 | ||
40 | @Override | |
41 | public void stop() { | |
42 | if (!PlatformUI.isWorkbenchRunning()) { | |
43 | return; | |
44 | } | |
45 | final IWorkbench workbench = PlatformUI.getWorkbench(); | |
46 | final Display display = workbench.getDisplay(); | |
47 | display.syncExec(new Runnable() { | |
48 | @Override | |
49 | public void run() { | |
50 | if (!display.isDisposed()) { | |
51 | workbench.close(); | |
52 | } | |
53 | } | |
54 | }); | |
55 | } | |
56 | } |