lttng: Add workspace location handling
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tracing.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 @Override
35 public Object start(IApplicationContext context) throws Exception {
36 Display display = PlatformUI.createDisplay();
37 try {
38 // fetch the Location that we will be modifying
39 Location instanceLoc = Platform.getInstanceLocation();
40
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
44 // default location
45 if (!instanceLoc.allowsDefault() && !instanceLoc.isSet()) {
46 File workspaceRoot = new File(TracingRcpPlugin.getWorkspaceRoot());
47
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;
53 }
54
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;
60 }
61
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$
65 }
66
67 int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor());
68 if (returnCode == PlatformUI.RETURN_RESTART) {
69 return IApplication.EXIT_RESTART;
70 }
71 return IApplication.EXIT_OK;
72 } finally {
73 display.dispose();
74 }
75 }
76
77 @Override
78 public void stop() {
79 if (!PlatformUI.isWorkbenchRunning()) {
80 return;
81 }
82 final IWorkbench workbench = PlatformUI.getWorkbench();
83 final Display display = workbench.getDisplay();
84 display.syncExec(new Runnable() {
85 @Override
86 public void run() {
87 if (!display.isDisposed()) {
88 workbench.close();
89 }
90 }
91 });
92 }
93 }
This page took 0.033892 seconds and 6 git commands to generate.