public Object start(IApplicationContext context) {

    // create and register a backend server
    // TODO: this info should be saved, not hard coded.
    try {
      context.applicationRunning(); // only run one
      //			MonitorServerManager.getInstance().getServers().get("");
      MonitorServer server = new MonitorServer("admin", "", "admin");
      MonitorServerManager.getInstance().registerServer(server);
      if (!login(server)) return IApplication.EXIT_OK;
      //			MonitorServerManager.getInstance().getCurServer().connectAndLogin();
      //			server.connectAndLogin();

    } catch (RemoteException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (NotBoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    Display display = PlatformUI.createDisplay();
    try {
      int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor());

      if (returnCode == PlatformUI.RETURN_RESTART) {
        return IApplication.EXIT_RESTART;
      }
      return IApplication.EXIT_OK;
    } finally {
      display.dispose();
    }
  }
Exemple #2
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();
      }
    }
  }