1 /**********************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.tracecompass
.internal
.tracing
.rcp
.ui
;
16 import java
.text
.MessageFormat
;
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
.osgi
.service
.datalocation
.Location
;
23 import org
.eclipse
.swt
.widgets
.Display
;
24 import org
.eclipse
.tracecompass
.internal
.tracing
.rcp
.ui
.messages
.Messages
;
25 import org
.eclipse
.ui
.IWorkbench
;
26 import org
.eclipse
.ui
.PlatformUI
;
29 * This class controls all aspects of the application's execution
30 * @author Bernd Hufmann
32 public class Application
implements IApplication
{
34 private Location fInstanceLoc
= null;
37 public Object
start(IApplicationContext context
) throws Exception
{
38 Display display
= PlatformUI
.createDisplay();
40 // fetch the Location that we will be modifying
41 fInstanceLoc
= Platform
.getInstanceLocation();
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
47 if (!fInstanceLoc
.allowsDefault() && !fInstanceLoc
.isSet()) {
48 File workspaceRoot
= new File(TracingRcpPlugin
.getWorkspaceRoot());
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
;
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
;
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$
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
;
76 int returnCode
= PlatformUI
.createAndRunWorkbench(display
, new ApplicationWorkbenchAdvisor());
77 if (returnCode
== PlatformUI
.RETURN_RESTART
) {
78 return IApplication
.EXIT_RESTART
;
80 return IApplication
.EXIT_OK
;
88 if (!PlatformUI
.isWorkbenchRunning()) {
91 final IWorkbench workbench
= PlatformUI
.getWorkbench();
92 final Display display
= workbench
.getDisplay();
93 fInstanceLoc
.release();
94 display
.syncExec(new Runnable() {
97 if (!display
.isDisposed()) {