1 /**********************************************************************
2 * Copyright (c) 2013 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
.linuxtools
.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
.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
;
29 * This class controls all aspects of the application's execution
30 * @author Bernd Hufmann
32 public class Application
implements IApplication
{
35 public Object
start(IApplicationContext context
) throws Exception
{
36 Display display
= PlatformUI
.createDisplay();
38 // fetch the Location that we will be modifying
39 Location instanceLoc
= Platform
.getInstanceLocation();
41 // -data @noDefault in <applName>.ini allows us to set the workspace here.
42 // If the user wants to change the location then he has to change
43 // @noDefault to a specific location or remove -data @noDefault for
45 if (!instanceLoc
.allowsDefault() && !instanceLoc
.isSet()) {
46 File workspaceRoot
= new File(TracingRcpPlugin
.getWorkspaceRoot());
48 if (!workspaceRoot
.exists()) {
49 MessageDialog
.openError(display
.getActiveShell(),
50 Messages
.Application_WorkspaceCreationError
,
51 MessageFormat
.format(Messages
.Application_WorkspaceRootNotExistError
, new Object
[] { TracingRcpPlugin
.getWorkspaceRoot() }));
52 return IApplication
.EXIT_OK
;
55 if (!workspaceRoot
.canWrite()) {
56 MessageDialog
.openError(display
.getActiveShell(),
57 Messages
.Application_WorkspaceCreationError
,
58 MessageFormat
.format(Messages
.Application_WorkspaceRootPermissionError
, new Object
[] { TracingRcpPlugin
.getWorkspaceRoot() }));
59 return IApplication
.EXIT_OK
;
62 String workspace
= TracingRcpPlugin
.getWorkspaceRoot() + File
.separator
+ TracingRcpPlugin
.WORKSPACE_NAME
;
63 // set location to workspace
64 instanceLoc
.set(new URL("file", null, workspace
), false); //$NON-NLS-1$
67 int returnCode
= PlatformUI
.createAndRunWorkbench(display
, new ApplicationWorkbenchAdvisor());
68 if (returnCode
== PlatformUI
.RETURN_RESTART
) {
69 return IApplication
.EXIT_RESTART
;
71 return IApplication
.EXIT_OK
;
79 if (!PlatformUI
.isWorkbenchRunning()) {
82 final IWorkbench workbench
= PlatformUI
.getWorkbench();
83 final Display display
= workbench
.getDisplay();
84 display
.syncExec(new Runnable() {
87 if (!display
.isDisposed()) {