Move RCP plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.rcp.ui / src / org / eclipse / linuxtools / internal / tracing / rcp / ui / Application.java
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 java.io.File;
15 import java.net.URL;
16 import java.text.MessageFormat;
17
18 import org.eclipse.core.runtime.Platform;
19 import org.eclipse.equinox.app.IApplication;
20 import org.eclipse.equinox.app.IApplicationContext;
21 import org.eclipse.jface.dialogs.MessageDialog;
22 import org.eclipse.linuxtools.internal.tracing.rcp.ui.messages.Messages;
23 import org.eclipse.osgi.service.datalocation.Location;
24 import org.eclipse.swt.widgets.Display;
25 import org.eclipse.ui.IWorkbench;
26 import org.eclipse.ui.PlatformUI;
27
28 /**
29 * This class controls all aspects of the application's execution
30 * @author Bernd Hufmann
31 */
32 public class Application implements IApplication {
33
34 private Location fInstanceLoc = null;
35
36 @Override
37 public Object start(IApplicationContext context) throws Exception {
38 Display display = PlatformUI.createDisplay();
39 try {
40 // fetch the Location that we will be modifying
41 fInstanceLoc = Platform.getInstanceLocation();
42
43 // -data @noDefault in <applName>.ini allows us to set the workspace here.
44 // If the user wants to change the location then he has to change
45 // @noDefault to a specific location or remove -data @noDefault for
46 // default location
47 if (!fInstanceLoc.allowsDefault() && !fInstanceLoc.isSet()) {
48 File workspaceRoot = new File(TracingRcpPlugin.getWorkspaceRoot());
49
50 if (!workspaceRoot.exists()) {
51 MessageDialog.openError(display.getActiveShell(),
52 Messages.Application_WorkspaceCreationError,
53 MessageFormat.format(Messages.Application_WorkspaceRootNotExistError, new Object[] { TracingRcpPlugin.getWorkspaceRoot() }));
54 return IApplication.EXIT_OK;
55 }
56
57 if (!workspaceRoot.canWrite()) {
58 MessageDialog.openError(display.getActiveShell(),
59 Messages.Application_WorkspaceCreationError,
60 MessageFormat.format(Messages.Application_WorkspaceRootPermissionError, new Object[] { TracingRcpPlugin.getWorkspaceRoot() }));
61 return IApplication.EXIT_OK;
62 }
63
64 String workspace = TracingRcpPlugin.getWorkspaceRoot() + File.separator + TracingRcpPlugin.WORKSPACE_NAME;
65 // set location to workspace
66 fInstanceLoc.set(new URL("file", null, workspace), false); //$NON-NLS-1$
67 }
68
69 if (!fInstanceLoc.lock()) {
70 MessageDialog.openError(display.getActiveShell(),
71 Messages.Application_WorkspaceCreationError,
72 MessageFormat.format(Messages.Application_WorkspaceInUseError, new Object[] { fInstanceLoc.getURL().getPath() }));
73 return IApplication.EXIT_OK;
74 }
75
76 int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor());
77 if (returnCode == PlatformUI.RETURN_RESTART) {
78 return IApplication.EXIT_RESTART;
79 }
80 return IApplication.EXIT_OK;
81 } finally {
82 display.dispose();
83 }
84 }
85
86 @Override
87 public void stop() {
88 if (!PlatformUI.isWorkbenchRunning()) {
89 return;
90 }
91 final IWorkbench workbench = PlatformUI.getWorkbench();
92 final Display display = workbench.getDisplay();
93 fInstanceLoc.release();
94 display.syncExec(new Runnable() {
95 @Override
96 public void run() {
97 if (!display.isDisposed()) {
98 workbench.close();
99 }
100 }
101 });
102 }
103 }
This page took 0.033803 seconds and 5 git commands to generate.