Пример #1
0
  /**
   * Cancel the client selection.
   *
   * @return boolean
   */
  public boolean performCancel() {
    final List<WizardFragment> list = getAllWizardFragments();
    IRunnableWithProgress runnable =
        new IRunnableWithProgress() {
          public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
              Iterator<WizardFragment> iterator = list.iterator();
              while (iterator.hasNext())
                executeTask((WizardFragment) iterator.next(), CANCEL, monitor);
            } catch (CoreException ce) {
              throw new InvocationTargetException(ce);
            }
          }
        };

    Throwable t = null;
    try {
      if (getContainer() != null) getContainer().run(true, true, runnable);
      else runnable.run(new NullProgressMonitor());
      return true;
    } catch (InvocationTargetException te) {
      t = te.getCause();
    } catch (Exception e) {
      t = e;
    }
    PHPUiPlugin.log(
        new Status(
            IStatus.ERROR, PHPUiPlugin.ID, 0, "Error cancelling task wizard", t)); // $NON-NLS-1$

    if (t instanceof CoreException) {
      openError(t.getLocalizedMessage(), ((CoreException) t).getStatus());
    } else openError(t.getLocalizedMessage());

    return false;
  }
  /** 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);
              }
            }
          });
    }
  }
Пример #3
0
  public static void refreshProject(IResource resource, IProgressMonitor monitor)
      throws InvocationTargetException, InterruptedException {
    IRunnableWithProgress op =
        new WorkspaceModifyOperation(null) {
          @Override
          protected void execute(IProgressMonitor monitor)
              throws CoreException, InterruptedException {
            try {
              IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
              root.refreshLocal(IResource.DEPTH_INFINITE, monitor);

            } catch (CoreException e) {

              e.printStackTrace();
            }
          }
        };
    op.run(monitor);
  }
Пример #4
0
 /**
  * Run the given runnable, waiting until the end to perform a refresh
  *
  * @param runnable
  * @param monitor
  */
 public void run(IRunnableWithProgress runnable, IProgressMonitor monitor)
     throws InvocationTargetException, InterruptedException {
   try {
     notificationLevel++;
     runnable.run(monitor);
   } finally {
     notificationLevel = Math.max(0, notificationLevel - 1);
     if (notificationLevel == 0) {
       try {
         Collection roots = changedRepositories.values();
         broadcastRepositoriesChanged(
             (ICVSRepositoryLocation[]) roots.toArray(new ICVSRepositoryLocation[roots.size()]));
       } finally {
         changedRepositories.clear();
       }
     }
   }
 }
Пример #5
0
  public boolean performFinish() {
    if (currentFragment != null) currentFragment.exit();

    final WizardFragment cFragment = currentFragment;

    status = Status.OK_STATUS;

    final List<WizardFragment> list = getAllWizardFragments();
    IRunnableWithProgress runnable =
        new IRunnableWithProgress() {
          public void run(IProgressMonitor monitor) {
            // enter & exit the remaining pages
            int index = list.indexOf(cFragment);
            while (index > 0 && index < list.size() - 1) {
              final WizardFragment fragment = (WizardFragment) list.get(++index);
              try {
                Display.getDefault()
                    .syncExec(
                        new Runnable() {
                          public void run() {
                            FragmentedWizardPage page = getFragmentData(fragment);
                            if (page.getControl() == null && pageContainerHook != null) {
                              page.createControl(pageContainerHook);
                            }
                            fragment.enter();
                            fragment.exit();
                          }
                        });
              } catch (Exception e) {
                PHPUiPlugin.log(
                    new Status(
                        IStatus.ERROR,
                        PHPUiPlugin.ID,
                        0,
                        "Could not enter/exit page",
                        e)); //$NON-NLS-1$
              }
            }

            if (useJob()) {
              class FinishWizardJob extends Job {
                public FinishWizardJob() {
                  super(getJobTitle());
                }

                public boolean belongsTo(Object family) {
                  return "org.eclipse.wst.server.ui.family".equals(family); // $NON-NLS-1$
                }

                public IStatus run(IProgressMonitor monitor2) {
                  try {
                    Iterator<WizardFragment> iterator = list.iterator();
                    while (iterator.hasNext()) executeTask(iterator.next(), FINISH, monitor2);
                  } catch (CoreException ce) {
                    Status status =
                        new Status(
                            IStatus.ERROR, PHPUiPlugin.ID, 0, ce.getLocalizedMessage(), null);
                    PHPUiPlugin.log(status);
                    return status;
                  }
                  return Status.OK_STATUS;
                }
              }

              FinishWizardJob job = new FinishWizardJob();
              job.setUser(true);
              job.schedule();
            } else {
              Iterator<WizardFragment> iterator = list.iterator();
              while (iterator.hasNext())
                try {
                  WizardFragment fragment = (WizardFragment) iterator.next();
                  if (!executeTask(fragment, FINISH, monitor)) {
                    status =
                        new Status(
                            IStatus.ERROR,
                            PHPUiPlugin.ID,
                            "Error during wizard page execution."); //$NON-NLS-1$
                  }
                } catch (CoreException e) {
                  PHPUiPlugin.log(e);
                }
            }
          }
        };

    Throwable t = null;
    try {
      if (getContainer() != null) getContainer().run(true, true, runnable);
      else runnable.run(new NullProgressMonitor());
      if (status.getSeverity() != IStatus.OK) {
        return false;
      }
      return true;
    } catch (InvocationTargetException te) {
      PHPUiPlugin.log(
          new Status(
              IStatus.ERROR, PHPUiPlugin.ID, 0, "Error finishing task wizard", te)); // $NON-NLS-1$
      t = te.getCause();
    } catch (Exception e) {
      PHPUiPlugin.log(
          new Status(
              IStatus.ERROR, PHPUiPlugin.ID, 0, "Error finishing task wizard 2", e)); // $NON-NLS-1$
      t = e;
    }
    if (t instanceof CoreException) {
      openError(t.getLocalizedMessage(), ((CoreException) t).getStatus());
    } else if (t instanceof NullPointerException) openError(PHPUIMessages.FragmentedWizard_7);
    else openError(t.getLocalizedMessage());

    return false;
  }
Пример #6
0
 /*
  * @see org.eclipse.jface.operation.IRunnableContext#run(boolean, boolean,
  * org.eclipse.jface.operation.IRunnableWithProgress)
  */
 @Override
 public void run(
     final boolean fork, final boolean cancelable, final IRunnableWithProgress runnable)
     throws InvocationTargetException, InterruptedException {
   runnable.run(null);
 }