Java Code Examples for org.eclipse.core.runtime.Platform#getInstanceLocation()
The following examples show how to use
org.eclipse.core.runtime.Platform#getInstanceLocation() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ToolboxIntroPart.java From tlaplus with MIT License | 5 votes |
@Override public void widgetSelected(SelectionEvent se) { final String spec = (String) se.widget.getData(specKey); final String zip = (String) se.widget.getData(zipKey); final URL resource = StandaloneActivator.getDefault().getBundle().getResource(zip); final Location instanceLocation = Platform.getInstanceLocation(); try { // Force-open the getting started guide that new users should read. final Map<String, String> params = new HashMap<>(); params.put("org.lamport.tla.toolbox.doc.contents.param", "/org.lamport.tla.toolbox.doc/html/gettingstarted/gettingstarted.html"); runCommand("org.lamport.tla.toolbox.doc.contents", params); // TODO If the zip is large, this will block the main/UI thread. final File destDir = ZipUtil.unzip(resource.openStream(), new File(instanceLocation.getURL().getFile() + File.separator + spec.replaceFirst(".tla$", "")), true); params.clear(); params.put("toolbox.command.spec.new.param", destDir.getAbsolutePath() + File.separator + spec); runCommand("toolbox.command.spec.new", params); } catch (IOException ex) { StandaloneActivator.getDefault().logError(ex.getMessage(), ex); } }
Example 2
Source File: N4JSApplication.java From n4js with Eclipse Public License 1.0 | 4 votes |
@Override public Object start(final IApplicationContext appContext) throws Exception { final Display display = createDisplay(); try { // look and see if there's a splash shell we can parent off of final Shell shell = WorkbenchPlugin.getSplashShell(display); if (shell != null) { // should should set the icon and message for this shell to be the // same as the chooser dialog - this will be the guy that lives in // the task bar and without these calls you'd have the default icon // with no message. shell.setText(ChooseWorkspaceDialog.getWindowTitle()); shell.setImages(Window.getDefaultImages()); } final Object instanceLocationCheck = checkInstanceLocation(shell, appContext.getArguments()); if (instanceLocationCheck != null) { WorkbenchPlugin.unsetSplashShell(display); appContext.applicationRunning(); return instanceLocationCheck; } // create the workbench with this advisor and run it until it exits // N.B. createWorkbench remembers the advisor, and also registers // the workbench globally so that all UI plug-ins can find it using // PlatformUI.getWorkbench() or AbstractUIPlugin.getWorkbench() final int returnCode = createAndRunWorkbench(display, new N4JSApplicationWorkbenchAdvisor()); // the workbench doesn't support relaunch yet (bug 61809) so // for now restart is used, and exit data properties are checked // here to substitute in the relaunch return code if needed if (returnCode != PlatformUI.RETURN_RESTART) { return EXIT_OK; } // if the exit code property has been set to the relaunch code, then // return that code now, otherwise this is a normal restart return EXIT_RELAUNCH.equals(Integer.getInteger(PROP_EXIT_CODE)) ? EXIT_RELAUNCH : EXIT_RESTART; } finally { if (display != null) { display.dispose(); } final Location instanceLoc = Platform.getInstanceLocation(); if (instanceLoc != null) instanceLoc.release(); } }
Example 3
Source File: Application.java From tracecompass with Eclipse Public License 2.0 | 4 votes |
@Override public Object start(IApplicationContext context) throws Exception { Display display = PlatformUI.createDisplay(); try { // fetch the Location that we will be modifying fInstanceLoc = Platform.getInstanceLocation(); // -data @noDefault in <applName>.ini allows us to set the workspace here. // If the user wants to change the location then he has to change // @noDefault to a specific location or remove -data @noDefault for // default location if (!fInstanceLoc.allowsDefault() && !fInstanceLoc.isSet()) { File workspaceRoot = new File(TracingRcpPlugin.getWorkspaceRoot()); if (!workspaceRoot.exists()) { MessageDialog.openError(display.getActiveShell(), Messages.Application_WorkspaceCreationError, MessageFormat.format(Messages.Application_WorkspaceRootNotExistError, new Object[] { TracingRcpPlugin.getWorkspaceRoot() })); return IApplication.EXIT_OK; } if (!workspaceRoot.canWrite()) { MessageDialog.openError(display.getActiveShell(), Messages.Application_WorkspaceCreationError, MessageFormat.format(Messages.Application_WorkspaceRootPermissionError, new Object[] { TracingRcpPlugin.getWorkspaceRoot() })); return IApplication.EXIT_OK; } String workspace = TracingRcpPlugin.getWorkspaceRoot() + File.separator + TracingRcpPlugin.WORKSPACE_NAME; // set location to workspace fInstanceLoc.set(new URL("file", null, workspace), false); //$NON-NLS-1$ } /* * Execute the early command line options. */ try { CliCommandLine cmdLine = CliParserManager.getInstance().parse(Platform.getCommandLineArgs()); TracingRcpPlugin.getDefault().setCommandLine(cmdLine); if (cmdLine != null && CliParserManager.applicationStartup(cmdLine)) { return IApplication.EXIT_OK; } } catch (CliParserException e) { TracingRcpPlugin.getDefault().logError("Error parsing command line arguments", e); //$NON-NLS-1$ return IApplication.EXIT_OK; } if (!fInstanceLoc.lock()) { MessageDialog.openError(display.getActiveShell(), Messages.Application_WorkspaceCreationError, MessageFormat.format(Messages.Application_WorkspaceInUseError, new Object[] { fInstanceLoc.getURL().getPath() })); return IApplication.EXIT_OK; } int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor()); if (returnCode == PlatformUI.RETURN_RESTART) { return IApplication.EXIT_RESTART; } return IApplication.EXIT_OK; } finally { display.dispose(); } }
Example 4
Source File: Application.java From gama with GNU General Public License v3.0 | 4 votes |
@Override public Object start(final IApplicationContext context) throws Exception { Thread.setDefaultUncaughtExceptionHandler((t, e) -> { if ( e instanceof OutOfMemoryError ) { final boolean close = MessageDialog.openConfirm(Display.getDefault().getActiveShell(), "Out of memory", "GAMA is out of memory and will likely crash. Do you want to close now ?"); if ( close ) { this.stop(); } e.printStackTrace(); } }); Display.setAppName("Gama Platform"); Display.setAppVersion("1.8.1"); // DEBUG.OUT(System.getProperties()); createProcessor(); final Object check = checkWorkspace(); if ( EXIT_OK.equals(check) ) { return EXIT_OK; } // if ( check == EXIT_RESTART ) { // ClearWorkspace(true); // No need to restart : the value will be checked later // return EXIT_RESTART; // } Display display = null; try { display = Display.getDefault(); checkWorkbenchXMI(); // final String splash = getProperty("org.eclipse.equinox.launcher.splash.location"); // if ( splash != null ) { // setProperty("org.eclipse.equinox.launcher.splash.location", splash.replace("bmp", "png")); // } final int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor()); if ( returnCode == PlatformUI.RETURN_RESTART ) { return IApplication.EXIT_RESTART; } return IApplication.EXIT_OK; } finally { if ( display != null ) { display.dispose(); } final Location instanceLoc = Platform.getInstanceLocation(); if ( instanceLoc != null ) { instanceLoc.release(); } } }
Example 5
Source File: Core.java From ice with Eclipse Public License 1.0 | 4 votes |
/** * This private operation configures the project area for the Core. It uses * the Eclipse Resources Plugin and behaves differently based on the value * of the osgi.instance.area system property. * </p> * <!-- end-UML-doc --> * * @return True if the setup operation was successful and false otherwise. */ private boolean setupProjectLocation() { // Local Declarations IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject project = null; boolean status = true; String defaultProjectName = "itemDB"; // Print some diagnostic information if (Platform.getInstanceLocation() != null) { logger.info("ICore Message: Default workspace location is " + Platform.getInstanceLocation().getURL().toString()); } // Create the project space for the *default* user. This will have to // change to something more efficient and better managed when multi-user // support is added. try { // Get the project handle project = workspaceRoot.getProject(defaultProjectName); // If the project does not exist, create it if (!project.exists()) { // Create the project description IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(defaultProjectName); // Create the project project.create(desc, null); } // Open the project if it is not already open. Note that this is not // an "else if" because it always needs to be checked. if (project.exists() && !project.isOpen()) { project.open(null); // Always refresh the project too in case users manipulated the // files. project.refreshLocal(IResource.DEPTH_INFINITE, null); } // Add the project to the master table projectTable.put("defaultUser", project); itemDBProject = project; } catch (CoreException e) { // Catch for creating the project logger.error(getClass().getName() + " Exception!", e); status = false; } // Load any SerializedItems that are stored in the default directory if (status) { status = loadDefaultAreaItems(); } return status; }