@Override
  public Object start(IApplicationContext applicationContext) throws Exception {
    // set the display name before the Display is
    // created to ensure the app name is used in any
    // platform menus, etc. See
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=329456#c14
    IProduct product = Platform.getProduct();
    if (product != null && product.getName() != null) {
      Display.setAppName(product.getName());
    }
    Display display = getApplicationDisplay();
    Location instanceLocation = null;
    try {
      E4Workbench workbench = createE4Workbench(applicationContext, display);

      instanceLocation = (Location) workbench.getContext().get(E4Workbench.INSTANCE_LOCATION);
      Shell shell = display.getActiveShell();
      if (shell == null) {
        shell = new Shell();
        // place it off so it's not visible
        shell.setLocation(0, 10000);
      }
      if (!checkInstanceLocation(instanceLocation, shell, workbench.getContext())) return EXIT_OK;

      // Create and run the UI (if any)
      workbench.createAndRunUI(workbench.getApplication());

      saveModel();
      workbench.close();

      if (workbench.isRestart()) {
        return EXIT_RESTART;
      }

      return EXIT_OK;
    } finally {
      if (display != null) display.dispose();
      if (instanceLocation != null) instanceLocation.release();
    }
  }
Example #2
0
  // @Override
  public Object startX(IApplicationContext context) throws Exception {

    final Display display = PlatformUI.createDisplay();
    final TakariWorkbenchAdvisor advisor = new TakariWorkbenchAdvisor();
    display.addListener(SWT.OpenDocument, advisor.getOpenDocumentHandler());

    // FIXME: Check unhandled arguments for a pom.xml file and treat like an
    // OpenDocument
    for (String arg : (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS)) {
      File f = new File(arg);
      if (f.exists()) {
        if ("pom.xml".equals(f.getName())) {
          Event e = new Event();
          e.text = arg;
          advisor.getOpenDocumentHandler().handleEvent(e);
        } else if (f.isDirectory() && (f = new File(f, "pom.xml")).exists()) {
          Event e = new Event();
          e.text = f.getPath();
          advisor.getOpenDocumentHandler().handleEvent(e);
        }
      }
    }

    try {
      int returnCode = PlatformUI.createAndRunWorkbench(display, advisor);
      if (returnCode == PlatformUI.RETURN_RESTART) {
        return IApplication.EXIT_RESTART;
      }
      return IApplication.EXIT_OK;
    } finally {
      Location loc = Platform.getInstanceLocation();
      if (loc != null) {
        loc.release();
      }
      display.dispose();
    }
  }
  /*
   * (non-Javadoc)
   * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext context)
   */
  public Object start(IApplicationContext context) throws Exception {
    System.out.println("S2MaterializerApplication.start");
    Display display = PlatformUI.createDisplay();

    try {
      // look and see if there's a splash shell we can parent off of
      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(Dialog.getDefaultImages());
      }
      //
      // if ( !checkInstanceLocation( shell ) )
      // {
      // WorkbenchPlugin.unsetSplashShell( display );
      // Platform.endSplash();
      // return EXIT_OK;
      // }

      String[] args = (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS);
      String s2ProjectURL = null;
      String nexusBaseURL = null;
      for (int i = 0; i < args.length - 1; i++) {
        if (ARG_DESCRIPTOR_URL.equals(args[i])) {
          s2ProjectURL = args[i + 1];
        }

        if (ARG_NEXUS_BASE_URL.equals(args[i])) {
          nexusBaseURL = args[i + 1];
        }
      }

      if (s2ProjectURL == null || nexusBaseURL == null) {
        System.err.println(
            "Syntax: "
                + ARG_DESCRIPTOR_URL
                + " <descriptor url> "
                + ARG_NEXUS_BASE_URL
                + " <nexus server url>");
        return EXIT_OK;
      }

      NexusFacade.setMainNexusServerData(
          nexusBaseURL, null /* username */, null /* password */, new NullProgressMonitor());

      // Dump some useful debug info :)
      System.out.println(PROP_LAUNCHER + "=" + System.getProperty(PROP_LAUNCHER));
      System.out.println(PROP_VM + "=" + System.getProperty(PROP_VM));
      System.out.println(PROP_VMARGS + "=" + System.getProperty(PROP_VMARGS));
      System.out.println(PROP_COMMANDS + "=" + System.getProperty(PROP_COMMANDS));

      // Save the current workspace location in the eclipse preferences
      Location instanceLoc = Platform.getInstanceLocation();
      File workspaceFile = new File(instanceLoc.getURL().getFile());
      Preferences node = new ConfigurationScope().getNode(IDEWorkbenchPlugin.IDE_WORKBENCH);
      node.put(IDE.Preferences.RECENT_WORKSPACES, workspaceFile.getCanonicalPath());
      node.putInt(
          IDE.Preferences.RECENT_WORKSPACES_PROTOCOL, PERS_ENCODING_VERSION_CONFIG_PREFS_NO_COMMAS);
      node.flush();

      // 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()
      int returnCode =
          PlatformUI.createAndRunWorkbench(
              display, new S2MaterializerWorkbenchAdvisor(s2ProjectURL));

      // 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
      String command_line = buildCommandLine();
      System.out.println("New command line=" + command_line);
      System.setProperty(PROP_EXIT_DATA, command_line);
      System.out.println(PROP_EXIT_DATA + "=" + System.getProperty(PROP_EXIT_DATA));
      System.setProperty(PROP_EXIT_CODE, "" + Integer.toString(EXIT_RELAUNCH));
      System.out.println(PROP_EXIT_CODE + "=" + System.getProperty(PROP_EXIT_CODE));

      return EXIT_RELAUNCH;
    } finally {
      if (display != null) {
        display.dispose();
      }
      Location instanceLoc = Platform.getInstanceLocation();
      if (instanceLoc != null) instanceLoc.release();
    }
  }
Example #4
0
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext context)
   */
  @Override
  public Object start(IApplicationContext appContext) throws Exception {

    // Display display = createDisplay();
    // processor must be created before we start event loop
    // DelayedEventsProcessor processor = new DelayedEventsProcessor(display);

    final Display display = PlatformUI.createDisplay();
    final TakariWorkbenchAdvisor advisor = new TakariWorkbenchAdvisor();
    display.addListener(SWT.OpenDocument, advisor.getOpenDocumentHandler());

    // FIXME: Check unhandled arguments for a pom.xml file and treat like an
    // OpenDocument
    for (String arg :
        (String[]) appContext.getArguments().get(IApplicationContext.APPLICATION_ARGS)) {
      File f = new File(arg);
      if (f.exists()) {
        if ("pom.xml".equals(f.getName())) {
          Event e = new Event();
          e.text = arg;
          advisor.getOpenDocumentHandler().handleEvent(e);
        } else if (f.isDirectory() && (f = new File(f, "pom.xml")).exists()) {
          Event e = new Event();
          e.text = f.getPath();
          advisor.getOpenDocumentHandler().handleEvent(e);
        }
      }
    }

    try {

      // look and see if there's a splash shell we can parent off of
      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());
      }

      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()
      // int returnCode = PlatformUI.createAndRunWorkbench(display, new
      // TakariWorkbenchAdvisor(processor));
      int returnCode = PlatformUI.createAndRunWorkbench(display, advisor);

      // 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();
      }
      Location instanceLoc = Platform.getInstanceLocation();
      if (instanceLoc != null) {
        instanceLoc.release();
      }
    }
  }