/**
   * Runs the dialog in headless mode. The dialog will run headless while the workflow can run.
   *
   * @param monitor
   * @param true if the workflow ran and completed correctly. False if it failed or the user
   *     cancelled (because user interaction was required)
   */
  public boolean runHeadless(IProgressMonitor monitor) {
    try {
      this.headless = true;
      int ticks = getWorkflowWizard().getWorkflow().getStates().length * 10;
      monitor.beginTask(Messages.WorkflowWizardDialog_importTask, ticks);
      // we must ensure that the contents of the dialog (shell) have been
      // creates, needed for wizard pages
      if (getShell() == null) {
        // do in ui thread
        PlatformGIS.syncInDisplayThread(
            new Runnable() {
              public void run() {
                create();
              }
            });
      }

      Workflow pipe = getWizard().getWorkflow();
      pipe.run(new SubProgressMonitor(monitor, ticks));
      final boolean[] result = new boolean[] {true};
      if (!pipe.isFinished()) {
        // show the page corresponding to the current state
        final IWizardPage page = getWizard().getPage(pipe.getCurrentState());
        if (page != null) {
          // ensure the page has a state if it is a DataPipelinePage
          if (page instanceof WorkflowWizardPage) {
            WorkflowWizardPage dpPage = (WorkflowWizardPage) page;
            if (dpPage.getState() == null) dpPage.setState(pipe.getCurrentState());
          }

          PlatformGIS.syncInDisplayThread(
              new Runnable() {
                public void run() {
                  headless = false;
                  showPage(page);
                  if (open() == Window.CANCEL) {
                    result[0] = false;
                  }
                };
              });
        }
      }

      this.headless = false;
      return result[0];
    } finally {
      monitor.done();
    }
  }
  /** Performs the initialization of the workflow. */
  protected void initWorkflow() {
    // start the workflow
    // TODO: This can potentially freeze up the ui if the fist state
    // does alot of work in the #init(IProgressMonitor) method. Perhaps
    // it should be made part of the contract of the dialog that the pipe
    // already be started before open is called.
    final Workflow pipe = getWizard().getWorkflow();
    final IRunnableWithProgress runnable =
        new IRunnableWithProgress() {
          public void run(IProgressMonitor monitor)
              throws InvocationTargetException, InterruptedException {
            if (!pipe.started) pipe.start(monitor);
          }
        };

    if (Display.getCurrent() != null) {
      try {
        runnable.run(ProgressManager.instance().get());
      } catch (Exception e) {
        throw (RuntimeException) new RuntimeException().initCause(e);
      }
    } else {
      PlatformGIS.syncInDisplayThread(
          new Runnable() {
            public void run() {
              try {
                PlatformUI.getWorkbench().getActiveWorkbenchWindow().run(false, false, runnable);
              } catch (Throwable e) {
                throw new RuntimeException(e);
              }
            }
          });
    }
  }
  private static Collection<String> extractEPSG(
      final IMap map, final CoordinateReferenceSystem crs) {

    if (CRS.equalsIgnoreMetadata(crs, DefaultGeographicCRS.WGS84)) {
      return Collections.singleton(EPSG_4326);
    }
    final Collection<String> codes = new HashSet<String>();
    codes.addAll(CRSUtil.extractAuthorityCodes(crs));

    final String DONT_FIND = "DONT_FIND";
    boolean search = map.getBlackboard().get(EPSG_CODE) != DONT_FIND;
    if (codes.isEmpty() && search) {
      PlatformGIS.syncInDisplayThread(
          new Runnable() {
            public void run() {
              Shell shell = Display.getCurrent().getActiveShell();

              ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
              try {
                dialog.run(
                    false,
                    true,
                    new IRunnableWithProgress() {

                      public void run(IProgressMonitor monitor)
                          throws InvocationTargetException, InterruptedException {
                        CoordinateReferenceSystem found = CRSUtil.findEPSGCode(crs, monitor);
                        if (found == null) {
                          return;
                        }

                        ViewportModel model = (ViewportModel) map.getViewportModel();
                        model.eSetDeliver(false);
                        try {
                          model.setCRS(found);
                          codes.addAll(CRSUtil.extractAuthorityCodes(found));
                        } finally {
                          model.eSetDeliver(true);
                        }
                      }
                    });
              } catch (InvocationTargetException e) {
                WMSPlugin.log("Error tracking down EPSG Code", e);
                dontFind(map, DONT_FIND);
              } catch (InterruptedException e) {
                WMSPlugin.log("Error tracking down EPSG Code", e);
                dontFind(map, DONT_FIND);
              }
              dontFind(map, DONT_FIND);
            }
          });
    }

    return codes;
  }
Esempio n. 4
0
  public static void showWhile(
      final ViewportPane pane, final Display display, final Runnable runnable) {

    PlatformGIS.syncInDisplayThread(
        new Runnable() {
          public void run() {
            pane.setCursor(display.getSystemCursor(SWT.CURSOR_WAIT));
            org.eclipse.swt.custom.BusyIndicator.showWhile(display, runnable);
            pane.setCursor(null);
          }
        });
  }
  public void backward(State current, State next) {
    if (headless) return;

    // move the wizard to the previous page
    PlatformGIS.syncInDisplayThread(
        new Runnable() {

          public void run() {
            backPressedSuper();
          }
        });
  }